Skip to content

Commit

Permalink
Update files to release 1.1
Browse files Browse the repository at this point in the history
- Added fade-in and fade-out effects
- Added new tile images
- Improved the way palettes are handled by the game
- Minor optimizations
- Modified endgame message layout
- Modified selector position offset
- Modified variable type names in header files for consistency
- Fixed an issue where loading a saved game doesn't properly set disqualified player colors
- Fixed an issue where menu sprites don't disappear before starting a new game
- Fixed grid rendering being visible for a split second
  • Loading branch information
Nightwolf-47 committed Sep 13, 2022
1 parent f19655c commit 2234995
Show file tree
Hide file tree
Showing 24 changed files with 149 additions and 108 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ src/boot/
.archive/
.vscode/
res/resources.h
*.txt
Binary file modified res/graphics/borderh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/graphics/borderv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/graphics/tile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/graphics/tile1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/graphics/tile2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/graphics/tile3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/graphics/tile4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified res/graphics/tileexp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions res/resources.res
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ IMAGE texTitleScr1 "graphics/titlescreen1.png" 2
IMAGE texMenuBG "graphics/menubg.png" 2
SPRITE sprAtom "graphics/atom.png" 1 1 NONE
SPRITE sprSel "graphics/selector.png" 4 4 NONE
WAV sfx_click "sfx/click.wav" 5
WAV sfx_put "sfx/put.wav" 5
WAV sfx_explode "sfx/explode.wav" 5
WAV sfx_click "sfx/click.wav" XGM
WAV sfx_put "sfx/put.wav" XGM
WAV sfx_explode "sfx/explode.wav" XGM
25 changes: 19 additions & 6 deletions src/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ u8 currentState = ST_GAMESTATE;

bool randomNoPattern = TRUE;

const char* versionStr = "1.0";
const char* versionStr = "1.1";

u16 newPalette[64] = {0};

struct VidReservedImage vimages[VIMAGE_MAXCOUNT]; //Array of image data with reserved VRAM tile positions

int vImageCount = 0;

u16 newVImagePos = TILE_USERINDEX;

bool isDemoPlaying = FALSE;

void data_init(void)
Expand Down Expand Up @@ -53,8 +53,8 @@ VidImagePtr reserveVImage(const Image* img)
}
VidImagePtr vidimg = &vimages[vImageCount];
vidimg->img = img;
vidimg->vPos = newVImagePos;
newVImagePos += img->tileset->numTile;
vidimg->vPos = curTileInd;
curTileInd += img->tileset->numTile;
vImageCount++;
return vidimg;
}
Expand All @@ -65,15 +65,28 @@ void changeState(enum States newState)
{
SYS_die("Invalid game state!");
}
switch(newState)
{
case ST_TITLESTATE:
PAL_setColors(0,palette_black,64,CPU);
break;
default:
PAL_fadeOut(0,63,10,FALSE);
break;
}
if(states[currentState].stop)
states[currentState].stop();
VDP_clearPlane(BG_A,TRUE);
VDP_clearPlane(BG_B,TRUE);
VDP_clearSprites();
SPR_defragVRAM();
SPR_update();
vImageCount = 0;
newVImagePos = TILE_USERINDEX;
curTileInd = TILE_USERINDEX;
currentState = newState;
memset(newPalette,0,sizeof(newPalette));
newPalette[15] = RGB24_TO_VDPCOLOR(0xEEEEEE);
if(states[currentState].init)
states[currentState].init();
PAL_fadeIn(0,63,newPalette,15,TRUE);
}
2 changes: 2 additions & 0 deletions src/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ extern struct KASettings settings; //Game settings, can be changed in main menu

extern const char* versionStr; //Version string, shows up in About menu

extern u16 newPalette[64]; //New palette, has to be set in init() function of a given state

extern struct VidReservedImage vimages[VIMAGE_MAXCOUNT];

extern bool isDemoPlaying;
Expand Down
3 changes: 1 addition & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
#include "states/game/gamestate.h"
#include "states/title/titlestate.h"
#include "states/menu/menustate.h"
#include <timer.h>

void joyEventHandler(u16 joy, u16 changed, u16 state)
{
if(states[currentState].joyevent)
if(states[currentState].joyevent && !PAL_isDoingFade())
states[currentState].joyevent(joy,changed,state);
}

Expand Down
5 changes: 3 additions & 2 deletions src/save.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef SAVE_H_DEFINED
#define SAVE_H_DEFINED
#include <types.h>

#define SETTINGS_SRAM_POS 1
#define SAVEDATA_SRAM_POS 11
Expand All @@ -15,11 +16,11 @@ void loadSRAM(void);
void invalidateSRAM(void);

//Load game data from SRAM
long loadGameData(void);
fix32 loadGameData(void);

//Save game data to SRAM as KSF (KleleAtoms 1.3 save format)
void saveGameData(void);

