1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include "stdafx.h"
#include "SDL.h"
#include "Food.h"
#include "serpiente.h"
const int GAME_SPEED = 50; //px por tick de juego.
//WINDOW START
SDL_Window *window = NULL;
SDL_Renderer *renderer = NULL;
SDL_Event evnt;
//WINDOW END
void init() {
SDL_Init(SDL_INIT_VIDEO);
window = SDL_CreateWindow("Snake", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
SDL_RenderClear(renderer);
}
void close() {
SDL_DestroyWindow(window);
window = NULL;
SDL_Quit();
}
int main(int argc, char *argv[]){
init();
bool quit = false;
serpiente snake(renderer);
Food food;
while (!quit) {
while (SDL_PollEvent(&evnt) != 0) {
if (evnt.type == SDL_QUIT) {
quit = true;
}
}
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
SDL_RenderClear(renderer);
snake.m_update(renderer);
food.m_update(renderer);
snake.foodCollision(snake, food);
snake.wallCollision(snake);
snake.selfCollision(snake);
SDL_RenderPresent(renderer);
SDL_Delay(GAME_SPEED);
}
close();
return 0;
}
| |