Skip to content

Commit 6dabbae

Browse files
author
Robert Schütz
committed
Add comments
1 parent 316aeb1 commit 6dabbae

File tree

6 files changed

+121
-90
lines changed

6 files changed

+121
-90
lines changed

master/character.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -633,20 +633,21 @@ void move(struct Character* character)
633633
character->jumpstate = 1;
634634
}
635635
if (protagonist->x < character->x)
636-
moveleft(character);
637-
else if (protagonist->x > character->x)
638-
moveright(character);
639-
else
640-
draw(character);
636+
moveleft(character);
637+
else if (protagonist->x > character->x)
638+
moveright(character);
639+
else
640+
draw(character);
641641
break;
642642
case BOMB:
643643
break;
644-
645644
case BOSS_DRAGON_AIR:
646645
if (character->y < CEILING_Y + 16
647646
&& (character->x < 20 || character->x > DISPLAY_WIDTH - character->width - 20)
648-
&& really_random_below(3) == 0) // 1/5 probability to attack
647+
&& really_random_below(3) == 0) // 1/3 probability to attack
649648
{
649+
// move down towards the middle of the screen,
650+
// then move up again while continuing in the previous horizontal direction
650651
character->movement = BOSS_DRAGON_ATTACK;
651652
if (character->x > DISPLAY_WIDTH / 2)
652653
character->direction = DIRECTION_LEFT;
@@ -675,7 +676,6 @@ void move(struct Character* character)
675676
break;
676677
case XPARASITE:
677678
break;
678-
679679
case SECROB:
680680
if (character->x >= DISPLAY_WIDTH - character->width - 8)
681681
{

master/drawing.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ void movedoorleft()
198198
page(x + 33, 24, 0xFF);
199199
}
200200
}
201-
202201
}
203202

204203
void movedoorright()
@@ -243,7 +242,7 @@ void drawdoorright_closed()
243242
i = 0;
244243
}
245244
}
246-
245+
247246
drawsprite(154, 20, 6, 5, doorright);
248247
}
249248

@@ -260,7 +259,7 @@ void drawdoorleft_closed()
260259
i = 0;
261260
}
262261
}
263-
262+
264263
drawsprite(0, 20, 6, 5, doorleft);
265264
}
266265

@@ -594,5 +593,5 @@ void drawletters(uint8_t x, uint8_t y, char* string)
594593
x += width + 1;
595594
}
596595
}
597-
}
596+
}
598597

master/level.c

+38-35
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ long obstacle(uint8_t x, uint8_t y)
2626
{
2727
if (y >= CEILING_Y && y < CEILING_Y + 4) // ceiling
2828
return 1l;
29+
// left door
2930
else if (doors & 0b00000010 && (x < 4 || (y >= DOOR_Y && x < 6)))
3031
return 1l;
32+
// right door
3133
else if (doors & 0b00000001 && (x >= DISPLAY_WIDTH - 4 || (y >= DOOR_Y && x >= DISPLAY_WIDTH - 6)))
3234
return 1l;
3335
else if (rechargeroom && x >= DISPLAY_WIDTH/2 - 12 && x < DISPLAY_WIDTH/2 + 12 && (y >= 23*4 || y < 17*4))
@@ -36,6 +38,7 @@ long obstacle(uint8_t x, uint8_t y)
3638
return 1l;
3739
else if (rechargeroom && y <= CEILING_Y + 4*5)
3840
return 1l;
41+
// water/spikes
3942
else if (y >= FLOOR_Y && y < FLOOR_Y + 4)
4043
return nofloor & (3l << x / 16 * 2);
4144
else if (y >= 19 * 4 && y < 20 * 4)
@@ -46,7 +49,6 @@ long obstacle(uint8_t x, uint8_t y)
4649
return !(platforms_24 & (3l << (x / 16 * 2)));
4750
else
4851
return 0l;
49-
5052
}
5153

5254
long obstacle_hill(uint8_t x)
@@ -62,13 +64,9 @@ long obstacle_levelpos(uint8_t x, uint8_t y, long level_pos)
6264
long platforms_24 = random();
6365
platforms_24 |= 3l << 0; // no hill at the display boundary
6466
platforms_24 |= 3l << 2 * (DISPLAY_WIDTH/16 - 1);
65-
long nofloor = random();
66-
//nofloor = INT32_MAX; // turn off water
67-
67+
6868
if (y >= CEILING_Y && y < CEILING_Y + 4) // ceiling
6969
return 1l;
70-
else if (y >= FLOOR_Y && y < FLOOR_Y + 4)
71-
return nofloor & (3l << x / 16 * 2);
7270
else if (y >= 19 * 4 && y < 20 * 4)
7371
return !(platforms_19 & (3l << (x / PLATFORM_WIDTH * 2)));
7472
else if (y >= 13 * 4 && y < 14 * 4)
@@ -82,15 +80,15 @@ long obstacle_levelpos(uint8_t x, uint8_t y, long level_pos)
8280
void redraw()
8381
{
8482
clear();
85-
83+
8684
drawlabels();
87-
85+
8886
// print ceiling
8987
for (uint8_t x = 0; x < DISPLAY_WIDTH; x++)
9088
{
9189
page(x, 5, pgm_read_byte_near(ceilingsprite + x % 16));
9290
}
93-
91+
9492
drawplatform();
9593
drawfloor();
9694

@@ -116,17 +114,18 @@ void redraw()
116114
{
117115
draw(energytankstruct);
118116
}
119-
117+
120118
if (rechargeroom)
121119
{
122120
drawrechargeroom();
123121
}
124-
122+
125123
draw(protagonist);
126124
}
127125

128126
void selectfloor()
129127
{
128+
// random floor sprite
130129
const uint8_t* rotatedfloorsprite = NULL;
131130
switch (random_below(7))
132131
{
@@ -162,6 +161,8 @@ void selectfloor()
162161
ceilingsprite = floorsprite;
163162
leftrotatedfloorsprite = rotatedfloorsprite;
164163
rightrotatedfloorsprite = rotatedfloorsprite;
164+
165+
// select from water and spikes
165166
switch (random_below(2))
166167
{
167168
case 0:
@@ -181,7 +182,7 @@ void newlevelpos()
181182

182183
for (uint8_t i = 0; i < NUM_MONSTERS; ++i)
183184
monsters[i]->look = LOOK_HIDDEN;
184-
185+
185186
if ((level >= 0 && level % BOSS_LEVEL_DISTANCE == BOSS_LEVEL_DISTANCE - 2) // recharge level
186187
|| (level < 0 && (level - 1) % BOSS_LEVEL_DISTANCE == 0))
187188
{
@@ -190,7 +191,7 @@ void newlevelpos()
190191
platforms_24 = UINT32_MAX;
191192
nofloor = UINT32_MAX;
192193
doors = 0b00000011;
193-
194+
194195
rechargeroom = true;
195196
}
196197
else if ((level >= 0 && level % BOSS_LEVEL_DISTANCE == BOSS_LEVEL_DISTANCE - 1) // boss level
@@ -205,9 +206,9 @@ void newlevelpos()
205206
platforms_24 = UINT32_MAX;
206207
nofloor = UINT32_MAX;
207208
doors = 0b00000011;
208-
209+
209210
bosslevel = true;
210-
211+
211212
monsters[0]->direction = 1 - protagonist->direction; // look at the protagonist
212213

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

267+
// set nofloor to a new random value as long as the door is not reachable
266268
do
267269
{
268270
nofloor = random();
@@ -277,9 +279,9 @@ void newlevelpos()
277279
}
278280
}
279281
while (!is_door_reachable());
280-
282+
281283
doors = 0;
282-
284+
283285
// draw door to previous level
284286
if (level_pos == 0)
285287
{
@@ -316,12 +318,13 @@ void newlevelpos()
316318
}
317319
}
318320

321+
// initialize monsters, their look, position etc.
319322
for (uint8_t i = 0; i < NUM_MONSTERS; ++i)
320323
{
321324
initcharacter(monsters[i]);
322325
if (monsters[i]->look == LOOK_HIDDEN)
323326
continue;
324-
327+
325328
monsters[i]->x = (DISPLAY_WIDTH - monsters[i]->width) / 2;
326329
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)
327330
{
@@ -359,12 +362,12 @@ void newlevelpos()
359362
}
360363
}
361364
}
362-
365+
363366
for (uint8_t i = 0; i < NUM_FIREBALLS; ++i)
364367
{
365368
fireballs[i]->movement = HIDDEN;
366369
}
367-
370+
368371
// no water/spikes when there is a frog/sidehopper
369372
// these would otherwise fall into the void
370373
for (uint8_t i = 0; i < NUM_MONSTERS; ++i)
@@ -404,16 +407,16 @@ void newlevelpos()
404407
}
405408
}
406409
}
407-
410+
408411
for (uint8_t i = 0; i < NUM_MONSTERS; ++i)
409412
{
410413
xparasites[i]->movement = HIDDEN;
411414
}
412-
415+
413416
if (bosslevel)
414417
{
418+
// show a nice message informing about the boss's abilities
415419
redraw();
416-
417420
char line[2][MAX_STRING_LEN];
418421
switch (monsters[0]->look)
419422
{
@@ -451,10 +454,10 @@ void newlevelpos()
451454
}
452455
delay(1000);
453456
}
454-
455-
redraw();
457+
456458
left_door_open = false;
457459
right_door_open = false;
460+
redraw();
458461
}
459462

