Skip to content

Commit

Permalink
Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Schütz committed Sep 27, 2017
1 parent 316aeb1 commit 6dabbae
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 90 deletions.
16 changes: 8 additions & 8 deletions master/character.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,20 +633,21 @@ void move(struct Character* character)
character->jumpstate = 1;
}
if (protagonist->x < character->x)
moveleft(character);
else if (protagonist->x > character->x)
moveright(character);
else
draw(character);
moveleft(character);
else if (protagonist->x > character->x)
moveright(character);
else
draw(character);
break;
case BOMB:
break;

case BOSS_DRAGON_AIR:
if (character->y < CEILING_Y + 16
&& (character->x < 20 || character->x > DISPLAY_WIDTH - character->width - 20)
&& really_random_below(3) == 0) // 1/5 probability to attack
&& really_random_below(3) == 0) // 1/3 probability to attack
{
// move down towards the middle of the screen,
// then move up again while continuing in the previous horizontal direction
character->movement = BOSS_DRAGON_ATTACK;
if (character->x > DISPLAY_WIDTH / 2)
character->direction = DIRECTION_LEFT;
Expand Down Expand Up @@ -675,7 +676,6 @@ void move(struct Character* character)
break;
case XPARASITE:
break;

case SECROB:
if (character->x >= DISPLAY_WIDTH - character->width - 8)
{
Expand Down
7 changes: 3 additions & 4 deletions master/drawing.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ void movedoorleft()
page(x + 33, 24, 0xFF);
}
}

}

void movedoorright()
Expand Down Expand Up @@ -243,7 +242,7 @@ void drawdoorright_closed()
i = 0;
}
}

drawsprite(154, 20, 6, 5, doorright);
}

Expand All @@ -260,7 +259,7 @@ void drawdoorleft_closed()
i = 0;
}
}

drawsprite(0, 20, 6, 5, doorleft);
}

Expand Down Expand Up @@ -594,5 +593,5 @@ void drawletters(uint8_t x, uint8_t y, char* string)
x += width + 1;
}
}
}
}

73 changes: 38 additions & 35 deletions master/level.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ long obstacle(uint8_t x, uint8_t y)
{
if (y >= CEILING_Y && y < CEILING_Y + 4) // ceiling
return 1l;
// left door
else if (doors & 0b00000010 && (x < 4 || (y >= DOOR_Y && x < 6)))
return 1l;
// right door
else if (doors & 0b00000001 && (x >= DISPLAY_WIDTH - 4 || (y >= DOOR_Y && x >= DISPLAY_WIDTH - 6)))
return 1l;
else if (rechargeroom && x >= DISPLAY_WIDTH/2 - 12 && x < DISPLAY_WIDTH/2 + 12 && (y >= 23*4 || y < 17*4))
Expand All @@ -36,6 +38,7 @@ long obstacle(uint8_t x, uint8_t y)
return 1l;
else if (rechargeroom && y <= CEILING_Y + 4*5)
return 1l;
// water/spikes
else if (y >= FLOOR_Y && y < FLOOR_Y + 4)
return nofloor & (3l << x / 16 * 2);
else if (y >= 19 * 4 && y < 20 * 4)
Expand All @@ -46,7 +49,6 @@ long obstacle(uint8_t x, uint8_t y)
return !(platforms_24 & (3l << (x / 16 * 2)));
else
return 0l;

}

long obstacle_hill(uint8_t x)
Expand All @@ -62,13 +64,9 @@ long obstacle_levelpos(uint8_t x, uint8_t y, long level_pos)
long platforms_24 = random();
platforms_24 |= 3l << 0; // no hill at the display boundary
platforms_24 |= 3l << 2 * (DISPLAY_WIDTH/16 - 1);
long nofloor = random();
//nofloor = INT32_MAX; // turn off water


if (y >= CEILING_Y && y < CEILING_Y + 4) // ceiling
return 1l;
else if (y >= FLOOR_Y && y < FLOOR_Y + 4)
return nofloor & (3l << x / 16 * 2);
else if (y >= 19 * 4 && y < 20 * 4)
return !(platforms_19 & (3l << (x / PLATFORM_WIDTH * 2)));
else if (y >= 13 * 4 && y < 14 * 4)
Expand All @@ -82,15 +80,15 @@ long obstacle_levelpos(uint8_t x, uint8_t y, long level_pos)
void redraw()
{
clear();

drawlabels();

// print ceiling
for (uint8_t x = 0; x < DISPLAY_WIDTH; x++)
{
page(x, 5, pgm_read_byte_near(ceilingsprite + x % 16));
}

drawplatform();
drawfloor();

Expand All @@ -116,17 +114,18 @@ void redraw()
{
draw(energytankstruct);
}

if (rechargeroom)
{
drawrechargeroom();
}

draw(protagonist);
}

