Difference between revisions of "Game Programming Class4"
(→Homework) |
m (Text replacement - "<csharp>" to "<syntaxhighlight lang="csharp" line="1" >") |
||
Line 83: | Line 83: | ||
− | <csharp> | + | <syntaxhighlight lang="csharp" line="1" > |
GameConsole gameConsole; | GameConsole gameConsole; | ||
Revision as of 18:28, 25 January 2016
Contents
IN Class demo for Part 1
http://iam.colum.edu/XNAProgramming/IntroSimpleSpriteUpdateGravityWindows.zip
in class
Extract sprite from pacman class and build new project
Sprite class
IntroPacManComponent.zip
Project that refactors the pacman class into two classes
Sprite.cs DrawableSprite.cs
Then the pacman class can inherit from one of these two classes.
PacMan.cs
Due to the desire to limit the number of spritebatches, I've created two classes. The sprite class cannot draw itself without being associated with and external spritebatch. The DrawableSprite has it's own spritebatch which makes it easier to use but less efficient.
Game Components
About components Application Overview
Game Components are reusable and easy to add to a game.
- GameComponent Class
- DrawGameComponent Class
http://blogs.msdn.com/xna/archive/2006/08/31/734204.aspx
Common methods
Enabled
- Indicates whether GameComponent.Update should be called when Game.Update is called.
UpdateOrder
- Indicates the order in which the GameComponent should be updated relative to other GameComponent instances. Lower values are updated first.
(available if it is a DrawableGameComponent)
Visible
- Indicates whether Draw should be called.
DrawOrder
- Order in which the component should be drawn, relative to other components that are in the same GameComponentCollection.
Game Service
A game service is a game component that uses an interface to enforce a singleton pattern and make a single instance of a game component accessible to all other components. It's a nice mechanism to maintain a loose coupling between components.
A singleton is a class that only allows a single instance of the class to be created. A game service is not a true singleton as it uses a unique interface to identify and expose it at the game level.
A game service is a built in mechanism that allows a game to create and manage a single instance of a component ans allows other components access to the service.
Good candidates for a game service are.
- InputHandler
- GameConsole
- Profiling Service
- Scoreboard
InputHandler Service
In a separate Library Class. We are going to start using this library for reusable components of our games.
Useful info missing from the XNA input states
WasPressed determines is a button was press between the last update and the current update. To do this we need to store that keyboard and controller states from the previous call to update.
Console Class
Separate IntroGameLibrary Project to help Encapsulate Reusable Code.
- IntroConsole.zip
- IntroGameLibrary.zip
IntroGameLibrary/GameConsole.cs To add the Component to the Game we make an declare in the game class. Then we need to add the component to the Game Components Collection.
<syntaxhighlight lang="csharp" line="1" >
GameConsole gameConsole;
public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content";
gameConsole = new GameConsole(this); this.Components.Add(gameConsole); }
</csharp>
IntroConsole/Game1.cs
Homework
- Use the fps component to create a baseline log for you project in Monogame note the number of frames you get when you set
- Convert Monogame Interesting movement Project to use the inputHandler service and a playerContoller class the uses good separation of concern for input