Re: Shooter with C#

Well, as I said, you can see one approach in my sample game, it contains menu, game screen and pause screen.
I have thought out this VirtualWindow based system myself, I wasn't using any gaming libraries before, but just recently, I have found out, that I wasn't alone who did it this way. Amethyst, a gaming library for Rust, inspired by libraries like Unity or UnrealEngine uses infact the same principle, just somewhat more advanced. VirtualWindow is called State there, WindowHandler is StateMachine, but idea is the same.
In short, the whole idea is to separate your game logic to windows, as your game always consists primarily of windows. MainMenu window, GameWindow, PauseWindow, Inventory Window etc.
Every window works infact in the same way, it receives events, like key presses, or mouse movement, and react in its own unique way, like moving down in a menu, when down arrow is pressed, moves player's character forward in GameWindow, when w is pressed etc.
Just one window can be active at a time, so events don't get messed up.

Therefore, there is one abstract class, named VirtualWindow. It defines various methods on it like OnActivate, OnDeactivate, OnKeyPress etc.
If you want to add a virtual window to your game, you just make a class, which implements VirtualWindow. You override OnActivate and OnDeactivate to define its behavior when it gets replaced by another window, you make its initialization in its constructor.
What's good on my implementation, or at least I find it very useful is, that you don't need to catch key events yourself, VirtualWindow has its own machinery for this, so all you need to do is define window's keyboard shortcuts in its constructor along with according methods to launch, when those shortcuts are pressed, and you just manage things from there.

Next, there is the WindowHandler class, what is a static class. This class is the only class communicating with real app's window in order to get events and send them to currently active VirtualWindow.

So, if you want to develop a game like Slide for example, you usually start with MainMenu VirtualWindow. You make that class with all its functions. Then, in the MainWindow's constructor, I mean the place where WPF app begins, you make an instance of the MainmenuVirtualWindow and pass it to WindowHandler. WindowHandler will store it, call its OnActivate method and will be passing events to it, making the window active.
Then you make the GameVirtualWindow class. You implement necessary game logics there. When you're done, you modify the MainMenuVirtualWindow class in such a way, that when Play option is selected, it creates a new instance of GameVirtualWindow and passes it to WindowHandler, what will cause the change of active windows and thus the game's behavior.
And you continue in this fashion, implementing all game windows, until you have the final, easily extendable product.

Best regards

Rastislav

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : jonikster via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Rastislav Kiss via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : vlad25 via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : jonikster via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : jonikster via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : omer via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : jonikster via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : nuno69 via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Rastislav Kiss via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : nuno69 via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : nuno69 via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Rastislav Kiss via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Rastislav Kiss via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : sanslash332 via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Rastislav Kiss via Audiogames-reflector
  • ... AudioGames . net Forum — Developers room : nuno69 via Audiogames-reflector

Reply via email to