diff --git a/cmake-build-debug/CMakeFiles/nhf.dir/C.includecache b/cmake-build-debug/CMakeFiles/nhf.dir/C.includecache index 1d7686855e712075dae64f9a64526ab1340e54b5..6c406a360f832d31c7b4cb1dd6c264e8a86eb5f1 100644 --- a/cmake-build-debug/CMakeFiles/nhf.dir/C.includecache +++ b/cmake-build-debug/CMakeFiles/nhf.dir/C.includecache @@ -6,6 +6,20 @@ #IncludeRegexTransform: +/home/blint/projects/nhf/main.c +view.h +/home/blint/projects/nhf/view.h +move.h +/home/blint/projects/nhf/move.h +SDL2/SDL_image.h +- +SDL2/SDL2_gfxPrimitives.h +- +stdbool.h +- +time.h +- + /home/blint/projects/nhf/move.c move.h /home/blint/projects/nhf/move.h @@ -15,8 +29,6 @@ SDL.h - stdbool.h - -math.h -- /home/blint/projects/nhf/move.h view.h diff --git a/cmake-build-debug/CMakeFiles/nhf.dir/main.c.o b/cmake-build-debug/CMakeFiles/nhf.dir/main.c.o index 1badde9d94d4da39773c09a263fc5ca93f833b78..9aa1369685dab0f9b7f77db2f76d008563bf353a 100644 Binary files a/cmake-build-debug/CMakeFiles/nhf.dir/main.c.o and b/cmake-build-debug/CMakeFiles/nhf.dir/main.c.o differ diff --git a/cmake-build-debug/CMakeFiles/nhf.dir/move.c.o b/cmake-build-debug/CMakeFiles/nhf.dir/move.c.o index 9cdd0c5e62a76bcb042f8b8d364803aac063a2fb..6f37d5fcef15346ac4c9566d5257e469bd7dd0a8 100644 Binary files a/cmake-build-debug/CMakeFiles/nhf.dir/move.c.o and b/cmake-build-debug/CMakeFiles/nhf.dir/move.c.o differ diff --git a/cmake-build-debug/nhf b/cmake-build-debug/nhf index ebcac7722abbdef13c6ddef2572d78bd16ae40b1..76f49be00cfdda8883bef1dd2b1d79c0f8a956b6 100755 Binary files a/cmake-build-debug/nhf and b/cmake-build-debug/nhf differ diff --git a/main.c b/main.c index c408f7c27a7947a670307216d2cd54a18e390ee0..3e413bd3131de8de286074829b74688f122054d2 100644 --- a/main.c +++ b/main.c @@ -5,6 +5,16 @@ #include <stdbool.h> #include <time.h> +void freeing(Palyaelem *elem) +{ + Palyaelem *mozgo = elem; + while (mozgo != NULL) + { + Palyaelem *kov = mozgo->kov; + free(mozgo); + mozgo = kov; + } +} Uint32 idozit(Uint32 ms, void *param) { SDL_Event ev; @@ -21,7 +31,7 @@ int main(int argc, char *argv[]) { SDL_Texture *bagoly = kep_betolt(renderer, "infoc.png"); - SDL_TimerID timer_id = SDL_AddTimer(1000/60, idozit, NULL); + SDL_TimerID timer_id = SDL_AddTimer(1000/120, idozit, NULL); SDL_RenderPresent(renderer); @@ -57,6 +67,7 @@ int main(int argc, char *argv[]) { } SDL_DestroyTexture(bagoly); + freeing(elem); SDL_Quit(); return 0; diff --git a/move.c b/move.c index 0f76ee085f2b5b01972720f05f17b78128eadd02..b16a7082faca14be07ddb0690c64df2ec7763f1e 100644 --- a/move.c +++ b/move.c @@ -6,53 +6,81 @@ #include "view.h" #include <SDL.h> #include <stdbool.h> -#include <math.h> -int v = 8; +int v = 5; int vj = 25; +int vx = 0, vy = 0; int t = 0; int ipszilon = 0; double g = 5; //saját gravitáció, mivel a 9.82 túl nehéz lenne... :'( +int jump_t = 0; bool jump = false; + int VPos(int y0){ - int time = t/2; + int time = t/4; return y0 - vj*time + ((int)g/2)*time*time; } -static void move(SDL_Event ev, int *x, int *y) +static bool move(SDL_Event ev, int *x, const int *y) { + switch (ev.type) { - case SDL_MOUSEMOTION: - return; case SDL_KEYDOWN: if (ev.key.keysym.sym == SDLK_a || ev.key.keysym.sym == SDLK_LEFT) { - *x -= v; + vx = -1; + vx *= v; break; } if (ev.key.keysym.sym == SDLK_d || ev.key.keysym.sym == SDLK_RIGHT) { - *x += v; + vx = 1; + vx *= v; break; } if (ev.key.keysym.sym == SDLK_w || ev.key.keysym.sym == SDLK_UP || ev.key.keysym.sym == SDLK_SPACE) { - //*y -= v; - t = 0; - ipszilon = *y; - jump = true; + + if (jump_t < 2) + { + t = 0; + ipszilon = *y; + jump = true; + } + jump_t++; break; } + case SDL_KEYUP: + switch (ev.key.keysym.sym) { + + case SDLK_a: + if (vx < 0) + vx = 0; + break; + + case SDLK_d: + if (vx > 0) + vx = 0; + break; + default: + break; + } + break; + + case SDL_USEREVENT: t++; break; + default: + return false; } + return true; } @@ -93,7 +121,10 @@ Palyaelem *palyamozgat(Palyaelem *eleje, int x) void move_draw(SDL_Event ev, SDL_Texture *kep, int *x, int *y, Palyaelem *eleje) { - move(ev, x, y); + if(move(ev, x, y)){ + *x += vx; + *y += vy; + } Palyaelem *mozgo; for (mozgo = eleje; mozgo != NULL; mozgo = mozgo->kov) @@ -104,8 +135,13 @@ void move_draw(SDL_Event ev, SDL_Texture *kep, int *x, int *y, Palyaelem *eleje) { *y = mozgo->y - owl; jump = false; + jump_t = 0; if (ev.key.keysym.sym == SDLK_w || ev.key.keysym.sym == SDLK_UP || ev.key.keysym.sym == SDLK_SPACE) + { jump = true; + jump_t++; + } + } } } @@ -120,6 +156,7 @@ void move_draw(SDL_Event ev, SDL_Texture *kep, int *x, int *y, Palyaelem *eleje) if (*y >= (H -2*owl)) { *y = H - 2*owl; + jump_t = 0; }