144 lines
4.1 KiB
C
144 lines
4.1 KiB
C
#include <gint/rtc.h>
|
|
#include <gint/display.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
#include "stalactites.h"
|
|
#include "wind.h"
|
|
|
|
void stalactites_init(struct stalactite* stalactites)
|
|
{
|
|
stalactites[0].x = 600;
|
|
stalactites[1].x = 840;
|
|
int type1 = rand()%4;
|
|
srand(rtc_ticks());
|
|
int type2;
|
|
do{
|
|
type2 = rand()%4;
|
|
srand(rtc_ticks());
|
|
}
|
|
while(type1==type2);
|
|
stalactites[0].type = type1;
|
|
stalactites[1].type = type2;
|
|
stalactites[0].wind = 0;
|
|
stalactites[1].wind = 0;
|
|
}
|
|
|
|
void stalactites_update(struct stalactite* stalactites, struct game* game)
|
|
{
|
|
for(int i=0; i<2; i++){
|
|
stalactites[i].x -= 4;
|
|
if(stalactites[i].x <= -76){
|
|
stalactites[i].x = stalactites[(i+1) % 2].x + 240;
|
|
int type = rand()%4;
|
|
while(type==stalactites[(i+1) % 2].type){
|
|
srand(rtc_ticks());
|
|
type = rand()%4;
|
|
}
|
|
stalactites[i].type = type;
|
|
game->score +=1;
|
|
if(game->score > 4){
|
|
if(game->score % 5 == 0)
|
|
stalactites[i].wind = 1;
|
|
else
|
|
stalactites[i].wind = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void stalactites_draw(struct stalactite* const stalactites, struct wind* const wind)
|
|
{
|
|
extern bopti_image_t img_stalactites;
|
|
for(int i=0;i<2;i++){
|
|
dsubimage(stalactites[i].x, 0, &img_stalactites, 79*stalactites[i].type, 0, 79, 224, DIMAGE_NONE);
|
|
if(stalactites[i].wind == 1)
|
|
wind_draw(&(stalactites[i]), wind);
|
|
}
|
|
|
|
}
|
|
|
|
int stalactites_collide(struct game const *game)
|
|
{
|
|
int testing_num = (game->stalactites[1].x < game->stalactites[0].x) ? 1 : 0;
|
|
int hitbox[8];
|
|
int type = game->stalactites[testing_num].type;
|
|
|
|
// GETTING HITBOX
|
|
if(type==TOP){
|
|
hitbox[0] = 17;
|
|
hitbox[1] = 0;
|
|
hitbox[2] = 48;
|
|
hitbox[3] = 52;
|
|
hitbox[4] = 19;
|
|
hitbox[5] = 109;
|
|
hitbox[6] = 51;
|
|
hitbox[7] = 224;
|
|
/* {
|
|
17, 0, //topstart
|
|
52, 52,//topfinish
|
|
13, 110,
|
|
51, 224
|
|
}; */
|
|
}
|
|
else if(type==HIGH){
|
|
hitbox[0] = 16;
|
|
hitbox[1] = 0;
|
|
hitbox[2] = 47;
|
|
hitbox[3] = 90;
|
|
hitbox[4] = 24;
|
|
hitbox[5] = 143;
|
|
hitbox[6] = 57;
|
|
hitbox[7] = 224;
|
|
/*int hitbox[] = {
|
|
15, 0,
|
|
52, 87,
|
|
23, 141,
|
|
50, 224
|
|
};*/
|
|
}
|
|
else if(type==LOW){
|
|
hitbox[0] = 22;
|
|
hitbox[1] = 0;
|
|
hitbox[2] = 53;
|
|
hitbox[3] = 104;
|
|
hitbox[4] = 22;
|
|
hitbox[5] = 164;
|
|
hitbox[6] = 47;
|
|
hitbox[7] = 224;
|
|
/*int hitbox[] = {
|
|
16, 0,
|
|
61, 105,
|
|
18, 163,
|
|
55, 224
|
|
};*/
|
|
}
|
|
else if(type==BOTTOM){
|
|
hitbox[0] = 25;
|
|
hitbox[1] = 0;
|
|
hitbox[2] = 58;
|
|
hitbox[3] = 137;
|
|
hitbox[4] = 26;
|
|
hitbox[5] = 197;
|
|
hitbox[6] = 59;
|
|
hitbox[7] = 224;
|
|
/*int hitbox[] = {
|
|
23, 0,
|
|
57, 141,
|
|
16, 197,
|
|
57, 224
|
|
};*/
|
|
}
|
|
|
|
int playerx = 78;
|
|
int playery = game->player->y + 25;
|
|
int stalactitex = game->stalactites[testing_num].x;
|
|
for(int i=0; i<8; i+=2)
|
|
hitbox[i] = hitbox[i] + stalactitex;
|
|
if(
|
|
(!(playery>hitbox[3] && playery<hitbox[5])) //Y axis matching
|
|
&& ((playerx>hitbox[0] && playerx<hitbox[2]) || (playerx>hitbox[4] && playerx<hitbox[6])) //X axis matching
|
|
) return 1;
|
|
|
|
return 0;
|
|
} |