tip banana in main menu
2
makefile
@ -1,7 +1,7 @@
|
||||
CC=gcc
|
||||
CFLAGS=-Wall -g -std=c99 -c
|
||||
#-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
|
||||
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)
|
||||
|
BIN
ressources/.east/Dancing_Banana1.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
ressources/.east/Dancing_Banana2.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
ressources/.east/Dancing_Banana3.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
ressources/.east/Dancing_Banana4.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
ressources/.east/Dancing_Banana5.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
ressources/.east/Dancing_Banana6.png
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
ressources/.east/Dancing_Banana7.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
BIN
ressources/.east/Dancing_Banana8.png
Normal file
After Width: | Height: | Size: 2.3 KiB |
@ -8,124 +8,121 @@
|
||||
#include "action_menu_principal.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <SDL/SDL_image.h>
|
||||
#include "globals.h"
|
||||
#include "affichage_menu_principal.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", ""}};
|
||||
switch (event->type)
|
||||
|
||||
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 colone = round(pos.x / (m->l + 1.) - .5);
|
||||
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 hex;
|
||||
|
||||
if (ligne % 2)
|
||||
{
|
||||
case SDL_MOUSEMOTION:
|
||||
{
|
||||
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 colone = round(pos.x / (m->l + 1.) - .5);
|
||||
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 hex;
|
||||
if (ligne % 2)
|
||||
if (proj.y < 0 && proj.x < m->r)
|
||||
{
|
||||
if (proj.y < 0 && proj.x < m->r)
|
||||
{
|
||||
/* haut */
|
||||
hex.y = ligne - 1;
|
||||
hex.x = colone - ligne / 2;
|
||||
}
|
||||
else if (relative.x > m->l / 2)
|
||||
{
|
||||
/* bas droite */
|
||||
hex.y = ligne;
|
||||
hex.x = colone - ligne / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* bas gauche */
|
||||
hex.y = ligne;
|
||||
hex.x = colone - ligne / 2 - 1;
|
||||
}
|
||||
/* haut */
|
||||
hex.y = ligne - 1;
|
||||
hex.x = colone - ligne / 2;
|
||||
}
|
||||
else if (relative.x > m->l / 2)
|
||||
{
|
||||
/* bas droite */
|
||||
hex.y = ligne;
|
||||
hex.x = colone - ligne / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (-proj.y > m->r/2)
|
||||
{
|
||||
/* haut droite */
|
||||
hex.y = ligne - 1;
|
||||
hex.x = colone - ligne / 2 + 1;
|
||||
}
|
||||
else if (proj.x < m->r/2)
|
||||
{
|
||||
/* haut gauche */
|
||||
hex.y = ligne - 1;
|
||||
hex.x = colone - ligne / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* bas */
|
||||
hex.y = ligne;
|
||||
hex.x = colone - ligne / 2;
|
||||
}
|
||||
/* bas gauche */
|
||||
hex.y = ligne;
|
||||
hex.x = colone - ligne / 2 - 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (-proj.y > m->r/2)
|
||||
{
|
||||
/* haut droite */
|
||||
hex.y = ligne - 1;
|
||||
hex.x = colone - ligne / 2 + 1;
|
||||
}
|
||||
else if (proj.x < m->r/2)
|
||||
{
|
||||
/* haut gauche */
|
||||
hex.y = ligne - 1;
|
||||
hex.x = colone - ligne / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* bas */
|
||||
hex.y = ligne;
|
||||
hex.x = colone - ligne / 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 > hex.x || hex.x >= 3 || 0 > hex.y || hex.y >= 3 || (hex.x != 1 && hex.y != 1))
|
||||
{
|
||||
hex.x = 1;
|
||||
hex.y = 1;
|
||||
}
|
||||
if (hex.x != m->cur.x || hex.y != m->cur.y)
|
||||
{
|
||||
Affiche_entry(m, entries [m->cur.x][m->cur.y], NORMAL);
|
||||
m->cur.x = hex.x;
|
||||
m->cur.y = hex.y;
|
||||
Affiche_entry(m, entries [hex.x][hex.y], POINTE);
|
||||
play_clik();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDL_KEYDOWN:
|
||||
while (!SDL_PollEvent(event))
|
||||
{
|
||||
Affiche_entry(m, entries [m->cur.x][m->cur.y], NORMAL);
|
||||
switch (event->key.keysym.sym)
|
||||
{
|
||||
case SDLK_RIGHT:
|
||||
++(m->cur.x);
|
||||
if (m->cur.y != 1)
|
||||
m->cur.y = 1;
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
--(m->cur.x);
|
||||
if (m->cur.y != 1)
|
||||
m->cur.y = 1;
|
||||
break;
|
||||
case SDLK_UP:
|
||||
--(m->cur.y);
|
||||
if (m->cur.x != 1)
|
||||
m->cur.x = 1;
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
++(m->cur.y);
|
||||
if (m->cur.x != 1)
|
||||
m->cur.x = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (m->cur.x >= 3)
|
||||
m->cur.x = 0;
|
||||
if (m->cur.x < 0)
|
||||
m->cur.x = 2;
|
||||
if (m->cur.y >= 3)
|
||||
m->cur.y = 0;
|
||||
if (m->cur.y < 0)
|
||||
m->cur.y = 2;
|
||||
Affiche_entry(m, entries [m->cur.x][m->cur.y], POINTE);
|
||||
play_clik();
|
||||
SDL_Delay (200);
|
||||
}
|
||||
if (0 > hex.x || hex.x >= 3 || 0 > hex.y || hex.y >= 3 || (hex.x != 1 && hex.y != 1))
|
||||
{
|
||||
hex.x = 1;
|
||||
hex.y = 1;
|
||||
}
|
||||
if (hex.x != m->cur.x || hex.y != m->cur.y)
|
||||
{
|
||||
Affiche_entry(m, entries [m->cur.x][m->cur.y], NORMAL);
|
||||
m->cur.x = hex.x;
|
||||
m->cur.y = hex.y;
|
||||
Affiche_entry(m, entries [hex.x][hex.y], POINTE);
|
||||
play_clik();
|
||||
}
|
||||
}
|
||||
|
||||
void deplacement_menu_key (menu_t m, SDLKey key)
|
||||
{
|
||||
|
||||
char* entries [3][3] = {{"", "Charger", ""}, {"Jouer", "HEX", "Quitter"}, {"", "Options", ""}};
|
||||
|
||||
Affiche_entry(m, entries [m->cur.x][m->cur.y], NORMAL);
|
||||
switch (key)
|
||||
{
|
||||
case SDLK_RIGHT:
|
||||
++(m->cur.x);
|
||||
if (m->cur.y != 1)
|
||||
m->cur.y = 1;
|
||||
break;
|
||||
case SDLK_LEFT:
|
||||
--(m->cur.x);
|
||||
if (m->cur.y != 1)
|
||||
m->cur.y = 1;
|
||||
break;
|
||||
case SDLK_UP:
|
||||
--(m->cur.y);
|
||||
if (m->cur.x != 1)
|
||||
m->cur.x = 1;
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
++(m->cur.y);
|
||||
if (m->cur.x != 1)
|
||||
m->cur.x = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (m->cur.x >= 3)
|
||||
m->cur.x = 0;
|
||||
if (m->cur.x < 0)
|
||||
m->cur.x = 2;
|
||||
if (m->cur.y >= 3)
|
||||
m->cur.y = 0;
|
||||
if (m->cur.y < 0)
|
||||
m->cur.y = 2;
|
||||
Affiche_entry(m, entries [m->cur.x][m->cur.y], POINTE);
|
||||
play_clik();
|
||||
}
|
||||
|
||||
bool selection_menu (menu_t m, int* r)
|
||||
@ -141,6 +138,12 @@ bool selection_menu (menu_t m, int* r)
|
||||
return true;
|
||||
case 11:
|
||||
*r = M_HEX;
|
||||
if (m->c == 15)
|
||||
{
|
||||
m->c = 0;
|
||||
}
|
||||
else
|
||||
++m->c;
|
||||
return false;
|
||||
case 12:
|
||||
*r = M_QUITTER;
|
||||
|
@ -12,7 +12,9 @@
|
||||
#include <stdbool.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);
|
||||
|
||||
|
@ -356,9 +356,10 @@ void free_scroll (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;
|
||||
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)
|
||||
{
|
||||
@ -387,3 +388,90 @@ SDL_Event scroll_msg (SDL_Surface* window, scrolling_t s)
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -23,4 +23,6 @@ void free_scroll (scrolling_t s);
|
||||
|
||||
SDL_Event scroll_msg (SDL_Surface* window, scrolling_t s);
|
||||
|
||||
void east1 (SDL_Surface* window, SDLKey key);
|
||||
|
||||
#endif /* _AFFICHAGE_MENU_PRICIPAL_ */
|
||||
|
13
src/en_jeu.c
@ -18,7 +18,7 @@ void en_jeu (SDL_Surface* window)
|
||||
Mix_PlayMusic(param->music, -1);
|
||||
plateau_t plateau = init_plateau (window);
|
||||
vec2 c = {0, 0};
|
||||
bool end = 0;
|
||||
bool end = false;
|
||||
while (!end)
|
||||
{
|
||||
SDL_Event event;
|
||||
@ -31,7 +31,7 @@ void en_jeu (SDL_Surface* window)
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym == SDLK_ESCAPE)
|
||||
end = 1;
|
||||
end = true;
|
||||
else if (event.key.keysym.sym == SDLK_f)
|
||||
{
|
||||
window = fullscreen_window(window);
|
||||
@ -49,10 +49,17 @@ void en_jeu (SDL_Surface* window)
|
||||
deplacement(plateau, &event, &c);
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
end = 1;
|
||||
end = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (!end)
|
||||
{
|
||||
SDL_Event event;
|
||||
SDL_WaitEvent (&event);
|
||||
if (event.type == SDL_QUIT)
|
||||
end = true;
|
||||
}
|
||||
free_plateau (plateau);
|
||||
Mix_HaltMusic();
|
||||
Mix_RewindMusic();
|
||||
|
@ -45,6 +45,7 @@ typedef struct s_menu {
|
||||
vec2 pos;
|
||||
vec2 cur;
|
||||
SDL_Surface* window;
|
||||
int c;
|
||||
}* menu_t;
|
||||
|
||||
typedef struct s_plateau {
|
||||
|
@ -11,6 +11,7 @@ menu_t init_menu_principal (SDL_Surface* window)
|
||||
m->window = window;
|
||||
m->cur.x = 1;
|
||||
m->cur.y = 1;
|
||||
m->c = 0;
|
||||
return m;
|
||||
}
|
||||
|
||||
@ -111,18 +112,33 @@ int menu_principal (SDL_Surface* window)
|
||||
else if (event.key.keysym.sym == SDLK_RETURN)
|
||||
end = selection_menu (m, &retour);
|
||||
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;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
end = selection_menu (m, &retour);
|
||||
break;
|
||||
case SDL_MOUSEMOTION:
|
||||
deplacement_menu (m, &event);
|
||||
deplacement_menu_mouse (m, &event);
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
retour = M_QUITTER;
|
||||
end = 1;
|
||||
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)
|
||||
{
|
||||
|