From ebe94f56119f7fcb2c7cbc76a113f7dd04a5fcd2 Mon Sep 17 00:00:00 2001 From: attilavs2 Date: Sat, 31 Aug 2024 23:10:08 +0200 Subject: [PATCH] feat : initial commit --- .gitignore | 4 ++ Makefile | 34 ++++++++++ plane.png | Bin 0 -> 817 bytes src/main.c | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++++ towers.png | Bin 0 -> 3088 bytes 5 files changed, 233 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 plane.png create mode 100644 src/main.c create mode 100644 towers.png diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3eee43e --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +build/ +raylib/ +*.amd64 +*.exe diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8f053e0 --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +OUTNAME = ttower + +CFLAGS = -O0 -g -Wall -Wextra -I.raylib/include +LDFLAGS = -L./raylib/lib -lraylib -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} + +test: all + ./${OUTPUT} + +clean: + rm -rf ${BUILD_DIR}/* + +.PHONY: all builddir test clean diff --git a/plane.png b/plane.png new file mode 100644 index 0000000000000000000000000000000000000000..578445880ab0b311cee2260e4e4f9eef8b5c37d6 GIT binary patch literal 817 zcmV-11J3-3P)EX>4Tx04R}tkv&MmKpe$iTg4(32MdZ63|O7)q9Ts93Pq?8YK2xEOfLO`CJjl7 zi=*ILaPVWX>fqw6tAnc`2!4P#J2)x2NQwVT3N2zhIPS;0dyl(!fWJ{;s@W9>RLwHd z$%K&2tqMJ_2qJ<(j9^q^ramW%DR_>rd-(Wz7vovp=l&dhO5S9EPauvn-LQx^h-Wq} zo%23%n3W`j_?&pcpbHW|a$R=$jdRgqKhF#sne;qym{=%wu-w6{WT?c`#8E}nDBquT zS>e3JS*_Gq>z@3Dp}e-T%ypU(B(aDkh!7y7hB7L!5TjKi#YCF+6CVCy$1jpgCRZ7Z z91EyIh2;3b|KNAGW?^d5O$sG|?ibts7z28Cfo9#dzmILZc>)BUfh(=;uQq_$Ptxmc zEqVm>Zvz+CZB5<-E_Z;TCtWfmM+(sN7Ye}p8GTa@7`O#`*WBJ(`#607GSpS-1~@nb z#*37_?(yzmXK(+WY4!I5);4m^^iV3s00006VoOIv00000008+zyMF)x010qNS#tmY zE+YT{E+YYWr9XB6000McNliru=m;GE92q9u0#N_}02y>eSad^gZEa<4bO1wgWnpw> zWFU8GbZ8()Nlj2!fese{009X}L_t(&-tE>gY63wRK;fqZOc{@m8(1fG$OSCDhh@ki z>~jlAWn)rU1q54ighFTz7|g7P||QBuSDaNdazw0q_RQfeo-t zpYwElkj`tg4lo3kDe%-R)A^ky#y$e$Uxx0_I9=ZuPr&TV*gUhePWA4A=^tbBOw)Q* z8wJJY8Py!y3y#gxi`?W*;9C9t1KsD>Z{Jt%FPw2sANY#eWGgWE19&(Ubj(kG2=Ezs z*NzNc0e6RfJQjW+G+P7R8iTh5?+;=7YzJ;?T_`qm-N@iYq2NWW!IMJ46Drk+=df>D vm;Nr@D*QO9PMa%Zup~*6BuSDa=|AlNk +#include +#include +#include +#include + +#include "raylib.h" + +#define min(x, minn) ((x) < (minn) ? (minn):(x)) + +#define max(x, maxn) ((x) > (maxn) ? (maxn):(x)) + +#define clamp(x, minn, maxn) (min(max((x),(maxn)),(minn))) + +#define PQUEUE_SIZE 256 + +typedef struct{ + + Vector2 pos; + float dist; + +} Plane; + +int lost = 0; + +int planen; + +Plane plane_queue[PQUEUE_SIZE]; + +void draw_planes(Texture2D *plane){ + int i; + if(!planen) + return; + for(i = 0; i < planen; i++){ + Plane *pln = &plane_queue[i]; + DrawTextureEx(*plane,pln->pos,0,pln->dist,WHITE); + } +} + +void spawn_plane(Vector2 pos){ + plane_queue[planen].pos = pos; + plane_queue[planen].dist = 0.1; + planen++; +} + +void pop_plane(){ + planen--; + memmove(plane_queue, &plane_queue[1], sizeof(Plane)*planen); +} + +void update_planes(int diff, int xpos){ + int i, j; + + //TODO : Redo + if(planen < 2){ + int nx = rand() % 600; + int ny = rand() % 400; + spawn_plane((Vector2){nx,ny}); + } + + 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; + int y; + xpos = xpos == 0 ? 1:xpos; + int sign = (double)(abs(xpos)/(double)xpos); + xpos = sqrt(abs(xpos)); + double exp = 2; + + for(y = 0; y < 600; y++){ + x = pow(xpos,exp) * sign; + exp -= 0.0016666666; + DrawTextureRec(*towers,(Rectangle){.height=1,.width=800,.x=0,.y=y}, + (Vector2){round(x),y},WHITE); + } +} + +char scorebuf[100]; + +void lost_men(int *score){ + + lost = 0; + + while(!IsKeyDown(KEY_ENTER) && !WindowShouldClose()){ + BeginDrawing(); + DrawRectangle(200,150,400,300,WHITE); + + snprintf(scorebuf,100,"Votre score : %d", *score); + + DrawText(scorebuf, 250, 275, 30, BLACK); + + DrawText("Appuyez sur entrée", 250, 350, 30, BLACK); + + EndDrawing(); + } + + while(planen){ + pop_plane(); + } + + *score = 0; +} + +int main(){ + + int rand_seed = GetTime(); + rand_seed &= 0xFFFFFFFF; + + srand(rand_seed); + + InitWindow(800, 600, "ttower"); + + Texture2D towers = LoadTexture("towers.png"); + + Texture2D plane = LoadTexture("plane.png"); + + int xpos = 0; + + int score = 0; + + SetTargetFPS(60); + + planen = 0; + memset(plane_queue, 0, sizeof(Plane)*PQUEUE_SIZE); + + while(!WindowShouldClose()){ + BeginDrawing(); + + ClearBackground(BLUE); + + if(IsKeyDown(KEY_LEFT)) + xpos-=3; + if(IsKeyDown(KEY_RIGHT)) + xpos+=3; + + xpos = clamp(xpos, -200, 200); + + update_planes(0, xpos); + + draw_planes(&plane); + + draw_towers(&towers, xpos); + + snprintf(scorebuf, 100, "Score : %d", score); + + DrawText(scorebuf, 0,0,30,BLACK); + + if(lost) + lost_men(&score); + + score++; + + EndDrawing(); + } + + CloseWindow(); + + return 0; +} diff --git a/towers.png b/towers.png new file mode 100644 index 0000000000000000000000000000000000000000..625365d3931685799c937d5df748a56722fd4630 GIT binary patch literal 3088 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i1B%QlYbs!1U~I{Bb`J1#c2+1T%1_J8 zNo8Qrm{>c}*5j~)%+dJhqe`Oe++89(5p&-xQtI2v<+?&3t2Ip4NAGWw8n0(p_u>ap z1s{?(zIyOz&FbdW3LJF}7S`EbwC$hB7@UeEi}x^U07O=n7H394-DQ0)*J@^{v{sQ zpX99;F4-f)y~3&W$&Z8oACzxTOU%0D%ca`zPW<*i3FfM@#1$&oI z28wVNctjR6Fz6|RFk{71`!b*)dx@v7EBgx$8F6Kq^?Uh>fI^Zbt`Q~9`MJ5Nc_j?a zMX8A;sVNHOnI#zt?w-B@;f;LaK(k(Wx;TbZ+1RgjZW+^#+CbhLXbgKM;@CVur$;&u_-eP28VBiqI#&Bo=ih`t28B8ot z5fp}i0#GqX1clMSzz7jRWv~Df6<7p2L%{)P7Dx(}0dgr=1cgBbw}btM;dZ!hP~8sl zANAZWj4jmYVl&WUP&iT{_)ub;Jh#IG6g9@-X#ge0;c0*>Zdb#a*63mLXw*YO*#{U9 zn8gfS1f`gvLslJeQSZ<&0~iDFat)IK3K4h?g)?ZERYzRZH!v6i>q&UIhRL8pN%!Lt ZoAh(;uH^0eVt}#D;OXk;vd$@?2>|8yZ1Dg9 literal 0 HcmV?d00001