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

jumping process is 90%

parent c179df89
No related branches found
No related tags found
1 merge request!4Blint
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -21,7 +21,7 @@ int main(int argc, char *argv[]) {
SDL_Texture *bagoly = kep_betolt(renderer, "infoc.png");
SDL_TimerID timer_id = SDL_AddTimer(1000, idozit, NULL);
SDL_TimerID timer_id = SDL_AddTimer(1000/60, idozit, NULL);
SDL_RenderPresent(renderer);
......
......@@ -9,12 +9,17 @@
#include <math.h>
int v = 5;
//int vx = 0;
//int vy = 0;
double g = 9.82;
double pi = 3.14159;
int v = 8;
int vj = 25;
int t = 0;
int ipszilon = 0;
double g = 5; //saját gravitáció, mivel a 9.82 túl nehéz lenne... :'(
bool jump = false;
int VPos(int y0){
int time = t/2;
return y0 - vj*time + ((int)g/2)*time*time;
}
static void move(SDL_Event ev, int *x, int *y)
{
......@@ -33,45 +38,17 @@ static void move(SDL_Event ev, int *x, int *y)
break;
}
if (ev.key.keysym.sym == SDLK_w || ev.key.keysym.sym == SDLK_UP) {
*y -= v;
break;
}
if (ev.key.keysym.sym == SDLK_s || ev.key.keysym.sym == SDLK_DOWN) {
*y += v;
break;
}
/*case SDL_KEYUP:
switch (ev.key.keysym.sym) {
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;
case SDLK_a:
if (vx < 0)
vx = 0;
break;
case SDLK_d:
if (vx > 0)
vx = 0;
break;
case SDLK_w:
if (vy < 0)
vy = 0;
break;
case SDLK_s:
if (vy > 0)
vy = 0;
break;
default:
break;
}
break;*/
case SDL_USEREVENT:
t++;
break;
......@@ -86,6 +63,8 @@ void keywatcher(SDL_Event ev, SDL_Texture *kep, int x, int y, bool *quit, bool *
switch (ev.key.keysym.sym) {
case SDLK_i:
kirajzol(renderer, kep, x, y);
t = 0;
ipszilon = 500;
*moving = true;
break;
case SDLK_ESCAPE:
......@@ -116,17 +95,43 @@ void move_draw(SDL_Event ev, SDL_Texture *kep, int *x, int *y, Palyaelem *eleje)
{
move(ev, x, y);
Palyaelem *mozgo;
for (mozgo = eleje; mozgo != NULL; mozgo = mozgo->kov)
{
if ((*x <= mozgo->x && (*x + owl) > (mozgo->x) ) || (*x >= mozgo->x && (*x + owl) <= (mozgo->x + mozgo->hossz)))
{
if ((*y + owl) <= mozgo->y + mozgo->magassag && (*y + owl) >= mozgo->y)
{
*y = mozgo->y - owl;
jump = false;
if (ev.key.keysym.sym == SDLK_w || ev.key.keysym.sym == SDLK_UP || ev.key.keysym.sym == SDLK_SPACE)
jump = true;
}
}
}
if (jump)
{
*y = VPos(ipszilon);
}
jump = true;
//talajszintnél lejjebb nem ugrik
if (*y >= (H -2*owl))
{
*y = H - 2*owl;
}
//pálya bal szélénél eltolja a koordinátákat
if (*x > (W - owl))
{
*x = W - owl;
palyamozgat(eleje, v);
}
//pálya jobb szélénél tolja el a koordinátákat
if (*x < 0)
{
*x = 0;
......
......@@ -17,7 +17,7 @@ extern double g;
extern double pi;
static void move(SDL_Event ev, int *x, int *y);
//static void move(SDL_Event ev, int *x, int *y);
void keywatcher(SDL_Event ev, SDL_Texture *kep, int x, int y, bool *quit, bool *moving);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment