Skip to content
Snippets Groups Projects
Commit 54f58f4a authored by Réthelyi Bálint's avatar Réthelyi Bálint :no_mouth:
Browse files

jumping is cool (with some handsome bu... featers)

parent 33224baa
No related branches found
No related tags found
1 merge request!5Blint
......@@ -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
......
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -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;
......
......@@ -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;
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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment