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
Es ist ja keine Schande etwas falsch zu machen, als Programmierer tu ich das täglich, [...].
Yannic
unregistriert
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 |
public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; private IState currentState; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } protected override void Initialize() { currentState = new Intro(); base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); } protected override void Update(GameTime gameTime) { currentState.Update(); base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); currentState.Render(); spriteBatch.End(); base.Draw(gameTime); } } |
C#-Quelltext |
|
1 2 3 4 5 |
public interface IState { void Load(); void Update(); void Render(); } |
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 |
public class Intro : IState { private IState currentState; Texture2D Titelbildschirm; public void Load(ContentManager content) { Titelbildschirm = content.Load<Texture2D>("gruft"); } public void Update() { KeyboardState kbState = Keyboard.GetState(); if (kbState.IsKeyDown(Keys.Space)) currentState = new Menu(); } public void Render(SpriteBatch batch) { batch.Begin(); batch.Draw(Titelbildschirm, new Rectangle(0, 0, 1280, 720), Color.White); batch.End(); } } |
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 |
public class Menu:IState { private IState currentState; private Game1 exit; Texture2D Auswahlbildschirm; public void Load(ContentManager content) { Auswahlbildschirm = content.Load<Texture2D>("menubild"); } public void Update() { KeyboardState kbState = Keyboard.GetState(); if (kbState.IsKeyDown(Keys.Enter)) currentState = new Hauptspiel(); if (kbState.IsKeyDown(Keys.Escape)) exit.Exit(); } public void Render(SpriteBatch batch) { batch.Begin(); batch.Draw(Auswahlbildschirm, new Rectangle(0, 0, 1280, 720), Color.White); batch.End(); } } |
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 |
public class Hauptspiel : IState { private IState currentState; private Game1 exit; Texture2D Spielbildschirm; public void Load(ContentManager content) { Spielbildschirm = content.Load<Texture2D>("hauszombie"); } public void Update() { KeyboardState kbState = Keyboard.GetState(); if (kbState.IsKeyDown(Keys.Escape)) exit.Exit(); } public void Render(SpriteBatch batch) { batch.Begin(); batch.Draw(Spielbildschirm, new Rectangle(0, 0, 1280, 720), Color.White); batch.End(); } } |
Es ist ja keine Schande etwas falsch zu machen, als Programmierer tu ich das täglich, [...].
Werbeanzeige