Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ** game.c for in /home/death/ETNA/prog_C/Xmas Project/Snake/jnih_s
- **
- ** Made by Sami Jnih
- ** Login <[email protected]>
- **
- ** Started on Tue Dec 24 23:09:00 2013 Sami Jnih
- ** Last update Wed Jan 1 02:32:05 2014 Sami Jnih
- */
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <SDL/SDL.h>
- #include <SDL/SDL_image.h>
- #include </usr/local/lib/fmod.h>
- #include "snake.h"
- void game(SDL_Event event, SDL_Surface *screen, SDL_Surface *snake, SDL_Surface *background, SDL_Surface *gameover_continuer, SDL_Surface *gameover_quitter)
- {
- SDL_Rect positionBackground, positionSnake;
- int game, snake_xval, snake_yval, tempsPrecedent, tempsActuel, pos;
- pos = 0;
- game = 1;
- tempsPrecedent = 0;
- tempsActuel = 0;
- snake_xval = 0;
- snake_yval = 0;
- positionBackground.x = 0;
- positionBackground.y = 0;
- positionSnake.x = 400 - 25;
- positionSnake.y = 320 - 25;
- background = IMG_Load("images/background.jpg");
- snake = IMG_Load("images/curseur.png");
- SDL_BlitSurface(background, NULL, screen, &positionBackground);
- while (game)
- {
- SDL_PollEvent(&event);
- //printf("positionSnake.x : %d\npositionSnake.y : %d\n", positionSnake.x, positionSnake.y);
- if (check_pos(game, positionSnake) == 0)
- {
- game = 0;
- gameover_menu(gameover_continuer, gameover_quitter, screen, event, snake, background);
- }
- tempsActuel = SDL_GetTicks();
- switch(event.type)
- {
- case SDL_QUIT:
- game = 0;
- break;
- case SDL_KEYDOWN:
- if (event.key.keysym.sym == SDLK_ESCAPE)
- {
- game = 0;
- printf("Vous quittez le jeu.\n");
- }
- else if (event.key.keysym.sym == SDLK_UP)
- pos = 1;
- else if (event.key.keysym.sym == SDLK_DOWN)
- pos = 2;
- else if (event.key.keysym.sym == SDLK_RIGHT)
- pos = 3;
- else if (event.key.keysym.sym == SDLK_LEFT)
- pos = 4;
- break;
- }
- if (tempsActuel - tempsPrecedent > 10)
- {
- switch (pos)
- {
- case 1:
- positionSnake.y -= 3;
- break;
- case 2:
- positionSnake.y += 3;
- break;
- case 3:
- positionSnake.x += 3;
- break;
- case 4:
- positionSnake.x -= 3;
- break;
- }
- tempsPrecedent = tempsActuel;
- }
- else
- SDL_Delay(10 - (tempsActuel - tempsPrecedent));
- SDL_BlitSurface(background, NULL, screen, &positionBackground);
- SDL_BlitSurface(snake, NULL, screen, &positionSnake);
- SDL_Flip(screen);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement