• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
crohnsandme

trying to understand gamestate,enum and main menu

7 posts in this topic

hi all, so i have followed a tutorial and made a basic space shooter but now i trying to go from scratch so i can fully understand each aspect .

i understand in the main class you create a enum for each of the scenes in the game, i have it so when i click a on my controller it switched from one to another, the next step is to get my simple characterand background to be drawn onto screen and then i will understand most of the rest until later stages,for now i have just made the background for the action scene drawn within the main class but i know its not correct way to draw every aspect of the action scene and to keep the updates in main class either? .

if someone can look at my main game class and then i will include the action scene code where i want to have the background,character,enemies tiles maps etc and just to to guide me to where to command the action scene draw, update methods etc?

thanks

Main Game Class

 

 

namespace HeliAttack
002 {
003     /// <summary>
004     /// This is the main type for your game
005     /// </summary>
006     public class HeliAttack : Microsoft.Xna.Framework.Game
007     {
008         GraphicsDeviceManager graphics;
009         SpriteBatch spriteBatch;
010         GamePadState oldgamepadstate;
011         private AudioLibrary audio;
012  
013         Texture2D backgroundTexture, optionsTexture;
014         
015  
016         //scenes
017         ActionScene actionScene;
018         Texture2D actionBackTexture;
019  
020         //crosshair stuff
021         Texture2D crosshairTexture;
022         Rectangle crosshairRect;
023         Vector2 crosshairPosition;
024         float rotation = 0f;
025         Vector2 origin;
026         int index = 0;
027         enum GameState
028         {
029             MainMenu,
030             Options,
031             Help,
032             Playing,
033         }
034         GameState CurrentGameState = GameState.MainMenu;
035  
036         //Screen Adjustments
037         int screenWidth = 1600, screenHeight = 900;
038  
039         public HeliAttack()
040         {
041             graphics = new GraphicsDeviceManager(this);
042             Content.RootDirectory = "Content";
043         }
044  
045         /// <summary>
046         /// Allows the game to perform any initialization it needs to before starting to run.
047         /// This is where it can query for any required services and load any non-graphic
048         /// related content.  Calling base.Initialize will enumerate through any components
049         /// and initialize them as well.
050         /// </summary>
051         protected override void Initialize()
052         {
053            
054             
055  
056             
057  
058             base.Initialize();
059         }
060  
061         /// <summary>
062         /// LoadContent will be called once per game and is the place to load
063         /// all of your content.
064         /// </summary>
065         protected override void LoadContent()
066         {
067             graphics.PreferredBackBufferWidth = screenWidth;
068             graphics.PreferredBackBufferHeight = screenHeight;
069             graphics.ApplyChanges();
070  
071             //scenes
072            
073             actionBackTexture = Content.Load<Texture2D>("images/landscape wallpaper");
074             actionScene = new ActionScene(actionBackTexture);
075             
076             
077             //audio elements
078             audio = new AudioLibrary();
079             audio.LoadContent(Content);
080             Services.AddService(typeof(AudioLibrary), audio);
081  
082             // Create a new SpriteBatch, which can be used to draw textures.
083             spriteBatch = new SpriteBatch(GraphicsDevice);
084             backgroundTexture = Content.Load<Texture2D>("images/Mainmenu");
085             optionsTexture = Content.Load<Texture2D>("images/OptionsMenu");
086             crosshairTexture = Content.Load<Texture2D>("images/target");
087             
088             crosshairPosition = new Vector2(600, 530);
089            
090             origin = new Vector2(crosshairTexture.Width/2,crosshairTexture.Height/2);
091             // TODO: use this.Content to load your game content here
092         }
093  
094         /// <summary>
095         /// UnloadContent will be called once per game and is the place to unload
096         /// all content.
097         /// </summary>
098         protected override void UnloadContent()
099         {
100             // TODO: Unload any non ContentManager content here
101         }
102  
103         /// <summary>
104         /// Allows the game to run logic such as updating the world,
105         /// checking for collisions, gathering input, and playing audio.
106         /// </summary>
107         /// <param name="gameTime">Provides a snapshot of timing values.</param>
108         protected override void Update(GameTime gameTime)
109         {
110             crosshairRect = new Rectangle((int)crosshairPosition.X, (int)crosshairPosition.Y, crosshairTexture.Width, crosshairTexture.Height);
111             // Allows the game to exit
112             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
113                 this.Exit();
114  
115             switch (CurrentGameState)
116             {
117                 case GameState.Playing:
118                     actionScene.LoadContent(Content);
119  
120                     break;
121  
122  
123                 case GameState.MainMenu:
124                     rotation += 0.02f;
125                     HandleMainMenuInput();
126  
127                     break;
128                 case GameState.Options:
129                     if (GamePad.GetState(PlayerIndex.One).Buttons.B == ButtonState.Pressed)
130                     {
131                        CurrentGameState = GameState.MainMenu;
132                     }
133                     break;
134                 
135             }
136  
137             base.Update(gameTime);
138         }
139  
140         public void HandleMainMenuInput()
141         {
142  
143             if (index == 0)
144                 crosshairPosition.Y = 530;
145             if (index == 1)
146                 crosshairPosition.Y = 647;
147             if (index == 2)
148                 crosshairPosition.Y = 760;
149            GamePadState gamepadstate = GamePad.GetState(PlayerIndex.One);
150             if (gamepadstate.DPad.Down == ButtonState.Pressed &&
151                 oldgamepadstate.DPad.Down == ButtonState.Released )
152             {
153                 index += 1;
154                 audio.MenuChange.Play();
155  
156                 if (index > 2)
157                     index = 0;
158                 if (index < 0)
159                     index = 2;
160             }
161             if (gamepadstate.DPad.Up == ButtonState.Pressed &&
162                 oldgamepadstate.DPad.Up == ButtonState.Released)
163             {
164                 index -= 1;
165                 audio.MenuChange.Play();
166  
167                 if (index > 2)
168                     index = 0;
169                 if (index < 0)
170                     index = 2;
171             }
172  
173             CheckForA();
174             oldgamepadstate = gamepadstate;
175         }
176         public void CheckForA()
177         {
178             if (CurrentGameState == GameState.MainMenu)
179             {
180                 if (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed)
181                 {
182                     if (index == 0)
183                     {
184                         CurrentGameState = GameState.Playing;
185                         audio.Select.Play();
186                     }
187                     if (index == 1)
188                     {
189                         CurrentGameState = GameState.Options;
190                         audio.Select.Play();
191                     }
192                     if (index == 2)
193                     {
194                         audio.Select.Play();
195                         this.Exit();
196                     }
197                 }
198             }
199         }
200         /// <summary>
201         /// This is called when the game should draw itself.
202         /// </summary>
203         /// <param name="gameTime">Provides a snapshot of timing values.</param>
204         protected override void Draw(GameTime gameTime)
205         {
206             GraphicsDevice.Clear(Color.CornflowerBlue);
207  
208             spriteBatch.Begin();
209             switch (CurrentGameState)
210             {
211                 case GameState.Playing:
212                     spriteBatch.Draw(actionBackTexture, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
213                     break;
214  
215                 case GameState.MainMenu:
216                     spriteBatch.Draw(backgroundTexture, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
217                     spriteBatch.Draw(crosshairTexture,crosshairRect,null,Color.White,rotation,origin,SpriteEffects.None,0);
218                     break;
219                 case GameState.Options:
220                     spriteBatch.Draw(optionsTexture, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
221                     break;
222  
223             }
224  
225             spriteBatch.End();
226  
227             base.Draw(gameTime);
228         }
229     }
230

}

 

Action Scene Code

 

 

namespace HeliAttack
02 {
03     class ActionScene
04     {
05         GraphicsDeviceManager graphics;
06         private Texture2D backgroundTexture;
07         private Rectangle backgroundRect;
08  
09         Player charater;
10  
11         public ActionScene(Texture2D newTexture)
12         {
13             backgroundTexture = newTexture;
14         }
15    
16         public void LoadContent(ContentManager Content)
17         {
18  
19             charater = new Player(Content.Load<Texture2D>("images/quick character"), new Rectangle(0, 800, 64, 64));
20            
21         }
22  
23         public void Draw(SpriteBatch spriteBatch)
24         {
25             spriteBatch.Draw(backgroundTexture,backgroundRect,Color.White);
26         }
27     }
28

}

 

ps. this is just my remake of the game heli attack so please dont tell me i am using an original name its purely for personal use and teaching


thanks

if any other code is needed please let me know thanks

 

 

ps. this is my first post on here but im hoping to make more posts on here i have been a guestie for a while now :)

 

1

Share this post


Link to post
Share on other sites

ahh you understood correctly :) yes i spent last night playing and got it working like you said , i realised the loadcontent was a bad idea when my character would keep resetting it self when it moved :) 

 

