Progrès 17/01

This commit is contained in:
attilavs2 2025-01-17 11:01:43 +01:00
parent 6098e9222c
commit 64fdf83576

View file

@ -17,6 +17,10 @@
#define PLANE_W 60 #define PLANE_W 60
#define PLANE_H 60 #define PLANE_H 60
#define TOW_W 104
#define TOW0_OFF 153
#define TOW1_OFF 420
#define WINDOW_W 800 #define WINDOW_W 800
#define WINDOW_H 600 #define WINDOW_H 600
@ -27,7 +31,7 @@ typedef struct{
} Plane; } Plane;
Rectangle Plane_coll = {.width = PLANE_W, .height = PLANE_H}; Rectangle plane_coll = {.width = PLANE_W, .height = PLANE_H};
int lost = 0; int lost = 0;
@ -51,24 +55,59 @@ void spawn_plane(Vector2 pos){
planen++; planen++;
} }
void pop_plane(){ void pop_plane(int pos){
planen--; planen--;
memmove(plane_queue, &plane_queue[1], sizeof(Plane)*planen); if(pos < PQUEUE_SIZE-1)
memmove(&plane_queue[pos], &plane_queue[pos+1], sizeof(Plane)*planen);
} }
#define PLANE_RECT 30 #define COLL_HEIGHT 30
void update_planes(int diff, int xpos){ void update_planes(int diff, int xpos){
while(planen < diff){
Vector2 pos;
//Split into zones to spawn where visible and avoidable
int zone = rand() % 3;
pos.y = rand()%350;
switch(zone){
case 0:
pos.x = rand()%145;
break;
case 1:
pos.x = rand()%170 + 253;
break;
case 2:
pos.x = rand()%200 + 520
break;
}
}
float x; float x;
int y; int y;
xpos = xpos? xpos:1; xpos = xpos? xpos:1;
int sign = abs(xpos)/xpos; int sign = abs(xpos)/xpos;
float fxpos = xpos/100.0; float fxpos = xpos/100.0;
Rectangle tcoll = {.width = TOW_W, .height = COLL_HEIGHT};
for(y = 0; y < WINDOW_H; y++){ for(y = 0; y < WINDOW_H; y+=COLL_HEIGHT){
//x = (5*(xpos/100)/WINDOW_W*y)^2 //x = (5*(xpos/100)/WINDOW_W*y)^2
x = (WINDOW_H-y)*((5.0*fxpos)/(float)WINDOW_W); x = (WINDOW_H-y)*((5.0*fxpos)/(float)WINDOW_W);
x *= x * sign; x *= x * sign;
tcoll.y = y;
for(int i = 0; i < planen; i++){
Plane *pln = &plane_queue[i];
plane_coll.x = pln->pos.x;
plane_coll.y = pln->pos.y;
tcoll.x = TOW0_OFF + x;
if(CheckCollisionRecs(plane_coll,tcoll)){
lost |= 1;
}
tcoll.x = TOW1_OFF + x;
if(CheckCollisionRecs(plane_coll,tcoll)){
lost |= 2;
}
}
} }
} }
@ -84,8 +123,14 @@ void draw_towers(Texture2D *towers, int xpos){
//x = (5*(xpos/100)/WINDOW_W*y)^2 //x = (5*(xpos/100)/WINDOW_W*y)^2
x = (WINDOW_H-y)*((5.0*fxpos)/(float)WINDOW_W); x = (WINDOW_H-y)*((5.0*fxpos)/(float)WINDOW_W);
x *= x * sign; x *= x * sign;
DrawTextureRec(*towers,(Rectangle){.height=1,.width=800,.x=0,.y=y}, if(!(lost&1)){
(Vector2){round(x),y},WHITE); DrawTextureRec(*towers,(Rectangle){.height=1,.width=TOW1_OFF,.x=0,.y=y},
(Vector2){round(x),y},WHITE);
}
if(!(lost&2)){
DrawTextureRec(*towers,(Rectangle){.height=1,.width=800,.x=TOW1_OFF,.y=y},
(Vector2){round(x),y},WHITE);
}
} }
} }
@ -147,7 +192,7 @@ int main(){
if(IsKeyDown(KEY_RIGHT) && xpos < WINDOW_W/2) if(IsKeyDown(KEY_RIGHT) && xpos < WINDOW_W/2)
xpos+=3; xpos+=3;
update_planes(0, xpos); update_planes(3, xpos);
draw_planes(&plane); draw_planes(&plane);
@ -159,7 +204,7 @@ int main(){
DrawFPS(0, 100); DrawFPS(0, 100);
if(lost) if(lost > 1)
lost_men(&score); lost_men(&score);
score++; score++;