SDLGameEngine

SgeStage

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

SGELAYERsgeLayerNew (SGESPRITE *sprite)
 create a new layer from a sprite
void sgeLayerDestroy (SGELAYER *l)
 destroy a layer and free the resources
SGESTAGEsgeStageNew (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
SGEPOSITIONsgeStageScreenToReal (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
SGESPRITESGELAYER::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
SGEARRAYSGESTAGE::layers
 a SGEARRAY holding all layers of the stage
SGEARRAYSGESTAGE::spriteGroups
 a SGEARRAY holding all sprite groups of the stage

Detailed Description

Parallax scrolling world with camera.


Define Documentation

#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

Parameters:
stagea pointer to SGESTAGE
groupthe index of the sprite group
Returns:
a pointer to SGESPRITEGROUP

example:

get the first sprite group in the current scene

Definition at line 55 of file sgestage.h.


Function Documentation

void sgeLayerDestroy ( SGELAYER l)

destroy a layer and free the resources

Parameters:
la pointer to SGELAYER

Definition at line 23 of file sgestage.c.

SGELAYER* sgeLayerNew ( SGESPRITE sprite)

create a new layer from a sprite

Parameters:
spritea pointer to SGESPRITE
Returns:
a pointer to a new SGELAYER

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.

int sgeStageAddLayer ( SGESTAGE s,
SGESPRITE sprite,
int  x,
int  y 
)

add a sprite as new layer to the stage

Parameters:
sa pointer to SGESTAGE
spritea pointer to the SGESPRITE to use as layer
xthe x position of the layer in the stage
ythe y position of the layer in the stage
Returns:
the position in the SGEARRAY of s->layers

Definition at line 58 of file sgestage.c.

int sgeStageAddSprite ( SGESTAGE s,
int  spriteGroup,
SGESPRITE sprite 
)

add a sprite to the stage

Parameters:
sa pointer to SGESTAGE
spriteGroupthe index of the SGESPRITEGROUP in s->spriteGroup
spritea pointer to SGESPRITE

Definition at line 107 of file sgestage.c.

int sgeStageAddSpriteGroup ( SGESTAGE s,
SGESPRITEGROUP g 
)

add a sprite group to the stage

Parameters:
sa pointer to SGESTAGE
ga pointer to SGESPRITEGROUP
Returns:
the position in the SGEARRAY of s->spriteGroups

Definition at line 102 of file sgestage.c.

void sgeStageDestroy ( SGESTAGE s)

destroy a stage and free resources

Parameters:
sa pointer to SGESTAGE

Definition at line 50 of file sgestage.c.

void sgeStageDrawLayer ( SGESTAGE s,
SDL_Surface *  dest,
int  layer 
)

draw a layer

Parameters:
sa pointer to SGESTAGE
desta SDL_Surface to draw on (e.g. screen)
layerthe 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

Parameters:
sa pointer to SGESTAGE
spriteGroupthe 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

Parameters:
sa pointer to SGESTAGE

Definition at line 118 of file sgestage.c.

SGESTAGE* sgeStageNew ( int  width,
int  height 
)

create a new stage

Parameters:
widththe width of the stage
heightthe height of the stage
Returns:
a pointer to SGESTAGE

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

Parameters:
sa pointer to SGESTAGE
xthe x position on the screen
ythe y position on the screen
Returns:
a pointer to SGEPOSITION
See also:
SGEPOSITION

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

Parameters:
sa pointer to SGESTAGE
layerthe index of the layer in s->layers
heightthe 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

Parameters:
sa pointer to SGESTAGE
layerthe index of the layer in s->layers
widththe new width of the layer

Definition at line 72 of file sgestage.c.

int sgeStageSpriteGroupCollideSprite ( SGESTAGE s,
int  b,
SGESPRITE a,
int  orientation 
)

test if a sprite collides a sprite group

Parameters:
sa pointer to SGESTAGE
bthe index of the SGESPRITEGROUP in s->spriteGroup
aa pointer to SGESPRITE
orientationRELATIVE/ABSOLUTE if the sprite coordinates should be treated as relative to the camera position or not
Returns:
YES/NO if there is a collision

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

Parameters:
sa pointer to SGESTAGE
athe index of the first SGESPRITEGROUP in s->spriteGroup
bthe index of the second SGESPRITEGROUP in s->spriteGroup
orientationRELATIVE/ABSOLUTE if the sprite coordinates should be treated as relative to the camera position or not
Returns:
YES/NO if there is a collision
See also:
sgeStageSpriteGroupCollideSprite

Definition at line 154 of file sgestage.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines