Skip to content

Commit

Permalink
Merge branch 'title'
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-rodrigues committed Oct 31, 2020
2 parents aced658 + 1826268 commit 1286a30
Show file tree
Hide file tree
Showing 17 changed files with 396 additions and 55 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ SOURCES += $(addprefix $(ICS32_SW_DIR)common/, \
)

CPU_SLOW_SOURCES := \
game_loop/title_loop.c \
debug/debug_custom_assert.c \
palette/palette_init.c \
level/level_loading.c \
Expand Down Expand Up @@ -137,6 +138,7 @@ PNGS := $(addprefix $(GFX_DIR), \
spr04.png \
spr06_07.png \
fg_bg.png \
title_main.png \
)

PNG_TILES := $(PNGS:$(GFX_DIR)%.png=$(GFX_DIR)%_tiles.bin)
Expand Down Expand Up @@ -267,14 +269,16 @@ palette/palette_init.o: $(addprefix $(GFX_DIR), \
miyamoto_palette.h \
fgbg_palette.h \
bg_palette.h \
title_main_palette.h \
)
vram/vram_animated_tiles.o: $(GFX_DIR)animated_tiles.h

level/level_loading.o: $(addprefix $(GFX_DIR), spr00_tiles.h spr01_tiles.h spr02_tiles.h spr06_07_tiles.h fg_bg_tiles.h)
level/level_loading.o: $(addprefix $(MAPS_DIR), bg_hills_no_clouds.h bg_hills_clouds.h)
level/level_attributes.o: $(addprefix $(LEVEL_DIR), level1.h level2.h sprites1.h sprites2.h)
level/block.o: $(addprefix $(LEVEL_DIR), block_map_table.h block_attributes.h)
game_loop.o: $(LEVEL_DIR)block_map_table.h
game_loop/game_loop.o: $(LEVEL_DIR)block_map_table.h
game_loop/game_loop.o: $(GFX_DIR)title_main_tiles.h

