Merge branch 'testing' into dev
This commit is contained in:
		
						commit
						a56c78e1ee
					
				@ -39,6 +39,9 @@ bool snakeIsAlive();
 | 
			
		||||
// Überprüfen, ob Schlange noch lebt
 | 
			
		||||
// Prüft Kollision mit sich selbst
 | 
			
		||||
 | 
			
		||||
void snakeSetHeadPos(); // optional
 | 
			
		||||
void snakeSetHeadPos(int xPos, int yPos); // optional
 | 
			
		||||
// für handlePortals
 | 
			
		||||
// generiert zufällige Zielsposition, wohin sich die Schlange nach Betreten eines Portals bewegt
 | 
			
		||||
// generiert zufällige Zielposition(Übergabeparameter), wohin sich die Schlange nach Betreten eines Portals bewegt
 | 
			
		||||
 | 
			
		||||
void snakeUpdateHeadPos();
 | 
			
		||||
// berechnet neue Position des Kopfs anhand der aktuellen Bewegungsrichtung
 | 
			
		||||
							
								
								
									
										15
									
								
								src/game.c
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/game.c
									
									
									
									
									
								
							@ -38,6 +38,7 @@ void gameInit()
 | 
			
		||||
    //load default map if no map loaded yet
 | 
			
		||||
    if (!game.mapIsLoaded){
 | 
			
		||||
        loadMapByName("default");
 | 
			
		||||
        //loadMapByName("empty");
 | 
			
		||||
        //loadMapByName("intermediate");
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
@ -92,8 +93,10 @@ void runGameCycle()
 | 
			
		||||
        // show leaderboard when collided
 | 
			
		||||
        // TODO consider game.lifesRemaining and reset if still good?
 | 
			
		||||
        LOGI("game: collided with wall or self! => show leaderboard\n");
 | 
			
		||||
        game.gameState = MENU;
 | 
			
		||||
        showLeaderboard();
 | 
			
		||||
        LOGI("DEBUG: collision currently disabled, game will continue in 1s...\n");
 | 
			
		||||
        DELAY(1000);
 | 
			
		||||
        //game.gameState = MENU; //TODO add config.collisionEnabled option?
 | 
			
		||||
        //showLeaderboard();
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -103,13 +106,13 @@ void runGameCycle()
 | 
			
		||||
    //--- handle food ---
 | 
			
		||||
    if (checkEaten()) {
 | 
			
		||||
        LOGI("game: picked up food at x=%d y=%d -> growing, placing food\n", game.foodX, game.foodY);
 | 
			
		||||
        // NOTE: order of place and grow is relevant, otherwise function in food.c will access invalid memory
 | 
			
		||||
        placeFood(); 
 | 
			
		||||
        snakeGrow();
 | 
			
		||||
        placeFood();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
    //--- update frame ---
 | 
			
		||||
    
 | 
			
		||||
    renderGame();
 | 
			
		||||
    //printMap(game.map); (render game to console)
 | 
			
		||||
    printMap(game.map); //render game to console
 | 
			
		||||
    return;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										12
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/main.cpp
									
									
									
									
									
								
							@ -20,6 +20,18 @@ extern "C"{
 | 
			
		||||
//uninitialize SDL
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//==========================
 | 
			
		||||
//====== enabled test ======
 | 
			
		||||
//==========================
 | 
			
		||||
//uncomment one test at a time to run the corresponding code in main()
 | 
			
		||||
//#define TEST__FOOD_PLACEMENT
 | 
			
		||||
//#define TEST__SDL_INPUT
 | 
			
		||||
#define TEST__GAME_WITH_CONSOLE_OUTPUT
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int main(int argc, char *argv[])
 | 
			
		||||
{
 | 
			
		||||
  gameInit();
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										22
									
								
								src/map.c
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/map.c
									
									
									
									
									
								
							@ -28,7 +28,7 @@ void renderGameToArray(int mapFrame[MAX_MAP_SIZE][MAX_MAP_SIZE], map_t map, snak
 | 
			
		||||
    {
 | 
			
		||||
        mapFrame[snake.tail[i][1]][snake.tail[i][0]] = 5;
 | 
			
		||||
    }
 | 
			
		||||
    // copy food
 | 
			
		||||
     // copy food
 | 
			
		||||
    mapFrame[game.foodY][game.foodX] = 6;
 | 
			
		||||
    // copy snake head (last element -> head overwrites previous elements)
 | 
			
		||||
    mapFrame[snake.headY][snake.headX] = 4;
 | 
			
		||||
@ -205,6 +205,22 @@ static const map_t map_default = {
 | 
			
		||||
         .color = "blue"}},
 | 
			
		||||
    .portalCount = 1};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static const map_t map_empty = {
 | 
			
		||||
    .width = 20,
 | 
			
		||||
    .height = 10,
 | 
			
		||||
    .name = "empty",
 | 
			
		||||
    .collisions = {},
 | 
			
		||||
    .collisionCount = 0,
 | 
			
		||||
    .portals = {
 | 
			
		||||
        {.posX = 5,
 | 
			
		||||
         .posY = 8,
 | 
			
		||||
         .targetX = 7,
 | 
			
		||||
         .targetY = 1,
 | 
			
		||||
         .color = "blue"}},
 | 
			
		||||
    .portalCount = 1};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static const map_t map_intermediate = {
 | 
			
		||||
    .width = 15,
 | 
			
		||||
    .height = 15,
 | 
			
		||||
@ -225,5 +241,5 @@ static const map_t map_intermediate = {
 | 
			
		||||
    .portalCount = 2};
 | 
			
		||||
 | 
			
		||||
// global variables for accessing the stored maps
 | 
			
		||||
const map_t *storedMaps[16] = {&map_default, &map_intermediate};
 | 
			
		||||
const int storedMapsCount = 2;
 | 
			
		||||
const map_t *storedMaps[16] = {&map_default, &map_empty, &map_intermediate};
 | 
			
		||||
const int storedMapsCount = 3;
 | 
			
		||||
							
								
								
									
										18
									
								
								src/snake.c
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								src/snake.c
									
									
									
									
									
								
							@ -45,8 +45,8 @@ void snakeMove()
 | 
			
		||||
{   
 | 
			
		||||
    int i = game.snake.length - 1;  // counter for snake moving
 | 
			
		||||
 | 
			
		||||
    // update head position
 | 
			
		||||
    snakeSetHeadPos();
 | 
			
		||||
    // update head position automatically
 | 
			
		||||
    snakeUpdateHeadPos();
 | 
			
		||||
 | 
			
		||||
    // tail part of[x,y][0,1] get coordinates of tail part before
 | 
			
		||||
    while(i)
 | 
			
		||||
@ -77,9 +77,19 @@ bool snakeIsAlive()
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void snakeSetHeadPos()
 | 
			
		||||
void snakeSetHeadPos(int xPos, int yPos)
 | 
			
		||||
{
 | 
			
		||||
        switch(game.snake.direction)
 | 
			
		||||
    game.snake.headX = xPos;
 | 
			
		||||
    game.snake.headY = yPos;
 | 
			
		||||
    game.snake.tail[0][0] = xPos;
 | 
			
		||||
    game.snake.tail[0][1] = yPos;
 | 
			
		||||
    return;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void snakeUpdateHeadPos()
 | 
			
		||||
{
 | 
			
		||||
    switch(game.snake.direction)
 | 
			
		||||
    {   
 | 
			
		||||
        // DOWN
 | 
			
		||||
        case DOWN:
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user