Scale the ball in the priority example

This commit is contained in:
CTurt 2014-12-04 16:40:31 +00:00
parent f6173460ed
commit 13a416dfca
3 changed files with 18 additions and 9 deletions

Binary file not shown.

View File

@ -55,4 +55,3 @@ void DSGM_SetupRooms(int room);
void ball_create(ballObjectInstance *me); void ball_create(ballObjectInstance *me);
void ball_loop(ballObjectInstance *me); void ball_loop(ballObjectInstance *me);
void ball_touch(ballObjectInstance *me);

View File

@ -25,7 +25,7 @@ DSGM_Object DSGM_Objects[DSGM_OBJECT_COUNT] = {
// ball // ball
{ {
&DSGM_Sprites[ballSprite], &DSGM_Sprites[ballSprite],
DSGM_NO_EVENT, (DSGM_Event)ball_create,
(DSGM_Event)ball_loop, (DSGM_Event)ball_loop,
DSGM_NO_EVENT, DSGM_NO_EVENT,
DSGM_NO_EVENT, DSGM_NO_EVENT,
@ -202,18 +202,28 @@ void DSGM_SetupRooms(int room) {
if(room != DSGM_ALL_ROOMS) return; if(room != DSGM_ALL_ROOMS) return;
} }
void ball_create(ballObjectInstance *me) {
// Only applies to the first instance of ball
if((DSGM_ObjectInstance *)me == &DSGM_GetGroup(me)->objectInstances[0]) {
// Enable object instance scaling to enhance the effect
// not needed when just changing an object instance's priority
DSGM_InitObjectInstanceRotScale(me);
}
}
void ball_loop(ballObjectInstance *me) { void ball_loop(ballObjectInstance *me) {
// Only move the first instance of ball
if((DSGM_ObjectInstance *)me == &DSGM_GetGroup(me)->objectInstances[0]) { if((DSGM_ObjectInstance *)me == &DSGM_GetGroup(me)->objectInstances[0]) {
me->x = 112 + (cosLerp(angle) * 32 >> 12); me->x = 112 + (cosLerp(angle) * 32 >> 12);
me->y = 80 - (sinLerp(angle) * 16 >> 12); me->y = 80 - (sinLerp(angle) * 16 >> 12);
if(angle >= degreesToAngle(180)) { // Display on top of the other ball
me->priority = 0; if(angle >= degreesToAngle(180)) me->priority = 0;
}
else { // Display behind the other ball
me->priority = 1; else me->priority = 1;
}
me->scale->x = 256 + (sinLerp(angle) >> 8);
me->scale->y = 256 + (sinLerp(angle) >> 8);
angle += degreesToAngle(6); angle += degreesToAngle(6);
angle %= degreesToAngle(360); angle %= degreesToAngle(360);