From 210f8174370a413456bdb852f3d2d10023da9f29 Mon Sep 17 00:00:00 2001 From: Michael Schwartz Date: Tue, 10 Nov 2020 16:12:30 -0800 Subject: [PATCH] seems done. Boss needs to be tested. Code is in, but not sure it works --- Evade2/CMakeLists.txt | 7 +- Evade2/src/GGame.cpp | 168 +++------------------- Evade2/src/GGame.h | 7 +- Evade2/src/GameState/GGameOverProcess.cpp | 39 +++++ Evade2/src/GameState/GGameOverProcess.h | 24 ++++ Evade2/src/GameState/GGameState.h | 2 +- Evade2/src/GameState/GPlayerProcess.cpp | 23 +-- Evade2/src/GameState/GPlayerProcess.h | 6 +- Evade2/src/SplashState/GSplashProcess.cpp | 13 -- Evade2/src/SplashState/GSplashState.cpp | 4 +- 10 files changed, 110 insertions(+), 183 deletions(-) create mode 100644 Evade2/src/GameState/GGameOverProcess.cpp create mode 100644 Evade2/src/GameState/GGameOverProcess.h diff --git a/Evade2/CMakeLists.txt b/Evade2/CMakeLists.txt index 2d20388..494fab5 100644 --- a/Evade2/CMakeLists.txt +++ b/Evade2/CMakeLists.txt @@ -10,7 +10,6 @@ include(ProcessorCount) SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/creative-engine/cmake.files) - #ADD_COMPILE_DEFINITIONS(__DINGUX__=true) ADD_COMPILE_DEFINITIONS(__MODUS_TARGET_SDL2_AUDIO__=true) ADD_COMPILE_DEFINITIONS(__MODUS_TARGET_DESKTOP_CONTROLS__=true) @@ -48,7 +47,7 @@ INCLUDE_DIRECTORIES( ${CREATIVE_ENGINE_INCLUDE_DIRS} ) -# gather Modite sources +# gather Evade 2 sources FILE(GLOB_RECURSE EVADE2_SRC RELATIVE ${CMAKE_SOURCE_DIR} "src/*.cpp") ADD_EXECUTABLE( @@ -56,7 +55,7 @@ ADD_EXECUTABLE( Resources.bin ${CREATIVE_ENGINE_SOURCE_FILES} ${EVADE2_SRC} - src/GameState/GGameState.cpp src/GameState/GGameState.h src/common/GStarfield.cpp src/common/GStarfield.h src/GameState/GPlayerBulletProcess.cpp src/GameState/GPlayerBulletProcess.h src/main.cpp src/GameState/GEnemyProcess.cpp src/GameState/GEnemyProcess.h src/GameState/GEnemyBulletProcess.cpp src/GameState/GEnemyBulletProcess.h src/AttractState/GAttractState.cpp src/AttractState/GAttractState.h src/AttractState/GAttractProcess.cpp src/AttractState/GAttractProcess.h src/MainMenuState/GMainMenuState.cpp src/MainMenuState/GMainMenuState.h src/MainMenuState/GMainMenuProcess.cpp src/MainMenuState/GMainMenuProcess.h src/GameState/GNextWaveProcess.cpp src/GameState/GNextWaveProcess.h src/GameState/GBossProcess.cpp src/GameState/GBossProcess.h) + src/GameState/GGameState.cpp src/GameState/GGameState.h src/common/GStarfield.cpp src/common/GStarfield.h src/GameState/GPlayerBulletProcess.cpp src/GameState/GPlayerBulletProcess.h src/main.cpp src/GameState/GEnemyProcess.cpp src/GameState/GEnemyProcess.h src/GameState/GEnemyBulletProcess.cpp src/GameState/GEnemyBulletProcess.h src/AttractState/GAttractState.cpp src/AttractState/GAttractState.h src/AttractState/GAttractProcess.cpp src/AttractState/GAttractProcess.h src/MainMenuState/GMainMenuState.cpp src/MainMenuState/GMainMenuState.h src/MainMenuState/GMainMenuProcess.cpp src/MainMenuState/GMainMenuProcess.h src/GameState/GNextWaveProcess.cpp src/GameState/GNextWaveProcess.h src/GameState/GBossProcess.cpp src/GameState/GBossProcess.h src/GameState/GGameOverProcess.cpp src/GameState/GGameOverProcess.h) ProcessorCount(N) if (NOT N EQUAL 0) @@ -69,7 +68,7 @@ BUILD_COMMAND( $(MAKE) --silent ) -# make Modite.app +# make Evade2.app if (APPLE) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE TRUE) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ".") diff --git a/Evade2/src/GGame.cpp b/Evade2/src/GGame.cpp index 8b1b2e4..e6fba3e 100644 --- a/Evade2/src/GGame.cpp +++ b/Evade2/src/GGame.cpp @@ -31,6 +31,7 @@ GGame::GGame() { mDifficulty = 1; gGameEngine = ENull; mState = 0; + mNextState = GAME_STATE_NONE; SetState(GAME_STATE_SPLASH); // SetState(GAME_STATE_GAME); } @@ -74,42 +75,7 @@ void GGame::SetState(GAMESTATE aNewState) { gDisplay.SetColor(EBULLET_COLOR, 50, 50, 255); gDisplay.SetColor(BOMB_COLOR, 255, 255, 50); - mState = aNewState; - switch (aNewState) { - case GAME_STATE_SPLASH: - printf("new State SPLASH\n"); - delete gGameEngine; - gGameEngine = new GSplashState(); - break; - case GAME_STATE_ATTRACT_MODE: - printf("new State ATTRACT\n"); - delete gGameEngine; - gGameEngine = new GAttractState(); - break; - case GAME_STATE_GAME: - printf("new State GAME\n"); - delete gGameEngine; - gGameEngine = new GGameState(); - break; - case GAME_STATE_MAIN_MENU: - printf("new State MAIN MENU\n"); - delete gGameEngine; - gGameEngine = new GMainMenuState(); - break; - case GAME_STATE_VICTORY: - printf("new State VICTORY\n"); - delete gGameEngine; - gGameEngine = new GGameState(); - break; - case GAME_STATE_CREDITS: - printf("new State CREDITS\n"); - delete gGameEngine; - gGameEngine = new GAttractState(); - break; -// case GAME_STATE_NEXT_WAVE: -// printf("new State NEXT WAVE\n"); -// break; - } + mNextState = aNewState; }; TBool GGame::IsGameState() const { @@ -128,148 +94,52 @@ void GGame::Run() { mShmoo.Set(TUint8(mShmoo.r + 16), TUint8(mShmoo.g + 16), TUint8(mShmoo.b + 16)); gDisplay.displayBitmap->SetColor(COLOR_SHMOO, mShmoo); gCamera->Move(); - gGameEngine->GameLoop(); - gDisplay.Update(); - - if (gControls.WasPressed(BUTTONQ)) { - done = ETrue; - } - } - -#if 0 -#ifdef ENABLE_OPTIONS - TBool muted = gOptions->muted; -#endif - - - TBool done = EFalse; - while (!done) { - Random(); // randomize - mShmoo.Set(TUint8(mShmoo.r + 16), TUint8(mShmoo.g + 16), TUint8(mShmoo.b + 16)); - Camera::Move(); - - gDisplay.displayBitmap->SetColor(COLOR_SHMOO, mShmoo); - gDisplay.displayBitmap->SetColor(COLOR_SHMOO_RED, mShmoo.r, 20, 20); - gDisplay.displayBitmap->SetColor(COLOR_SHMOO_GREEN, 20, mShmoo.g, 20); - - // TODO: Add all the basic colors here - gDisplay.SetColor(STAR_COLOR, 180, 180, 180); - gDisplay.SetColor(COLOR_SPACE, 0, 0, 0); - - // The master game loop needs to clear the screen because the star field is ALWAYS running - gDisplay.renderBitmap->Clear(COLOR_SPACE); - - mStarField->Render(); if (mNextState != mState) { + mState = mNextState; switch (mNextState) { case GAME_STATE_SPLASH: + printf("new State SPLASH\n"); delete gGameEngine; gGameEngine = new GSplashState(); break; - case GAME_STATE_MAIN_MENU: - delete gGameEngine; - gGameEngine = new GMainMenuState((GGameState *)gGameEngine); - break; - case GAME_STATE_MAIN_OPTIONS: - delete gGameEngine; - gGameEngine = new GMainOptionsState(); - break; - case GAME_STATE_RESET_OPTIONS: - delete gGameEngine; - gGameEngine = new GResetOptionsState(); - break; case GAME_STATE_ATTRACT_MODE: + printf("new State ATTRACT\n"); delete gGameEngine; - gGameEngine = new GAttractModeState(); + gGameEngine = new GAttractState(); break; - case GAME_STATE_RESET_GAME: case GAME_STATE_GAME: + printf("new State GAME\n"); delete gGameEngine; gGameEngine = new GGameState(); break; - case GAME_STATE_LOAD_SAVEGAME: - case GAME_STATE_RESUME_GAME: + case GAME_STATE_MAIN_MENU: + printf("new State MAIN MENU\n"); delete gGameEngine; - gGameEngine = new GGameState((char *)mLocalData); + gGameEngine = new GMainMenuState(); break; - case GAME_STATE_VICTORY: + printf("new State VICTORY\n"); delete gGameEngine; - gGameEngine = new GVictoryState((GGameState *)gGameEngine); + gGameEngine = new GGameState(); break; - case GAME_STATE_CREDITS: + printf("new State CREDITS\n"); delete gGameEngine; - gGameEngine = new GCreditsState((GGameState *)gGameEngine); + gGameEngine = new GAttractState(); break; - - case GAME_STATE_QUIT: - done = ETrue; - default: - continue; +// case GAME_STATE_NEXT_WAVE: +// printf("new State NEXT WAVE\n"); +// break; } - // reset dKeys so next state doesn't react to any keys already pressed - gControls.dKeys = 0; - mState = mNextState; - } - - - - if (mInventory) { - mInventory->GameLoop(); - } - else if (mGameMenu) { - gGameEngine->GameLoop(); - mGameMenu->GameLoop(); - } - else if (mDebugMenu) { - gGameEngine->GameLoop(); - mDebugMenu->GameLoop(); - } - else { - gGameEngine->GameLoop(); } + gGameEngine->GameLoop(); gDisplay.Update(); - TUint32 now = Milliseconds(); - start = now; - -#ifdef FRAME_RATE_INFO - TUint32 elapsed = now - start; - printf("elapsed %4d\r", elapsed); -#endif - -#ifdef DEBUG_MODE - if (gControls.WasPressed(CONTROL_DEBUG)) { - if (IsGameState()) { - ToggleDebugMenu(); - } - } -#endif - - if (IsGameState() && gControls.WasPressed(BUTTON_START)) { - ToggleInGameMenu(); - } - - // right shoulder button brings up inventory - if (IsGameState() && gControls.WasPressed(CONTROL_INVENTORY)) { - ToggleInventory(); - } + // TODO: @Jay there is no BUTTONQ on device... maybe we want to exit the game on device by some keys? if (gControls.WasPressed(BUTTONQ)) { done = ETrue; } -#ifdef ENABLE_OPTIONS - if (gControls.WasPressed(BUTTON2)) { - muted = !muted; - gOptions->muted = muted; - gOptions->Save(); -#ifdef ENABLE_AUDIO - // //gSoundPlayer.MuteMusic(muted); -#endif - } -#endif } -#endif } diff --git a/Evade2/src/GGame.h b/Evade2/src/GGame.h index 26f9abb..87df871 100644 --- a/Evade2/src/GGame.h +++ b/Evade2/src/GGame.h @@ -1,15 +1,14 @@ #ifndef BRICKOUT_GGAME_H #define BRICKOUT_GGAME_H -//#include "Game.h" #include -//#include "GStarFieldProcess.h" class BGameEngine; class BFont; enum GAMESTATE { + GAME_STATE_NONE, GAME_STATE_SPLASH, GAME_STATE_MAIN_MENU, GAME_STATE_ATTRACT_MODE, @@ -37,7 +36,9 @@ class GGame : public BApplication { TUint8 mDifficulty; static TBool mDebug; + protected: + TInt mNextState; TInt mState; TRGB mShmoo; }; @@ -46,4 +47,4 @@ extern GGame *gGame; extern BGameEngine *gGameEngine; extern BFont *gFont8x8, *gFont16x16; -#endif //BRICKOUT_GGAME_H +#endif //GGame.h diff --git a/Evade2/src/GameState/GGameOverProcess.cpp b/Evade2/src/GameState/GGameOverProcess.cpp new file mode 100644 index 0000000..4c953c6 --- /dev/null +++ b/Evade2/src/GameState/GGameOverProcess.cpp @@ -0,0 +1,39 @@ +// +// Created by Michael Schwartz on 11/10/20. +// + +#include "GGameOverProcess.h" +#include "GGameState.h" +#include "GMainMenuState.h" +#include "GCamera.h" + +GGameOverProcess::GGameOverProcess() : BProcess() { + gGameState->mState = STATE_GAME_OVER; + mTheta = 0; + mTimer = 200; + gCamera->vx = gCamera->vy = 0; + gCamera->vz = CAMERA_WARP_VZ; + gControls.Reset(); + // TODO: @Jay game over sound here +} + +GGameOverProcess::~GGameOverProcess() noexcept = default; + +TBool GGameOverProcess::RunBefore() { + if (mTimer-- < 0) { + gGame->SetState(GAME_STATE_MAIN_MENU); + return EFalse; + } + return ETrue; +} + +TBool GGameOverProcess::RunAfter() { + mTheta += 6; + gVectorFont->scale = 3; + gVectorFont->color = COLOR_SHMOO; + gVectorFont->print_string_rotatedx(53, 80, mTheta, "GAME OVER"); + gVectorFont->scale = 1.5; + gVectorFont->color = COLOR_WHITE; + gVectorFont->printf(gGameState->mWave < 9 ? 50 : 45, 160, "WAVES SURVIVED: %d", gGameState->mWave - 1); + return ETrue; +} diff --git a/Evade2/src/GameState/GGameOverProcess.h b/Evade2/src/GameState/GGameOverProcess.h new file mode 100644 index 0000000..93cf41c --- /dev/null +++ b/Evade2/src/GameState/GGameOverProcess.h @@ -0,0 +1,24 @@ +// +// Created by Michael Schwartz on 11/10/20. +// + +#ifndef EVADE2_GGAMEOVERPROCESS_H +#define EVADE2_GGAMEOVERPROCESS_H + +#include "Game.h" + +class GGameOverProcess : public BProcess { +public: + GGameOverProcess(); + ~GGameOverProcess(); + +public: + TBool RunBefore(); + TBool RunAfter(); +protected: + TFloat mTheta; + TInt16 mTimer; +}; + + +#endif //EVADE2_GGAMEOVERPROCESS_H diff --git a/Evade2/src/GameState/GGameState.h b/Evade2/src/GameState/GGameState.h index 320e2ad..d23fe1d 100644 --- a/Evade2/src/GameState/GGameState.h +++ b/Evade2/src/GameState/GGameState.h @@ -11,6 +11,7 @@ enum { STATE_PLAY, STATE_BOSS, STATE_NEXT_WAVE, + STATE_GAME_OVER }; class GPlayerProcess; @@ -29,7 +30,6 @@ class GGameState : public BGameEngine { TInt32 mState; TInt16 mKills; TInt16 mWave; - }; extern GGameState *gGameState; diff --git a/Evade2/src/GameState/GPlayerProcess.cpp b/Evade2/src/GameState/GPlayerProcess.cpp index 25e6c48..fcfca49 100644 --- a/Evade2/src/GameState/GPlayerProcess.cpp +++ b/Evade2/src/GameState/GPlayerProcess.cpp @@ -5,6 +5,8 @@ #include "Game.h" #include "GCamera.h" +#include "GGameState.h" +#include "GGameOverProcess.h" #include "GPlayerBulletProcess.h" #include "img/hud_console_img.h" @@ -25,7 +27,7 @@ const TUint8 crosshair_right_4x8[] = { #define MAX_LIFE 100 GPlayerProcess::GPlayerProcess() { - color = COLOR_WHITE; + color = COLOR_WHITE; gCamera->vz = CAMERA_VZ; power = MAX_POWER; shield = MAX_LIFE; @@ -47,7 +49,7 @@ void GPlayerProcess::DrawLine(TFloat x1, TFloat y1, TFloat x2, TFloat y2) const gDisplay.renderBitmap->DrawLine(gViewPort, x1, y1, x2, y2, color); } -void GPlayerProcess::DrawBitmap(TInt16 x, TInt16 y, const TUint8 *bitmap, TUint8 w, TUint8 h, TUint8 aColor) const { +void GPlayerProcess::DrawBitmap(TInt16 x, TInt16 y, const TUint8 *bitmap, TUint8 w, TUint8 h, TUint8 aColor) const { if (x + w < 0 || x > SCREEN_WIDTH - 1 || y + h < 0 || y > SCREEN_HEIGHT - 1) { return; } @@ -102,6 +104,7 @@ void GPlayerProcess::DrawBitmap(TInt16 x, TInt16 y, const TUint8 *bitmap, TUint8 void GPlayerProcess::Hit(TInt8 amount) { shield -= amount; if (shield <= 0) { + gGameEngine->AddProcess(new GGameOverProcess()); // ProcessManager::birth(GameOver::entry); } else { mHit = ETrue; @@ -122,15 +125,16 @@ void GPlayerProcess::recharge_power() { } TBool GPlayerProcess::RunBefore() { + if (gGameState->mState == STATE_GAME_OVER) { + return EFalse; + } if (gGame->GetState() != GAME_STATE_GAME) { - // if (game_mode != MODE_GAME) { gCamera->vx = gCamera->vy = 0; return ETrue; } if (gControls.WasPressed(CONTROL_FIRE)) { if (mNumBullets < MAX_BULLETS) { - TInt8 deltaX = 0, deltaY = 0; @@ -140,7 +144,6 @@ TBool GPlayerProcess::RunBefore() { deltaY = gControls.IsPressed(CONTROL_JOYUP) ? -11 : deltaY; deltaY = gControls.IsPressed(CONTROL_JOYDOWN) ? 13 : deltaY; - gGameEngine->AddProcess(new GPlayerBulletProcess(deltaX, deltaY, mAlt)); mAlt = !mAlt; @@ -190,12 +193,12 @@ TBool GPlayerProcess::RunBefore() { void GPlayerProcess::DrawHud(TFloat x, TFloat y) { const TUint8 color = COLOR_WHITE; - const TFloat width = 0x30, height = 0x08; + const TFloat width = 0x30, height = 0x08; const TUint8 *bitmap = hud_console_img; for (TInt xx = 0, xxx = 0; xx < width; xx++, xxx += 2) { for (TInt yy = 0, yyy = 0; yy < height; yy++, yyy += 2) { - if (y + yy > SCREEN_HEIGHT-1) { + if (y + yy > SCREEN_HEIGHT - 1) { continue; } TInt8 byte = bitmap[xx + (yy / 8)]; @@ -253,6 +256,7 @@ void GPlayerProcess::DrawMeter(TInt8 side, TInt8 value, TInt8 deltaXMeter, TInt8 } #else +// TODO: @Jay - we should probably remove this code/condition. This else code is not touched/ported to CE // 13 == full. Anything less, and we draw "less meter" void GPlayerProcess::DrawMeter(TInt8 side, TInt8 value) { @@ -293,6 +297,9 @@ void GPlayerProcess::DrawMeter(TInt8 side, TInt8 value) { #endif // #if ENABLE_HUD_MOVEMENTS TBool GPlayerProcess::RunAfter() { + if (gGameState->mState == STATE_GAME_OVER) { + return EFalse; + } if (mHit) { gDisplay.SetColor(0, 255, 255, 255); } else { @@ -328,7 +335,7 @@ TBool GPlayerProcess::RunAfter() { } } - const TFloat screenMidX = TFloat(SCREEN_WIDTH)/2, screenMidY = TFloat(SCREEN_HEIGHT)/2; + const TFloat screenMidX = TFloat(SCREEN_WIDTH) / 2, screenMidY = TFloat(SCREEN_HEIGHT) / 2; DrawHud(screenMidX - (0x30) + consoleX, (240 + consoleY) - 12); diff --git a/Evade2/src/GameState/GPlayerProcess.h b/Evade2/src/GameState/GPlayerProcess.h index eb48be0..a3a80e2 100644 --- a/Evade2/src/GameState/GPlayerProcess.h +++ b/Evade2/src/GameState/GPlayerProcess.h @@ -13,9 +13,9 @@ class GPlayerProcess : public BProcess { GPlayerProcess(); public: - TInt8 power; - TInt8 shield; - TInt8 mNumBullets; + TInt16 power; + TInt16 shield; + TInt16 mNumBullets; // TUint8 flags; TUint8 color; TBool mAlt; diff --git a/Evade2/src/SplashState/GSplashProcess.cpp b/Evade2/src/SplashState/GSplashProcess.cpp index dcdbaea..7e5ba24 100644 --- a/Evade2/src/SplashState/GSplashProcess.cpp +++ b/Evade2/src/SplashState/GSplashProcess.cpp @@ -20,19 +20,6 @@ TBool GSplashProcess::RunBefore() { return ETrue; } -TBool GSplashProcess::FadeInState() { -// mColor += (255 / 30); -// if (mColor > 255) { -// mColor = 255; -// } -// gDisplay.SetColor(COLOR_TEXT, mColor, mColor, mColor); -// if (mColor == 255) { -// mState = STATE_WAIT; -// mTimer = 2 * 30; -// } - return ETrue; -} - TBool GSplashProcess::FadeOutState() { // mColor -= (255 / 30); // if (mColor < 0) { diff --git a/Evade2/src/SplashState/GSplashState.cpp b/Evade2/src/SplashState/GSplashState.cpp index 91f31bf..e06ec22 100644 --- a/Evade2/src/SplashState/GSplashState.cpp +++ b/Evade2/src/SplashState/GSplashState.cpp @@ -10,7 +10,7 @@ GSplashState::GSplashState() : BGameEngine(gViewPort) { } GSplashState::~GSplashState() { - delete mPlayfield; - mPlayfield = ENull; +// delete mPlayfield; +// mPlayfield = ENull; }