ifeq ($(MUSIC), 1)
audio/music.o: $(addprefix $(AUDIO_ASSETS_DIR), track1_left.h track1_right.h track2_left.h track2_right.h)
Expand Down
Binary file added assets/graphics/title_main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions debug/debug_playfield.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void dbg_spawn_platform(const Hero *hero) {

void dbg_print_sandbox_instructions() {
static const char * const line_1 = "Start: Pause";
static const char * const line_2 = "Select: Reset game world";
static const char * const line_2 = "Select: Return to menu";

const int16_t base_x = 320;
const int16_t base_y = 10;
Expand All @@ -50,7 +50,7 @@ void dbg_frame_action(GameContext *context) {
// Select: reset game world (fade out and reload)
if (!gl_fading(context) && p1_pad_edge->select && !context->paused) {
ExtraTask *reload_task = level_reload_sequence_task_init(0, true);
reload_task->level_reload_sequence.final_action = GL_ACTION_RESET_WORLD;
reload_task->level_reload_sequence.final_action = GL_ACTION_SHOW_TITLE;
context->current_fade_handle = reload_task->handle;
}
}
2 changes: 1 addition & 1 deletion game_loop/credits_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void credits_loop_init(GameContext *context) {
state_transition(context, CREDITS_STATE_INITIAL_DELAY);

context->credits.showing_tech_attributions = false;
context->gameplay_active = false;
context->game_loop = GL_CREDITS;
}

void credits_frame_ended_update(CreditsState state) {
Expand Down
83 changes: 52 additions & 31 deletions game_loop/game_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "affine.h"
#include "gameplay_loop.h"
#include "credits_loop.h"
#include "title_loop.h"

GameLoopAction gl_run_frame(GameContext *context) {
const bool show_raster_counter = false;
Expand All @@ -34,29 +35,35 @@ GameLoopAction gl_run_frame(GameContext *context) {

GameLoopAction result_action = GL_ACTION_NONE;

if (context->gameplay_active) {
dbg_frame_action(context);

if (hero->pad_edge.start && !gl_fading(context)) {
context->paused = !context->paused;

uint8_t alpha = context->paused ? 0x8 : 0xf;
pb_alpha_mask_all(alpha, true);
}
switch (context->game_loop) {
case GL_GAMEPLAY: {
dbg_frame_action(context);

if (hero->pad_edge.start && !gl_fading(context)) {
context->paused = !context->paused;

uint8_t alpha = context->paused ? 0x8 : 0xf;
pb_alpha_mask_all(alpha, true);
}

if (!context->paused) {
result_action = gameplay_step_frame(context);

if (!context->paused) {
result_action = gameplay_step_frame(context);
if (show_raster_counter) {
st_write_hex(VDP_CURRENT_RASTER_Y, 64, 8);
}
}
} break;
case GL_CREDITS: {
result_action = credits_step_frame(context);

if (show_raster_counter) {
st_write_hex(VDP_CURRENT_RASTER_Y, 64, 8);
}
}
} else {
result_action = credits_step_frame(context);

if (show_raster_counter) {
st_write_hex(VDP_CURRENT_RASTER_Y, 64, 8);
}
} break;
case GL_TITLE:
result_action = title_step_frame(context);
break;
}

// Finished entire frame worth of processing hopefully before the cutoff line
Expand All @@ -66,17 +73,24 @@ GameLoopAction gl_run_frame(GameContext *context) {

// Offscreen updates this frame

if (context->gameplay_active) {
if (!context->paused) {
// Sprites are preserved when paused, otherwise they need redrawing every frame
sb_upload();
}
switch (context->game_loop) {
case GL_GAMEPLAY:
if (!context->paused) {
// Sprites are preserved when paused, otherwise they need redrawing every frame
sb_upload();
}

gameplay_frame_ended_update(context);
vcq_run();
} else {
credits_frame_ended_update(context->credits.state);
sb_upload();
gameplay_frame_ended_update(context);
vcq_run();
break;
case GL_CREDITS:
credits_frame_ended_update(context->credits.state);
sb_upload();
break;
case GL_TITLE:
title_frame_ended_update(context);
sb_upload();
break;
}

// Palette RAM always updated even when paused (for the fade effect)
Expand All @@ -95,7 +109,8 @@ GameLoopAction gl_run_frame(GameContext *context) {
void gl_reset_context(GameContext *context,
Hero *hero,
Camera *camera,
SpriteLoadingContext *sprite_context)
SpriteLoadingContext *sprite_context,
uint8_t level)
{
const GameContext context_initialized = {
.players = {
Expand All @@ -109,9 +124,9 @@ void gl_reset_context(GameContext *context,
.sprite_context = sprite_context
}
},
.game_loop = GL_GAMEPLAY,
.paused = false,
.gameplay_active = true,
.level = 0,
.level = level,

.current_fade_handle = ET_HANDLE_FREE
};
Expand All @@ -125,6 +140,12 @@ void gl_load_credits(GameContext *context) {
credits_loop_init(context);
}

void gl_load_title(GameContext *context) {
const LevelAttributes *base_level = level_attributes(0);
level_load(base_level);
title_loop_init(context);
}

bool gl_fading(const GameContext *context) {
return et_handle_live(context->current_fade_handle);
}
37 changes: 34 additions & 3 deletions game_loop/game_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,23 @@ enum CreditsState {
CREDITS_STATE_FADE_OUT_MUSIC
};

enum TitleState {
TITLE_STATE_INITIAL_DELAY,
TITLE_STATE_INITIAL_FADE_IN,
TITLE_STATE_DISPLAYING_TITLE,
TITLE_STATE_DISPLAYING_MENU,
TITLE_STATE_FADE_OUT
};

enum GameLoop {
GL_TITLE,
GL_GAMEPLAY,
GL_CREDITS
};

enum GameLoopAction {
GL_ACTION_NONE = 0,
GL_ACTION_SHOW_TITLE,
GL_ACTION_RESET_WORLD,
GL_ACTION_RELOAD_LEVEL,
GL_ACTION_SHOW_CREDITS
Expand All @@ -41,6 +56,16 @@ struct CreditsContext {
bool showing_tech_attributions;
};

struct TitleContext {
TitleState state;
uint16_t state_counter;
uint8_t presentation_delay;
int16_t scale;
bool fullscreen_blink_started;
uint8_t selected_menu_option;
bool exiting;
};

struct PlayerContext {
Hero *hero;
Camera *camera;
Expand All @@ -55,19 +80,25 @@ struct GameContext {
// 1P only for now
PlayerContext players[1];

CreditsContext credits;
union {
CreditsContext credits;
TitleContext title;
};

GameLoop game_loop;
bool paused;
bool gameplay_active;
uint8_t level;

ExtraTaskHandle current_fade_handle;
};

void gl_reset_context(GameContext *context,
Hero *hero,
Camera *camera,
SpriteLoadingContext *sprite_context);
SpriteLoadingContext *sprite_context,
uint8_t level);

void gl_load_title(GameContext *context);
void gl_load_credits(GameContext *context);

GameLoopAction gl_run_frame(GameContext *context);
Expand Down
3 changes: 3 additions & 0 deletions game_loop/game_loop_types.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#ifndef game_loop_types_h
#define game_loop_types_h

typedef enum GameLoop GameLoop;
typedef enum GameLoopAction GameLoopAction;
typedef struct PlayerContext PlayerContext;

typedef struct GameContext GameContext;
typedef enum CreditsState CreditsState;
typedef enum TitleState TitleState;
typedef struct CreditsContext CreditsContext;
typedef struct TitleContext TitleContext;

#endif /* game_loop_types_h */
4 changes: 3 additions & 1 deletion game_loop/gameplay_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ static void end_state_check(GameContext *context) {
// Level complete?
if (hero->goal_reached) {
context->level++;

bool roll_credits = (context->level == LEVEL_COUNT);
if (roll_credits) {
context->level = 0;
}

const uint8_t fade_delay = 30;
ExtraTask *task = level_reload_sequence_task_init(fade_delay, false);
Expand Down
Loading

0 comments on commit 1286a30

Please sign in to comment.