Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // movement.c
- // Created 5/8/2009; 11:14:51 PM
- //31
- #include "all.h"
- #define BOB_LEFT_BOUND 3
- #define BOB_RIGHT_BOUND 12
- #define BOB_UP_BOUND 0
- #define BOB_DOWN_BOUND 20
- #define ENEMY1_LEFT_BOUND_FACING_LEFT 1
- #define ENEMY1_RIGHT_BOUND_FACING_LEFT 12
- #define ENEMY1_UP_BOUND 0
- #define ENEMY1_DOWN_BOUND 16
- //This function helps slow down movement
- void delay(short time)
- {
- short int randNum;
- // generate random numbers to slow down the program...
- while (time-- > 0) {
- randNum = rand() % time;
- }
- }
- /*
- void moveTile (void)
- {
- static short x;
- if (x == 0)x=1;
- else x = 0;
- fg_map[3+1][9] = x;
- }*/
- void Die ()
- {
- if (bob.health == 0)
- {
- if (fishx-10 < bob.coordinates.xLocal)
- {
- GrayClipSprite16_MASK_R (fishx, fishy, 16, fish[2], &fish[2][16], fish[3], &fish[3][16], dBufHPL_G, dBufHPD_G);
- }
- else
- {
- GrayClipSprite16_MASK_R (fishx, fishy, 16, fish[0], &fish[0][16], fish[1], &fish[1][16], dBufHPL_G, dBufHPD_G);
- }
- fishx--;
- }
- }
- void firstBulletMovement (BULLET *bullet)
- {
- /*(*blist)->xLocal+=((*blist)->direction*((BULLET_TYPE*)(*blist)->type)->speed+globs->shiftfgx);
- ((BULLET*)bullet)->xLocal+=
- (*blist)->yLocal+=globs->shiftfgy;
- (*blist)->xGlobal+=((*blist)->direction*((BULLET_TYPE*)(*blist)->type)->speed);*/
- }
- void secondBulletMovement (BULLET *bullet)
- {
- }
- static inline BOOL collision (BOB *bob, short direction, char *map)
- {
- //int x;
- //GrayClipSprite8_MASK_R (bob->xLocal+10+random (10), bob->y+random (10), 8, Blood[0], &Blood[0][8], Blood[1], &Blood[1][8], dBufAPL_G, dBufAPD_G);
- switch (direction)
- {
- case M_DOWN:
- return
- *(map+((bob->coordinates.yGlobal+20)>>3)*((Plane*)RunningLevel->planes[1])->width+((bob->coordinates.xGlobal+5)>>3)) > 0
- ||
- *(map+((bob->coordinates.yGlobal+20)>>3)*((Plane*)RunningLevel->planes[1])->width+((bob->coordinates.xGlobal+10)>>3)) > 0;
- case M_UP:
- //return map[(bob->coordinates.yGlobal)/8][(bob->coordinates.xGlobal+5)/8] || map[(bob->coordinates.yGlobal)/8][(bob->coordinates.xGlobal+10)/8];
- return
- *(map+((bob->coordinates.yGlobal)>>3)*((Plane*)RunningLevel->planes[1])->width+((bob->coordinates.xGlobal+5)>>3)) > 0
- ||
- *(map+((bob->coordinates.yGlobal)>>3)*((Plane*)RunningLevel->planes[1])->width+((bob->coordinates.xGlobal+10)>>3)) > 0;
- case M_LEFT:
- //return map[(bob->coordinates.yGlobal)/8][(bob->coordinates.xGlobal+3)/8] || map[(bob->coordinates.yGlobal+8)/8][(bob->coordinates.xGlobal+3)/8] || map[(bob->coordinates.yGlobal+16)/8][(bob->coordinates.xGlobal+3)/8] || map[(bob->coordinates.yGlobal+19)/8][(bob->coordinates.xGlobal+3)/8];
- return
- *(map+((bob->coordinates.yGlobal)>>3)*((Plane*)RunningLevel->planes[1])->width+((bob->coordinates.xGlobal+3)>>3)) > 0
- ||
- *(map+((bob->coordinates.yGlobal+8)>>3)*((Plane*)RunningLevel->planes[1])->width+((bob->coordinates.xGlobal+3)>>3)) > 0
- ||
- *(map+((bob->coordinates.yGlobal+16)>>3)*((Plane*)RunningLevel->planes[1])->width+((bob->coordinates.xGlobal+3)>>3)) > 0
- ||
- *(map+((bob->coordinates.yGlobal+19)>>3)*((Plane*)RunningLevel->planes[1])->width+((bob->coordinates.xGlobal+3)>>3)) > 0;
- case M_RIGHT:
- //return map[(bob->coordinates.yGlobal)/8][(bob->coordinates.xGlobal+12)/8] || map[(bob->coordinates.yGlobal+8)/8][(bob->coordinates.xGlobal+12)/8] || map[(bob->coordinates.yGlobal+16)/8][(bob->coordinates.xGlobal+12)/8] || map[(bob->coordinates.yGlobal+19)/8][(bob->coordinates.xGlobal+12)/8];
- return
- *(map+((bob->coordinates.yGlobal)>>3)*((Plane*)RunningLevel->planes[1])->width+((bob->coordinates.xGlobal+12)>>3)) > 0
- ||
- *(map+((bob->coordinates.yGlobal+8)>>3)*((Plane*)RunningLevel->planes[1])->width+((bob->coordinates.xGlobal+12)>>3)) > 0
- ||
- *(map+((bob->coordinates.yGlobal+16)>>3)*((Plane*)RunningLevel->planes[1])->width+((bob->coordinates.xGlobal+12)>>3)) > 0
- ||
- *(map+((bob->coordinates.yGlobal+19)>>3)*((Plane*)RunningLevel->planes[1])->width+((bob->coordinates.xGlobal+12)>>3)) > 0;
- }
- }
- //for bob:
- /*
- LEFT_BOUND = 4 (FOR UP AND DOWN IT IS 5!!!!)
- RIGHT_BOUND = 11 (FOR UP AND DOWN IT IS 10!!!!!)
- UP_BOUND = 0
- DOWN_BOUND = 20
- */
- //collision (bob->coordinates.xGlobal, bob->y, BOB_LEFT_BOUND, BOB_RIGHT_BOUND, BOB_UP_BOUND, BOB_DOWN_BOUND, M_DOWN, fg_map);
- static BOOL collisionEnemy (short x, short y, short LEFT_BOUND, short RIGHT_BOUND, short UP_BOUND, short DOWN_BOUND, short direction, char *map)
- {
- switch (direction)
- {
- case M_DOWN:
- return
- *(map+((y+DOWN_BOUND)>>3)*((Plane*)RunningLevel->planes[1])->width+((x+LEFT_BOUND+1)>>3)) > 0
- ||
- *(map+((y+DOWN_BOUND)>>3)*((Plane*)RunningLevel->planes[1])->width+((x+RIGHT_BOUND)>>3)) > 0
- ||
- *(map+((y+DOWN_BOUND)>>3)*((Plane*)RunningLevel->planes[1])->width+((x+RIGHT_BOUND-1)>>3)) > 0;
- case M_UP:
- return
- *(map+((y+UP_BOUND)>>3)*((Plane*)RunningLevel->planes[1])->width+((x+LEFT_BOUND+1)>>3)) > 0
- ||
- *(map+((y+UP_BOUND)>>3)*((Plane*)RunningLevel->planes[1])->width+((x+9)>>3)) > 0
- ||
- *(map+((y+UP_BOUND)>>3)*((Plane*)RunningLevel->planes[1])->width+((x+RIGHT_BOUND-1)>>3)) > 0;
- case M_LEFT:
- return
- *(map+((y+UP_BOUND)>>3)*((Plane*)RunningLevel->planes[1])->width+((x+LEFT_BOUND)>>3)) > 0
- ||
- *(map+((y+(DOWN_BOUND/3)-1)>>3)*((Plane*)RunningLevel->planes[1])->width+((x+LEFT_BOUND)>>3)) > 0
- ||
- *(map+(((y+(2/3)*DOWN_BOUND)-1)>>3)*((Plane*)RunningLevel->planes[1])->width+((x+LEFT_BOUND)>>3)) > 0
- ||
- *(map+((y+DOWN_BOUND-1)>>3)*((Plane*)RunningLevel->planes[1])->width+((x+LEFT_BOUND)>>3)) > 0;
- case M_RIGHT:
- return
- *(map+((y+UP_BOUND)>>3)*((Plane*)RunningLevel->planes[1])->width+((x+RIGHT_BOUND)>>3)) > 0
- ||
- *(map+((y+(DOWN_BOUND>>1))>>3)*((Plane*)RunningLevel->planes[1])->width+((x+RIGHT_BOUND)>>3)) > 0
- ||
- *(map+((y+DOWN_BOUND-1)>>3)*((Plane*)RunningLevel->planes[1])->width+((x+RIGHT_BOUND)>>3)) > 0
- ||
- *(map+((y+(DOWN_BOUND>>1))>>3)*((Plane*)RunningLevel->planes[1])->width+((x+RIGHT_BOUND)>>3)) > 0;
- }
- }
- void follow(ENEMY *enemies)
- {
- if (enemies->xGlobal > bob.coordinates.xGlobal)
- {
- enemies->moveDirectionX = -1;
- enemies->facing = 0;
- }
- else if (enemies->xGlobal < bob.coordinates.xGlobal)
- {
- enemies->moveDirectionX = 1;
- enemies->facing = 2;
- }
- }
- void movePear(ENEMY *enemies)
- {
- if (collisionEnemy (enemies->xGlobal, enemies->yGlobal, enemies->type->left_bound, enemies->type->right_bound, enemies->type->up_bound, enemies->type->down_bound, M_RIGHT, (char*)((Plane*)RunningLevel->planes[1])->matrix))
- {
- enemies->moveDirectionX = -1;
- enemies->facing = 0;
- }
- else if (collisionEnemy (enemies->xGlobal, enemies->yGlobal, enemies->type->left_bound, enemies->type->right_bound, enemies->type->up_bound, enemies->type->down_bound, M_LEFT, (char*)((Plane*)RunningLevel->planes[1])->matrix))
- {
- enemies->moveDirectionX = 1;
- enemies->facing = 2;
- }
- }
- void moveJump(ENEMY *enemies)
- {
- follow(enemies);
- if ((collisionEnemy (enemies->xGlobal, enemies->yGlobal, enemies->type->left_bound, enemies->type->right_bound, enemies->type->up_bound, enemies->type->down_bound, M_RIGHT, (char*)((Plane*)RunningLevel->planes[1])->matrix) && enemies->moveDirectionX == 1) || (collisionEnemy (enemies->xGlobal, enemies->yGlobal, enemies->type->left_bound, enemies->type->right_bound, enemies->type->up_bound, enemies->type->down_bound, M_LEFT, (char*)((Plane*)RunningLevel->planes[1])->matrix) && enemies->moveDirectionX == -1))
- {
- enemies->moveDirectionX = 0;
- }
- if (collisionEnemy (enemies->xGlobal, enemies->yGlobal, enemies->type->left_bound, enemies->type->right_bound, enemies->type->up_bound, enemies->type->down_bound, M_DOWN, (char*)((Plane*)RunningLevel->planes[1])->matrix))
- {
- enemies->jumping = TRUE;
- }
- if (enemies->jumping && enemies->jumpCount < enemies->type->jumpHeight && !collisionEnemy (enemies->xGlobal, enemies->yGlobal, enemies->type->left_bound, enemies->type->right_bound, enemies->type->up_bound, enemies->type->down_bound, M_UP, (char*)((Plane*)RunningLevel->planes[1])->matrix))
- {
- enemies->jumpCount++;
- enemies->yGlobal--;
- enemies->yLocal--;
- }
- else
- {
- enemies->jumping = FALSE;
- enemies->jumpCount = 0;
- }
- }
- void smartJump(ENEMY *enemies)
- {
- if ((collisionEnemy (enemies->xGlobal, enemies->yGlobal, enemies->type->left_bound, enemies->type->right_bound, enemies->type->up_bound, enemies->type->down_bound, M_RIGHT, (char*)((Plane*)RunningLevel->planes[1])->matrix) && enemies->moveDirectionX == 1) || (collisionEnemy (enemies->xGlobal, enemies->yGlobal, enemies->type->left_bound, enemies->type->right_bound, enemies->type->up_bound, enemies->type->down_bound, M_LEFT, (char*)((Plane*)RunningLevel->planes[1])->matrix) && enemies->moveDirectionX == -1) && !enemies->jumping)
- {
- enemies->moveDirectionX = 0;
- if (collisionEnemy (enemies->xGlobal, enemies->yGlobal, enemies->type->left_bound, enemies->type->right_bound, enemies->type->up_bound, enemies->type->down_bound, M_DOWN, (char*)((Plane*)RunningLevel->planes[1])->matrix))
- {
- enemies->jumping = TRUE;
- }
- }
- else
- {
- if (!enemies->jumping)
- follow (enemies);
- }
- if (enemies->jumping && enemies->jumpCount < enemies->type->jumpHeight && !collisionEnemy (enemies->xGlobal, enemies->yGlobal, enemies->type->left_bound, enemies->type->right_bound, enemies->type->up_bound, enemies->type->down_bound, M_UP, (char*)((Plane*)RunningLevel->planes[1])->matrix))
- {
- enemies->jumpCount++;
- enemies->yGlobal--;
- enemies->yLocal--;
- }
- else
- {
- enemies->jumpCount = 0;
- enemies->jumping = FALSE;
- }
- }
- short radarUP = 0;
- short radarDOWN = 0;
- BOOL travel = FALSE;
- void evil (ENEMY *enemies)
- {
- if (!travel)
- {
- follow (enemies);
- }
- if (enemies->xGlobal == bob.coordinates.xGlobal && !travel)
- {
- if (enemies->yGlobal > bob.coordinates.yGlobal)
- {
- travel = TRUE;
- }
- }
- if (travel)
- {
- for (radarUP = enemies->yGlobal; radarUP > bob.coordinates.yGlobal; radarUP--, radarDOWN++)
- {
- if (collisionEnemy (enemies->xGlobal-5, radarUP, 0, 8, 0, 8, M_UP, (char*)((Plane*)RunningLevel->planes[1])->matrix))
- {
- break;
- }
- }
- if (radarUP <= bob.coordinates.yGlobal)
- {
- //enemies->type->jumpHeight = radarDOWN + 8;
- enemies->jumping = TRUE;
- enemies->moveDirectionX = 0;
- enemies->facing = 0;
- }
- else
- {
- enemies->moveDirectionX = 1;
- enemies->facing = 2;
- }
- }
- if ((collisionEnemy (enemies->xGlobal, enemies->yGlobal, enemies->type->left_bound, enemies->type->right_bound, enemies->type->up_bound, enemies->type->down_bound, M_RIGHT, (char*)((Plane*)RunningLevel->planes[1])->matrix) && enemies->moveDirectionX == 1) || (collisionEnemy (enemies->xGlobal, enemies->yGlobal, enemies->type->left_bound, enemies->type->right_bound, enemies->type->up_bound, enemies->type->down_bound, M_LEFT, (char*)((Plane*)RunningLevel->planes[1])->matrix) && enemies->moveDirectionX == -1) && !enemies->jumping)
- {
- enemies->moveDirectionX = 0;
- if (collisionEnemy (enemies->xGlobal, enemies->yGlobal, enemies->type->left_bound, enemies->type->right_bound, enemies->type->up_bound, enemies->type->down_bound, M_DOWN, (char*)((Plane*)RunningLevel->planes[1])->matrix))
- {
- enemies->jumping = TRUE;
- }
- }
- if (enemies->jumping && enemies->jumpCount < enemies->type->jumpHeight && !collisionEnemy (enemies->xGlobal, enemies->yGlobal, enemies->type->left_bound, enemies->type->right_bound, enemies->type->up_bound, enemies->type->down_bound, M_UP, (char*)((Plane*)RunningLevel->planes[1])->matrix))
- {
- enemies->jumpCount++;
- enemies->yGlobal--;
- enemies->yLocal--;
- }
- else
- {
- enemies->jumpCount = 0;
- enemies->jumping = FALSE;
- }
- if (enemies->yGlobal+5 == bob.coordinates.yGlobal)
- {
- travel = FALSE;
- radarUP = 0;
- radarDOWN = 0;
- }
- }
- void moveGhost (ENEMY *enemies)
- {
- if (enemies->xGlobal > bob.coordinates.xGlobal)
- {
- enemies->moveDirectionX = -1;
- enemies->facing = 0;
- }
- else if (enemies->xGlobal < bob.coordinates.xGlobal)
- {
- enemies->moveDirectionX = 1;
- enemies->facing = 2;
- }
- if (enemies->yGlobal > bob.coordinates.yGlobal)
- {
- enemies->moveDirectionY = -1;
- }
- else if (enemies->yGlobal < bob.coordinates.yGlobal)
- {
- enemies->moveDirectionY = 1;
- }
- }
- /*
- static inline BOOL collisionBullet(BULLET* bullet, short direction, char** map)
- {
- switch(direction)
- {
- case M_RIGHT:
- return map[(bullet->yGlobal)/8][(bullet->xGlobal+7)/8] || map[(bullet->yGlobal+3)/8][(bullet->xGlobal+7)/8];
- }
- }*/
- static inline BOOL collisionBullet (BULLET *bullet, short direction, char *map)
- {
- switch (direction)
- {
- case M_RIGHT:
- return
- *(map+((bullet->yGlobal+0)>>3)*((Plane*)RunningLevel->planes[1])->width+((bullet->xGlobal+6)>>3)) > 0
- ||
- *(map+((bullet->yGlobal+(6>>1))>>3)*((Plane*)RunningLevel->planes[1])->width+((bullet->xGlobal+6)>>3)) > 0;
- case M_LEFT:
- return
- *(map+((bullet->yGlobal+(0))>>3)*((Plane*)RunningLevel->planes[1])->width+((bullet->xGlobal)>>3)) > 0
- ||
- *(map+((bullet->yGlobal+(6>>1))>>3)*((Plane*)RunningLevel->planes[1])->width+((bullet->xGlobal)>>3)) > 0;
- }
- }
- void renderBullets (void)
- {
- {
- /*for (;i < BULLETS_ALLOWED; i++)
- {
- if (Bullets_On_Screen[i].x < 1 || Bullets_On_Screen[i].x > 160 || Bullets_On_Screen[i].x == DEAD_BULLET || collisionBullet(&Bullets_On_Screen[i], M_RIGHT, fg_map))
- {
- Bullets_On_Screen[i].x = DEAD_BULLET;
- }
- else
- {
- GrayClipSprite8_MASK_R (Bullets_On_Screen[i].x, Bullets_On_Screen[i].y, 3, Bullets[Bullets_On_Screen[i].bullet], &Bullets[Bullets_On_Screen[i].bullet][3], guns[Bullets_On_Screen[i].bullet+1], &Bullets[Bullets_On_Screen[i].bullet+1][6], dBufAPL_G, dBufAPD_G);
- Bullets_On_Screen[i].x+=Bullets_On_Screen[i].countValue;
- Bullets_On_Screen[i].xGlobal+=Bullets_On_Screen[i].countValue;
- }
- }*/
- int i = BULLETS_ALLOWED-1;
- do
- {
- Bullets_On_Screen[i].y+=globs->shiftfgy;
- Bullets_On_Screen[i].x+=globs->shiftfgx;
- if (Bullets_On_Screen[i].x == DEAD_BULLET || collisionBullet(&Bullets_On_Screen[i], M_RIGHT, fg_map))
- {
- Bullets_On_Screen[i].x = DEAD_BULLET;
- }
- else
- {
- GrayClipSprite8_MASK_R (Bullets_On_Screen[i].x, Bullets_On_Screen[i].y, 8, Bullets[Bullets_On_Screen[i].bullet], &Bullets[Bullets_On_Screen[i].bullet][8], Bullets[Bullets_On_Screen[i].bullet+1], &Bullets[Bullets_On_Screen[i].bullet+1][8], dBufHPL_G, dBufHPD_G);
- if (Bullets_On_Screen[i].counter < bullet_speed)
- {
- Bullets_On_Screen[i].counter++;
- }
- else
- {
- Bullets_On_Screen[i].x+=Bullets_On_Screen[i].countValue;
- Bullets_On_Screen[i].xGlobal+=Bullets_On_Screen[i].countValue;
- Bullets_On_Screen[i].counter = 0;
- }
- }
- i--;
- }
- while (i >= 0);
- }
- }
- //Display Bob
- inline void display_BOB (BOB* bob, short position, short facing)
- {
- short gun_side = 0;
- if (gun_facing == 2)
- {
- gun_side = -22;
- }
- int val = 0;
- if (facing == LEFT_NORMAL && position == 1)
- {
- val = 2;
- }
- else
- {
- val = 0;
- }
- //GrayDBufToggle ();
- //GrayDBufToggleSync ();
- switch(position)
- {
- case 0:
- {
- GrayClipSprite16_MASK_R (bob->coordinates.xLocal, bob->coordinates.yLocal, 20, sprite_BOB[facing], &sprite_BOB[facing][20], sprite_BOB[facing+1], &sprite_BOB[facing+1][20], dBufHPD_G, dBufHPL_G);
- //GrayClipSprite16_SMASK_R(bob->coordinates.xLocal, bob->y, 20, sprite_BOB[facing], &sprite_BOB[facing][20], &sprite_BOB[facing+2], dBufAPD_G, dBufAPL_G);
- GrayClipSprite8_MASK_R (bob->coordinates.xLocal+15+gun_side, bob->coordinates.yLocal+11, 6, guns[gun_facing], &guns[gun_facing][6], guns[gun_facing+1], &guns[gun_facing+1][6], dBufHPD_G, dBufHPL_G);
- //GrayClipSprite8_MASK_R (bob->coordinates.xLocal+4+val, bob->coordinates.yLocal-6, 8, hats[0], &hats[0][8], hats[1], &hats[1][8], dBufHPL_G, dBufHPD_G);
- break;
- }
- case 1:
- {
- //FastCopyScreen (dBufHPL_G, dBufAPL_G);FastCopyScreen (dBufHPD_G, dBufAPD_G);
- //GrayDBufToggleSync(); //set drawbuffer as active screen
- //dBufHPL_G = GrayDBufGetHiddenPlane(LIGHT_PLANE);
- //dBufHPD_G = GrayDBufGetHiddenPlane(DARK_PLANE);
- GrayClipSprite16_MASK_R (bob->coordinates.xLocal, bob->coordinates.yLocal, 20, sprite_BOB[facing+2], &sprite_BOB[facing+2][20], sprite_BOB[facing+3], &sprite_BOB[facing+3][20], dBufHPL_G, dBufHPD_G);
- GrayClipSprite8_MASK_R (bob->coordinates.xLocal+15+gun_side, bob->coordinates.yLocal+8, 6, guns[gun_facing], &guns[gun_facing][6], guns[gun_facing+1], &guns[gun_facing+1][6], dBufHPL_G, dBufHPD_G);
- //GrayClipSprite8_MASK_R (bob->coordinates.xLocal+3+val, bob->coordinates.yLocal-6, 8, hats[0], &hats[0][8], hats[1], &hats[1][8], dBufHPL_G, dBufHPD_G);
- break;
- }
- }
- //GrayClipSprite16_TRANW_R (bob->coordinates.xLocal + 20, bob->y, 20, sprite_BOB[facing+2], &sprite_BOB[facing+2][20], dBufAPL_G, dBufAPD_G);
- //GrayClipSprite16_SMASK_R(bob->coordinates.xLocal, bob->y, 20, sprite_BOB[facing], &sprite_BOB[facing][20], sprite_BOB[facing+1], dBufAPL_G, dBufAPD_G);
- //GrayDBufToggleSync ();
- }
- static inline void spawnEnemy (ENEMY *enemy)
- {
- // enemy->type = &pear;
- enemy->health = 31;
- enemy->moveDirectionX = -1;
- enemy->moveSpeed = 0;
- enemy->onscreen =TRUE;
- enemy->xLocal = bob.coordinates.xLocal;//154;
- enemy->xGlobal = bob.coordinates.xGlobal;
- enemy->yGlobal = 0;
- enemy->yLocal = 0 - y_fg;
- enemyCount++;
- //enemy->health = enemySpawnPoints;
- }
- //short earthx = 0;
- //short earthy = 0;
- short increment = 0;
- short earthrange = 10;
- short earthcount = 0;
- short earthspeed = 20;
- void earthquake (void)
- {
- if (earthcount < earthspeed)
- {
- earthcount++;
- }
- else
- {
- increment = random (earthrange) - 5;
- x_fg += increment;
- if (collision (&bob, M_LEFT, ((Plane*)RunningLevel->planes[1])->matrix))
- {
- bob.coordinates.xLocal-=increment;
- }
- else if (collision (&bob, M_RIGHT, ((Plane*)RunningLevel->planes[1])->matrix))
- {
- bob.coordinates.xLocal-=increment;
- }
- else
- bob.coordinates.xGlobal += increment;
- earthcount = 0;
- }
- }
- static inline void display_ENEMY (void)
- {
- ENEMY* backup = *enemyList;
- if (*enemyList != NULL)
- do
- {
- // if ((*enemyList)->yGlobal > y_fg - (*enemyList)->type->height && (*enemyList)->yGlobal < y_fg+100)
- GrayClipSprite16_MASK_R ((*enemyList)->xLocal, (*enemyList)->yLocal, (*enemyList)->type->height,
- &gfx.enemy_gfx[(*enemyList)->type->index][(2*(*enemyList)->facing*(*enemyList)->type->height)],
- &gfx.enemy_gfx[(*enemyList)->type->index][(*enemyList)->type->height+2*(*enemyList)->facing*(*enemyList)->type->height],
- &gfx.enemy_gfx[(*enemyList)->type->index][2*(*enemyList)->facing*(*enemyList)->type->height+2*(*enemyList)->type->height],
- &gfx.enemy_gfx
- [(*enemyList)->type->index][(*enemyList)->type->height+2*(*enemyList)->type->height*(*enemyList)->facing+2*(*enemyList)->type->height],
- dBufHPL_G, dBufHPD_G);
- *enemyList = (*enemyList)->next;
- }
- while ((*enemyList) != backup);
- }
- static inline void display_STATUS (void)
- {
- GrayClipSprite32_MASK_R (0, 91, 9, Status[0], &Status[0][9], StatusMask[0], &StatusMask[0][9], dBufHPL_G, dBufHPD_G);
- GraySprite32_RPLC_R(32, 91, 9, Status[1], &Status[1][9], dBufHPL_G, dBufHPD_G);
- GraySprite32_RPLC_R(64, 91, 9, Status[2], &Status[2][9], dBufHPL_G, dBufHPD_G);
- GraySprite32_RPLC_R(96, 91, 9, Status[3], &Status[3][9], dBufHPL_G, dBufHPD_G);
- GrayClipSprite32_MASK_R (128, 91, 9, Status[4], &Status[4][9], StatusMask[1], &StatusMask[1][9], dBufHPL_G, dBufHPD_G);
- GrayFastFillRect_R(dBufHPL_G, dBufHPD_G, 28, 94, 28+bob.health, 96, COLOR_BLACK);
- if (bob.health == 0)
- GrayFastFillRect_R(dBufHPL_G, dBufHPD_G, 27, 94, 30, 96, COLOR_WHITE);
- GrayFastOutlineRect_R(dBufHPL_G, dBufHPD_G, 27, 93, 58, 97, COLOR_WHITE);
- }
- static void handleBullets (BLIST **blist, LEVEL *level)
- {
- BLIST *backup = NULL;
- if (level->bulletTimer > 0)
- {
- if (level->bulletTimer == (*blist)->type->period)
- level->bulletTimer = 0;
- else
- level->bulletTimer++;
- }
- if (_keytest (RR_SHIFT))
- {
- if (level->bulletTimer == 0)
- {
- PullTrigger (blist, &bob, facing, &gfx.bullet_types[0]);
- level->bulletTimer++;
- }
- }
- backup = *blist;
- if (*blist != NULL)
- do
- {
- (*blist)->xLocal+=((*blist)->direction*(*blist)->type->speed+globs->shiftfgx);
- (*blist)->yLocal+=globs->shiftfgy;
- (*blist)->xGlobal+=((*blist)->direction*(*blist)->type->speed);
- if (collisionEnemy ((*blist)->xGlobal, (*blist)->yGlobal, 0, 8, 0, 6,M_LEFT, (char*)((Plane*)RunningLevel->planes[1])->matrix) || collisionEnemy ((*blist)->xGlobal, (*blist)->yGlobal, 0, 8, 0, 6, M_RIGHT, (char*)((Plane*)RunningLevel->planes[1])->matrix) || (*blist)->xLocal < -100 || (*blist)->xLocal > 200)
- {
- if (*blist == backup)
- {
- backup = (*blist)->next;
- }
- deleteBullet (blist);
- //temporary fix
- if (*blist == NULL)
- {
- level->bulletTimer = 0;
- return;
- }
- }
- //pick sprite for bullet direction
- int base_offset = ((*blist)->direction > 0) ? 0 : 4*(*blist)->type->height;
- GrayClipSprite8_MASK_R ((*blist)->xLocal, (*blist)->yLocal,
- (*blist)->type->height,
- (char*)(((*blist)->type)->data + base_offset),
- (char*)((*blist)->type->data+(*blist)->type->height + base_offset),
- (char*)((*blist)->type->data+2*(*blist)->type->height + base_offset),
- (char*)((*blist)->type->data+3*(*blist)->type->height + base_offset),
- dBufHPL_G, dBufHPD_G);
- *blist = (*blist)->next;
- }
- while (*blist != backup);
- }
- static inline void render(LEVEL *level)
- {
- RenderPlane (x_fg, y_fg, level);
- int i = 0;
- for (;i < 4; i++)
- GrayClipSprite8_MASK_R (moving_tiles[i].xLocal, moving_tiles[i].yLocal, 5, moving_tiles_sprites[0], &moving_tiles_sprites[0][5], moving_tiles_sprites[1], &moving_tiles_sprites[1][5], dBufHPL_G, dBufHPD_G);
- display_ENEMY();
- display_BOB (&bob, position, facing);
- display_STATUS();
- Die();
- handleBullets(level->bullets,level);
- //renderBullets();
- //GrayClipSprite16_MASK_R (30, 50, 16, Enemies[8], &Enemies[8][16], Enemies[9], &Enemies[9][16], dBufHPL_G, dBufHPD_G);
- //GrayDBufToggle ();
- //UpsideDownGrayClipSprite16_MASK_R(bob.coordinates.xLocal, bob.coordinates.yLocal, 20, sprite_BOB[facing+2], &sprite_BOB[facing+2][20], sprite_BOB[facing+3], &sprite_BOB[facing+3][20], dBufHPL_G, dBufHPD_G);
- FastCopyScreen (dBufHPL_G, dBufAPL_G);
- FastCopyScreen (dBufHPD_G, dBufAPD_G);
- }
- BOOL collisionTile (void)
- {
- int i = 0;
- for (;i < MOVING_TILE_NUMBER; i++)
- {
- if (bob.coordinates.xGlobal+12 >= moving_tiles[i].xGlobal && bob.coordinates.xGlobal+3 <= moving_tiles[i].xGlobal+8)
- {
- if(bob.coordinates.yGlobal+20 >= moving_tiles[i].yGlobal && bob.coordinates.yGlobal+20 <= moving_tiles[i].yGlobal+5)
- {
- tile_index = i;
- return TRUE;
- }
- }
- }
- tile_index = -1;
- return FALSE;
- }
- BOOL calibrate = FALSE;
- BOOL calibrate2 = FALSE;
- short midpoint = 0;
- //keep Bob towards the ground
- static void gravity (void)
- {
- if (!collision (&bob, M_DOWN, (char*)((Plane*)RunningLevel->planes[1])->matrix) && !collisionTile() && jumping == JUMP_DISTANCE)
- {
- if (Gravity_Step == 2)
- {
- if (bob.coordinates.yGlobal%2)
- {
- bob.coordinates.yGlobal--;
- bob.coordinates.yLocal--;
- }
- }
- else if (Gravity_Step == 4)
- {
- if (!calibrate)
- {
- while ((bob.coordinates.yGlobal)%4)
- {
- bob.coordinates.yGlobal--;
- bob.coordinates.yLocal--;
- }
- calibrate = TRUE;
- }
- }
- bob.coordinates.yGlobal+=Gravity_Step;
- short i = 0;
- if (bob.coordinates.yLocal > 33 && y_fg+100 < LITERAL_MAP_HEIGHT)
- {
- y_fg+=Gravity_Step;
- globs->shiftfgy-=Gravity_Step;
- }
- else
- {
- bob.coordinates.yLocal+=Gravity_Step;
- }
- bob.Gravity_Counter++;
- if (bob.Gravity_Counter > 20 && bob.Gravity_Counter < 40)
- {
- Gravity_Step = 2;
- }
- else if (bob.Gravity_Counter >= 40)
- {
- Gravity_Step = 4;
- }
- }
- else
- {
- bob.Gravity_Limit = GRAVITY_SPEED;
- Gravity_Step = 1;
- bob.Gravity_Counter = 0;
- calibrate = FALSE;
- calibrate2 = FALSE;
- }
- }
- short global_count = 0;
- #define healthWait 500
- short healthcount = healthWait;
- //Initiate a keytest sequence. This function must run in a loop!
- inline void move_BOB (BOB *bob, LEVEL *level)
- {
- Scankeys();
- if (keymap.run)
- {
- accel = 1;
- }
- else
- {
- accel = 0;
- }
- if (jumping < JUMP_DISTANCE)
- {
- if (keymap.jump && !collision (bob, M_UP, (char*)((Plane*)RunningLevel->planes[1])->matrix)) //up
- {
- if (jump_counter < JUMP_SPEED)
- {
- jump_counter++;
- }
- else if (jumping < JUMP_DISTANCE)
- {
- if (bob->coordinates.yGlobal%2)
- {
- bob->coordinates.yGlobal++;
- bob->coordinates.yLocal++;
- }
- bob->coordinates.yGlobal-=2;
- if (bob->coordinates.yLocal < 35 && bob->coordinates.yGlobal > 33)
- {
- y_fg-=2;
- globs->shiftfgy+=2;
- }
- else
- {
- bob->coordinates.yLocal-=2;
- }
- if (position == 0)position = 1;
- else position = 0;
- jump_counter = 0;
- jumping+=2;
- }
- }
- else
- {
- jumping = JUMP_DISTANCE;
- }
- }
- if (keymap.right)
- {
- facing = RIGHT_NORMAL;
- if (!collision (bob, M_RIGHT, (char*)((Plane*)RunningLevel->planes[1])->matrix) && bob->health > 0) //If right key is pressed, then move right
- {
- gun_facing = 0;
- if (accel == 1)
- {
- if (bob->coordinates.xGlobal % 2)
- {
- bob->coordinates.xGlobal--;
- bob->coordinates.xLocal--;
- }
- }
- if (right_counter < RIGHT_SPEED)
- {
- right_counter++;
- }
- else if (bob->coordinates.xLocal >= 50 && bob->coordinates.xGlobal < ((Plane*)level->planes[1])->width*8-111)
- {
- x_fg+=(1+accel);
- globs->shiftfgx+=-(1+accel);
- bob->coordinates.xGlobal+=(1+accel);
- right_counter = 0;
- }
- else
- {
- bob->coordinates.xLocal+=(1+accel);
- bob->coordinates.xGlobal+=(1+accel);
- right_counter = 0;
- }
- if (position == 0)position = 1;
- else position = 0;
- }
- }
- else if (keymap.left)
- {
- facing = LEFT_NORMAL;
- if (bob->coordinates.xGlobal > LEFT && !collision (bob, M_LEFT, (char*)((Plane*)RunningLevel->planes[1])->matrix) && bob->health > 0) //If left key is pressed, then move left
- {
- gun_facing = 2;
- if (accel == 1)
- {
- if (bob->coordinates.xGlobal % 2)
- {
- bob->coordinates.xGlobal--;
- bob->coordinates.xLocal--;
- }
- }
- if (left_counter < LEFT_SPEED)
- {
- left_counter++;
- }
- else if (bob->coordinates.xLocal > 30 || bob->coordinates.xGlobal <= 30)
- {
- bob->coordinates.xLocal-=(1+accel);
- bob->coordinates.xGlobal-=(1+accel);
- left_counter = 0;
- }
- else if (bob->coordinates.xGlobal > 30)
- {
- x_fg-=(1+accel);
- short i = 19;
- globs->shiftfgx=1+accel;
- bob->coordinates.xGlobal-=(1+accel);
- left_counter = 0;
- }
- if (position == 0)position = 1;
- else position = 0;
- }
- }
- if (keymap.plus)
- {
- OSContrastUp();
- }
- if (keymap.minus)
- {
- OSContrastDn ();
- }
- //handleBullets (level->bullets);
- gravity ();
- if (collision (bob, M_DOWN, (char*)((Plane*)RunningLevel->planes[1])->matrix) || collisionTile())
- {
- jumping = 0;
- if (position == 1 && !_rowread(0)) //put Bob in his default position
- {
- position = 0;
- }
- }
- if (_keytest(RR_ENTER) && bob->health != 0)
- {
- bob->health--;
- }
- int counter = 19;
- int bleh;
- fishy = bob->coordinates.yLocal+5;
- int tilei = 0;
- for (;tilei < MOVING_TILE_NUMBER; tilei++)
- {
- if (moving_tiles[tilei].yGlobal == moving_tiles[tilei].yspawnpoint+moving_tiles[tilei].range && moving_tiles[tilei].sum == 1)
- moving_tiles[tilei].sum = -1;
- if (moving_tiles[tilei].yGlobal == moving_tiles[tilei].yspawnpoint && moving_tiles[tilei].sum == -1)
- moving_tiles[tilei].sum = 1;
- moving_tiles[tilei].xLocal+=globs->shiftfgx;
- }
- tileshiftfgy = globs->shiftfgy;
- if (collisionTile())
- {
- if (bob->coordinates.yLocal > 33 && y_fg+100 < LITERAL_MAP_HEIGHT)
- {
- y_fg++;
- tileshiftfgy--;
- globs->shiftfgy--;
- }
- if (bob->coordinates.yLocal < 35 && bob->coordinates.yGlobal > 33)
- {
- y_fg--;
- tileshiftfgy++;
- globs->shiftfgy++;
- }
- moving_tiles[tile_index].yLocal+=moving_tiles[tile_index].sum+tileshiftfgy;
- moving_tiles[tile_index].yGlobal+=moving_tiles[tile_index].sum;
- if (!collision (bob, M_DOWN, fg_map) || moving_tiles[tile_index].sum == -1)
- {
- bob->coordinates.yGlobal=moving_tiles[tile_index].yGlobal-20;
- bob->coordinates.yLocal=moving_tiles[tile_index].yLocal-20;
- }
- }
- for (tilei = 0;tilei < MOVING_TILE_NUMBER; tilei++)
- {
- if (tilei != tile_index)
- {
- moving_tiles[tilei].yGlobal+=moving_tiles[tilei].sum;
- moving_tiles[tilei].yLocal+=moving_tiles[tilei].sum+globs->shiftfgy;
- }
- }
- static int var = 0;
- ENEMY *ebackup = *enemyList;
- if (*enemyList != NULL)
- do
- {
- OUTERLOOP:
- (*enemyList)->type->move(*enemyList);
- //Move the enemy in the x direction calculated in the previous executed function.
- if ((*enemyList)->moveCounter < (*enemyList)->moveSpeed)
- {
- (*enemyList)->moveCounter++;
- }
- else// if (counter < enemyCount)
- {
- (*enemyList)->xLocal+=(*enemyList)->moveDirectionX;
- (*enemyList)->xGlobal+=(*enemyList)->moveDirectionX;
- (*enemyList)->moveCounter = 0;
- }
- //Move enemies in the y direction. Currently I have not decided if this should be timed or not.
- (*enemyList)->yLocal+=(*enemyList)->moveDirectionY;
- (*enemyList)->yGlobal+=(*enemyList)->moveDirectionY;
- //Make sure the enemies' x,y coordinates remain relative to bo. Move the enemies whenever the screen moves.
- (*enemyList)->xLocal+=globs->shiftfgx;
- (*enemyList)->yLocal+=globs->shiftfgy;
- //Test collision for enemies
- if (!collisionEnemy ((*enemyList)->xGlobal, (*enemyList)->yGlobal, (*enemyList)->type->left_bound, (*enemyList)->type->right_bound, (*enemyList)->type->up_bound, (*enemyList)->type->down_bound, M_DOWN, ((Plane*)RunningLevel->planes[1])->matrix) && !(*enemyList)->jumping)
- {
- (*enemyList)->yLocal++;
- (*enemyList)->yGlobal++;
- }
- //This is both a timer for intervals when to test for enemy collision (to give the player time to move). If there is a collision, take away health.
- if (healthcount < healthWait)
- {
- healthcount++;
- }
- if (TestCollide162h_R((*enemyList)->xLocal, (*enemyList)->yLocal, bob->coordinates.xLocal, bob->coordinates.yLocal, 16, 20, gfx.enemy_gfx[0], gfx.bob_gfx[0]))
- {
- if (healthcount >= 10)
- {
- bob->health -= (*enemyList)->type->damage;
- healthcount = 0;
- }
- }
- //Move game objects:
- GameObject *gobackup = *level->gobjects;
- if (*level->gobjects != NULL)
- do
- {
- (*level->gobjects)->type->action(*level->gobjects, level);
- (*level->gobjects)->type->render(*level->gobjects, level);
- *level->gobjects = (*level->gobjects)->next;
- }
- while (gobackup != *level->gobjects);
- //test collsion with bullets
- BLIST *bbackup = *level->bullets;
- if (*level->bullets != NULL)
- do
- {
- if (TestCollide162h_R((*enemyList)->xLocal, (*enemyList)->yLocal,(*level->bullets)->xLocal , (*level->bullets)->yLocal, 16, 6, gfx.enemy_gfx[0], gfx.bullet_gfx[1]))
- {
- if (*level->bullets == bbackup)
- bbackup = (*level->bullets)->next;
- if (*enemyList == ebackup)
- ebackup = (*enemyList)->next;
- ENEMY *b = *enemyList;
- deleteEnemyFromLList(enemyList);
- free (b);
- deleteBullet (level->bullets);
- if (*enemyList == NULL && *level->bullets == NULL)
- {
- level->bulletTimer = 0;
- goto DOUBLE_BREAK;
- }
- if (*enemyList == NULL)
- {
- *level->bullets = bbackup;
- goto DOUBLE_BREAK;
- }
- if (*level->bullets == NULL)
- {
- level->bulletTimer = 0;
- goto OUTERLOOP;
- }
- }
- *level->bullets = (*level->bullets)->next;
- }
- while (*level->bullets != bbackup);
- *level->bullets = bbackup;
- if (*enemyList == NULL)
- break;
- *enemyList = (*enemyList)->next;
- //Prune List of active enemies:m
- if ((*enemyList)->xLocal < -100)
- {
- ENEMY *b = *enemyList;
- if (*enemyList == ebackup)
- {
- ebackup = (*enemyList)->next;
- }
- deleteEnemyFromLList(enemyList);
- pushEnemy(enemyStackLeft,b);
- }
- else if ((*enemyList)->xLocal > 260)
- {
- ENEMY *b = *enemyList;
- if (*enemyList == ebackup)
- {
- ebackup = (*enemyList)->next;
- }
- deleteEnemyFromLList(enemyList);
- pushEnemy(enemyStackRight,b);
- }
- }
- while ((*enemyList)!= ebackup && *enemyList != NULL);
- DOUBLE_BREAK:
- if (bob->coordinates.xGlobal >= (*enemyStackRight)->xGlobal-110 && (*enemyStackRight != NULL))
- {
- if (*enemyList != NULL)
- *enemyList = (*enemyList)->prev;
- addEnemyToLList (enemyList, popEnemy(enemyStackRight));
- (*enemyList)->xLocal = bob->coordinates.xLocal + ((*enemyList)->xGlobal - bob->coordinates.xGlobal);
- (*enemyList)->yLocal = bob->coordinates.yLocal + ((*enemyList)->yGlobal - bob->coordinates.yGlobal);
- (*enemyList) = (*enemyList)->next;
- (*enemyList)->onscreen = TRUE;
- }
- if (bob->coordinates.xGlobal <= (*enemyStackLeft)->xGlobal+110 && (*enemyStackLeft != NULL))
- {
- if (*enemyList != NULL)
- *enemyList = (*enemyList)->prev;
- addEnemyToLList (enemyList, popEnemy(enemyStackLeft));
- (*enemyList)->xLocal = bob->coordinates.xLocal + ((*enemyList)->xGlobal - bob->coordinates.xGlobal);
- (*enemyList)->yLocal = bob->coordinates.yLocal + ((*enemyList)->yGlobal - bob->coordinates.yGlobal);
- (*enemyList) = (*enemyList)->next;
- (*enemyList)->onscreen = TRUE;
- }
- render(level);
- tileshiftfgy=globs->shiftfgx=globs->shiftfgy=0;
- if (bob->health <= 0)
- {
- renderPicture();
- while(!_keytest(RR_DIAMOND))
- {
- delay(5000);
- }
- }
- }
Add Comment
Please, Sign In to add comment