Add map rotate and speed change via keys (1, 2 , m)
This commit is contained in:
parent
9afeb85635
commit
cc4f8f169f
@ -46,6 +46,10 @@ void loadMapByName(char *name);
|
||||
void loadMap(map_t map);
|
||||
|
||||
|
||||
//load next map in stored maps (rotate through stored maps)
|
||||
void rotateMapNext();
|
||||
|
||||
|
||||
//return true when provided coordinate matches the position of a collision box
|
||||
bool checkCollides(map_t map, int x, int y);
|
||||
|
||||
|
@ -30,10 +30,6 @@ gameData_t game = {
|
||||
void gameInit()
|
||||
{
|
||||
LOGI("game: initializing game...\n");
|
||||
//----- snake -----
|
||||
// defines initial values of game.snake
|
||||
snakeInit(); //TODO assign return value to game.snake?
|
||||
|
||||
//----- load map -----
|
||||
//load default map if no map loaded yet
|
||||
if (!game.mapIsLoaded){
|
||||
@ -41,6 +37,10 @@ void gameInit()
|
||||
loadMapByName(config.defaultMapName);
|
||||
}
|
||||
|
||||
//----- snake -----
|
||||
// defines initial values of game.snake
|
||||
snakeInit(); //TODO assign return value to game.snake?
|
||||
|
||||
//--- place initial food ---
|
||||
placeFood();
|
||||
LOGI("game: placed initial food at x=%d, y=%d\n", game.foodX, game.foodY);
|
||||
|
22
src/input.c
22
src/input.c
@ -4,6 +4,7 @@
|
||||
#include "game.h"
|
||||
#include "menu.h"
|
||||
#include "snake.h"
|
||||
#include "map.h"
|
||||
|
||||
|
||||
|
||||
@ -18,16 +19,17 @@ void handleInput_runningState(SDL_Event event)
|
||||
{
|
||||
switch (event.key.keysym.sym)
|
||||
{
|
||||
case SDLK_q:
|
||||
case SDLK_q: // q: quit
|
||||
game.gameState = EXIT;
|
||||
break;
|
||||
|
||||
case SDLK_p:
|
||||
case SDLK_p: // p: pause
|
||||
case SDLK_ESCAPE:
|
||||
game.gameState = PAUSED;
|
||||
showPauseScreen();
|
||||
break;
|
||||
|
||||
//--- control snake direction ---
|
||||
case SDLK_UP:
|
||||
case SDLK_w:
|
||||
snakeSetDir(UP);
|
||||
@ -48,14 +50,26 @@ void handleInput_runningState(SDL_Event event)
|
||||
snakeSetDir(RIGHT);
|
||||
break;
|
||||
|
||||
case SDLK_m: // m: cycle through maps
|
||||
rotateMapNext();
|
||||
break;
|
||||
|
||||
case SDLK_2: // 2: speed up game by increment
|
||||
config.cycleDurationMs -= sqrt(config.cycleDurationMs) + 1;
|
||||
if (config.cycleDurationMs < 20)
|
||||
config.cycleDurationMs = 20;
|
||||
break;
|
||||
|
||||
case SDLK_1: // 1: slow down game by increment
|
||||
config.cycleDurationMs += 50;
|
||||
break;
|
||||
|
||||
default:
|
||||
LOGD("input: key %d is not handled in RUNNING mode\n", event.key.keysym.sym);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=============================
|
||||
//===== processInputEvent =====
|
||||
//=============================
|
||||
|
20
src/map.c
20
src/map.c
@ -3,6 +3,8 @@
|
||||
#include "game.h"
|
||||
#include "common.h"
|
||||
|
||||
int indexLoadedMap = 0;
|
||||
|
||||
//===========================
|
||||
//==== renderGameToArray ====
|
||||
//===========================
|
||||
@ -167,6 +169,20 @@ void loadMap(map_t map)
|
||||
}
|
||||
|
||||
|
||||
//===========================
|
||||
//====== rotateMapNext ======
|
||||
//===========================
|
||||
//load next map in stored maps (rotate through stored maps)
|
||||
void rotateMapNext(){
|
||||
if (indexLoadedMap >= storedMapsCount -1 ){
|
||||
indexLoadedMap = 0;
|
||||
} else {
|
||||
indexLoadedMap ++;
|
||||
}
|
||||
loadMap(*storedMaps[indexLoadedMap]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//===========================
|
||||
//====== checkCollides ======
|
||||
@ -208,7 +224,7 @@ static const map_t map_default = {
|
||||
|
||||
static const map_t map_empty = {
|
||||
.width = 20,
|
||||
.height = 10,
|
||||
.height = 15,
|
||||
.name = "empty",
|
||||
.collisions = {},
|
||||
.collisionCount = 0,
|
||||
@ -225,7 +241,7 @@ static const map_t map_intermediate = {
|
||||
.width = 15,
|
||||
.height = 15,
|
||||
.name = "intermediate",
|
||||
.collisions = {{8, 9}, {8, 8}, {4, 5}, {0, 1}, {9, 9}, {7, 5}, {4, 0}, {3, 0}, {12, 11}, {14, 13}},
|
||||
.collisions = {{8, 9}, {8, 8}, {4, 6}, {0, 1}, {9, 9}, {7, 6}, {4, 0}, {3, 0}, {12, 11}, {14, 13}},
|
||||
.collisionCount = 10,
|
||||
.portals = {
|
||||
{.posX = 5,
|
||||
|
Loading…
x
Reference in New Issue
Block a user