void selectfloor()
{
// random floor sprite
const uint8_t* rotatedfloorsprite = NULL;
switch (random_below(7))
{
Expand Down Expand Up @@ -162,6 +161,8 @@ void selectfloor()
ceilingsprite = floorsprite;
leftrotatedfloorsprite = rotatedfloorsprite;
rightrotatedfloorsprite = rotatedfloorsprite;

// select from water and spikes
switch (random_below(2))
{
case 0:
Expand All @@ -181,7 +182,7 @@ void newlevelpos()

for (uint8_t i = 0; i < NUM_MONSTERS; ++i)
monsters[i]->look = LOOK_HIDDEN;

if ((level >= 0 && level % BOSS_LEVEL_DISTANCE == BOSS_LEVEL_DISTANCE - 2) // recharge level
|| (level < 0 && (level - 1) % BOSS_LEVEL_DISTANCE == 0))
{
Expand All @@ -190,7 +191,7 @@ void newlevelpos()
platforms_24 = UINT32_MAX;
nofloor = UINT32_MAX;
doors = 0b00000011;

rechargeroom = true;
}
else if ((level >= 0 && level % BOSS_LEVEL_DISTANCE == BOSS_LEVEL_DISTANCE - 1) // boss level
Expand All @@ -205,9 +206,9 @@ void newlevelpos()
platforms_24 = UINT32_MAX;
nofloor = UINT32_MAX;
doors = 0b00000011;

bosslevel = true;

monsters[0]->direction = 1 - protagonist->direction; // look at the protagonist

switch(random_below(4))
Expand Down Expand Up @@ -263,6 +264,7 @@ void newlevelpos()
platforms_24 |= 1l << 0; // no hill at the display boundary
platforms_24 |= 1l << 2 * (DISPLAY_WIDTH/16 - 1);

// set nofloor to a new random value as long as the door is not reachable
do
{
nofloor = random();
Expand All @@ -277,9 +279,9 @@ void newlevelpos()
}
}
while (!is_door_reachable());

doors = 0;

// draw door to previous level
if (level_pos == 0)
{
Expand Down Expand Up @@ -316,12 +318,13 @@ void newlevelpos()
}
}

// initialize monsters, their look, position etc.
for (uint8_t i = 0; i < NUM_MONSTERS; ++i)
{
initcharacter(monsters[i]);
if (monsters[i]->look == LOOK_HIDDEN)
continue;

monsters[i]->x = (DISPLAY_WIDTH - monsters[i]->width) / 2;
if (monsters[i]->look == LOOK_BOSS_MEGACOREX || monsters[i]->look == LOOK_BOSS_SECROB || monsters[i]->look == LOOK_BOSS_ZAZABI || monsters[i]->look == LOOK_NEO_RIDLEY_DRAGON)
{
Expand Down Expand Up @@ -359,12 +362,12 @@ void newlevelpos()
}
}
}

for (uint8_t i = 0; i < NUM_FIREBALLS; ++i)
{
fireballs[i]->movement = HIDDEN;
}

// no water/spikes when there is a frog/sidehopper
// these would otherwise fall into the void
for (uint8_t i = 0; i < NUM_MONSTERS; ++i)
Expand Down Expand Up @@ -404,16 +407,16 @@ void newlevelpos()
}
}
}

for (uint8_t i = 0; i < NUM_MONSTERS; ++i)
{
xparasites[i]->movement = HIDDEN;
}

if (bosslevel)
{
// show a nice message informing about the boss's abilities
redraw();

char line[2][MAX_STRING_LEN];
switch (monsters[0]->look)
{
Expand Down Expand Up @@ -451,10 +454,10 @@ void newlevelpos()
}
delay(1000);
}

redraw();

left_door_open = false;
right_door_open = false;
redraw();
}

void newlevel()
Expand All @@ -464,14 +467,14 @@ void newlevel()
uart_putc('i');
else
uart_putc('j');

eeprom_write_block(&level, &level_stored, sizeof level);

level_seed = initial_level + level * (2 * MAX_LEVEL_WIDTH + 1);

srand(level_seed);
srandom(level_seed);

max_level_pos = random_below(MAX_LEVEL_WIDTH);

if (protagonist->x > DISPLAY_WIDTH / 2)
Expand All @@ -488,9 +491,9 @@ void newlevel()
protagonist->x = DISPLAY_WIDTH - 6 - protagonist->width - 1;
protagonist->direction = DIRECTION_LEFT;
}

protagonist->y = FLOOR_Y - protagonist->height;

selectfloor();

newlevelpos();
Expand All @@ -500,7 +503,7 @@ void newgame()
{
protagonist->look = LOOK_PROTAGONIST;
initcharacter(protagonist);

if (initial_level == 0) // start a new game
{
initial_level = getMsTimer();
Expand Down Expand Up @@ -533,18 +536,18 @@ void newgame()
protagonist->x = 0; // make the protagonist appear on the right
else
protagonist->x = DISPLAY_WIDTH; // make the protagonist appear on the left

for (uint8_t i = 0; i < NUM_ROCKETS; ++i)
{
projectiles[i]->look = LOOK_ROCKET;
initcharacter(projectiles[i]);
}

bombstruct->look = LOOK_BOMB;
initcharacter(bombstruct);

left_door_open = true;
right_door_open = true;

newlevel();
}
4 changes: 3 additions & 1 deletion master/level.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,13 @@ bool rechargeroom;
bool recharging;
bool bosslevel;

// whether there is an obstacle at x, y at the current level_pos
long obstacle(uint8_t x, uint8_t y);

// whether there is a platform at 96<=y<100
// whether there is a platform at 96 <= y < 100
long obstacle_hill(uint8_t x);

// whether there is an obstacle at x, y at level_pos
long obstacle_levelpos(uint8_t x, uint8_t y, long level_pos);

void redraw();
Expand Down
Loading

0 comments on commit 6dabbae

Please sign in to comment.