Skip to content

Commit

Permalink
Merge pull request #79 from AEFeinstein/breakout
Browse files Browse the repository at this point in the history
Breakout - part 2: electric boogaloo
  • Loading branch information
AEFeinstein authored Sep 17, 2023
2 parents 190b796 + b568d5b commit d9df853
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 144 deletions.
1 change: 1 addition & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ idf_component_register(SRCS "swadge2024.c"
"modes/breakout/gameData.c"
"modes/breakout/soundManager.c"
"modes/breakout/aabb_utils.c"
"modes/breakout/starfield.c"
"modes/touchTest/touchTest.c"
"modes/quickSettings/menuQuickSettingsRenderer.c"
"modes/quickSettings/quickSettings.c"
Expand Down
6 changes: 0 additions & 6 deletions main/modes/breakout/aabb_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
#include <stdbool.h>
#include <palette.h>

typedef struct
{
int32_t x;
int32_t y;
} vector_t;

typedef struct
{
int32_t x0;
Expand Down
67 changes: 24 additions & 43 deletions main/modes/breakout/breakout.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,24 @@
#include "leveldef.h"
#include "mainMenu.h"

#include "fill.h"
#include "starfield.h"

#include <esp_log.h>

//==============================================================================
// Defines
//==============================================================================

/// Physics math is done with fixed point numbers where the bottom four bits are the fractional part. It's like Q28.4
#define DECIMAL_BITS 4

#define BALL_RADIUS (5 << DECIMAL_BITS)
#define PADDLE_WIDTH (8 << DECIMAL_BITS)
#define PADDLE_HEIGHT (40 << DECIMAL_BITS)
#define FIELD_HEIGHT (TFT_HEIGHT << DECIMAL_BITS)
#define FIELD_WIDTH (TFT_WIDTH << DECIMAL_BITS)

#define SPEED_LIMIT (30 << DECIMAL_BITS)

//==============================================================================
// Enums
//==============================================================================

/**
* @brief Enum of screens that may be shown in breakout mode
*/
typedef enum
{
BREAKOUT_MENU,
BREAKOUT_GAME,
} breakoutScreen_t;

//==============================================================================
// Structs
//==============================================================================
typedef void (*gameUpdateFunction_t)(void *self, int64_t elapsedUs);
typedef struct
typedef void (*gameUpdateFunction_t)(breakout_t *self, int64_t elapsedUs);
struct breakout_t
{
menu_t* menu; ///< The menu structure
menuLogbookRenderer_t* mRenderer; ///< The menu renderer
Expand All @@ -74,9 +57,10 @@ typedef struct
int32_t frameTimer;

soundManager_t soundManager;
starfield_t starfield;

gameUpdateFunction_t update;
} breakout_t;
};

//==============================================================================
// Function Prototypes
Expand Down Expand Up @@ -243,7 +227,8 @@ static void breakoutEnterMode(void)
initializeTileMap(&(breakout->tilemap));
initializeSoundManager(&(breakout->soundManager));
initializeEntityManager(&(breakout->entityManager), &(breakout->tilemap), &(breakout->gameData), &(breakout->soundManager));

initializeStarfield(&(breakout->starfield));

breakout->tilemap.entityManager = &(breakout->entityManager);
breakout->tilemap.executeTileSpawnAll = true;
breakout->tilemap.mapOffsetX = -4;
Expand All @@ -269,6 +254,9 @@ static void breakoutEnterMode(void)

addSingleItemToMenu(breakout->menu, breakoutExit);

//Set frame rate to 60 FPS
setFrameRateUs(16666);

// Set the mode to menu mode
breakout->update = &breakoutUpdateTitleScreen;
}
Expand Down Expand Up @@ -405,7 +393,10 @@ static void breakoutGameLoop(breakout_t *self, int64_t elapsedUs)
breakoutDetectGameStateChange(self);
updateEntities(&(self->entityManager));

updateStarfield(&(self->starfield));

// Draw the field
drawStarfield(&(self->starfield));
drawTileMap(&(self->tilemap));
drawEntities(&(self->entityManager));
drawBreakoutHud(&(self->ibm_vga8), &(breakout->gameData));
Expand Down Expand Up @@ -438,24 +429,7 @@ static void breakoutGameLoop(breakout_t *self, int64_t elapsedUs)
*/
static void breakoutBackgroundDrawCallback(int16_t x, int16_t y, int16_t w, int16_t h, int16_t up, int16_t upNum)
{
// Use TURBO drawing mode to draw individual pixels fast
SETUP_FOR_TURBO();

// Draw a grid
for (int16_t yp = y; yp < y + h; yp++)
{
for (int16_t xp = x; xp < x + w; xp++)
{
if ((0 == xp % 40) || (0 == yp % 40))
{
TURBO_SET_PIXEL(xp, yp, c110);
}
else
{
TURBO_SET_PIXEL(xp, yp, c001);
}
}
}
fillDisplayArea(x, y, x + w, y + h, c000);
}

void breakoutDetectGameStateChange(breakout_t *self){
Expand Down Expand Up @@ -515,6 +489,10 @@ void breakoutUpdateDead(breakout_t *self, int64_t elapsedUs){

updateLedsInGame(&(self->gameData));
updateEntities(&(self->entityManager));

updateStarfield(&(self->starfield));
drawStarfield(&(self->starfield));

drawTileMap(&(self->tilemap));
drawEntities(&(self->entityManager));
drawBreakoutHud(&(self->ibm_vga8), &(self->gameData));
Expand Down Expand Up @@ -631,7 +609,7 @@ void breakoutUpdateLevelClear(breakout_t *self, int64_t elapsedUs){
//Hey look, it's a frame rule!
deactivateAllEntities(&(self->entityManager), false, false);

uint16_t levelIndex = self->gameData.level;
uint16_t levelIndex = self->gameData.level - 1;

if(levelIndex >= NUM_LEVELS - 1){
//Game Cleared!
Expand Down Expand Up @@ -681,6 +659,8 @@ void breakoutUpdateLevelClear(breakout_t *self, int64_t elapsedUs){
}

//updateEntities(&(self->entityManager));

drawStarfield(&(self->starfield));
drawTileMap(&(self->tilemap));
drawEntities(&(self->entityManager));
drawBreakoutHud(&(self->ibm_vga8), &(self->gameData));
Expand Down Expand Up @@ -757,6 +737,7 @@ void breakoutUpdatePause(breakout_t *self, int64_t elapsedUs){
self->update=&breakoutGameLoop;
}

drawStarfield(&(self->starfield));
drawTileMap(&(self->tilemap));
drawEntities(&(self->entityManager));
drawBreakoutHud(&(self->ibm_vga8), &(self->gameData));
Expand Down
49 changes: 49 additions & 0 deletions main/modes/breakout/breakout_typedef.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#ifndef BREAKOUT_TYPEDEF_INCLUDED
#define BREAKOUT_TYPEDEF_INCLUDED

typedef struct breakout_t breakout_t;
typedef struct entityManager_t entityManager_t;
typedef struct tilemap_t tilemap_t;
typedef struct entity_t entity_t;

typedef enum {
ST_NULL,
ST_TITLE_SCREEN,
ST_READY_SCREEN,
ST_GAME,
ST_DEAD,
ST_LEVEL_CLEAR,
ST_GAME_CLEAR,
ST_GAME_OVER,
ST_HIGH_SCORE_ENTRY,
ST_HIGH_SCORE_TABLE,
ST_PAUSE
} gameStateEnum_t;

typedef enum {
BGM_NO_CHANGE,
BGM_MAIN,
BGM_ATHLETIC,
BGM_UNDERGROUND,
BGM_FORTRESS,
BGM_NULL
} bgmEnum_t;

typedef enum {
SP_PADDLE_0,
SP_PADDLE_1,
SP_PADDLE_2,
SP_PADDLE_VERTICAL_0,
SP_PADDLE_VERTICAL_1,
SP_PADDLE_VERTICAL_2,
SP_BALL,
SP_BOMB_0,
SP_BOMB_1,
SP_BOMB_2,
SP_EXPLOSION_0,
SP_EXPLOSION_1,
SP_EXPLOSION_2,
SP_EXPLOSION_3
} spriteDef_t;

#endif
90 changes: 0 additions & 90 deletions main/modes/breakout/common_typedef.h

This file was deleted.

2 changes: 1 addition & 1 deletion main/modes/breakout/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <stdint.h>
#include <stdbool.h>
#include "common_typedef.h"
#include "breakout_typedef.h"
#include "tilemap.h"
#include "gameData.h"
#include "soundManager.h"
Expand Down
2 changes: 1 addition & 1 deletion main/modes/breakout/entityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <stdint.h>
#include <stdbool.h>
#include "common_typedef.h"
#include "breakout_typedef.h"
#include "entity.h"
#include "tilemap.h"
#include "gameData.h"
Expand Down
2 changes: 1 addition & 1 deletion main/modes/breakout/gameData.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "hdw-led.h"
#include "common_typedef.h"
#include "breakout_typedef.h"
#include "palette.h"

//==============================================================================
Expand Down
Loading

0 comments on commit d9df853

Please sign in to comment.