Gameprogrammeren: Klassen en objecten in Painter

Slides:



Advertisements
Similar presentations
Specially made for you Wat te doen in het leven What To Do In Life Be Calm Wees Kalm.
Advertisements

Console applicatie static void Main ( ) class Hallo { } { } Console. WriteLine("Hallo " + naam + "!" ); statische methodestatische methoden Console. WriteLine("Wat.
Vervolg C Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1 Onderwerpen voor vandaag functie definitions;.h files;
Sprites, User Input, and Collision COSC 315 Fall 2014 Bridget M. Blodgett.
Onderwerpen voor vandaag
Constructor and New Fields // Don't synch draw() with vertical retrace of monitor graphics.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = true;
Using effects within a SpriteBatch or as a post render effect
Animation (動畫) 靜宜大學資工系 蔡奇偉 副教授 © 大綱 Introduction Game Loop Motion Animation Game Components 範例 參考資料.
COMPUTER PROGRAMMING 2 Chapter 7 Sound. Objectives Find out how to prepare sounds for inclusion in Microsoft XNA projects. Incorporate sounds into XNA.
2D Graphics in XNA Game Studio Express (Modeling a Class in UML) Game Design Experience Professor Jim Whitehead February 5, 2008 Creative Commons Attribution.
Hoofdstuk 13 Object-georiënteerd ontwerp. Methode-aanroep: Type van parameters void paint(Graphics g) { g.drawRect( ); class Graphics { void drawRect(int.
2D Graphics in XNA Game Studio Express (Plus, Random numbers in C#) Game Design Experience Professor Jim Whitehead January 16, 2009 Creative Commons Attribution.
Wordpress Hoe doe je dat bij DSE Bloggen met. Log in op de homepage, klik in mijn account op Wordpress installeren.
Console I/O in C# 2D Graphics in XNA Game Studio Express (Modeling a Class in UML) Game Design Experience Professor Jim Whitehead January 14, 2009 Creative.
Finishing 2D COSC 315 Fall 2014 Bridget M. Blodgett.
Display 480x800 QVGA 320x480 HVGA Capacitive touch 4 or more contact points Camera 5 mega pixels or more Dedicated camera button Hardware buttons.
Computer Science – Game DesignUC Santa Cruz CMPS 20: Game Design Experience January 14, 2010 Arnav Jhala.
CHAPTER 4 Images XNA Game Studio 4.0. Objectives Find out how the Content Manager lets you add pictures to Microsoft XNA games. Discover how pictures.
Getting Started. XNA Game Studio 4.0 To download XNA Game Studio 4.0 itself, go to XNA Game.
Using Namepsaces  This section lists the namespaces that the application will be using frequently. Saves the programmer from specifying a fully qualified.
Developing the Game User Interface (UI) Lesson 5.
Computertechniek 2 – ARM assembler Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1  Herhaling ARM assembler instructies.
1 Useful Tools for Making Video Games Part V An overview of.
Computer Science – Game DesignUC Santa Cruz CMPS 20: Game Design Experience XNA Game Studio January 12, 2010 Arnav Jhala Adapted from Jim Whitehead’s slides.
9.3. P ARTICLE S YSTEMS Development of a particle system.
User Input and Collisions COSC 315 Fall 2014 Bridget M. Blodgett.
Introduction to XNA Graphics Programming Asst. Prof. Rujchai Ung-arunyawee COE, KKU.
CHAPTER 10 Using C# Methods to Solve Problem XNA Game Studio 4.0.
Object Oriented Design COSC 315 Fall 2014 Bridget M. Blodgett.
XNA Game Studio 4.0 Keyboard and Mouse Controls + more on Animated Sprites.
11 Making a Sprite Session 4.2. Session Overview  Describe the principle of a game sprite, and see how to create a sprite in an XNA game  Learn more.
Rob Miles. How does an XNA game program work? Programs tell computers what to do A program is written in a programming language – C# is a programming.
Sprites, User Input, and Collision COSC 315 Fall 2014 Bridget M. Blodgett.
2.3. A RCHITECTURAL D ESIGN I Example approach for game screen management.
XNA Basic Displaying Image & Collision Detect. What’s format image that XNA support? XNA support only.bmp.png and.jpg image..PNG have transparent region.
CHAPTER 6 Multiplayer XNA Game Studio 4.0. Objectives Discover how to detect and use individual button-press events in a game. Learn how to create and.
Using classes. One step instantiation, Composition I JFrame myWindow = new JFrame( ); Two step Instantiation, Composition II private JFrame myWindow;
(2.2) Hallo één klasse...met één methode...met acht opdrachten accolades begrenzen klasse en methode using Android.OS; using Android.App; using Android.Widget;
11 Writing Text Session 5.1. Session Overview  Show how fonts are managed in computers  Discover the difference between bitmap fonts and vector fonts.
Playing with Sprites. XNA Game Lifecycle In the faceBall demo program we bounced a smiley face around the graphical display against a background image.
XNA ● Proprietary Microsoft framework ● C#. Interface.
23 November 2015 Scheiden van HTML en PHP emplatePower.
XNA Tutorial 1 For CS134 Lecture. Overview Some of the hard work has already been done for you. If you build and run your game now, the GraphicsDeviceManager.
XNA Sound Effects. float volume, pitch, pan; SoundEffect boing1; SoundEffect boing2; boing1 = Content.Load ("boing1"); boing2 = Content.Load ("boing2");
Rob Miles. Creating a Broken MoodLight An XNA game contains game data which is used by the Draw and Update methods – Update updates the game data – Draw.
Consumer Windows Phone Emulator Phone Emulator SamplesDocumentation GuidesCommunity Packaging and Verification Tools Windows Phone Dev Tools AppHub.
NU BURGERSCHAP 3/4 Project online 2Reclame: daar trap jij toch niet in? Voeg hier je commercial in: Invoegen > Video > Onlinevideo. Lukt dat niet? Geef.
Rubber vloeren in de aanbieding online
CHAPTER 5 Text XNA Game Studio 4.0. Objectives Discover how text is drawn using Microsoft XNA. Add some font resources to your XNA program. Draw some.
Paragraaf 3.2: De energie van de toekomst. 1 Herhaling vorige les 2 Energietransitie 3 Duurzaam en zuinige energie 4 Maken opdrachten 5 (Werken aan je.
Motivatie & Commitment – Een eerste stap naar slagen voor je examen statistiek
XNA 4.0 Side Scrolling.
Lecture 4 Using SpriteFonts
Object-Oriented Programming Concepts
Week 2 - Monday CS361.
Sprite Sheets, Game States
Using and Creating Sprites
Voorbeeld-programma's
(H9.1) CirkelKlikker ARRAY int x, y; [ ] int n=0;
Example: Card Game Create a class called “Card”
Gameprogrammeren: Edit states
Gameprogrammeren: Menu’s in Penguin Pairs
Collision Detection.
Animated Sprites.
Side Scrolling Game Development.
Gameprogrammeren: Interactie in Penguin Pairs
Gameprogrammeren: Game states
MTA-4201 Game Programming Chapter 8 : Scrolling Background & Font
Development of a particle system
Collisions with Static Objects
Presentation transcript:

Gameprogrammeren: Klassen en objecten in Painter Arjan Egges Paul Bergervoet Wouter van Toll

Onderwerpen in dit voorbeeld Variabelen Klassen en objecten Properties Static Willekeurigheid

Game-objecten ontwerpen Wat doet een game-object? Invoer van de speler afhandelen Zichzelf bijwerken (update) Zichzelf tekenen (draw) Bijbehorende methoden: HandleInput, Update, Draw Daarnaast: Reset ...?

Klasse Cannon met methoden public void Draw(GameTime gameTime, SpriteBatch spriteBatch) { spriteBatch.Draw(cannonBarrel, position, null, Color.White, angle, barrelOrigin, 1f, SpriteEffects.None, 0); spriteBatch.Draw(currentColor, position, null, Color.White, 0f, colorOrigin, 1f, SpriteEffects.None, 0); } public void Reset() currentColor = colorBlue; color = Color.Blue; angle = 0.0f;

Property voor lezen positie Type van de property Naam van de property public Vector2 Position { get return position; } Property lezen Zo gebruiken we de property: Vector2 cannonPos = cannon.Position;

public Color Color { get { return color; } set if (value != Color.Red && value != Color.Green && value != Color.Blue) return; color = value; if (color == Color.Red) currentColor = colorRed; else if (color == Color.Green) currentColor = colorGreen; else if (color == Color.Blue) currentColor = colorBlue; } Property lezen Controleren of het wel mag. Property schrijven value bevat de rechterkant van de toekenning

GameWorld-klasse class GameWorld { Texture2D background; Cannon cannon; public GameWorld(ContentManager Content) background = Content.Load<Texture2D>("spr_background"); cannon = new Cannon(Content); } public void HandleInput(InputHelper inputHelper) cannon.HandleInput(inputHelper); ... Game wereld bestaat uit alle game objecten

... public void Update(GameTime gameTime) { } public void Draw(GameTime gameTime, SpriteBatch spriteBatch) spriteBatch.Begin(); spriteBatch.Draw(background, Vector2.Zero, Color.White); cannon.Draw(gameTime, spriteBatch); spriteBatch.End(); public Cannon Cannon get { return cannon; }

GraphicsDeviceManager graphics; SpriteBatch spriteBatch; class Painter : Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; InputHelper inputHelper; static GameWorld gameWorld; … protected override void LoadContent() spriteBatch = new SpriteBatch(GraphicsDevice); gameWorld = new GameWorld(Content); } public static GameWorld GameWorld get { return gameWorld; } Static membervariabele Constructie van de gamewereld Static property om erbij te kunnen

protected override void Update(GameTime gameTime) { inputHelper.Update(); gameWorld.HandleInput(inputHelper); gameWorld.Update(gameTime); } protected override void Draw(GameTime gameTime) GraphicsDevice.Clear(Color.White); gameWorld.Draw(gameTime, spriteBatch);

Ball-klasse class Ball { Texture2D colorRed, colorGreen, colorBlue; Texture2D currentColor; Vector2 position, velocity; Color color; bool shooting; // methoden en properties } De verfbal heeft twee toestanden

Ball: invoer afhandelen “Je mag niet schieten tijdens het schieten” public void HandleInput(InputHelper inputHelper) { if (inputHelper.MouseLeftButtonPressed() && !shooting) shooting = true; velocity = (inputHelper.MousePosition - position) / 40; } Bereken de snelheid aan de hand van de muispositie

Ball: Update public void Update(GameTime gameTime) { if (shooting) { velocity.X *= 0.99f; velocity.Y += 6f; position += velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; } else { Color = Painter.GameWorld.Cannon.Color; position = Painter.GameWorld.Cannon.BallPosition - Center; if (Painter.GameWorld.IsOutsideWorld(position)) Reset(); Luchtweerstand Zwaartekracht Hoe vinden we uit hoe groot de wereld is?

Schermdimensies (Painter-klasse) Bewaren we in een static membervariabele: Initialisatie in LoadContent: En een (static) property om erbij te kunnen: static Point screen; screen = new Point(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); public static Point Screen { get { return screen; } }

IsOutsideWorld-methode In de GameWorld-klasse: public bool IsOutsideWorld(Vector2 position) { return position.X < 0 || position.X > Painter.Screen.X || position.Y > Painter.Screen.Y; }

Klassen met meerdere instanties Klassedefinitie: In de GameWorld-klasse: class PaintCan { … } PaintCan can1, can2, can3;

willekeurige snelheid PaintCan-klasse Elke verfbus heeft: Sprites Positie Snelheid Kleur Doelkleur Minimumsnelheid class PaintCan { Texture2D colorRed, colorGreen, colorBlue; Texture2D currentColor; Vector2 position, velocity; Color color, targetcolor; float minVelocity; // methoden… } Gebruiken we om willekeurige snelheid te berekenen!

Painter-klasse uitbreiden static Random membervariabele: Met een (static) property om erbij te kunnen: static Random random; public static Random Random { get { return random; } }

Random snelheid en kleur Willekeurige snelheid in de PaintCan-klasse Het bepalen van een willekeurige kleur: return new Vector2(0.0f, (float)Painter.Random.NextDouble() / 2 + minVelocity); public Color CalculateRandomColor() { int randomval = random.Next(3); if (randomval == 0) return Color.Red; else if (randomval == 1) return Color.Green; else return Color.Blue; }

PaintCan-object maken public PaintCan(ContentManager Content, float positionOffset, Color targetcol) { this.colorRed = Content.Load<Texture2D>("spr_can_red"); this.colorGreen = Content.Load<Texture2D>("spr_can_green"); this.colorBlue = Content.Load<Texture2D>("spr_can_blue"); targetcolor = targetcol; minVelocity = 30; Color = Color.Blue; position = new Vector2(positionOffset, -currentColor.Height); velocity = Vector2.Zero; }

class GameWorld { Texture2D background; Ball ball; PaintCan can1, can2, can3; Cannon cannon; public GameWorld(ContentManager Content) background = Content.Load<Texture2D>("spr_background"); cannon = new Cannon(Content); ball = new Ball(Content); can1 = new PaintCan(Content, 450.0f, Color.Red); can2 = new PaintCan(Content, 575.0f, Color.Green); can3 = new PaintCan(Content, 700.0f, Color.Blue); } ...

Game-objecten De Update-methode: Draw-methode Zie de voorbeeldcode public void Update(GameTime gameTime) { ball.Update(gameTime); can1.Update(gameTime); can2.Update(gameTime); can3.Update(gameTime); }

Handige properties public Ball Ball { get { return ball; } } public Cannon Cannon get { return cannon; }

PaintCan-object updaten if (velocity.Y == 0.0f && Painter.Random.NextDouble() < 0.01) { velocity = CalculateRandomVelocity(); Color = CalculateRandomColor(); } position += velocity * (float)gameTime.ElapsedGameTime.TotalSeconds; ...

PaintCan-object updaten ... Vector2 distanceVector = (Painter.GameWorld.Ball.Position + Painter.GameWorld.Ball.Center) - (position + Center); if (Math.Abs(distanceVector.X) < Center.X && Math.Abs(distanceVector.Y) < Center.Y) { Color = Painter.GameWorld.Ball.Color; Painter.GameWorld.Ball.Reset(); } if (Painter.GameWorld.IsOutsideWorld(position)) Reset(); minVelocity += 0.001f;