Skip to content

Commit

Permalink
Fixed issue #9, black background, pause menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
mb88a committed Dec 3, 2022
1 parent 5bdf736 commit 9716034
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/MathRace.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h1>MathRace</h1>
}
</style>
</head>
<body style = "height: 100%; width: 100%;">
<body style = "height: 100%; width: 100%; background-color: #000000;">
<!-- <div id = "game" style = "height: 100%; width: 100%;"> -->
<canvas id = "canvas" width = "64" height = "48">
MathRace game
Expand Down
7 changes: 6 additions & 1 deletion src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@
#define MENU_X 48
#define MENU_Y 16

#define PAUSED_X 16
#define PAUSED_Y 16

#define PAUSED_LEN 1

typedef struct {
int stat, seed, loops, start_time;
unsigned char *map, *tilesheet;
unsigned int *speed, *start_x, *start_y, *calcs, *type;
unsigned int menu_selection, menu_len, menu_canmove, menu_canmove_world, menu_world, menu_worlds;
unsigned int menu_selection, menu_len, menu_canmove, menu_canmove_world, menu_world, menu_worlds, paused_selection;
unsigned char world_info[20];
int world_info_len;
} Game;
Expand Down
39 changes: 38 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ void loop() {
dtext(player.choices, player.choices_x, 10, 60, (unsigned char*)font_data, font_width, 8, 8);
}
}
if(input_space()){
game.menu_canmove = 1;
game.paused_selection = 0;
jump(5);
}
dtext(player.loopinfo, 1, 87, 20, (unsigned char*)font_data, font_width, 8, 8);
dtext(player.timeinfo, 127-player.timelen*9, 87, 20, (unsigned char*)font_data, font_width, 8, 8);
update();
Expand Down Expand Up @@ -202,10 +207,42 @@ void loop() {
init_audio("square");
set_frequency((*game.speed/2)*50+(player.direction*5));
start_beep();
game.stat = 1;
jump(1);
game.start_time = ms_time();
}
update();
}else if(game.stat == 5){
if(input_up() && game.menu_canmove){
if(game.paused_selection){
game.paused_selection--;
}else{
game.paused_selection = PAUSED_LEN;
}
game.menu_canmove = 0;
}
if(input_down() && game.menu_canmove){
game.paused_selection++;
if(game.paused_selection > PAUSED_LEN){
game.paused_selection = 0;
}
game.menu_canmove = 0;
}
if(!input_up() && !input_down() && !game.menu_canmove){
game.menu_canmove = 1;
}
drawmap(0, 0, player.x, player.y, WIDTH, HEIGHT, MAP_WIDTH, MAP_HEIGHT, game.map, player.direction, game.tilesheet);
draw_image_del_color(PAUSED_X, PAUSED_Y+game.paused_selection*9+9, arrow_data, 8, 8, 0, 0, 0, 0);
dtext((unsigned char*)"Paused", PAUSED_X+9, PAUSED_Y, 6, (unsigned char*)font_data, font_width, 8, 8);
dtext((unsigned char*)"Continue\nMain menu", PAUSED_X+9, PAUSED_Y+9, 18, (unsigned char*)font_data, font_width, 8, 8);
update();
if(input_space()){
if(game.paused_selection == 0){
jump(1);
}else{
init_game(&player, &game, (int)game.start_x, (int)game.start_y, (int)game.speed);
jump(0);
}
}
}
time = clock() - start;
printf("Time : %d\n", (int)(time / 1000));
Expand Down
12 changes: 10 additions & 2 deletions src/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,17 @@ int get_collision(Player *player, Game *game, unsigned char *map, int map_w, int
n = 0;
while(is_in(player->intchoices, 3, n)){
if(rand() % 2){
n = player->intchoices[player->choice] - (rand() % (player->n2) + 1);
if(player->n2>2){
n = player->intchoices[player->choice] - (rand() % (player->n2) + 1);
}else{
n = player->intchoices[player->choice] - (rand() % 4);
}
}else{
n = player->intchoices[player->choice] + (rand() % (player->n2) + 1);
if(player->n2>2){
n = player->intchoices[player->choice] + (rand() % (player->n2) + 1);
}else{
n = player->intchoices[player->choice] + (rand() % 4);
}
}
}
player->intchoices[i] = n;
Expand Down

0 comments on commit 9716034

Please sign in to comment.