Refonte Makefile + refonte pli

This commit is contained in:
attilavs2 2025-01-14 23:07:50 +01:00
parent ebe94f5611
commit 6098e9222c
2 changed files with 40 additions and 64 deletions

View file

@ -1,34 +1,32 @@
OUTNAME = ttower
CFLAGS = -O0 -g -Wall -Wextra -I.raylib/include
LDFLAGS = -L./raylib/lib -lraylib -lm
CFLAGS = -O2 -g -Wall -Wextra -I./raylib/include
#linux
#LDFLAGS = -static -L./raylib/lib -lraylib -lm
#windows
LDFLAGS = -static -lraylib -lgdi32 -lwinmm -lm
CC = gcc
OUTPUT = "${OUTNAME}.amd64"
ifeq "${TARGET_IS_WIN}" "true"
CC = x86_64-w64-mingw32-gcc
OUTPUT = "${OUTNAME}.exe"
endif
BUILD_DIR = build
SRC_DIR = src
$(BUILD_DIR)/%.o : $(SRC_DIR)/%.c
${CC} -c ${CFLAGS} -o $@ $< ${LDFLAGS}
OBJS = $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(wildcard $(SRC_DIR)/*.c))
all: $(OBJS)
${CC} ${CFLAGS} -o ${OUTPUT} ${OBJS} ${LDFLAGS}
win: all
mv $(OUTPUT) "$(OUTNAME).exe"
test: all
./${OUTPUT}
clean:
rm -rf ${BUILD_DIR}/*
.PHONY: all builddir test clean
.PHONY: all test clean win

View file

@ -14,6 +14,12 @@
#define PQUEUE_SIZE 256
#define PLANE_W 60
#define PLANE_H 60
#define WINDOW_W 800
#define WINDOW_H 600
typedef struct{
Vector2 pos;
@ -21,6 +27,8 @@ typedef struct{
} Plane;
Rectangle Plane_coll = {.width = PLANE_W, .height = PLANE_H};
int lost = 0;
int planen;
@ -48,64 +56,34 @@ void pop_plane(){
memmove(plane_queue, &plane_queue[1], sizeof(Plane)*planen);
}
#define PLANE_RECT 30
void update_planes(int diff, int xpos){
int i, j;
float x;
int y;
xpos = xpos? xpos:1;
int sign = abs(xpos)/xpos;
float fxpos = xpos/100.0;
//TODO : Redo
if(planen < 2){
int nx = rand() % 600;
int ny = rand() % 400;
spawn_plane((Vector2){nx,ny});
for(y = 0; y < WINDOW_H; y++){
//x = (5*(xpos/100)/WINDOW_W*y)^2
x = (WINDOW_H-y)*((5.0*fxpos)/(float)WINDOW_W);
x *= x * sign;
}
double exp = 2-(0.0016666666*147);
double sign = (double)(abs(xpos)/(double)xpos);
//TODO : Redo
for(i = 0; i < planen; i++){
Plane *pln = &plane_queue[i];
pln->dist += 0.003;
if(pln->dist >= 1){
for(j = 0; j < 8; j++){
double x = pow(sqrt(abs(xpos)),exp) * sign + 153;
exp -= 0.0016666666*60;
//DrawRectangle(x,147+j*60,50,60,BLACK);
//DrawRectangle(x+260,147+j*60,50,60,BLACK);
int coll = 0;
coll = pln->pos.x < x+104 && pln->pos.x+60 > x &&
pln->pos.y > j*60 && pln->pos.y < j*60+60;
coll = coll | (pln->pos.x < x+104+163 && pln->pos.x+60 > x+163 &&
pln->pos.y > j*60 && pln->pos.y < j*60+60);
if(coll){
lost = 1;
}
}
pop_plane();
}
else {
for(j = 0; j < 8; j++){
double x = pow(sqrt(abs(xpos)),exp) * sign + 153;
exp -= 0.0016666666*60;
DrawRectangle(x,147+j*60,50,60,WHITE);
DrawRectangle(x+260,147+j*60,50,60,WHITE);
}
}
}
}
void draw_towers(Texture2D *towers, int xpos){
double x;
float x;
int y;
xpos = xpos == 0 ? 1:xpos;
int sign = (double)(abs(xpos)/(double)xpos);
xpos = sqrt(abs(xpos));
double exp = 2;
xpos = xpos? xpos:1;
int sign = abs(xpos)/xpos;
float fxpos = xpos/100.0;
for(y = 0; y < 600; y++){
x = pow(xpos,exp) * sign;
exp -= 0.0016666666;
for(y = 0; y < WINDOW_H; y++){
//x = (5*(xpos/100)/WINDOW_W*y)^2
x = (WINDOW_H-y)*((5.0*fxpos)/(float)WINDOW_W);
x *= x * sign;
DrawTextureRec(*towers,(Rectangle){.height=1,.width=800,.x=0,.y=y},
(Vector2){round(x),y},WHITE);
}
@ -164,13 +142,11 @@ int main(){
ClearBackground(BLUE);
if(IsKeyDown(KEY_LEFT))
if(IsKeyDown(KEY_LEFT) && xpos > WINDOW_W/-2)
xpos-=3;
if(IsKeyDown(KEY_RIGHT))
if(IsKeyDown(KEY_RIGHT) && xpos < WINDOW_W/2)
xpos+=3;
xpos = clamp(xpos, -200, 200);
update_planes(0, xpos);
draw_planes(&plane);
@ -181,6 +157,8 @@ int main(){
DrawText(scorebuf, 0,0,30,BLACK);
DrawFPS(0, 100);
if(lost)
lost_men(&score);