460463
void newlevel()
@@ -464,14 +467,14 @@ void newlevel()
464467
uart_putc('i');
465468
else
466469
uart_putc('j');
467-
470+
468471
eeprom_write_block(&level, &level_stored, sizeof level);
469-
472+
470473
level_seed = initial_level + level * (2 * MAX_LEVEL_WIDTH + 1);
471-
474+
472475
srand(level_seed);
473476
srandom(level_seed);
474-
477+
475478
max_level_pos = random_below(MAX_LEVEL_WIDTH);
476479

477480
if (protagonist->x > DISPLAY_WIDTH / 2)
@@ -488,9 +491,9 @@ void newlevel()
488491
protagonist->x = DISPLAY_WIDTH - 6 - protagonist->width - 1;
489492
protagonist->direction = DIRECTION_LEFT;
490493
}
491-
494+
492495
protagonist->y = FLOOR_Y - protagonist->height;
493-
496+
494497
selectfloor();
495498

496499
newlevelpos();
@@ -500,7 +503,7 @@ void newgame()
500503
{
501504
protagonist->look = LOOK_PROTAGONIST;
502505
initcharacter(protagonist);
503-
506+
504507
if (initial_level == 0) // start a new game
505508
{
506509
initial_level = getMsTimer();
@@ -533,18 +536,18 @@ void newgame()
533536
protagonist->x = 0; // make the protagonist appear on the right
534537
else
535538
protagonist->x = DISPLAY_WIDTH; // make the protagonist appear on the left
536-
539+
537540
for (uint8_t i = 0; i < NUM_ROCKETS; ++i)
538541
{
539542
projectiles[i]->look = LOOK_ROCKET;
540543
initcharacter(projectiles[i]);
541544
}
542-
545+
543546
bombstruct->look = LOOK_BOMB;
544547
initcharacter(bombstruct);
545548

546549
left_door_open = true;
547550
right_door_open = true;
548-
551+
549552
newlevel();
550553
}

master/level.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@ bool rechargeroom;
7171
bool recharging;
7272
bool bosslevel;
7373

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

76-
// whether there is a platform at 96<=y<100
77+
// whether there is a platform at 96 <= y < 100
7778
long obstacle_hill(uint8_t x);
7879

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

8183
void redraw();

0 commit comments

Comments
 (0)