feat: add custom background rendering and speed scaling features for snake gameplay
This commit is contained in:
1 parent
93c0a44027
commit
60bf111400
13 files changed
+711
-26
No files matched your search
+18
-8
@@ -8,6 +8,7 @@
|
||||
#include <game_render.h>
|
||||
#include <game_audio.h>
|
||||
#include <game_input.h>
|
||||
#include <game_bg.h>
|
||||
|
||||
#include "tilemap.h"
|
||||
|
||||
@@ -28,6 +29,7 @@ volatile uint16_t &snakelength = gameState.snakelength;
|
||||
***/
|
||||
volatile uint16_t &snakeDirection = gameState.snakeDirection;
|
||||
volatile uint16_t &score = gameState.score;
|
||||
volatile uint16_t &applesEaten = gameState.applesEaten;
|
||||
|
||||
bool &gameOver = gameState.gameOver;
|
||||
bool &paused = gameState.paused;
|
||||
@@ -46,6 +48,7 @@ int sound;
|
||||
AudioContext audioContext;
|
||||
|
||||
RenderAssets renderAssets;
|
||||
BackgroundContext bgContext;
|
||||
|
||||
const void * get_sprite_pointer(uint16_t spriteIndex) {
|
||||
return &tilemapTiles[spriteIndex*16];
|
||||
@@ -64,8 +67,11 @@ void setup() {
|
||||
consoleInit(&bottomScreen, 3,BgType_Text4bpp, BgSize_T_256x256, X_MAX, 0, false, true);
|
||||
oamInit(&oamSub, SpriteMapping_1D_32, false);
|
||||
|
||||
bg_setup(bgContext, topScreen.bgId, bottomScreen.bgId);
|
||||
|
||||
renderAssets.topScreen = &topScreen;
|
||||
renderAssets.bottomScreen = &bottomScreen;
|
||||
renderAssets.bg_context = &bgContext;
|
||||
|
||||
renderAssets.gfx_segment = oamAllocateGfx(&oamSub, SpriteSize_8x8, SpriteColorFormat_256Color);
|
||||
renderAssets.gfx_segment_small = oamAllocateGfx(&oamSub, SpriteSize_8x8, SpriteColorFormat_256Color);
|
||||
@@ -127,6 +133,7 @@ void setup() {
|
||||
}
|
||||
void handle_vblank() {
|
||||
frame++;
|
||||
bg_update(bgContext, gameState, frame);
|
||||
if (gameState.scene == Scene::Playing) {
|
||||
consoleSelect(&topScreen);
|
||||
draw_stats(gameState, renderAssets, internals, audio_is_music_enabled(audioContext), frame);
|
||||
@@ -151,6 +158,8 @@ void do_tick() {
|
||||
check_collision_self(gameState);
|
||||
if (check_collision_apples(gameState)) {
|
||||
audio_play_pickup(audioContext);
|
||||
bg_trigger_pulse(bgContext);
|
||||
timerStart(0, ClockDivider_1024, calculate_timer_reload(gameState), do_tick);
|
||||
}
|
||||
if (check_collision_apples_rotten(gameState)) {
|
||||
audio_play_boom(audioContext);
|
||||
@@ -173,10 +182,11 @@ void do_tick() {
|
||||
}
|
||||
|
||||
void init_game() {
|
||||
|
||||
applesEaten = 0;
|
||||
if (hardMode) {
|
||||
timerStart(0, ClockDivider_1024, static_cast<uint16_t>(TIMER_FREQ_1024(9)), do_tick);
|
||||
setBackdropColorSub(RGB15(10,5,5));
|
||||
timerStart(0, ClockDivider_1024, calculate_timer_reload(gameState), do_tick);
|
||||
setBackdropColorSub(RGB15(8, 3, 3));
|
||||
setBackdropColor(RGB15(6, 2, 2));
|
||||
score = 0;
|
||||
snakelength = START_LENGTH_HARD;
|
||||
snake = { {2,1,1}, {1,1,1} };
|
||||
@@ -197,8 +207,9 @@ void init_game() {
|
||||
}
|
||||
else
|
||||
{
|
||||
timerStart(0, ClockDivider_1024, static_cast<uint16_t>(TIMER_FREQ_1024(5)), do_tick);
|
||||
setBackdropColorSub(RGB15(5,5,5));
|
||||
timerStart(0, ClockDivider_1024, calculate_timer_reload(gameState), do_tick);
|
||||
setBackdropColorSub(RGB15(3, 4, 7));
|
||||
setBackdropColor(RGB15(2, 3, 6));
|
||||
score = 0;
|
||||
snakelength = START_LENGTH;
|
||||
snake = { {4,1,1}, {3,1,1}, {2,1,1}, {1,1,1} };
|
||||
@@ -215,9 +226,6 @@ void init_game() {
|
||||
oamClear(&oamSub,0,128);
|
||||
audio_start_music(audioContext);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
@@ -226,6 +234,8 @@ int main(void) {
|
||||
irqSet(IRQ_VBLANK, handle_vblank);
|
||||
|
||||
setup();
|
||||
setBackdropColor(RGB15(2, 2, 6));
|
||||
setBackdropColorSub(RGB15(2, 2, 6));
|
||||
draw_menu(gameState, renderAssets, audio_is_music_enabled(audioContext));
|
||||
|
||||
InputContext inputContext;
|
||||
|
||||
Reference in new issue
Block a user