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

menu is on and play function is work

parent 6878fc0e
Branches
No related tags found
1 merge request!5Blint
......@@ -6,20 +6,6 @@
#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
......@@ -40,22 +26,6 @@ stdbool.h
math.h
-
/home/blint/projects/nhf/view.c
view.h
/home/blint/projects/nhf/view.h
SDL2/SDL.h
-
SDL2/SDL_image.h
-
SDL2/SDL2_gfxPrimitives.h
-
SDL2/SDL_ttf.h
-
stdlib.h
-
stdio.h
-
/home/blint/projects/nhf/view.h
SDL2/SDL.h
-
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -37,7 +37,7 @@ int main(int argc, char *argv[]) {
bool quit = false;
bool moving = false;
bool reset = false;
bool loading = false;
int elozo_x = 0;
int elozo_y = W - 2*owl;
......@@ -46,6 +46,25 @@ int main(int argc, char *argv[]) {
elem = palya_gen(elem, platform,50);
Button start;
start.x = W/6;
start.y = H/9;
start.w = (W - W/6) - start.x;
start.h = (2*H/9) - start.y;
strcpy(start.title, "Kezdjük már el!");
start.over = false;
start.click = false;
Button load;
load.x = W/6;
load.y = (2*H/9 + H/18);
load.w = (W - W/6) - load.x;
load.h = (3*H/9 + H/18) - load.y;
strcpy(load.title, "Betöltöm a korábbi pályát");
load.over = false;
load.click = false;
......@@ -64,7 +83,7 @@ int main(int argc, char *argv[]) {
} else
{
menu(ev);
menu(ev, &start, &load, &moving, &loading);
}
SDL_RenderPresent(renderer);
......
......@@ -81,10 +81,10 @@ void keywatcher(SDL_Event ev, SDL_Texture *kep, int x, int y, bool *quit, bool *
switch (ev.type) {
case SDL_KEYUP:
switch (ev.key.keysym.sym) {
case SDLK_i:
/*case SDLK_i:
kirajzol(kep, x, y);
*moving = true;
break;
break;*/
case SDLK_ESCAPE:
*quit = true;
break;
......@@ -165,15 +165,23 @@ void move_draw(SDL_Event ev, SDL_Texture *kep, int *x, int *y, Palyaelem *eleje)
Button clickwatcher(SDL_Event ev, Button button)
{
int x, y;
switch (ev.type) {
case SDL_MOUSEMOTION:
if (ev.motion.x <= button.x && ev.motion.x >= (button.x + button.w) && ev.motion.y <= button.y && ev.motion.y >= (button.y + button.h))
x = ev.motion.x;
y = ev.motion.y;
if ((x >= button.x && x <= (button.x + button.w) ) && (y >= button.y && y <= (button.y + button.h))){
button.over = true;
else button.over = false;
}
else{
button.over = false;
}
break;
case SDL_MOUSEBUTTONUP:
if (ev.motion.x <= button.x && ev.motion.x >= (button.x + button.w) && ev.motion.y <= button.y && ev.motion.y >= (button.y + button.h))
x = ev.motion.x;
y = ev.motion.y;
if ((x >= button.x && x <= (button.x + button.w) ) && (y >= button.y && y <= (button.y + button.h)))
button.click = true;
else button.click = false;
break;
......@@ -184,30 +192,33 @@ Button clickwatcher(SDL_Event ev, Button button)
return button;
}
void menu(SDL_Event ev)
void menu(SDL_Event ev, Button *start, Button *load, bool *moving, bool *loading)
{
Color red = (Color){255, 0, 0};
Color green = (Color){0, 255, 0};
Color white = (Color){255, 255, 255};
Button start;
start.x = W/6;
start.y = H/9;
start.w = (W - W/6) - start.x;
start.h = (2*H/9) - start.y;
strcpy(start.title, "Kezdjük már el!");
start.over = false;
start.click = false;
Button load;
load.x = W/6;
load.y = (2*H/9 + H/18);
load.w = (W - W/6) - load.x;
load.h = (3*H/9 + H/18) - load.y;
strcpy(load.title, "Betöltöm a korábbi pályát");
load.over = false;
load.click = false;
draw_button(start, red, white);
draw_button(load, red, white);
*start = clickwatcher(ev, *start);
*load = clickwatcher(ev, *load);
if (start->over)
draw_button(*start, green, white);
else
draw_button(*start, red, white);
if (load->over)
draw_button(*load, green, white);
else
draw_button(*load, red, white);
if (start->click)
*moving = true;
else
*moving = false;
if (load->click)
*loading = true;
else
*loading = false;
}
\ No newline at end of file
......@@ -26,6 +26,6 @@ Palyaelem *palyamozgat(Palyaelem *eleje, int x);
Button clickwatcher(SDL_Event ev, Button button);
void menu(SDL_Event ev);
void menu(SDL_Event ev, Button *start, Button *load, bool *moving, bool *loading);
#endif //NHF_MOVE_H
\ No newline at end of file
......@@ -207,4 +207,6 @@ void draw_button(Button button, Color button_color, Color text_color)
hova.h = button_s->h;
SDL_RenderCopy(renderer, button_t, NULL, &hova);
SDL_FreeSurface(button_s);
SDL_DestroyTexture(button_t);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment