almost
This commit is contained in:
parent
b8a36bc685
commit
893a5cb38b
@ -1,227 +0,0 @@
|
||||
/*
|
||||
* action_menu_principal.c
|
||||
*
|
||||
* Created on: 21 avr. 2016
|
||||
* Author: nathan
|
||||
*/
|
||||
|
||||
#include "action_menu_principal.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <SDL/SDL_image.h>
|
||||
#include <SDL/SDL_mixer.h>
|
||||
#include <SDL/SDL_rotozoom.h>
|
||||
|
||||
#include "globals.h"
|
||||
#include "affichage_menu_principal.h"
|
||||
#include "sound.h"
|
||||
void deplacement_menu_mouse (menu_t m, const SDL_Event* event)
|
||||
{
|
||||
char* entries [3][3] = {{"", "Charger", ""}, {"Jouer", "HEX", "Quitter"}, {"", "Options", ""}};
|
||||
|
||||
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)
|
||||
{
|
||||
/* 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;
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
void boom (SDL_Surface* window)
|
||||
{
|
||||
SDL_Surface* tmp = IMG_Load ("ressources/.east/Boom.png");
|
||||
SDL_Surface* boom = rotozoomSurface(tmp, .0, fmin(window->h / (float)tmp->h, window->w / (float)tmp->w), 1);
|
||||
SDL_Rect p = {(window->w - boom->w) / 2, (window->h - boom->h) / 2};
|
||||
SDL_Surface* lum = SDL_CreateRGBSurface (SDL_HWSURFACE, window->w, window->h, window->format->BitsPerPixel, 0, 0, 0, 0);
|
||||
|
||||
SDL_FreeSurface(tmp);
|
||||
tmp = SDL_CreateRGBSurface (SDL_HWSURFACE, window->w, window->h, window->format->BitsPerPixel, 0, 0, 0, 0);
|
||||
SDL_BlitSurface (window, NULL, tmp, NULL);
|
||||
|
||||
Mix_Chunk* boomS = Mix_LoadWAV("ressources/.east/Boom.wav");
|
||||
Mix_VolumeChunk (boomS, .1 * MIX_MAX_VOLUME);
|
||||
if (boomS == NULL)
|
||||
fprintf (stderr, "ressources/.east/Boom.mp3 : %s\n", SDL_GetError());
|
||||
Mix_PlayChannel(0, boomS, 0);
|
||||
|
||||
bool end = false;
|
||||
|
||||
int i = 255;
|
||||
while (i >= 0)
|
||||
{
|
||||
if (!(SDL_GetTicks() % 40))
|
||||
{
|
||||
SDL_FillRect (window, NULL, SDL_MapRGB (window->format, 0, 0, 0));
|
||||
|
||||
SDL_BlitSurface (boom, NULL, window, &p);
|
||||
|
||||
Uint32 white = SDL_MapRGB (window->format, 255, 255, 255);
|
||||
SDL_FillRect (lum, NULL, white);
|
||||
SDL_SetAlpha(lum, SDL_SRCALPHA, i);
|
||||
SDL_BlitSurface (lum, NULL, window, NULL);
|
||||
SDL_Flip (window);
|
||||
i -= 4;
|
||||
}
|
||||
}
|
||||
|
||||
Uint32 black = SDL_MapRGB (window->format, 0, 0, 0);
|
||||
SDL_FillRect (lum, NULL, black);
|
||||
SDL_SetAlpha(lum, SDL_SRCALPHA, 1);
|
||||
|
||||
while (i < 256)
|
||||
{
|
||||
if (!(SDL_GetTicks() % 10))
|
||||
{
|
||||
SDL_BlitSurface (lum, NULL, window, NULL);
|
||||
SDL_Flip (window);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
while (!end)
|
||||
{
|
||||
SDL_Event e;
|
||||
SDL_PollEvent (&e);
|
||||
if (e.type == SDL_QUIT || (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE))
|
||||
end = true;
|
||||
}
|
||||
|
||||
SDL_BlitSurface (tmp, NULL, window, NULL);
|
||||
|
||||
SDL_FreeSurface(tmp);
|
||||
SDL_FreeSurface(boom);
|
||||
SDL_FreeSurface(lum);
|
||||
Mix_FreeChunk (boomS);
|
||||
}
|
||||
|
||||
bool selection_menu (menu_t m, int* r)
|
||||
{
|
||||
switch (10 * m->cur.x + m->cur.y)
|
||||
{
|
||||
case 01:
|
||||
*r = M_CHARGER;
|
||||
return true;
|
||||
case 10:
|
||||
*r = M_JOUER;
|
||||
play_gong();
|
||||
return true;
|
||||
case 11:
|
||||
*r = M_HEX;
|
||||
if (m->c == 15)
|
||||
{
|
||||
boom (m->window);
|
||||
m->c = 0;
|
||||
}
|
||||
else
|
||||
++m->c;
|
||||
return false;
|
||||
case 12:
|
||||
*r = M_QUITTER;
|
||||
return true;
|
||||
case 21:
|
||||
*r = M_OPTIONS;
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
/*
|
||||
* action_menu_principal.h
|
||||
*
|
||||
* Created on: 21 avr. 2016
|
||||
* Author: nathan
|
||||
*/
|
||||
|
||||
#ifndef _ACTION_MENU_PRINCIPAL_H_
|
||||
#define _ACTION_MENU_PRINCIPAL_H_
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include <stdbool.h>
|
||||
#include "globals.h"
|
||||
|
||||
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);
|
||||
|
||||
#endif /* _ACTION_MENU_PRINCIPAL_H_ */
|
@ -1,370 +0,0 @@
|
||||
#include "affichage_menu_principal.h"
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include <SDL/SDL_ttf.h>
|
||||
#include <SDL/SDL_rotozoom.h>
|
||||
#include <SDL/SDL_image.h>
|
||||
#include <assert.h>
|
||||
#include "param.h"
|
||||
#include "draw.h"
|
||||
|
||||
#define NBOPTIONS 5
|
||||
|
||||
#define LEFT 0
|
||||
#define RIGHT 1
|
||||
|
||||
|
||||
/* Menu */
|
||||
/* Interne */
|
||||
|
||||
void Redim_entry (SDL_Surface** entry, int rayon, int l)
|
||||
{
|
||||
SDL_Surface* entry_dim;
|
||||
if ((*entry)->h / (float)(*entry)->w < rayon / (float)l)
|
||||
entry_dim = rotozoomSurface(*entry, 0, l/(float)(*entry)->w, 1);
|
||||
else
|
||||
entry_dim = rotozoomSurface(*entry, 0, rayon/(float)(*entry)->h, 1);
|
||||
SDL_FreeSurface (*entry);
|
||||
*entry = entry_dim;
|
||||
}
|
||||
|
||||
SDL_Surface* Incruste (SDL_Surface* hex, char* title, int l, TTF_Font* font, SDL_Color c)
|
||||
{
|
||||
SDL_Surface* hex_entry = SDL_CreateRGBSurface (SDL_HWSURFACE, hex->w, hex->h, hex->format->BitsPerPixel, 0, 0, 0, 0);
|
||||
SDL_BlitSurface (hex, NULL, hex_entry, NULL);
|
||||
|
||||
SDL_Surface* entry = TTF_RenderText_Blended(font, title, c);
|
||||
Redim_entry(&entry, hex->w / 2, l - 20);
|
||||
|
||||
SDL_Rect position = {hex->w / 2 - l / 2 + (l - entry->w) / 2 - 1, hex->w / 2 / 2 + (hex->w / 2 - entry->h) / 2};
|
||||
|
||||
SDL_BlitSurface (entry , NULL, hex_entry, &position);
|
||||
SDL_SetColorKey (hex_entry, SDL_SRCCOLORKEY, SDL_MapRGB(hex->format, 0, 0, 0));
|
||||
|
||||
SDL_FreeSurface (entry);
|
||||
return hex_entry;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Case_menu (menu_t m, int rayon)
|
||||
{
|
||||
SDL_Color fontColor = {100, 100, 100};
|
||||
|
||||
int l;
|
||||
SDL_Surface* hex = SDL_CreateRGBSurface (SDL_HWSURFACE, 2*rayon, 2*rayon, m->window->format->BitsPerPixel, 0, 0, 0, 0);
|
||||
Hexagon (hex, rayon, param->ex, param->in, 10, &l);
|
||||
int xorig = (m->window->w - 4 * (l + 1)) / 2;
|
||||
/* Charger */
|
||||
int dx = xorig - rayon + l/2 + 1;
|
||||
SDL_Rect position = {dx + 1 * (l + 1) / 2, 0 + 1 * (1.5 * rayon)};
|
||||
SDL_Surface* hex_entry = Incruste(hex, "Charger", l, param->font, fontColor);
|
||||
SDL_BlitSurface (hex_entry, NULL, m->window, &position);
|
||||
SDL_FreeSurface (hex_entry);
|
||||
|
||||
m->l = l;
|
||||
m->r = rayon;
|
||||
m->pos.x = dx;
|
||||
m->pos.y = 0;
|
||||
|
||||
/* Option */
|
||||
dx = xorig + 2 * (l + 1) - rayon + l/2 + 1;
|
||||
position.x = dx + 1 * (l + 1) / 2;
|
||||
hex_entry = Incruste(hex, "Options", l, param->font, fontColor);
|
||||
SDL_BlitSurface (hex_entry, NULL, m->window, &position);
|
||||
SDL_FreeSurface (hex_entry);
|
||||
|
||||
dx = xorig + 1 * (l + 1) - rayon + l/2 + 1;
|
||||
char* entry [3] = {"Jouer", "HEX", "Quitter"};
|
||||
for (int j = 0; j < 3; ++j)
|
||||
{
|
||||
position.x = dx + j * (l + 1) / 2;
|
||||
position.y = 0 + j * (1.5 * rayon);
|
||||
hex_entry = Incruste(hex, entry[j], l, param->font, fontColor);
|
||||
SDL_BlitSurface (hex_entry, NULL, m->window, &position);
|
||||
SDL_FreeSurface (hex_entry);
|
||||
}
|
||||
|
||||
SDL_FreeSurface(hex);
|
||||
}
|
||||
|
||||
/* Externes */
|
||||
|
||||
void Affiche_menu_principal (menu_t m)
|
||||
{
|
||||
int width = m->window->w - 20;
|
||||
int height = m->window->h * 11. / 12;
|
||||
|
||||
int r1 = width / (3 * RAC3);
|
||||
int r2 = height / 5;
|
||||
|
||||
if (r1 < r2)
|
||||
r1 = r1 - r1 % 2;
|
||||
else
|
||||
r1 = r2 - r2 % 2;
|
||||
|
||||
Case_menu (m, r1);
|
||||
Affiche_entry(m, "HEX", POINTE);
|
||||
SDL_Flip (m->window);
|
||||
}
|
||||
|
||||
void Affiche_entry (menu_t m, char* entry, bool pointe)
|
||||
{
|
||||
int dx = m->pos.x + m->cur.x * (m->l + 1);
|
||||
SDL_Rect position = {dx + m->cur.y * (m->l + 1) / 2, m->pos.y + m->cur.y * (1.5 * m->r)};
|
||||
SDL_Surface* hex = SDL_CreateRGBSurface (SDL_HWSURFACE, 2*m->r, 2*m->r, m->window->format->BitsPerPixel, 0, 0, 0, 0);
|
||||
SDL_Surface* hex_entry;
|
||||
SDL_Color c;
|
||||
if (pointe)
|
||||
{
|
||||
Hexagon (hex, m->r, param->j1, param->in, 10, &(m->l));
|
||||
c.r = 255; c.g = 0; c.b = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Hexagon (hex, m->r, param->ex, param->in, 10, &(m->l));
|
||||
c.r = 100; c.g = 100; c.b = 100;
|
||||
}
|
||||
hex_entry = Incruste (hex, entry, m->l, param->font, c);
|
||||
SDL_FreeSurface (hex);
|
||||
SDL_BlitSurface (hex_entry, NULL, m->window, &position);
|
||||
SDL_FreeSurface (hex_entry);
|
||||
SDL_Flip (m->window);
|
||||
}
|
||||
|
||||
/* Menu options */
|
||||
/* Interne */
|
||||
|
||||
/*void print_arrow (SDL_Surface* window, bool side, )
|
||||
{
|
||||
SDL_Surface* arrow = SDL_CreateRGBSurface (SDL_HWSURFACE, 2*m->r, 2*m->r, window->format->BitsPerPixel, 0, 0, 0, 0);
|
||||
}*/
|
||||
|
||||
SDL_Rect cadre_options (SDL_Surface* window, int l)
|
||||
{
|
||||
SDL_Rect pos = {(window->w - 4 * (l + 1)) / 2 + (l + 1) / 2, 0, 2 * l + 1, window->h * 11. /12};
|
||||
SDL_FillRect (window, &pos, param->ex);
|
||||
pos.x += 10;
|
||||
pos.y += 10;
|
||||
pos.w -= 20;
|
||||
pos.h -= 20;
|
||||
SDL_FillRect (window, &pos, param->in);
|
||||
return pos;
|
||||
}
|
||||
|
||||
int create_options_surfaces (SDL_Surface* entry [NBOPTIONS])
|
||||
{
|
||||
char* entry_name [NBOPTIONS] = {"Musique : ", "Son : ", "Couleurs : ", "Taille : ", "Retour"};
|
||||
// Also modify NBOPTIONS
|
||||
int maxw = 0;
|
||||
for (int i = 0; i < NBOPTIONS; ++i)
|
||||
{
|
||||
entry [i] = TTF_RenderUTF8_Blended (param->font, entry_name [i], param->rgb_ex);
|
||||
if (maxw < entry[i]->w)
|
||||
maxw = entry[i]->w;
|
||||
}
|
||||
return maxw;
|
||||
}
|
||||
|
||||
SDL_Rect blit_redim_options (SDL_Surface* window, SDL_Surface* entry [NBOPTIONS], SDL_Rect pos, int maxw, int size, int margev)
|
||||
{
|
||||
for (int i = 0; i < NBOPTIONS - 1; ++i)
|
||||
{
|
||||
SDL_Surface* entry_dim;
|
||||
if (pos.w / 2 < entry[i]->w)
|
||||
{
|
||||
entry_dim = rotozoomSurface(entry[i], 0, pos.w / (2. * maxw), 1);
|
||||
SDL_FreeSurface (entry[i]);
|
||||
}
|
||||
else if (size < entry[i]->h)
|
||||
{
|
||||
entry_dim = rotozoomSurface(entry[i], 0, pos.w / (2. * maxw), 1);
|
||||
SDL_FreeSurface (entry[i]);
|
||||
}
|
||||
else
|
||||
entry_dim = entry[i];
|
||||
|
||||
SDL_Rect pos_entry = {pos.x + (pos.w / 2 - entry_dim->w) / 2, pos.y + (size - entry_dim->h) / 2, 0, 0};
|
||||
SDL_BlitSurface (entry_dim, NULL, window, &pos_entry);
|
||||
|
||||
pos.y += size + margev;
|
||||
|
||||
SDL_FreeSurface (entry_dim);
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
SDL_Rect blit_redim_retour (SDL_Surface* window, SDL_Surface* entry [NBOPTIONS], SDL_Rect pos, int maxw, int size)
|
||||
{
|
||||
SDL_Surface* entry_dim;
|
||||
if (pos.w / 2 < entry[NBOPTIONS-1]->w)
|
||||
{
|
||||
entry_dim = rotozoomSurface(entry[NBOPTIONS-1], 0, pos.w / (2. * maxw), 1);
|
||||
SDL_FreeSurface (entry[NBOPTIONS-1]);
|
||||
}
|
||||
else if (size < entry[NBOPTIONS-1]->h)
|
||||
{
|
||||
entry_dim = rotozoomSurface(entry[NBOPTIONS-1], 0, pos.w / (2. * maxw), 1);
|
||||
SDL_FreeSurface (entry[NBOPTIONS-1]);
|
||||
}
|
||||
else
|
||||
entry_dim = entry[NBOPTIONS-1];
|
||||
|
||||
SDL_Rect pos_entry = {pos.x + (pos.w - entry_dim->w)/2 + 10, pos.y + (size - entry_dim->h) / 2, 0, 0};
|
||||
SDL_Rect pos_cadre = {pos_entry.x - 10, pos_entry.y - 10, entry_dim->w + 20, entry_dim->h + 20};
|
||||
SDL_FillRect (window, &pos_cadre, param->ex);
|
||||
pos_cadre.x += 5;
|
||||
pos_cadre.y += 5;
|
||||
pos_cadre.w -= 10;
|
||||
pos_cadre.h -= 10;
|
||||
SDL_FillRect (window, &pos_cadre, param->in);
|
||||
SDL_BlitSurface (entry_dim, NULL, window, &pos_entry);
|
||||
|
||||
SDL_FreeSurface (entry_dim);
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
/* Externe */
|
||||
|
||||
void Affiche_menu_options (SDL_Surface* window, int rayon, int l)
|
||||
{
|
||||
SDL_Surface* hex = SDL_CreateRGBSurface (SDL_HWSURFACE, rayon * 2, rayon * 2, window->format->BitsPerPixel, 0, 0, 0, 0);
|
||||
Hexagon_single (hex, rayon, SDL_MapRGB(hex->format, 0, 0, 0), &l);
|
||||
int dx = (window->w - 4 * (l + 1)) / 2 - rayon + l/2 + 1 + (l + 1);
|
||||
SDL_Rect pos_hex = {dx + 2 * (l + 1) / 2, 2 * (1.5 * rayon)};
|
||||
SDL_BlitSurface (hex, NULL, window, &pos_hex);
|
||||
SDL_FreeSurface (hex);
|
||||
|
||||
SDL_Rect pos = cadre_options (window, l);
|
||||
|
||||
int size = pos.h * 2 / 3. / NBOPTIONS;
|
||||
int margev = pos.h / 3. / (NBOPTIONS + 1);
|
||||
|
||||
pos.y += margev;
|
||||
pos.w -= 40;
|
||||
pos.x += 10;
|
||||
|
||||
SDL_Surface* entry [NBOPTIONS];
|
||||
|
||||
int maxw = create_options_surfaces (entry);
|
||||
|
||||
pos = blit_redim_options (window, entry, pos, maxw, size, margev);
|
||||
pos = blit_redim_retour (window, entry, pos, maxw, size);
|
||||
|
||||
for (int i = 0 ; i < window->h; ++i)
|
||||
putPixel (window, pos.x + pos.w/2 + 10, i, SDL_MapRGB (window->format, 0, 255, 0));
|
||||
|
||||
|
||||
SDL_Flip (window);
|
||||
}
|
||||
|
||||
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;
|
||||
int cur = 0;
|
||||
char* passcode = "stopdancingstupidbanana";
|
||||
bool pause = false;
|
||||
while (!end)
|
||||
{
|
||||
if (!(SDL_GetTicks() % 100) && !pause)
|
||||
{
|
||||
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;
|
||||
if (SDL_PollEvent (&e) && e.type == SDL_KEYDOWN)
|
||||
{
|
||||
switch (e.key.keysym.sym)
|
||||
{
|
||||
case SDLK_p:
|
||||
pause = true;
|
||||
break;
|
||||
case SDLK_r:
|
||||
pause = false;
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
//Uint8* key = SDL_GetKeyState(NULL);
|
||||
if (e.key.keysym.sym == passcode[cur])
|
||||
++cur;
|
||||
else
|
||||
cur = 0;
|
||||
if (cur == strlen (passcode))
|
||||
end = true;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_BlitSurface (erase, NULL, window, &p);
|
||||
SDL_Flip (window);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#ifndef _AFFICHAGE_MENU_PRICIPAL_
|
||||
#define _AFFICHAGE_MENU_PRICIPAL_
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
#include "globals.h"
|
||||
|
||||
void Affiche_menu_principal (menu_t m);
|
||||
|
||||
void Affiche_menu_options (SDL_Surface* window, int rayon, int l);
|
||||
|
||||
void Affiche_entry (menu_t m, char* entry, bool pointe);
|
||||
|
||||
void east1 (SDL_Surface* window, SDLKey key);
|
||||
|
||||
#endif /* _AFFICHAGE_MENU_PRICIPAL_ */
|
Loading…
Reference in New Issue
Block a user