Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C#-Quelltext |
|
1 |
if (kbState.IsKeyDown(Keys.Q))game1.ChangeGameState(Game1.GameStates.MaingameState);
|
C#-Quelltext |
|
1 |
if (kbState.IsKeyDown(Keys.Enter))game1.ChangeGameState(Game1.GameStates.MaingameState);
|
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; IState lastState, currentState; public enum GameStates { IntroState = 0, MenuState = 1, MaingameState = 2, IngamemenuState = 3, GameoverState = 4 } public void ChangeGameState(GameStates newState) { if (newState == currentGameState) return; lastGameState = currentGameState; lastState = currentState; switch (newState) { case GameStates.IntroState: currentState = new Intro(this); currentGameState = GameStates.IntroState; break; case GameStates.MenuState: currentState = new Menu(this); currentGameState = GameStates.MenuState; break; case GameStates.MaingameState: currentState = new Maingame(this); currentGameState = GameStates.MaingameState; break; case GameStates.IngamemenuState: currentState = new Ingamemenu(this); currentGameState = GameStates.IngamemenuState; break; case GameStates.GameoverState: currentState = new Gameover(this); currentGameState = GameStates.GameoverState; break; } currentState.Load(Content); } public void ChangeCurrentToLastGameState() { currentGameState = lastGameState; currentState = lastState; } public GameStates CurrentState { get { return currentGameState; } set { currentGameState = value; } } public GameStates LastState { get { return lastGameState; } set { lastGameState = value; } } private GameStates currentGameState = GameStates.IntroState; private GameStates lastGameState; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } protected override void Initialize() { currentState = new Intro(this); currentGameState = GameStates.IntroState; base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); currentState.Load(Content); } protected override void Update(GameTime gameTime) { currentState.Update(gameTime); if ((lastGameState == GameStates.MaingameState) && (currentGameState == GameStates.IngamemenuState)) { lastState.Update(gameTime); } base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); if ((lastGameState == GameStates.MaingameState) && (currentGameState == GameStates.IngamemenuState)) { lastState.Render(spriteBatch); } currentState.Render(spriteBatch); spriteBatch.End(); base.Draw(gameTime); } } |
C#-Quelltext |
|
1 2 3 4 5 |
public interface IState { void Load(ContentManager content); void Update(GameTime gametime); void Render(SpriteBatch batch); } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
public class Intro : IState { Texture2D Titelbildschirm; private Game1 game1; public Intro(Game1 game) { game1 = game; } private KeyboardState oldState; public void Load(ContentManager content) { Titelbildschirm = content.Load<Texture2D>("gruft"); } public void Update(GameTime gametime) { KeyboardState newState = Keyboard.GetState(); if(oldState.IsKeyUp(Keys.Space) && newState.IsKeyDown(Keys.Space)) game1.ChangeGameState(Game1.GameStates.MenuState); oldState = newState; } public void Render(SpriteBatch batch) { batch.Draw(Titelbildschirm, new Rectangle(0, 0, 1280, 720), Color.White); } } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
public class Menu : IState { Texture2D Choosescreen; private Game1 game1; public Menu(Game1 game) { game1 = game; } private KeyboardState oldState; public void Load(ContentManager content) { Choosescreen = content.Load<Texture2D>("menubild"); } public void Update(GameTime gametime) { KeyboardState newState = Keyboard.GetState(); if(oldState.IsKeyUp(Keys.Enter) && newState.IsKeyDown(Keys.Enter)) game1.ChangeGameState(Game1.GameStates.MaingameState); if(oldState.IsKeyUp(Keys.Escape) && newState.IsKeyDown(Keys.Escape)) game1.Exit(); oldState = newState; } public void Render(SpriteBatch batch) { batch.Draw(Choosescreen, new Rectangle(0, 0, 1280, 720), Color.White); } } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
public class Maingame : IState { Texture2D Spielbildschirm, axe; Vector2 position = new Vector2(100,100); private Game1 game1; public Maingame(Game1 game) { game1 = game; } private KeyboardState oldState; public void Load(ContentManager content) { Spielbildschirm = content.Load<Texture2D>("hauszombie"); axe = content.Load<Texture2D>("axxx"); } public void Update(GameTime gametime) { KeyboardState newState = Keyboard.GetState(); float delta = (float)gametime.ElapsedGameTime.TotalSeconds; position.X += 5 * delta; position.Y += 3 * delta; if (oldState.IsKeyUp(Keys.Escape) && newState.IsKeyDown(Keys.Escape)) game1.ChangeGameState(Game1.GameStates.IngamemenuState); if (oldState.IsKeyUp(Keys.A) && newState.IsKeyDown(Keys.A)) game1.ChangeGameState(Game1.GameStates.GameoverState); oldState = newState; } public void Render(SpriteBatch batch) { batch.Draw(Spielbildschirm, new Rectangle(0, 0, 1280, 720), Color.White); batch.Draw(axe, position, Color.White); } } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
public class Ingamemenu : IState { Texture2D Quitscreen; private Game1 game1; public Ingamemenu(Game1 game) { game1 = game; } private KeyboardState oldState; public void Load(ContentManager content) { Quitscreen = content.Load<Texture2D>("quit"); } public void Update(GameTime gametime) { KeyboardState newState = Keyboard.GetState(); if (oldState.IsKeyUp(Keys.Y) && newState.IsKeyDown(Keys.Y)) game1.ChangeGameState(Game1.GameStates.MenuState); if (oldState.IsKeyUp(Keys.N) && newState.IsKeyDown(Keys.N)) game1.ChangeCurrentToLastGameState(); oldState = newState; } public void Render(SpriteBatch batch) { batch.Draw(Quitscreen, new Rectangle(200, 200, 200, 200), Color.White); } } |
C#-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
public class Gameover : IState { Texture2D Gameoverscreen; private Game1 game1; public Gameover(Game1 game) { game1 = game; } private KeyboardState oldState; public void Load(ContentManager content) { Gameoverscreen = content.Load<Texture2D>("gameover"); } public void Update(GameTime gametime) { KeyboardState newState = Keyboard.GetState(); if(oldState.IsKeyUp(Keys.Enter) && newState.IsKeyDown(Keys.Enter)) game1.ChangeGameState(Game1.GameStates.MenuState); oldState = newState; } public void Render(SpriteBatch batch) { batch.Draw(Gameoverscreen, new Rectangle(0, 0, 1280, 720), Color.White); } } |
Community-Fossil
C#-Quelltext |
|
1 |
if (kbState.IsKeyDown(Keys.Enter))game1.ChangeGameState(Game1.GameStates.MaingameState);
|
C#-Quelltext |
|
1 2 |
KeyboardState lastState; KeyboardState currentState; |
C#-Quelltext |
|
1 |
currentState = Keyboard.GetState;
|
C#-Quelltext |
|
1 2 |
lastState = currentState; currentState = Keyboard.GetState(); |
C#-Quelltext |
|
1 |
if(currentState.IsKeyDown(Keys.Enter) && lastState.IsKeyUp(Keys.Enter)) game.ChangeState(game.Menu); |
Werbeanzeige