Skip to main content
GameDev.net gamedev.net
🔒 Locked

Sprites... again

Started by Andre Luiz Silva Apr 23, 2003 at 9:25 AM 24 replies 3.1k views
Original Post
Andre Luiz Silva
Andre Luiz Silva
Hello everybody, I am posting a picture of an editor I've been working on. So far things are going fine. But I am at a point that I would like to create a system where I could create my sprites, and assign them behaviour. Picture from my editor. I am using Mario 3 tiles and sprites but I am creating it so I can build any type of platform game. My questions: What I would like to do: - Create an application where I can define my sprites, and how will they interact with the world. So I can add a sprite to a level and define that it will be aware of other sprites. Another one, will only walk around. A platform will have an up-down movement, but the same platform (same image) in another place will follow a pre-defined pattern. Thanks for your time, Andre "- To begin with, said the Cat, a dog's not mad. You grant that? - I suppose so, said Alice. - Well, then, - the Cat went on - you see, a dog growls when it's angry, and wags its tail when it's pleased. Now I growl when I'm pleased, and wag my tail when I'm angry. Therefore I'm mad." [edited by - Andre Luiz Silva on April 23, 2003 10:26:20 AM] [edited by - Andre Luiz Silva on April 23, 2003 10:28:06 AM]
"- To begin with, said the Cat, a dog's not mad. You grant that? - I suppose so, said Alice. - Well, then, - the Cat went on - you see, a dog growls when it's angry, and wags its tail when it's pleased. Now I growl when I'm pleased, and wag my tail when I'm angry. Therefore I'm mad."
Andre Luiz Silva
Andre Luiz Silva
anyone?
"- To begin with, said the Cat, a dog's not mad. You grant that? - I suppose so, said Alice. - Well, then, - the Cat went on - you see, a dog growls when it's angry, and wags its tail when it's pleased. Now I growl when I'm pleased, and wag my tail when I'm angry. Therefore I'm mad."
Hoser
Hoser
To me, the solution would be to create game "objects" which are separate from the sprite. The game object would be assigned certain properties...and it would be assigned a "sprite" for displaying. Take the case of platforms for instance. You would define two types of platform objects...one that falls when the player walks on it, and one that follows a pattern. For each of these objects, you could then associate the SAME sprite to it.

Basically, the solution involves decoupling the "physical" properties of an item in the game from the sprite which is used to display the item.

Hope that helps a bit.
Andre Luiz Silva
Andre Luiz Silva
thanks for your reply Hoser.
How do you usually do this kind of stuff? For example if you have 3 different types of enemies. Do you just hard code them?

"- To begin with, said the Cat, a dog''s not mad. You grant that?
- I suppose so, said Alice.
- Well, then, - the Cat went on - you see, a dog growls when it''s angry, and wags its tail when it''s pleased. Now I growl when I''m pleased, and wag my tail when I''m angry. Therefore I''m mad."
"- To begin with, said the Cat, a dog's not mad. You grant that? - I suppose so, said Alice. - Well, then, - the Cat went on - you see, a dog growls when it's angry, and wags its tail when it's pleased. Now I growl when I'm pleased, and wag my tail when I'm angry. Therefore I'm mad."
grasshopa55
grasshopa55
If you wanted to go the OOP route, you could create a base abstract class called CEnemy and derive your three others from it. I''ll continue with the Mario example, and on the suggestions of Hoser.

CEnemy should contain attributes like:
Velocity X, Y, Z(if needed)
Position X, Y, Z(if needed)
MaxPosition X, Y, Z
etc..

So when you create your enemies, you set their properties accordingly. Take the normal turtle:

  
CTurtle : public CEnemy
{
// provide a velocity at 10 pixels per second

D3DXVECTOR2 velocity = D3DXVECTOR2( 10, 10 );
D3DXVECTOR2 position = D3DXVECTOR2( 100, 100 );

// now since we only want him to move at most, 10 spaces

int nMaxMovement = 10;
}

Although this is a very simple example done off the cuff, this is one approach that may help.



-----------------------------
kevin@mayday-anime.com
http://www.mayday-anime.com
-----------------------------kevin@mayday-anime.comhttp://www.mayday-anime.com
Andre Luiz Silva
Andre Luiz Silva
Ok. But how do you usually do it in your games? The problem to hardcoding is that I will always have to edit the cpp''s to create/change a sprite.

"- To begin with, said the Cat, a dog''s not mad. You grant that?
- I suppose so, said Alice.
- Well, then, - the Cat went on - you see, a dog growls when it''s angry, and wags its tail when it''s pleased. Now I growl when I''m pleased, and wag my tail when I''m angry. Therefore I''m mad."
"- To begin with, said the Cat, a dog's not mad. You grant that? - I suppose so, said Alice. - Well, then, - the Cat went on - you see, a dog growls when it's angry, and wags its tail when it's pleased. Now I growl when I'm pleased, and wag my tail when I'm angry. Therefore I'm mad."
McCrutch67
McCrutch67
I think to get rid of the hardcoding problem you would use scripting. I''m not really an expert on it but I usually just create text files. Like for example an enemies.txt could look like this

0
Turtle
5
8
3

1
OtherTurtle
8
10
2

2
SomeOtherTurtle
5
2
3

where the numbers(don''t mean anything in the example) could represent coordinates or speeds or things like that, numbers above the name would be the array member.
You''ll have to look up scripting though cuz I probably do it wrong :-)
Andre Luiz Silva
Andre Luiz Silva
quote:
Original post by McCrutch67
I think to get rid of the hardcoding problem you would use scripting. I''m not really an expert on it but I usually just create text files. Like for example an enemies.txt could look like this

0
Turtle
5
8
3

1
OtherTurtle
8
10
2

2
SomeOtherTurtle
5
2
3

where the numbers(don''t mean anything in the example) could represent coordinates or speeds or things like that, numbers above the name would be the array member.
You''ll have to look up scripting though cuz I probably do it wrong :-)


Yes. I am thinking on something like it. But not pretty sure on how I could make it to give different kinds of behaviour for each sprite. Problably it will have to be hardcoded...

"- To begin with, said the Cat, a dog''s not mad. You grant that?
- I suppose so, said Alice.
- Well, then, - the Cat went on - you see, a dog growls when it''s angry, and wags its tail when it''s pleased. Now I growl when I''m pleased, and wag my tail when I''m angry. Therefore I''m mad."
"- To begin with, said the Cat, a dog's not mad. You grant that? - I suppose so, said Alice. - Well, then, - the Cat went on - you see, a dog growls when it's angry, and wags its tail when it's pleased. Now I growl when I'm pleased, and wag my tail when I'm angry. Therefore I'm mad."
raging_jakl
raging_jakl
quote:
Original post by Andre Luiz Silva

Yes. I am thinking on something like it. But not pretty sure on how I could make it to give different kinds of behaviour for each sprite. Problably it will have to be hardcoded...




try something like this in your file

[OBJECT_FALLING]
yVel = -1 ;falls downward, use for position updates
xVel = 0 ;no horizontal action


[SPRITE_PLATFORM]
type = OBJECT_FALLING ;platform falls downward


That is the way I have done similar things in the past.
Andre Luiz Silva
Andre Luiz Silva
Hello everybody,

Thanks for your replies. Although it is still no clear to me, I am spending a good time thinking about it. My question now is:

Suppose I have some classes like:


class CGameObject
{
private:
int id;
public:
SetID( int ID ) { id = ID; }
};

class CSprite : public CGameObject
{
private:
int x, y;
public:
SetX( int X ) { x = X; }
SetY( int Y ) { y = Y; }
};

class CTurtle : public CSprite
{
private:
int z;
public:
SetZ( int Z ) { z = Z; }
}

class CPlatform : public CSprite
{
private:
int velocity;
public:
SetVelocity( int v ) { velocity = v; }
}

When I'll read a level file, I'll have to load all sprites on that level. Using this kind of solution, I'll have to end up creating a big switch/if statement, determining each type of sprite and loading its different set of attributes. I suppose there is a better solution. Any comments?

"- To begin with, said the Cat, a dog's not mad. You grant that?
- I suppose so, said Alice.
- Well, then, - the Cat went on - you see, a dog growls when it's angry, and wags its tail when it's pleased. Now I growl when I'm pleased, and wag my tail when I'm angry. Therefore I'm mad."

[edited by - Andre Luiz Silva on April 26, 2003 10:43:01 AM]
"- To begin with, said the Cat, a dog's not mad. You grant that? - I suppose so, said Alice. - Well, then, - the Cat went on - you see, a dog growls when it's angry, and wags its tail when it's pleased. Now I growl when I'm pleased, and wag my tail when I'm angry. Therefore I'm mad."
Roof Top Pew Wee
Roof Top Pew Wee
I have been working on my 2D engine for quite some time now, and came across the same problem. If you are interested, and I definitely am, we can talk on AOL Instant messenger. My screen names are ArmySarj and ShavenMcJagger. I''m sure I can give you some insight, and I''d love to see your work as well.

--Vic--
CraZeE
CraZeE
you wouldnt have a huge if/switch statement coz its proportional to the number of enemy TYPES u have. say, u have a turtle and a fish... u shud have only 2 if''s for the different set of parameters each have. of course, each individual enemy will require initialization but thats a generic io operation from ur input file and is standard for a particular enemy type.

a more dynamic approach is to use a typeID alongside objectID. if objectID is unique to each object, typeID shud be unique to every category of enemies. so u may have 10 turtles and 2 fishes but u actually have 12 objectID and 2 typeID. getting me?

now the typeID shud be an index into an array of function pointers that handle initialization of a particular object type. so for every enemy type, u add an additional ''initializer'' to the list. this way ur loader function could be simple and clean.

for( every segment read from script file)
read typeID;
CallFunction[typeID]()
end for


wat do you guys think?
To learn, we share... Give some to take some -
Rob Loach
Rob Loach
OOP.

Have a "BEHAVIOUR" flag to signify what the behaviour of the sprite is. Also, I have done it before, but try having a "BEHAVIOURTIME" property which would signify how long that behaviour would go between states (use ms). BEHAVIOUR examples:
0 - No behaviour (just sits there)
1 - moves right
2 - moves left
4 - moves up
8 - moves down
16 - goes in circles
32 - dances a gig

Also, you could also have a different branch of behaviours depending on the "OBJECT_TYPE" flag.
0 - Nothing... Just sits there... static
1 - Enemy
2 - Moving Object
4 - Player
8 - Ally

I haven''t used OBJECT_TYPE or BEHAVIOURTIME before, but I think it''s a resonable solution.



- Rob Loach
Current Project: Upgrade to .NET and DirectX 9

"Do or do not. There is no try."
- Yoda
Rob Loach [Website] [Projects] [
SumDude
SumDude
Why not use an enum like

enum Enemy_Movement
{
MOVE_R,
MOVE_L,
MOVE_D,
MOVE_U,
BACK_AND_F = 16,
CIRCLE,
JUMPING_R,
JUMPING_L
}

and have its states like

enum Enemy_State (or Platform state)
{
DEAD,
ALIVE,
SCARED
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                                          
Looking for video game music? Check out some of my samples at http://www.youtube.c...ser/cminortunes            
                                                          
I'm currently looking to create music for a project, if you are inte
Andre Luiz Silva
Andre Luiz Silva
Hello,

Thanks for all your replies. Right now I''m testing some of your ideas. I''ll be posting here really soon.

Again, thank you very much.

Andre

"- To begin with, said the Cat, a dog''s not mad. You grant that?
- I suppose so, said Alice.
- Well, then, - the Cat went on - you see, a dog growls when it''s angry, and wags its tail when it''s pleased. Now I growl when I''m pleased, and wag my tail when I''m angry. Therefore I''m mad."
"- To begin with, said the Cat, a dog's not mad. You grant that? - I suppose so, said Alice. - Well, then, - the Cat went on - you see, a dog growls when it's angry, and wags its tail when it's pleased. Now I growl when I'm pleased, and wag my tail when I'm angry. Therefore I'm mad."
Andre Luiz Silva
Andre Luiz Silva
Hello everybody,

While testing some of your ideas and some of my own, I've noticed that in W2K my demo runs much slower than in Win98.

Could you please make me a favor and just test it. It is kinda ugly but it is just a demo to test my code...

I would like to know:
- your system specs;
- OS
-initial fps
-the ending fps (when the screen stops scrolling and Mario gets out of the screen).

I did not tested it a lot, so please save your work before continuing...

ESC will cancel it.

download at MapReader.zip

Thank you very much

"- To begin with, said the Cat, a dog's not mad. You grant that?
- I suppose so, said Alice.
- Well, then, - the Cat went on - you see, a dog growls when it's angry, and wags its tail when it's pleased. Now I growl when I'm pleased, and wag my tail when I'm angry. Therefore I'm mad."

[edited by - Andre Luiz Silva on April 29, 2003 8:05:09 PM]

[edited by - Andre Luiz Silva on April 29, 2003 8:07:34 PM]
"- To begin with, said the Cat, a dog's not mad. You grant that? - I suppose so, said Alice. - Well, then, - the Cat went on - you see, a dog growls when it's angry, and wags its tail when it's pleased. Now I growl when I'm pleased, and wag my tail when I'm angry. Therefore I'm mad."
drslush
drslush
Andre, may I ask how you got your sprites? Is there a program that can make a BMP from a rom or something?
raging_jakl
raging_jakl
I tried to run it and it had an invalid floating point operation error upon loading the program.
Andre Luiz Silva
Andre Luiz Silva
Hi,

drslush: the Mario All Star version uses 16x16 pixels tiles. So what i did was use ZSnes to capture some screens and PSP to make them 32x32.

raging_jakl: I''ve uploaded another version. But I don''t know if I''ve solved the problem. Please give it another try.

Thanks,

Andre

"- To begin with, said the Cat, a dog''s not mad. You grant that?
- I suppose so, said Alice.
- Well, then, - the Cat went on - you see, a dog growls when it''s angry, and wags its tail when it''s pleased. Now I growl when I''m pleased, and wag my tail when I''m angry. Therefore I''m mad."
"- To begin with, said the Cat, a dog's not mad. You grant that? - I suppose so, said Alice. - Well, then, - the Cat went on - you see, a dog growls when it's angry, and wags its tail when it's pleased. Now I growl when I'm pleased, and wag my tail when I'm angry. Therefore I'm mad."
raging_jakl
raging_jakl
It still crashes with the same error.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.