Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu #3

Merged
merged 7 commits into from
Oct 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ foreach(bitmap_path ${bitmaps}) # /path/file.png
endforeach()

# Alpha bitmaps

file(GLOB bitmaps
_res/drill.png _res/tool.png
_res/drill_2.png _res/tool_2.png
_res/track.png _res/jet.png
_res/logo.png
)

set(color_transparent "\\#993399")
foreach(bitmap_path ${bitmaps}) # /path/file.png
get_filename_component(bitmap_file_png ${bitmap_path} NAME) # file.png
Expand Down
Binary file added _res/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 34 additions & 16 deletions src/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "tile.h"
#include "window.h"
#include "vendor.h"
#include "menu.h"

static tView *s_pView;
static tVPort *s_pVpMain;
Expand All @@ -28,20 +29,32 @@ static UWORD s_uwColorBg;
tFont *g_pFont;
UBYTE g_is2pPlaying;

static void goToMenu(void) {
// Switch to menu, after popping it will process gameGsLoop
gamePushState(menuGsCreate, menuGsLoop, menuGsDestroy);
}

void gameStart(void) {
tileInit();
vehicleReset(&g_pVehicles[0]);
vehicleReset(&g_pVehicles[1]);
hudReset();
}

void gameGsCreate(void) {
s_pView = viewCreate(0,
TAG_VIEW_GLOBAL_CLUT, 1,
TAG_END);
s_pView = viewCreate(0,
TAG_VIEW_GLOBAL_CLUT, 1,
TAG_END);

g_pFont = fontCreate("data/silkscreen5.fnt");
s_pTiles = bitmapCreateFromFile("data/tiles.bm");
hudCreate(s_pView, g_pFont);

s_pVpMain = vPortCreate(0,
TAG_VPORT_VIEW, s_pView,
TAG_VPORT_BPP, 4,
TAG_END);
g_pMainBuffer = tileBufferCreate(0,
s_pVpMain = vPortCreate(0,
TAG_VPORT_VIEW, s_pView,
TAG_VPORT_BPP, 4,
TAG_END);
g_pMainBuffer = tileBufferCreate(0,
TAG_TILEBUFFER_VPORT, s_pVpMain,
TAG_TILEBUFFER_BITMAP_FLAGS, BMF_CLEAR | BMF_INTERLEAVED,
TAG_TILEBUFFER_BOUND_TILE_X, 11,
Expand All @@ -50,7 +63,7 @@ void gameGsCreate(void) {
TAG_TILEBUFFER_TILE_SHIFT, 5,
TAG_TILEBUFFER_REDRAW_QUEUE_LENGTH, 100,
TAG_TILEBUFFER_TILESET, s_pTiles,
TAG_END);
TAG_END);

paletteLoad("data/aminer.plt", s_pVpMain->pPalette, 16);
s_uwColorBg = s_pVpMain->pPalette[0];
Expand All @@ -67,15 +80,19 @@ void gameGsCreate(void) {
vehicleBitmapsCreate();
vehicleCreate(&g_pVehicles[0], PLAYER_1);
vehicleCreate(&g_pVehicles[1], PLAYER_2);
menuPreload();
bobNewAllocateBgBuffers();
systemUnuse();

g_pMainBuffer->pCamera->uPos.sUwCoord.uwX = 32;

s_isDebug = 0;
g_is2pPlaying = 1;
tileBufferInitialDraw(g_pMainBuffer);

// Load the view
viewLoad(s_pView);
// Load the view
viewLoad(s_pView);
goToMenu();
}

static void gameProcessInput(void) {
Expand Down Expand Up @@ -118,8 +135,8 @@ static inline void debugColor(UWORD uwColor) {
}

void gameGsLoop(void) {
if(keyCheck(KEY_ESCAPE)) {
gameClose();
if(keyUse(KEY_ESCAPE)) {
goToMenu();
return;
}
if(keyUse(KEY_B)) {
Expand All @@ -146,15 +163,15 @@ void gameGsLoop(void) {
bobNewEnd();
hudUpdate();

UWORD uwCamX, uwCamY;
UWORD uwCamX = 32, uwCamY;
if(!g_is2pPlaying) {
// One player only
uwCamX = fix16_to_int(g_pVehicles[0].fX) + VEHICLE_WIDTH / 2;
// uwCamX = fix16_to_int(g_pVehicles[0].fX) + VEHICLE_WIDTH / 2;
uwCamY = fix16_to_int(g_pVehicles[0].fY) + VEHICLE_HEIGHT / 2;
}
else {
// Two players
uwCamX = (fix16_to_int(g_pVehicles[0].fX) + fix16_to_int(g_pVehicles[1].fX) + VEHICLE_WIDTH) / 2;
// uwCamX = (fix16_to_int(g_pVehicles[0].fX) + fix16_to_int(g_pVehicles[1].fX) + VEHICLE_WIDTH) / 2;
uwCamY = (fix16_to_int(g_pVehicles[0].fY) + fix16_to_int(g_pVehicles[1].fY) + VEHICLE_HEIGHT) / 2;
}
cameraCenterAt(
Expand All @@ -173,6 +190,7 @@ void gameGsDestroy(void) {
// Cleanup when leaving this gamestate
systemUse();

menuUnload();
bitmapDestroy(s_pTiles);
fontDestroy(g_pFont);
vehicleDestroy(&g_pVehicles[0]);
Expand Down
2 changes: 2 additions & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ void gameGsLoop(void);

void gameGsDestroy(void);

void gameStart(void);

extern tTileBufferManager *g_pMainBuffer;
extern tFont *g_pFont;
extern UBYTE g_is2pPlaying;
Expand Down
15 changes: 12 additions & 3 deletions src/hud.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void hudCreate(tView *pView, const tFont *pFont) {
s_pFont = pFont;
s_pLinebuffer = fontCreateTextBitMap(s_pHudBuffer->uBfrBounds.sUwCoord.uwX, 5);

s_uwHudOffsX = 0;
for(UBYTE ubPlayer = PLAYER_1; ubPlayer <= PLAYER_2; ++ubPlayer) {
fontDrawStr(
s_pHudBuffer->pBack, s_pFont, s_uwHudOffsX + FUEL_LABEL_X, ROW_1_Y,
Expand All @@ -91,7 +92,16 @@ void hudCreate(tView *pView, const tFont *pFont) {
s_pHudBuffer->pBack, s_pFont, s_uwHudOffsX + CASH_LABEL_X, ROW_2_Y,
"Cash:", COLOR_ACTIVE, FONT_LAZY
);
// Move to 2nd player's HUD
s_uwHudOffsX = 160;
}

hudReset();
}

void hudReset(void) {
s_uwHudOffsX = 0;
for(UBYTE ubPlayer = PLAYER_1; ubPlayer <= PLAYER_2; ++ubPlayer) {
// Fuel inactive gauge
for(UBYTE i = 0; i < 30; ++i) {
chunkyToPlanar(
Expand All @@ -117,11 +127,10 @@ void hudCreate(tView *pView, const tFont *pFont) {
);
}

// Move to 2nd player's HUD
s_uwHudOffsX = 160;
}

// Values to display - P1
for(UBYTE ubPlayer = PLAYER_1; ubPlayer <= PLAYER_2; ++ubPlayer) {
// Values to display
s_pPlayerData[ubPlayer].uwOldDepth = 0xFFFF;
s_pPlayerData[ubPlayer].uwDepth = 0;
s_pPlayerData[ubPlayer].ulOldCash = 0xFFFFFFFF;
Expand Down
2 changes: 2 additions & 0 deletions src/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ void hudCreate(tView *pView, const tFont *pFont);

void hudDestroy(void);

void hudReset(void);

void hudSetDepth(UBYTE ubPlayer, UWORD uwDepth);

void hudSetScore(UBYTE ubPlayer, ULONG ulCash);
Expand Down
176 changes: 176 additions & 0 deletions src/menu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "menu.h"
#include <ace/managers/key.h>
#include <ace/managers/game.h>
#include "game.h"
#include "bob_new.h"
#include "text_bob.h"

typedef enum _tMenuState {
MENU_STATE_ROLL_IN = 0,
MENU_STATE_SELECTING,
MENU_STATE_ROLL_OUT
} tMenuState;

typedef enum _tMenuPos {
MENU_POS_START,
MENU_POS_MODE,
MENU_POS_PLAYERS,
MENU_POS_EXIT
} tMenuPos;

#define MENU_COLOR_INACTIVE 10
#define MENU_COLOR_ACTIVE 14

static tMenuState s_eMenuState;
static tMenuPos s_eActivePos;
static tBitMap *s_pLogo, *s_pLogoMask;
static tTextBob s_pMenuPositions[4];
static tBobNew s_sBobLogo;
static UWORD s_uwOffsY;

void menuPreload(void) {
s_pLogo = bitmapCreateFromFile("data/logo.bm");
s_pLogoMask = bitmapCreateFromFile("data/logo_mask.bm");
bobNewInit(
&s_sBobLogo, bitmapGetByteWidth(s_pLogo) * 8, s_pLogo->Rows,
0, s_pLogo, s_pLogoMask, 0, 0
);
for(UBYTE i = 0; i < 4; ++i) {
textBobCreate(&s_pMenuPositions[i], g_pFont, "Some longish menu text");
}
}

void menuUnload(void) {
bitmapDestroy(s_pLogo);
bitmapDestroy(s_pLogoMask);
for(UBYTE i = 0; i < 4; ++i) {
textBobDestroy(&s_pMenuPositions[i]);
}
}

void menuGsCreate(void) {
s_eMenuState = MENU_STATE_ROLL_IN;
}

void menuGsLoop(void) {
if(keyUse(KEY_ESCAPE)) {
gameClose();
return;
}

bobNewBegin();

UWORD *pCamY = &g_pMainBuffer->pCamera->uPos.sUwCoord.uwY;
UWORD uwAvailHeight = g_pMainBuffer->pScroll->uwBmAvailHeight;
switch(s_eMenuState) {
case MENU_STATE_ROLL_IN: {
if(*pCamY < uwAvailHeight) {
*pCamY += 4;
}
else if(*pCamY > uwAvailHeight) {
*pCamY = uwAvailHeight + (*pCamY % uwAvailHeight);
if(*pCamY - uwAvailHeight > 4) {
*pCamY -= 4;
}
else {
*pCamY = uwAvailHeight;
}
}
else {
s_eMenuState = MENU_STATE_SELECTING;
s_eActivePos = MENU_POS_START;
s_sBobLogo.sPos.ulYX = g_pMainBuffer->pCamera->uPos.ulYX;
s_sBobLogo.sPos.sUwCoord.uwX += (320 - s_sBobLogo.uwWidth)/2;
s_sBobLogo.sPos.sUwCoord.uwY += 16;
s_uwOffsY = s_sBobLogo.sPos.sUwCoord.uwY + s_sBobLogo.uwHeight + 50;
const char * const pMenuTexts[4] = {
"Start game", "Mode: free play", "Players: 1", "Exit to Workbench"
};
g_is2pPlaying = 0;
for(UBYTE i = 0; i < 4; ++i) {
textBobSet(
&s_pMenuPositions[i], pMenuTexts[i],
i == 0 ? MENU_COLOR_ACTIVE : MENU_COLOR_INACTIVE,
160 + 32 - s_pMenuPositions[i].uwWidth / 2,
s_uwOffsY + i * 10, 0
);
textBobUpdate(&s_pMenuPositions[i]);
}
}
} break;

case MENU_STATE_SELECTING: {
if(keyUse(KEY_UP) || keyUse(KEY_W)) {
if(s_eActivePos) {
textBobChangeColor(&s_pMenuPositions[s_eActivePos], MENU_COLOR_INACTIVE);
textBobUpdate(&s_pMenuPositions[s_eActivePos]);
--s_eActivePos;
textBobChangeColor(&s_pMenuPositions[s_eActivePos], MENU_COLOR_ACTIVE);
textBobUpdate(&s_pMenuPositions[s_eActivePos]);
}
}
else if(keyUse(KEY_DOWN) || keyUse(KEY_S)) {
if(s_eActivePos < 4-1) {
textBobChangeColor(&s_pMenuPositions[s_eActivePos], MENU_COLOR_INACTIVE);
textBobUpdate(&s_pMenuPositions[s_eActivePos]);
++s_eActivePos;
textBobChangeColor(&s_pMenuPositions[s_eActivePos], MENU_COLOR_ACTIVE);
textBobUpdate(&s_pMenuPositions[s_eActivePos]);
}
}
else if(keyUse(KEY_LEFT) || keyUse(KEY_A)) {
if(s_eActivePos == MENU_POS_PLAYERS && g_is2pPlaying) {
g_is2pPlaying = 0;
textBobChangeText(&s_pMenuPositions[MENU_POS_PLAYERS], "Players: 1");
textBobUpdate(&s_pMenuPositions[MENU_POS_PLAYERS]);
}
}
else if(keyUse(KEY_RIGHT) || keyUse(KEY_D)) {
if(s_eActivePos == MENU_POS_PLAYERS && !g_is2pPlaying) {
g_is2pPlaying = 1;
textBobChangeText(&s_pMenuPositions[MENU_POS_PLAYERS], "Players: 2");
textBobUpdate(&s_pMenuPositions[MENU_POS_PLAYERS]);
}
}
else if(keyUse(KEY_RETURN) || keyUse(KEY_SPACE)) {
if(s_eActivePos == MENU_POS_START) {
gameStart();
s_eMenuState = MENU_STATE_ROLL_OUT;
}
else if(s_eActivePos == MENU_POS_EXIT) {
gameClose();
return;
}
}
bobNewPush(&s_sBobLogo);
bobNewPush(&s_pMenuPositions[MENU_POS_START].sBob);
bobNewPush(&s_pMenuPositions[MENU_POS_MODE].sBob);
bobNewPush(&s_pMenuPositions[MENU_POS_PLAYERS].sBob);
bobNewPush(&s_pMenuPositions[MENU_POS_EXIT].sBob);
} break;

case MENU_STATE_ROLL_OUT: {
if(g_pMainBuffer->pCamera->uPos.sUwCoord.uwY) {
g_pMainBuffer->pCamera->uPos.sUwCoord.uwY -= 4;
}
else {
gamePopState();
}
}
}

bobNewPushingDone();
bobNewEnd();

viewProcessManagers(g_pMainBuffer->sCommon.pVPort->pView);
copProcessBlocks();
vPortWaitForEnd(g_pMainBuffer->sCommon.pVPort);
}

void menuGsDestroy(void) {

}
17 changes: 17 additions & 0 deletions src/menu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef _MENU_H_
#define _MENU_H_

void menuGsCreate(void);

void menuGsLoop(void);

void menuGsDestroy(void);

void menuPreload(void);
void menuUnload(void);

#endif // _MENU_H_
Loading