Archive for May, 2008|Monthly archive page
For every game that has more than one game screen, you need a way to manage those screens. Even the old games such as Super Mario Bros or before that, Pong.. They often had at least two screens, sometimes more.
1) Main Menu Screen – Select players, show splash screen
2) Game Screen – Handles all game logic and render the game to screen
3) Credits – shows the names of all the developers and any final messages
4) Game Over – displays a Game Over screen and asks if you wish to continue
For a game with so few screens, you could simply just load them as you need them in a stack or, *shutter*, a few switch blocks in a main Update() method. With a game as complex as an action RPG such as my project, that won’t work. And thus, the ScreenManager class was born.
This class is based off of the XNA Websites GameScreenManager sample, with various changes to suit my needs. Each screen in the game inherits from a GameScreen class, and is then loaded into a few lists in the Screen Manager.
List<GameScreen> screens = new List<GameScreen>();
List<GameScreen> screensToUpdate = new List<GameScreen>();
List<GameScreen> screensToRemove = new List<GameScreen>();
Every GameScreen loaded to memory is in the Screens list, and only those screens needing to be updated is filtered into the screensToUpdate list. If a screen is needing to be removed (such as if you’re finished editing your map, and wish to exit the map editor and play it in the game) that screen is added to the screens to remove list.
Inside the screen manager, there are a few methods designed to keep the game screens in order; these are
AddScreen(GameScreen screen) – Adds a new game screen into the game
RemoveScreen(GameScreen screen) – Removes a game screen from the game
RemoveScreen(string asset) – Removes the game screen with the name you specify
the above methods are public, and are accessible anywhere within the program, and one private method that is only accessible from within the Screen Manager class is the ClearRemovedScreens(), which takes all the screens from the screensToRemove list and unloads all textures, sounds, and other assets associated with that gamescreen from memory, and finally removes that screen from the lists.
The only thing left to do now, is Update all screens needing to be updated, and render all screens to the screen. That is the job of our next two methods, ironically called “Update” and “Draw”
public void Update()
public void Draw()
In a nutshell, this is our screen class.
Link to full source code: Click Here
Since I took a small break from codename ShackRPG project, I have turned my attention to learn some more programming techniques and various 3D aspects of game programming. Confident in the knowledge I’ve gained since then (mind you, it has only been a month or two) I am now re-visiting the ShackRPG project to push out an official demo.
As of right now, I re-built it from the ground up. So far, I have written several core systems such as the Screen Manager to handle the update and drawing logic of all game screens, re-built the tile engine to be more efficient and much less confusing, built in a fully customizable Console system where if you hit the tilde key, you now have access to several commands such as “fps_show” and “map_tilesize” “map_NewName <map name>” and so on. I have also taken EVERY aspect that needs to be customized and pulled it from the code and inserted it into the content pipeline. What does this mean? It means everything can be changed, modified, edited, re-built, and fed into the game without changing ANY of the games programming.
Think of it this way. Lets say I have a map designer come in and create my world for me. All he would have to do is open the game, hit Tilde to open the console, type “map_editor 1” to turn on the map editor, and start editing the current map. “map_saveMap” saves his current data, “map_newMap” creates a new map, and he can continue on until he’s created the entire world. Great thing about this, is not once has he opened up Visual Studio to look at the programming!
I know its not that exciting unless you’re a tech guy like me, but think of it this way. With the system I’m making, my hope is instead of just making a simple “demo,” someone could take the tools that have been developed and create their own game. Real Time Strategy? No problem! Secret of mana style RPG? No problem! Final Fantasy style RPG? No Problem! This way I can create a wide variety of games when I get bored of learning 3D code (or when I need a break from the long hours of school / work that I’ve been accumulating.)
So, what I will end up doing is as a new system is built, I’ll lend some information on what the system does and how it works posting code snips along the way. As far as I can figure, there will be several major systems and a few minor systems needing to be put into place, including:
Tile Engine – Majority of the work, completed
Map Editor – Skeleton in place, user interface needs to be started
Console System – Working perfectly. Needs polish
Helper Systems – works great, add them as i need them
Screen manager – Works great, albeit a bit confusing (taken from XNA website)
and many more…
Penny Arcade has been around for a long, long time and has been very entertaining through the years. It was only a matter of time before they ventured into the realm of game development.
Penny Arcade Adventures is an episodic adventure, with the first episode being released this week. The writing is superb, funny, and gameplay is very entertaining. I do have a few gripes with some gameplay mechanics, but those few gripes are not enough to discount this game. I will looking for the future parts in this series.
For those who wish to check out the Penny Arcade Adventures, you can download the demo at Fileplanet or XBox Live Arcade. Go! You will enjoy it!
Taking a break from the terrain and 3D programming, I decided to take another look at my star field and design a particle effects system that can be used for 2D games. The dynamic sky background used in the space ship game was a good start, so I went to work and created a particle class, ParticleEffects class, and an effects manager class with the sole intention of having things go… BOOM!
With the current system, I’ve only designed a basic “firework” effect, but using the same logic I am attempting to create a system that can do a wide range of 2d effects, from basic cloud cover, smoke, fire, explosions, stars in the night sky, even rain.
I’ll be working on it a lot in the next little bit until trying to get the class usable in a variety of 2D programs, but for now… enjoy the boom!
so how do you get this:
to turn into this:
Doing some research on how to actually do 3D programming is really interesting, but more complex than I had realized. First step for me was to create a triangle.. just a simple triangle. 3 points in space with a line connecting those points. Add some color and you have the first picture!
Along the way, learning about 3D programming (Matrices, Vertex buffers, Vectors, and all other sorts of fun stuff) I ran into a few tutorials that explained just how to turn your triangle, into many… many MANY triangles to create a dynamic 3D landscape. The tutorial can be found at http://www.riemers.net, and is a great way to learn the process of 3D programming. A little hard to follow at first, but after re-reading it for the 2nd or so time and researching, its finally sinking in. So whats the next step? I’ve been very curious about Octree collision detection, and I have a feeling I’ll be needing it for any terrain engine that I’ll be making. We’ll see what kind of project can come from this… but for now I’ll just keep plugging away :)
Few hours of boredom, and wanting to play around with some new ideas and just a 2D program, and a very basic “space” shooter was born.
And while this game isn’t overly complex, it was fun to just put together a small, very simple game while not having to worry about 3D math and graphics :) I think my next project will not be a game, really.. but more so a particle engine or a more complex editor for putting together a 2d terrain. We’ll see how it goes. I would like to eventually put together a mini-RPG like game (think Secret of mana style) eventually, but learning 3D is priority for me at the moment.
So one of the cool things I was trying out with the screenshots above, was a dynamic sky background. I kinda wanted to see how many stars you could get on screen before the game started dropping frames left and right… and to my surprise even when putting 10,000 stars in the background (which didn’t look good AT ALL) and having each one of those stars update every frame with random modifiers for velocity and intensity, the game still ran at a silky smooth 60fps. In case you’re wondering, the cut-off before I got any sort of frame drops was around 35,000 stars in the sky. It really isn’t that complex of code either.. but here is the stars Update method;
public void Update(GameTime gameTime)
//Updates the stars position in the sky
_position.X -= (float)(gameTime.ElapsedGameTime.TotalSeconds * RNG.GetRandomFloat(.1f, 10f));
//if the star goes off screen, recycle star
if (_position.X < 0)
_position.X += Globals.GraphicsDevice.Viewport.Width;
Now normally I wouldn’t do anything like this in a real game, I’d just create a star texture for the background and maybe a set number of dynamic stars, but to have 1000 stars in-game like this.. looks pretty cool for a small game :)
So with my first learning process into the world of programming, I have started to pick up C# and the XNA framework. For my first project? Building a tilemap engine!
Although right now I don’t have (nor do I expect) a full product to be finished anytime soon, learning the basics of engine programming is very entertaining. I may just pick up a small project and put together a small game that can be played by a lot of people, but for now I am still learning the basics.
First XNA project was codename ShackRPG, and it is basically a 2d RPG tile engine, dynamic map editor, and battle system. For a first project, although the logic behind it all is pretty simple (being that its 2D, and Super Nintendo quality tech wise) this thing was actually pretty complex for someone new to the ideas.
This shows the very basic map editor when selecting a texture to paint on the ground.
Once the texture is selected, exit the texture selection screen and you can paint the map in real time directly from within the game.
Once your textures and objects are painted on the scene, you could add collision detection directly from within the map editor, ensuring that your character would be blocked from walking on tiles that they were not supposed to such as a mountain or tables.
Once the map is textured, add pre-loaded enemies into the map
Then, exit the map editor and view the game demo that has been created. Walk around the map, battle the enemies you’ve placed down, explore the different areas.
So that was my first project with learning how to program using Microsofts C Sharp programming language and the XNA framework. I’ve started moving towards 3D, but still in the back of my mind am wanting to finish a 2D project. We’ll see what happens in the next little bit with classes and work schedules.