tip banana in main menu

This commit is contained in:
Tropicananass 2016-05-04 00:51:45 +02:00
parent 318baf5274
commit cfb9a0739f
17 changed files with 231 additions and 112 deletions

BIN
bin/hex

Binary file not shown.

View File

@ -1,7 +1,7 @@
CC=gcc CC=gcc
CFLAGS=-Wall -g -std=c99 -c CFLAGS=-Wall -g -std=c99 -c
#-lm `sdl-config --cflags --libs` -lSDL_ttf #-lm `sdl-config --cflags --libs` -lSDL_ttf
LDFLAGS=-std=c99 -lm `sdl-config --cflags --libs` -lSDL_ttf -lSDL_gfx -lSDL_mixer LDFLAGS=-std=c99 -lm `sdl-config --cflags --libs` -lSDL_ttf -lSDL_gfx -lSDL_mixer -lSDL_image
EXEC=bin/hex EXEC=bin/hex
SRC=src/hex.c src/affichage_plateau.c src/action_plateau.c src/affichage_menu_principal.c src/window.c src/param.c src/en_jeu.c src/menu_principal.c src/draw.c src/action_menu_principal.c src/sound.c src/testJeu.c SRC=src/hex.c src/affichage_plateau.c src/action_plateau.c src/affichage_menu_principal.c src/window.c src/param.c src/en_jeu.c src/menu_principal.c src/draw.c src/action_menu_principal.c src/sound.c src/testJeu.c
#$(wildcard src/*.c) #$(wildcard src/*.c)

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -8,23 +8,22 @@
#include "action_menu_principal.h" #include "action_menu_principal.h"
#include <math.h> #include <math.h>
#include <SDL/SDL_image.h>
#include "globals.h" #include "globals.h"
#include "affichage_menu_principal.h" #include "affichage_menu_principal.h"
#include "sound.h" #include "sound.h"
void deplacement_menu (menu_t m, SDL_Event* event) void deplacement_menu_mouse (menu_t m, const SDL_Event* event)
{ {
char* entries [3][3] = {{"", "Charger", ""}, {"Jouer", "HEX", "Quitter"}, {"", "Options", ""}}; char* entries [3][3] = {{"", "Charger", ""}, {"Jouer", "HEX", "Quitter"}, {"", "Options", ""}};
switch (event->type)
{
case SDL_MOUSEMOTION:
{
vec2 pos = {event->motion.x - m->pos.x + m->l/2 - m->r, event->motion.y - m->pos.y}; vec2 pos = {event->motion.x - m->pos.x + m->l/2 - m->r, event->motion.y - m->pos.y};
int ligne = round(pos.y / (1.5 * m->r) - .5); int ligne = round(pos.y / (1.5 * m->r) - .5);
int colone = round(pos.x / (m->l + 1.) - .5); int colone = round(pos.x / (m->l + 1.) - .5);
vec2 relative = {pos.x % (m->l + 1), pos.y % (int)(1.5 * m->r)}; vec2 relative = {pos.x % (m->l + 1), pos.y % (int)(1.5 * m->r)};
vec2 proj = {relative.y + relative.x / RAC3, relative.y - relative.x / RAC3}; vec2 proj = {relative.y + relative.x / RAC3, relative.y - relative.x / RAC3};
vec2 hex; vec2 hex;
if (ligne % 2) if (ligne % 2)
{ {
if (proj.y < 0 && proj.x < m->r) if (proj.y < 0 && proj.x < m->r)
@ -81,13 +80,15 @@ void deplacement_menu (menu_t m, SDL_Event* event)
Affiche_entry(m, entries [hex.x][hex.y], POINTE); Affiche_entry(m, entries [hex.x][hex.y], POINTE);
play_clik(); play_clik();
} }
break; }
}
case SDL_KEYDOWN: void deplacement_menu_key (menu_t m, SDLKey key)
while (!SDL_PollEvent(event)) {
{
char* entries [3][3] = {{"", "Charger", ""}, {"Jouer", "HEX", "Quitter"}, {"", "Options", ""}};
Affiche_entry(m, entries [m->cur.x][m->cur.y], NORMAL); Affiche_entry(m, entries [m->cur.x][m->cur.y], NORMAL);
switch (event->key.keysym.sym) switch (key)
{ {
case SDLK_RIGHT: case SDLK_RIGHT:
++(m->cur.x); ++(m->cur.x);
@ -122,10 +123,6 @@ void deplacement_menu (menu_t m, SDL_Event* event)
m->cur.y = 2; m->cur.y = 2;
Affiche_entry(m, entries [m->cur.x][m->cur.y], POINTE); Affiche_entry(m, entries [m->cur.x][m->cur.y], POINTE);
play_clik(); play_clik();
SDL_Delay (200);
}
break;
}
} }
bool selection_menu (menu_t m, int* r) bool selection_menu (menu_t m, int* r)
@ -141,6 +138,12 @@ bool selection_menu (menu_t m, int* r)
return true; return true;
case 11: case 11:
*r = M_HEX; *r = M_HEX;
if (m->c == 15)
{
m->c = 0;
}
else
++m->c;
return false; return false;
case 12: case 12:
*r = M_QUITTER; *r = M_QUITTER;

View File

@ -12,7 +12,9 @@
#include <stdbool.h> #include <stdbool.h>
#include "globals.h" #include "globals.h"
void deplacement_menu (menu_t m, SDL_Event* event); void deplacement_menu_mouse (menu_t m, const SDL_Event* event);
void deplacement_menu_key (menu_t m, SDLKey key);
bool selection_menu (menu_t m, int* r); bool selection_menu (menu_t m, int* r);

View File

@ -356,9 +356,10 @@ void free_scroll (scrolling_t s)
SDL_Event scroll_msg (SDL_Surface* window, scrolling_t s) SDL_Event scroll_msg (SDL_Surface* window, scrolling_t s)
{ {
SDL_Event event; int t0 = SDL_GetTicks();
SDL_Event event = {0};
bool delay; bool delay;
while ((delay = !SDL_PollEvent(&event))) while ((delay = !SDL_PollEvent(&event)) && SDL_GetTicks() - t0 < 200)
{ {
for (int i = s->first_msg; i < s->first_msg + s->nb_msg; ++i) for (int i = s->first_msg; i < s->first_msg + s->nb_msg; ++i)
{ {
@ -387,3 +388,90 @@ SDL_Event scroll_msg (SDL_Surface* window, scrolling_t s)
} }
return event; return event;
} }
void banane (SDL_Surface* window)
{
SDL_Surface* gif [8];
SDL_Rect p = {0, 0};
for (int i = 1; i <= 8; ++i)
{
char dir [254];
sprintf (dir, "ressources/.east/Dancing_Banana%d.png", i);
SDL_Surface* tmpB = IMG_Load (dir);
float ch = window->h / (float)tmpB->h, cw = window->w / (float)tmpB->w;
if (cw < ch)
{
gif [i - 1] = rotozoomSurface(tmpB, .0, cw, 1);
p.y = (window->h - gif [i - 1]->h) / 2;
}
else
{
gif [i - 1] = rotozoomSurface(tmpB, .0, ch, 1);
p.x = (window->w - gif [i - 1]->w) / 2;
}
SDL_FreeSurface (tmpB);
}
SDL_Surface* erase = SDL_CreateRGBSurface (SDL_HWSURFACE, gif[0]->w, gif[0]->h, window->format->BitsPerPixel, 0, 0, 0, 0);
p.w = gif [0]->w;
p.h = gif [0]->h;
SDL_BlitSurface (window, &p, erase, NULL);
bool end = false;
int i = 0;
while (!end)
{
if (!(SDL_GetTicks() % 100))
{
SDL_BlitSurface (gif [i%8], NULL, window, &p);
SDL_Flip (window);
SDL_BlitSurface (erase, NULL, window, &p);
i = (i + 1) % 8 + 8;
}
SDL_Event e;
SDL_PollEvent (&e);
if (e.type == SDL_QUIT || (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE))
end = true;
}
for (int i = 0; i < 8; ++i)
{
SDL_FreeSurface (gif [i]);
}
SDL_FreeSurface (erase);
}
void east1 (SDL_Surface* window, SDLKey key)
{
static int banana = 0;
switch (key)
{
case SDLK_a:
if (banana % 2)
++banana;
else
banana = 0;
break;
case SDLK_b:
if (banana == 0)
++banana;
else
banana = 0;
break;
case SDLK_n:
if (banana == 2 || banana == 4)
++banana;
else
banana = 0;
break;
default:
banana = 0;
}
if (banana == 6)
{
banane (window);
banana = 0;
}
}

View File

@ -23,4 +23,6 @@ void free_scroll (scrolling_t s);
SDL_Event scroll_msg (SDL_Surface* window, scrolling_t s); SDL_Event scroll_msg (SDL_Surface* window, scrolling_t s);
void east1 (SDL_Surface* window, SDLKey key);
#endif /* _AFFICHAGE_MENU_PRICIPAL_ */ #endif /* _AFFICHAGE_MENU_PRICIPAL_ */

View File

@ -18,7 +18,7 @@ void en_jeu (SDL_Surface* window)
Mix_PlayMusic(param->music, -1); Mix_PlayMusic(param->music, -1);
plateau_t plateau = init_plateau (window); plateau_t plateau = init_plateau (window);
vec2 c = {0, 0}; vec2 c = {0, 0};
bool end = 0; bool end = false;
while (!end) while (!end)
{ {
SDL_Event event; SDL_Event event;
@ -31,7 +31,7 @@ void en_jeu (SDL_Surface* window)
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_ESCAPE) if (event.key.keysym.sym == SDLK_ESCAPE)
end = 1; end = true;
else if (event.key.keysym.sym == SDLK_f) else if (event.key.keysym.sym == SDLK_f)
{ {
window = fullscreen_window(window); window = fullscreen_window(window);
@ -49,10 +49,17 @@ void en_jeu (SDL_Surface* window)
deplacement(plateau, &event, &c); deplacement(plateau, &event, &c);
break; break;
case SDL_QUIT: case SDL_QUIT:
end = 1; end = true;
break; break;
} }
} }
while (!end)
{
SDL_Event event;
SDL_WaitEvent (&event);
if (event.type == SDL_QUIT)
end = true;
}
free_plateau (plateau); free_plateau (plateau);
Mix_HaltMusic(); Mix_HaltMusic();
Mix_RewindMusic(); Mix_RewindMusic();

View File

@ -45,6 +45,7 @@ typedef struct s_menu {
vec2 pos; vec2 pos;
vec2 cur; vec2 cur;
SDL_Surface* window; SDL_Surface* window;
int c;
}* menu_t; }* menu_t;
typedef struct s_plateau { typedef struct s_plateau {

View File

@ -11,6 +11,7 @@ menu_t init_menu_principal (SDL_Surface* window)
m->window = window; m->window = window;
m->cur.x = 1; m->cur.x = 1;
m->cur.y = 1; m->cur.y = 1;
m->c = 0;
return m; return m;
} }
@ -111,18 +112,33 @@ int menu_principal (SDL_Surface* window)
else if (event.key.keysym.sym == SDLK_RETURN) else if (event.key.keysym.sym == SDLK_RETURN)
end = selection_menu (m, &retour); end = selection_menu (m, &retour);
else if (SDLK_UP <= event.key.keysym.sym && event.key.keysym.sym <= SDLK_LEFT) else if (SDLK_UP <= event.key.keysym.sym && event.key.keysym.sym <= SDLK_LEFT)
deplacement_menu (m, &event); deplacement_menu_key (m, event.key.keysym.sym);
else
east1 (window, event.key.keysym.sym);
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
end = selection_menu (m, &retour); end = selection_menu (m, &retour);
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
deplacement_menu (m, &event); deplacement_menu_mouse (m, &event);
break; break;
case SDL_QUIT: case SDL_QUIT:
retour = M_QUITTER; retour = M_QUITTER;
end = 1; end = 1;
break; break;
default:
{
Uint8 *keyboard = SDL_GetKeyState(NULL);
if (keyboard [SDLK_UP])
deplacement_menu_key (m, SDLK_UP);
if (keyboard [SDLK_DOWN])
deplacement_menu_key (m, SDLK_DOWN);
if (keyboard [SDLK_LEFT])
deplacement_menu_key (m, SDLK_LEFT);
if (keyboard [SDLK_RIGHT])
deplacement_menu_key (m, SDLK_RIGHT);
}
} }
if (retour == M_OPTIONS) if (retour == M_OPTIONS)
{ {