|
SDLGameEngine
|
Parallax scrolling world with camera. More...
Data Structures | |
| struct | SGELAYER |
| information about a layer More... | |
| struct | SGESTAGE |
| information about the stage More... | |
Defines | |
| #define | ABSOLUTE 0 |
| #define | RELATIVE 1 |
| #define | sgeStageGetSpriteGroup(stage, group) sgeArrayGet(stage->spriteGroups, group) |
| get a sprite group from the stage | |
Functions | |
| SGELAYER * | sgeLayerNew (SGESPRITE *sprite) |
| create a new layer from a sprite | |
| void | sgeLayerDestroy (SGELAYER *l) |
| destroy a layer and free the resources | |
| SGESTAGE * | sgeStageNew (int width, int height) |
| create a new stage | |
| void | sgeStageDestroy (SGESTAGE *s) |
| destroy a stage and free resources | |
| int | sgeStageAddLayer (SGESTAGE *s, SGESPRITE *sprite, int x, int y) |
| add a sprite as new layer to the stage | |
| void | sgeStageSetLayerHeight (SGESTAGE *s, int layer, int height) |
| change the height of a layer in the stage | |
| void | sgeStageSetLayerWidth (SGESTAGE *s, int layer, int width) |
| change the width of a layer in the stage | |
| void | sgeStageDrawLayer (SGESTAGE *s, SDL_Surface *dest, int layer) |
| draw a layer | |
| int | sgeStageAddSpriteGroup (SGESTAGE *s, SGESPRITEGROUP *g) |
| add a sprite group to the stage | |
| int | sgeStageAddSprite (SGESTAGE *s, int spriteGroup, SGESPRITE *sprite) |
| add a sprite to the stage | |
| void | sgeStageDrawSpriteGroup (SGESTAGE *s, int spriteGroup) |
| draw a sprite group to the screen | |
| void | sgeStageDrawSpriteGroups (SGESTAGE *s) |
| draw all sprite groups on the screen | |
| int | sgeStageSpriteGroupCollideSprite (SGESTAGE *s, int b, SGESPRITE *a, int orientation) |
| test if a sprite collides a sprite group | |
| int | sgeStageSpriteGroupCollideSpriteGroup (SGESTAGE *s, int a, int b, int orientationa) |
| test if two sprite groups within a scene have a collision | |
| SGEPOSITION * | sgeStageScreenToReal (SGESTAGE *s, int x, int y) |
| calculate thie position of a coordinate on screen within the stage | |
Variables | |
| int | SGELAYER::y |
| the y position of the layer | |
| int | SGELAYER::w |
| the width of the layer | |
| int | SGELAYER::h |
| the height of the layer | |
| SGESPRITE * | SGELAYER::sprite |
| the sprite (image) of the layer | |
| int | SGESTAGE::cameraY |
| the y position of the camera | |
| int | SGESTAGE::w |
| the width of the stage | |
| int | SGESTAGE::h |
| the height of the stage | |
| SGEARRAY * | SGESTAGE::layers |
| a SGEARRAY holding all layers of the stage | |
| SGEARRAY * | SGESTAGE::spriteGroups |
| a SGEARRAY holding all sprite groups of the stage | |
Parallax scrolling world with camera.
| #define ABSOLUTE 0 |
ABSOLUTE
Interpret coordinates without camera position in mind
Definition at line 32 of file sgestage.h.
| #define RELATIVE 1 |
RELATIVE
Interpret coordinates relative to the camera position
Definition at line 39 of file sgestage.h.
| #define sgeStageGetSpriteGroup | ( | stage, | |
| group | |||
| ) | sgeArrayGet(stage->spriteGroups, group) |
get a sprite group from the stage
| stage | a pointer to SGESTAGE |
| group | the index of the sprite group |
example:
get the first sprite group in the current scene
SGESPRITEGROUP *g=sgeStageGetSpriteGroup(myStage, 0);
Definition at line 55 of file sgestage.h.
| void sgeLayerDestroy | ( | SGELAYER * | l | ) |
destroy a layer and free the resources
| l | a pointer to SGELAYER |
Definition at line 23 of file sgestage.c.
create a new layer from a sprite
| sprite | a pointer to SGESPRITE |
a layer is a background image layer which moves depending on its with.
For example on a side scroller you would have a layer for the sky, which is less wide then a layer over it of the hills, which is less wide then a layer of nearer objects like houses and street lamps.
Definition at line 11 of file sgestage.c.
add a sprite as new layer to the stage
| s | a pointer to SGESTAGE |
| sprite | a pointer to the SGESPRITE to use as layer |
| x | the x position of the layer in the stage |
| y | the y position of the layer in the stage |
Definition at line 58 of file sgestage.c.
add a sprite to the stage
| s | a pointer to SGESTAGE |
| spriteGroup | the index of the SGESPRITEGROUP in s->spriteGroup |
| sprite | a pointer to SGESPRITE |
Definition at line 107 of file sgestage.c.
| int sgeStageAddSpriteGroup | ( | SGESTAGE * | s, |
| SGESPRITEGROUP * | g | ||
| ) |
add a sprite group to the stage
| s | a pointer to SGESTAGE |
| g | a pointer to SGESPRITEGROUP |
Definition at line 102 of file sgestage.c.
| void sgeStageDestroy | ( | SGESTAGE * | s | ) |
destroy a stage and free resources
| s | a pointer to SGESTAGE |
Definition at line 50 of file sgestage.c.
| void sgeStageDrawLayer | ( | SGESTAGE * | s, |
| SDL_Surface * | dest, | ||
| int | layer | ||
| ) |
draw a layer
| s | a pointer to SGESTAGE |
| dest | a SDL_Surface to draw on (e.g. screen) |
| layer | the index of the layer in s->layers |
Definition at line 77 of file sgestage.c.
| void sgeStageDrawSpriteGroup | ( | SGESTAGE * | s, |
| int | spriteGroup | ||
| ) |
draw a sprite group to the screen
| s | a pointer to SGESTAGE |
| spriteGroup | the index of the SGESPRITEGROUP in s->spriteGroup |
Definition at line 113 of file sgestage.c.
| void sgeStageDrawSpriteGroups | ( | SGESTAGE * | s | ) |
draw all sprite groups on the screen
| s | a pointer to SGESTAGE |
Definition at line 118 of file sgestage.c.
| SGESTAGE* sgeStageNew | ( | int | width, |
| int | height | ||
| ) |
create a new stage
| width | the width of the stage |
| height | the height of the stage |
If you use layers, you usually want to be the stage the same width as the largest foreground layer (or height if you go for a vertical scrolling game)
Definition at line 28 of file sgestage.c.
| SGEPOSITION* sgeStageScreenToReal | ( | SGESTAGE * | s, |
| int | x, | ||
| int | y | ||
| ) |
calculate thie position of a coordinate on screen within the stage
| s | a pointer to SGESTAGE |
| x | the x position on the screen |
| y | the y position on the screen |
example:
test where the mouseclick would end up in the stage
SGEPOSITION *pos=sgeStageScreenToReal(myStage, mouseX, mouseY); printf("you clicked on stage position %d,%d\n",pos->x, pos->y); sgePositionDestroy(pos);
Definition at line 174 of file sgestage.c.
| void sgeStageSetLayerHeight | ( | SGESTAGE * | s, |
| int | layer, | ||
| int | height | ||
| ) |
change the height of a layer in the stage
| s | a pointer to SGESTAGE |
| layer | the index of the layer in s->layers |
| height | the new height of the layer |
Definition at line 67 of file sgestage.c.
| void sgeStageSetLayerWidth | ( | SGESTAGE * | s, |
| int | layer, | ||
| int | width | ||
| ) |
change the width of a layer in the stage
| s | a pointer to SGESTAGE |
| layer | the index of the layer in s->layers |
| width | the new width of the layer |
Definition at line 72 of file sgestage.c.
test if a sprite collides a sprite group
| s | a pointer to SGESTAGE |
| b | the index of the SGESPRITEGROUP in s->spriteGroup |
| a | a pointer to SGESPRITE |
| orientation | RELATIVE/ABSOLUTE if the sprite coordinates should be treated as relative to the camera position or not |
Normally you want to use RELATIVE as orientation, which takes the camera coordinations in account.
#define ENEMY_GROUP 2 if (sgeStageSpriteGroupCollideSprite(myStage, ENEMY_GROUP, player, RELATIVE)) { // player hits enemy, start player die animation }
Definition at line 127 of file sgestage.c.
| int sgeStageSpriteGroupCollideSpriteGroup | ( | SGESTAGE * | s, |
| int | a, | ||
| int | b, | ||
| int | orientationa | ||
| ) |
test if two sprite groups within a scene have a collision
| s | a pointer to SGESTAGE |
| a | the index of the first SGESPRITEGROUP in s->spriteGroup |
| b | the index of the second SGESPRITEGROUP in s->spriteGroup |
| orientation | RELATIVE/ABSOLUTE if the sprite coordinates should be treated as relative to the camera position or not |
Definition at line 154 of file sgestage.c.