Advertisement

04.08 - Animation Anticipation

Started by June 02, 2001 02:25 PM
51 comments, last by Teej 21 years, 10 months ago
I was having problems getting the DrawFont to work with BaseCode 2, until i looked in the directx SDK, and found that BltFast (used in draw font) does not work on a surface with a clipper. In my case i removed the clipper (I didnt need it) but you might have to rewrite a bit of the DrawFont function using Blt instead of BltFast.
Well, I have just put my little attempt online at http://www.sfu.ca/~dbrokens/silly.zip

The controls are the arrow keys to move and space to shoot. You can shoot a maximum of one bullet every half second. The computer player is a bit lame but he will still come try to shoot you and dodge a little when you shoot back. No score keeping or anything as yet though. Enjoy

"Fall seven times, stand up eight."
-Japanese Proverb
Advertisement
Ible,
You have to put the Sample.wav file in the zip too, even though you''re not using it in your program, it''s still being loaded in DS_Init()
Oops, the fixed zip is up now, still at http://www.sfu.ca/~dbrokens/silly.zip so lemme know what you think.



"Fall seven times, stand up eight."
-Japanese Proverb
Hi there!
I''ve done the bullet thing and now I''m working on a little kick-boxing game.
I have run into a small problem thou, that maybe someone can help me with.
I have made a struct like this:

struct FIGHTER {
int xPos;
int yPos;
ACTION action; // A predefined data type
int hits; };

Then in Game_Main() I initialize the object:

static FIGHTER leftFighter = {(SCREEN_WIDTH/4)-(SPRITE_WIDTH/2),
(SCREEN_WIDTH/2),
NONE, 0};

The problem is that everytime the program enters Game_Main() the variable gets initialized with the default values.
But if I use single variables for the data, like:

static int leftFighter_xPos = (SCREEN_WIDTH/4)-(SPRITE_WIDTH/2);
static int leftFighter_yPos = (SCREEN_WIDTH/2);
static ACTION leftFighter_action = NONE;

then the variables only gets initialized the first time and the game works fine, but the code doesn''t look that nice.
So the question is:
How do I get the struct to only get initialized the first time?

Finally I just want to give Teej standing ovations for this tutorial, great stuff!

// Swede
// Swede
Swede:

quote:
How do I get the struct to only get initialized the first time?


Try this:

static struct FIGHTER {
int xPos;
int yPos;
ACTION action; // A predefined data type
int hits;
};

Then in Game_Main:

FIGHTER leftFighter = {(SCREEN_WIDTH/4)-(SPRITE_WIDTH/2),
(SCREEN_WIDTH/2),
NONE,
0
};

I think that this will work.
Advertisement
Swede:

Put all your initialization stuff in the Game_Initialize func in the "InitTerm" File.

Game_Initialize() is only called once before the main loop in Winbase starts whereas Game_Main() is called continually,
make sense?
C++, C++, C++
Thanks for your input!

Weatherman, i''m pretty sure you can''t put static in the declaration when there isn''t any variable declared. It''s the instance of the variable that you declare static.

Yes, there are some ways of going around the problem of which Lowas is probably the best, but why does it differ between declaring a static struct and a static int (for example)?



// Swede
Swede, both of those last 2 ideas would work fine.

with the static struct you would just phrase it differently:

define your struct first, then initialise it like this

static fighter LeftFighter {blah blah}
you could put these into globals.h too if you wanted

it would be much clearer, and easier to read, if you used the class keyword instead of struct, and then you could make 2 constructors that initialise both fighters, and keep these initialisations in GameInit and the definitions in an .h file
Ible,
Great program, the computer controlled guy is pretty funny

This topic is closed to new replies.

Advertisement