all works now just got the character to shoot at the crosshair which is being controlled by the right axis on the controller so im happy with the progress plus i am going through each part once it works commenting on each section of code so i understand for future reference , i start a games programming course at university in september so looking for that headstart which i hope to get by making a second game in xna before moving onto some C++ and directX as i know that is alot harder to grasp and its needed for my course :)

0

Share this post


Link to post
Share on other sites

thanks for that link spiro but i will be honest i am a beginner, learning c# for the last 2-3 months from books on my own so looking at that C++ is very intimidating as i cant follow it 100% i understand to use polymorphism instead of the switch cases but as for now i feel i would be jumping ahead and not understanding things if i was to try and implement what you are suggesting i expect once i have more confidence and experience i will learn better ways etc i suppose if i had knowledge of C++ i would understand that tutorial better and would be able to follow what they are saying 

0

Share this post


Link to post
Share on other sites

While I agree that a switch statement is not an ideal way to handle game states, if your project is simple enough (read: You only have a few states) and you don't already have a more robust system handy, then a switch/case will work fine. Spending time building (or getting acquainted with a pre-built) GameState Management system is certainly a good investment in the long run, but for a simple learning project where you're trying to get used to the language and high level game dev concepts it can get in the way of the more interesting things like making things move around on the screen. smile.png

2

Share this post


Link to post
Share on other sites

thanks yes atm the moment i have gone back to create a sprite manager (which i just learnt) so its helping me make sure i understand it proerly , then i will go back to focusing on getting the camera to follow camera plus side scrolling, then finally create a map then i will be happy , i want to then look at perpixelcollision plus getting enemies into the game maybe attacking with swords instead of bullets everywhere plus it helps show the perpixelcollision :) so alot of work to do i hope to try spend a few hours a day on this before university starts in september so i have a decent background in making the 2d games so i can then focu on the 3D games

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0