Update 22/01 : Jeu fonctionel

This commit is contained in:
attilavs2 2025-01-22 10:41:15 +01:00
parent b9038faec2
commit 6da8cdf73c
3 changed files with 42 additions and 19 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@ build/
raylib/
*.amd64
*.exe
*.swp

View file

@ -23,10 +23,19 @@ all: $(OBJS)
win: all
mv $(OUTPUT) "$(OUTNAME).exe"
prodwin: win
mkdir ttower
cp *.png "$(OUTNAME).exe" ttower/
7z a ttower.zip ttower/
rm -rf ttower
testwin: win
./"$(OUTNAME).exe"
test: all
./${OUTPUT}
clean:
rm -rf ${BUILD_DIR}/*
.PHONY: all test clean win
.PHONY: all test clean win testwin prodwin

View file

@ -20,6 +20,7 @@
#define TOW_W 104
#define TOW0_OFF 153
#define TOW1_OFF 420
#define TOW_H 453
#define WINDOW_W 800
#define WINDOW_H 600
@ -61,7 +62,7 @@ void pop_plane(int pos){
memmove(&plane_queue[pos], &plane_queue[pos+1], sizeof(Plane)*planen);
}
#define COLL_HEIGHT 30
#define COLL_HEIGHT (TOW_H/20)
void update_planes(int diff, int xpos){
@ -84,22 +85,30 @@ void update_planes(int diff, int xpos){
spawn_plane(pos);
}
float x;
int y;
double x = 0;
int y = 0;
xpos = xpos? xpos:1;
int sign = abs(xpos)/xpos;
float fxpos = xpos/100.0;
double fxpos = xpos/100.0;
Rectangle tcoll = {.width = TOW_W, .height = COLL_HEIGHT};
for(int j = 0; j < planen; j++){
plane_queue[j].dist += 0.01;
plane_queue[j].dist += 0.005;
/*plane_coll.x = plane_queue[j].pos.x;
plane_coll.y = plane_queue[j].pos.y;
DrawRectangleRec(plane_coll, BLACK);*/
}
for(y = 0; y < WINDOW_H; y+=COLL_HEIGHT){
for(y = WINDOW_H-1; y > WINDOW_H-TOW_H; y-=COLL_HEIGHT){
//x = (5*(xpos/100)/WINDOW_W*y)^2
x = (WINDOW_H-y)*((5.0*fxpos)/(float)WINDOW_W);
x *= x * sign;
tcoll.y = y;
tcoll.y = y - COLL_HEIGHT;
//Debug
/*tcoll.x = x + TOW0_OFF;
DrawRectangleRec(tcoll, WHITE);
tcoll.x = x + TOW1_OFF ;
DrawRectangleRec(tcoll, WHITE);*/
for(int i = 0; i < planen; i++){
Plane *pln = &plane_queue[i];
if(pln->dist < 0.9)
@ -109,17 +118,15 @@ void update_planes(int diff, int xpos){
tcoll.x = TOW0_OFF + x;
if(CheckCollisionRecs(plane_coll,tcoll)){
lost |= 1;
return;
}
tcoll.x = TOW1_OFF + x;
if(CheckCollisionRecs(plane_coll,tcoll)){
lost |= 2;
return;
}
pop_plane(i);
if(pln->dist > 1)
pop_plane(i);
}
}
}
void draw_towers(Texture2D *towers, int xpos){
@ -138,8 +145,8 @@ void draw_towers(Texture2D *towers, int xpos){
(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);*/
DrawTextureRec(*towers,(Rectangle){.height=1,.width=800,.x=TOW1_OFF,.y=y},
(Vector2){round(x)+TOW1_OFF,y},WHITE);
}
}
}
@ -152,6 +159,7 @@ void lost_men(int *score){
while(!IsKeyDown(KEY_ENTER) && !WindowShouldClose()){
BeginDrawing();
DrawRectangle(200,150,400,300,WHITE);
snprintf(scorebuf,100,"Votre score : %d", *score);
@ -170,6 +178,8 @@ void lost_men(int *score){
*score = 0;
}
#define XPOS_MAX (WINDOW_W/2)
int main(){
int rand_seed = GetTime();
@ -183,7 +193,7 @@ int main(){
Texture2D plane = LoadTexture("plane.png");
int xpos = 0;
int xpos = 50;
int score = 0;
@ -197,9 +207,9 @@ int main(){
ClearBackground(BLUE);
if(IsKeyDown(KEY_LEFT) && xpos > WINDOW_W/-2)
if(IsKeyDown(KEY_LEFT) && xpos > -XPOS_MAX)
xpos-=5;
if(IsKeyDown(KEY_RIGHT) && xpos < WINDOW_W/2)
if(IsKeyDown(KEY_RIGHT) && xpos < XPOS_MAX)
xpos+=5;
update_planes(2 + score/1000, xpos);
@ -208,17 +218,20 @@ int main(){
draw_towers(&towers, xpos);
snprintf(scorebuf, 100, "Score : %d", score);
snprintf(scorebuf, 100, "Score : %d lost : %d", score, lost);
DrawText(scorebuf, 0,0,30,BLACK);
DrawFPS(0, 100);
if(lost > 1)
if(lost == 3)
lost_men(&score);
score++;
if(score >= 3000)
lost |= 1;
EndDrawing();
}