Skip to content

Commit

Permalink
Fix for hole state after guard climbs out
Browse files Browse the repository at this point in the history
  • Loading branch information
CJLove committed Mar 1, 2020
1 parent e7a8470 commit 09e6e66
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 41 deletions.
7 changes: 3 additions & 4 deletions Issues.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Known Issues
- occasionally able to run over a hole that is about to be filled
- occasional issue with gold count after guards have taken gold making it impossible to complete level

# Rough plans
- Longer term: consider incorporating tilesets and concepts from LodeRunner Mad Monks Revenge
- Figure out sound
- Add opening screen with world/level selection, support for jumping to specific level
- Add game over screen
- Add game editor? This would require kernel SAVE support from banked RAM
- Support for jumping to specific level
- Add game editor? This would require kernal SAVE support from banked RAM

# TODO
- Code cleanup/reorg among files
Expand Down
22 changes: 2 additions & 20 deletions assets/custom.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
{"levels": {
"name": "custom",
"total": 3,
"total": 2,
"level-001": [

" S ",
" & S ",
" X####HH######HHHHH S",
" H # H S ",
" $ H H# H S ",
" #$ HH# H S ",
" ###$ H# H S ",
" #####$ H# H S ",
"######## H# H S ",
" $##### H# H S ",
" ### H# H S ",
" # H# H S ",
" H# H S",
" H##############X######### S",
" ############### H#S",
"################ $$$$$$H##"],
"level-002": [
" S",
" S",
" S",
Expand All @@ -36,7 +18,7 @@
"H H",
"H H",
"############################"],
"level-003": [
"level-002": [
" S",
" S",
" S",
Expand Down
6 changes: 6 additions & 0 deletions src/guard.c
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,12 @@ void guardMoveStep(uint8_t id, uint8_t action)
if (stayCurrentPos && yOffset < 0)
yOffset = 0;
else if (yOffset < -H2) {
if (curToken == TILE_BRICK || curToken == TILE_HIDDEN) {
// In hole or on hidden ladder, so this check makes
// sure that the runner won't be able to run over a
// hole that a guard has climbed out of
curToken = TILE_BLANK;
}
// Move to y-1 position
map[x][y].act = curToken;
y--;
Expand Down
70 changes: 53 additions & 17 deletions src/runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ static uint8_t digRight[2][DIG_LENGTH] = {
#define STATE_FALLING 2

// Define this to enable runner debug information
//#define DEBUG
// #define DEBUG
// Define this to debug hole fill (NOTE: slows down the game)
//#define DEBUG_FILL

// Debug: display runner x & xOffset, y & yOffset
void displayPos()
Expand Down Expand Up @@ -143,19 +145,49 @@ void displayDig()
char buffer[15];
uint8_t i = 0;
if (hole.action) {
sprintf(buffer,"%c:%1d %2d %2d %2d",1,hole.action, hole.idx, hole.x, hole.y);
// Format: "A:x xx xx xx"
} else {
memset(buffer,32,sizeof(buffer));
sprintf(buffer,"%c:%1d %2d %2d %2d",1,hole.action, hole.idx, hole.x, hole.y);

for (i = 0; i < 12; i++) {
setTile(28+i,10,buffer[i],0);
}
}
}

// Debug: display state regarding hole filling (expensive!)
void displayFill()
{
char buffer[15];
uint8_t i = 0;
uint8_t j = 0;
uint8_t r = 11;
for (i = 0; i < MAX_HOLES; i++) {
if (holes[i].active) {
// Format: X:x Y:y ccc
sprintf(buffer,"%c:%d%c:%d %03d",24,holes[i].x,25,holes[i].y,holes[i].count);
for (j = 0; j < 12; j++) {
setTile(28+j,r,buffer[j],0);
}
r++;
}
}
for (i = 0; i < 12; i++) {
setTile(28+i,10,buffer[i],0);
for (; r < 30; r++) {
for (j = 0; j < 12; j++) {
setTile(28+j,r,0,0);
}
}

}

// Debug: display gold count
void displayGold()
{
setTile(38,20,goldCount+48,0);
uint8_t i;
char buffer[5];
sprintf(buffer,"%02d %d",goldCount, goldComplete);
for (i = 0; i < 4; i++) {
setTile(36+i,20,buffer[i],0);
}
}

void decGold()
Expand All @@ -167,19 +199,27 @@ void decGold()
// TODO: Sound for finishing all gold
}
}

#ifdef DEBUG
displayGold();
#endif
}

void removeGold(uint8_t x, uint8_t y)
{
map[x][y].base = TILE_BLANK;
setTile(x,y,TILE_BLANK,0);
#ifdef DEBUG
displayGold();
#endif
}

void addGold(uint8_t x, uint8_t y)
{
map[x][y].base = TILE_GOLD;
setTile(x,y,TILE_GOLD,0);
#ifdef DEBUG
displayGold();
#endif
}

void setRunnerDead()
Expand Down Expand Up @@ -517,9 +557,6 @@ void runnerMoveStep(uint8_t action, uint8_t stayCurrentPos)
removeGold(x,y);
decGold();
displayScore(SCORE_GET_GOLD);
#ifdef DEBUG
displayGold();
#endif
}
}

Expand Down Expand Up @@ -716,10 +753,8 @@ void fillComplete(uint8_t holeIdx)
int8_t id = guardId(x,y);
removeFromShake(id);
if (id != -1) {
// Debug: show the id of the dead guard
//setTile(1,21,id+48,0);
if (guard[id].hasGold > 0) {
// decGold();
decGold();
guard[id].hasGold = 0;
}
}
Expand All @@ -738,6 +773,9 @@ void fillComplete(uint8_t holeIdx)
void processFillHole()
{
uint8_t i = 0;
#ifdef DEBUG_FILL
displayFill();
#endif
for (i = 0; i < MAX_HOLES; i++) {
if (holes[i].active) {
uint8_t x = holes[i].x;
Expand All @@ -752,7 +790,7 @@ void processFillHole()
setTile(x,y,TILE_REGEN2,0);
} else if (holes[i].count == HOLE_REGEN3) {
setTile(x,y,TILE_REGEN3,0);
} else if (holes[i].count == HOLE_REGEN4) {
} else if (holes[i].count >= HOLE_REGEN4) {
setTile(x,y,TILE_BRICK,0);
fillComplete(i);
}
Expand Down Expand Up @@ -820,8 +858,6 @@ void processDigHole()
setTile(hole.x,hole.y,digRight[DIG_UPPER][hole.idx],0);
setTile(hole.x,hole.y+1,digRight[DIG_LOWER][hole.idx],0);
}
// Debug: display hole animation index
// setTile(38,27,hole.idx+48,0);
} else {
digComplete();
}
Expand Down

0 comments on commit 09e6e66

Please sign in to comment.