extern unsigned short saveValid;
extern bool saveValid;

#endif //SAVE_H_DEFINED
9 changes: 5 additions & 4 deletions src/states/game/gameai.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ void aiGetSpecialTiles(int difficulty, s16 (*psptiles)[84], s16 (*ptiles)[84], s
{
for(int y=0; y<grid.height; y++)
{
struct Tile* curtile = &grid.tiles[GXYIndex(x,y)];
u16 tileIndex = GXYIndex(x,y); //Current checked tile index
struct Tile* curtile = &grid.tiles[tileIndex];
if(curtile->playerNum == curPlayer || curtile->playerNum == NOPLAYER) //Atom can be placed on that tile
{
bool isSpTile = FALSE;
Expand All @@ -132,7 +133,7 @@ void aiGetSpecialTiles(int difficulty, s16 (*psptiles)[84], s16 (*ptiles)[84], s
{
if(aiCheckPreCrit(x,y)) //Tile is special if you and another player have near-critical atom tiles near each other
{
if(curtile->atomCount == (critGrid[GXYIndex(x,y)]-1))
if(curtile->atomCount == (critGrid[tileIndex]-1))
{
sptiles[*pspcount] = PACKCoords(x,y);
*pspcount += 1;
Expand All @@ -156,7 +157,7 @@ void aiGetSpecialTiles(int difficulty, s16 (*psptiles)[84], s16 (*ptiles)[84], s
}
else if(aiCheckPreCrit(x,y)) //The same as in difficulty 2
{
if(atomcount == (critGrid[GXYIndex(x,y)]-1))
if(atomcount == (critGrid[tileIndex]-1))
{
sptiles[*pspcount] = PACKCoords(x,y);
*pspcount += 1;
Expand All @@ -170,7 +171,7 @@ void aiGetSpecialTiles(int difficulty, s16 (*psptiles)[84], s16 (*ptiles)[84], s
}
bool isAdvantage = FALSE;
if(!isSpTile) //If a tile isn't special, check if you have an atom advantage over another player
isAdvantage = aiCheckAdvantage(x,y,(s16)(atomcount)-(s16)(critGrid[GXYIndex(x,y)]));
isAdvantage = aiCheckAdvantage(x,y,(s16)(atomcount)-(s16)(critGrid[tileIndex]));

if(!tileAvoided && isCorner && (aicornercount == 0 || aiCornerCheck(x,y))) //Add the corner tile to the corner array
{
Expand Down
5 changes: 3 additions & 2 deletions src/states/game/gameai.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#ifndef GAMEAI_H_INCLUDED
#define GAMEAI_H_INCLUDED
#include <types.h>

extern unsigned short aiPlayerTab[4]; //If TRUE, player is AI-controlled
extern bool aiPlayerTab[4]; //If TRUE, player is AI-controlled

extern int aiDifficulty[4]; //Array of AI difficulty (1-3) per player

void ai_init(void);

void ai_resetTime(void);

void ai_tryMove(long dt);
void ai_tryMove(fix32 dt);

#endif //GAMEAI_H_INCLUDED
26 changes: 18 additions & 8 deletions src/states/game/gamelogic.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,19 @@ const char* playerNames[4] = {"Red","Blue","Green","Yellow"};

bool logicEnd = FALSE; //If TRUE the game will end and it will wait for a button press

void logic_endMessage(char* msg)
const fix32 baseExplodeTime = FIX32(0.3); //Longest duration of explosion sprite being shown after atom explosion

void logic_endMessage(const char* msg)
{
logicEnd = TRUE;
VDP_clearText(5+8*curPlayer,3,1);
VDP_clearText(8+8*curPlayer,3,1);
VDP_clearText(0,5,40);
VDP_clearTileMapRect(BG_B,1,0,40,6);
VDP_drawText(msg,20-(strlen(msg)>>1),1);
VDP_drawText("Press any button to go to menu",5,2);
VDP_clearText(31,0,9);
VDP_clearText(1,0,10);
VDP_drawText(msg,GETCENTERX(msg),0);
VDP_drawText("Press any button to go to menu",5,2);
curPlayer = 0;
}

Expand Down Expand Up @@ -292,7 +294,7 @@ void explodeAtoms(u8 x, u8 y, s16 atplayer)
explosionCount++;
u16 index = GXYIndex(x,y);
struct Tile* curTile = &grid.tiles[index];
curTile->explodeTime = FIX32(0.3)/max(min(explosionCount,1000)/10,1);
curTile->explodeTime = baseExplodeTime/max(min(explosionCount,1000)/10,1);
u8 extra = (u8)max(curTile->atomCount-critGrid[index],0); //Amount of atoms above critical amount
curTile->atomCount = 0;
curTile->playerNum = NOPLAYER;
Expand Down Expand Up @@ -423,7 +425,7 @@ void logic_loadAll(u8 gridWidth, u8 gridHeight, u8 (*ppttab)[4])
}
else //Player is not present, make their icon black (invisible)
{
PAL_setColor((i*16)+6,RGB24_TO_VDPCOLOR(0x000000));
newPalette[(i*16)+6] = RGB24_TO_VDPCOLOR(0x000000);
}
}
if(curPlayer == NOPLAYER || playerCount < 2)
Expand Down Expand Up @@ -488,9 +490,16 @@ void logic_fixLoadedData()
}
for(int i=0; i<4; i++)
{
if(playerTab[i]==PTAB_NO)
switch(playerTab[i])
{
PAL_setColor((i*16)+6,RGB24_TO_VDPCOLOR(0x000000));
case PTAB_NO:
newPalette[(i*16)+6] = RGB24_TO_VDPCOLOR(0x000000);
break;
case PTAB_LOST:
newPalette[(i*16)+6] = RGB24_TO_VDPCOLOR(0x808080);
break;
default:
break;
}
}
animPlaying = FALSE;
Expand Down Expand Up @@ -567,7 +576,8 @@ void logic_tick(fix32 dt)
else if(asPos > 0)
{
int curAsPos = asPos;
for(int i=0; i<min(asPos,50); i++) //Pop up to 50 positions from atomStack, stop if a critical tile is found or atomStack is empty
int popCount = min(asPos,50);
for(int i=0; i<popCount; i++) //Pop up to 50 positions from atomStack, stop if a critical tile is found or atomStack is empty
{
s8 ttposx = atomStack[curAsPos-1] >> 4;
s8 ttposy = atomStack[curAsPos-1] & 0xF;
Expand Down
58 changes: 32 additions & 26 deletions src/states/game/gamelogic.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#ifndef GAMELOGIC_H_INCLUDED
#define GAMELOGIC_H_INCLUDED
#include <types.h>

#define GRIDSIZE 24

#define ATOMSPEED 30
Expand All @@ -16,22 +20,22 @@

struct Tile
{
short playerNum;
unsigned char atomCount;
long explodeTime; //If > 0, explosion sprite will appear
s16 playerNum;
u8 atomCount;
fix32 explodeTime; //If > 0, explosion sprite will appear
};

struct AtomPosition
{
short destx;
short desty;
s16 destx;
s16 desty;
};

struct KAExplodePos
{
unsigned char x;
unsigned char y;
unsigned short willExplode;
u8 x;
u8 y;
bool willExplode;
};

struct KAGrid
Expand All @@ -43,60 +47,62 @@ struct KAGrid

extern struct KAGrid grid;

extern unsigned char critGrid[84];
extern u8 critGrid[84];

extern unsigned short animPlaying;
extern bool animPlaying;

extern short curPlayer;
extern s16 curPlayer;

extern int playerTab[4];

extern int playerAtoms[4];

extern unsigned short playerMoved[4];
extern bool playerMoved[4];

extern int playerCount;

extern int startPlayers;

extern unsigned char* atomStack;
extern u8* atomStack;

extern int asPos;

extern struct KAExplodePos explodePos;

extern short playerWon;
extern s16 playerWon;

extern int explosionCount;

extern struct AtomPosition atompos[16];

extern short atomposIndex;
extern s16 atomposIndex;

extern unsigned short logicEnd;
extern bool logicEnd;

extern short gridStartX;
extern s16 gridStartX;

extern short gridStartY;
extern s16 gridStartY;

//End the current game with a message
void logic_endMessage(char* msg);
void logic_endMessage(const char* msg);

const char* logic_getPlayerName(short playerNum);
const char* logic_getPlayerName(s16 playerNum);

void logic_loadAll(unsigned char gridWidth, unsigned char gridHeight, unsigned char (*ppttab)[4]);
void logic_loadAll(u8 gridWidth, u8 gridHeight, u8 (*ppttab)[4]);

void logic_fixLoadedData(void);

void logic_clickedTile(unsigned char tx, unsigned char ty, unsigned short isAI);
void logic_clickedTile(u8 tx, u8 ty, bool isAI);

void logic_tick(long dt);
void logic_tick(fix32 dt);

void logic_draw(long dt);
void logic_draw(fix32 dt);

void logic_stop(void);

void drawTile(unsigned char x, unsigned char y, short playerNum, unsigned char atomCount);
void drawTile(u8 x, u8 y, s16 playerNum, u8 atomCount);

//Convert grid tile position (x,y) to pixel position (pixelx,pixely)
void tileToPixels(unsigned char x, unsigned char y, short* pixelx, short* pixely);
void tileToPixels(u8 x, u8 y, s16* pixelx, s16* pixely);

#endif //GAMELOGIC_H_INCLUDED
Loading

0 comments on commit 2234995

Please sign in to comment.