Sign in to follow this  
  • entries
    686
  • comments
    1952
  • views
    386230

You decide the attacks (because I can't)

Sign in to follow this  
Stompy9999

42 views

I started working on the artwork for Commander Awesome today. I had just gotten the graphic done of him standing, and took a second to think about my ideas for how he would fight. And after thinking about it, I decided to scrap my origional idea.

I than went and thought up some various cliche Superhero attacks that I could string together to make a boss fight:

Heat vision - Shoots laser beams from his eyes

Death Rain - Rains down giant meteor blasts from the sky. Probably won't use this till he is about to die.

And...well, that's all I got. If you would like to pitch in an attack idea for Commander Awesome, be sure to leave a comment.

----------------------------------------------------------------------------

And now I'm going to start something here that will probably be common over the next few months. It is as follows:

Non-1337 C# code theater

Where I showcase various C# code snippets that I wrote that don't seem...right to me.

Today's entry comes from me trying to write a Game State manager in C#. Now when I did this in C++, I used 1) An abstract base class for game states, 2) Global variables and functions to manage and switch the game states.

Now, C# doesn't have global variables or functions, everything is in a class. But that didn't stop me from cramming all of that functionality into one class:


public class State
{
private static State[] states;
private const int max_states = 30;
private static int cur_state;
private static int cur_add_state;

static State()
{
states = new State[max_states];
cur_state = 0;
cur_add_state = 0;
}

public State()
{
states[cur_add_state] = this;
cur_add_state++;
}

public virtual void start() {}
public virtual void input() {}
public virtual void process() {}
public virtual void draw(Surface screen) {}
public virtual void end() {}

public static void setState(int num)
{
cur_state = num;
}

public static void switchState(int num)
{
states[cur_state].end();
cur_state = num;
states[cur_state].start();
}

public static void GameInput()
{
states[cur_state].input();
}

public static void GameProcess()
{
states[cur_state].process();
}

public static void GameDraw(Surface screen)
{
states[cur_state].draw(screen);
}


}



I can proudly say it works (pretty well in fact). All game states derive from this class and must call the base constructor so they can be added to the manager.
Sign in to follow this  


1 Comment


Recommended Comments

If you don't want to set yourself a hard limit on the number of game starts you can do the following:


public interface IGameState
{
Start();
// ... various other methods.
}



public StateManager
{
IGameState currentStart;

// various methods to change the state.

}


Then you implement the IGameState interface for any state you want to make. Probably a bit overkill but in case you wanted to know :D ... actually now I'm worried I've totally misread your code - but I'm going to post this anyway :D

Share this comment


Link to comment

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