Skip to content

Commit

Permalink
Expanding menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ifilot committed Jun 1, 2024
1 parent 7af0079 commit 7af94df
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 72 deletions.
1 change: 1 addition & 0 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
#define GAME_STOP 0x00
#define GAME_RUN 0x01
#define GAME_MENU 0x02
#define GAME_SETTINGS 0x03

#define PLAYER_HUMAN 0x00
#define PLAYER_CPU 0x01
Expand Down
1 change: 1 addition & 0 deletions src/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ uint8_t board_offset_x = 6;
uint8_t board_offset_y = 4;
uint8_t no_move_counter = 0;
uint16_t cpu_waittime = 200;
uint8_t background_scroll = YES;

/**
* @brief Initialize the game scene
Expand Down
2 changes: 2 additions & 0 deletions src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "constants.h"
#include "video.h"
#include "sound.h"
#include "sound_low.h"
#include "mouse.h"

extern uint8_t *board; // store board configuration
Expand All @@ -50,6 +51,7 @@ extern uint8_t board_offset_x; // board x-offset with respect to screen
extern uint8_t board_offset_y; // board y-offset with respect to screen
extern uint8_t no_move_counter; // how many turns in a row no move can be made
extern uint16_t cpu_waittime; // time to wait until the computer makes a move
extern uint8_t background_scroll; // whether or not to perform background scrolling

/**
* @brief Initialize the game scene
Expand Down
7 changes: 6 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ void main() {
while(1) {
while(gamestate == GAME_MENU) {
clear_screen();
game_menu();
game_title();
}

while(gamestate == GAME_SETTINGS) {
clear_screen();
game_settings();
}

while(gamestate == GAME_RUN) {
Expand Down
120 changes: 95 additions & 25 deletions src/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,81 @@

#include "menu.h"

/**
* @brief Show game title screen
*
*/
void game_title() {
static unsigned char keycode;
static const uint8_t offsetx = 8;

write_string("CX16-OTHELLO", 0, 0);
write_string("music by Crisps", 1, 5);
write_string("1.2.0", 0, 15);

// build sample board
build_board(6, 4, offsetx);

// set sprites
assign_sprite(1, stone_color1);
assign_sprite(2, stone_color2);
assign_sprite(3, stone_color1);
assign_sprite(4, stone_color2);

// print stone colors
set_sprite(1, 6, offsetx+2);
set_sprite(2, 6, offsetx+3);
set_sprite(3, 7, offsetx+3);
set_sprite(4, 7, offsetx+2);

write_string("(S) SETTINGS", 11, 0);
write_string("(H) HELP", 12, 0);
write_string("(ENTER) START", 14, 0);

while(1) {
asm("jsr $FFE4");
asm("sta %v", keycode);

switch(keycode) {
case 83:
gamestate = GAME_SETTINGS;
return;
case KEYCODE_RETURN:
gamestate = GAME_RUN;
init_game();
return;
}

// update sound buffer
sound_fill_buffers();
update_background_diagonal();
}
}

/**
* @brief Show game menu
*
*/
void game_menu() {
void game_settings() {
static unsigned char keycode;
unsigned short *mouse_x = (unsigned short *)0x2;
unsigned short *mouse_y = (unsigned short *)0x4;

write_string("CX16-OTHELLO", 0, 1);
write_string("music by Crisps", 1, 5);
write_string("1.1.0", 0, 15);
write_string("SETTINGS", 0, 0);

write_string("(1) Player 1:", 1, 0);
write_string("(2) Player 2:", 2, 0);
write_string("(B) Board:", 4, 0);

write_string("(1) PLAYER 1:", 3, 1);
write_string("(2) PLAYER 2:", 4, 1);
write_string("(B) BOARD:", 6, 1);
write_string("(S) Size:", 6, 0);

write_string("(S) SIZE:", 8, 1);
write_string("(C) Disc player 1:", 9, 0);
write_string("(V) Disc player 2:", 10, 0);

write_string("(C) TILE COLOR 1:", 11, 1);
write_string("(V) TILE COLOR 2:", 12, 1);
write_string("(G) BG scroll:", 12, 0);
write_string("(M) Music:", 13, 0);

write_string("Hit ENTER to start", 14, 1);
write_string("(ESCAPE) BACK", 14, 0);

print_choice();

Expand All @@ -63,6 +115,19 @@ void game_menu() {
board_type = (board_type == BOARD_STONE ? BOARD_WOOD : BOARD_STONE);
print_choice();
break;
case 71:
background_scroll = (background_scroll == YES ? NO : YES);
print_choice();
break;
case 77:
music = (music == YES ? NO : YES);
if(music == YES) {
start_bgmusic();
} else {
stop_bgmusic();
}
print_choice();
break;
case 67:
stone_color1++;

Expand Down Expand Up @@ -108,9 +173,8 @@ void game_menu() {

print_choice();
break;
case KEYCODE_RETURN:
gamestate = GAME_RUN;
init_game();
case KEYCODE_ESCAPE:
gamestate = GAME_MENU;
return;
}

Expand All @@ -129,13 +193,19 @@ void print_choice() {
static const uint8_t offsetx = 12;

// print whether player 1 is a human or a cpu
write_string(player1_type == PLAYER_HUMAN ? "HUMAN" : "CPU ", 3, 14);
write_string(player1_type == PLAYER_HUMAN ? "HUMAN" : "CPU ", 1, 14);

// print whether player 2 is a human or a cpu
write_string(player2_type == PLAYER_HUMAN ? "HUMAN" : "CPU ", 4, 14);
write_string(player2_type == PLAYER_HUMAN ? "HUMAN" : "CPU ", 2, 14);

// print board style
write_string(board_type == BOARD_STONE ? "STONE" : "WOOD ", 7, 1);
write_string(board_type == BOARD_STONE ? "STONE" : "WOOD ", 5, 1);

// background scrolling
write_string(background_scroll == YES ? "YES" : "NO ", 12, 15);

// music
write_string(music == YES ? "ON " : "OFF ", 13, 11);

// print board size
switch(boardsize) {
Expand All @@ -149,10 +219,10 @@ void print_choice() {
memcpy(buf, "10 x 10", 8);
break;
}
write_string(buf, 9, 1);
write_string(buf, 7, 1);

// build sample board
build_board(4, 6, offsetx);
build_board(4, 4, offsetx);

// set sprites
assign_sprite(1, stone_color1);
Expand All @@ -161,11 +231,11 @@ void print_choice() {
assign_sprite(4, stone_color2);

// print stone colors
set_sprite(1, 7, offsetx+1);
set_sprite(2, 7, offsetx+2);
set_sprite(3, 8, offsetx+2);
set_sprite(4, 8, offsetx+1);
set_sprite(1, 5, offsetx+1);
set_sprite(2, 5, offsetx+2);
set_sprite(3, 6, offsetx+2);
set_sprite(4, 6, offsetx+1);

set_tile(11, 18, stone_color1, 0x00);
set_tile(12, 18, stone_color2, 0x00);
set_tile(9, 18, stone_color1, 0x00);
set_tile(10, 18, stone_color2, 0x00);
}
10 changes: 8 additions & 2 deletions src/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,16 @@
#include "sound.h"

/**
* @brief Show game menu
* @brief Show game settings menu
*
*/
void game_menu();
void game_settings();

/**
* @brief Show game title screen
*
*/
void game_title();

/**
* @brief Print current game configuration to the screen
Expand Down
33 changes: 33 additions & 0 deletions src/sound.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**************************************************************************
* *
* Author: Ivo Filot <ivo@ivofilot.nl> *
* *
* CX16-OTHELLO is free software: *
* you can redistribute it and/or modify it under the terms of the *
* GNU General Public License as published by the Free Software *
* Foundation, either version 3 of the License, or (at your option) *
* any later version. *
* *
* CX16-OTHELLO is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty *
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see http://www.gnu.org/licenses/. *
* *
**************************************************************************/

#include "sound.h"

uint8_t music = YES;

/**
* @brief Fill sound buffer
*
*/
void sound_fill_buffers() {
if(music) {
sound_fill_buffers_asm();
}
}
35 changes: 6 additions & 29 deletions src/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,17 @@
#ifndef _SOUND_H
#define _SOUND_H

/**
* @brief Initialize sound engine
*
*/
void __fastcall__ init_sound();
#include <stdint.h>

/**
* @brief Start background music
*
*/
void __fastcall__ start_bgmusic();
#include "constants.h"
#include "sound_low.h"

/**
* @brief Stop background music
*
*/
void __fastcall__ stop_bgmusic();

/**
* @brief Rewind background music
*
*/
void __fastcall__ rewind_bgmusic();

/**
* @brief Fill sound buffers
*
*/
void __fastcall__ sound_fill_buffers();
extern uint8_t music; // whether to play music

/**
* @brief Play short sound when placing down a stone
* @brief Fill sound buffer
*
*/
void __fastcall__ play_thumb();
void sound_fill_buffers();

#endif // _SOUND_H
60 changes: 60 additions & 0 deletions src/sound_low.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**************************************************************************
* *
* Author: Ivo Filot <ivo@ivofilot.nl> *
* *
* CX16-OTHELLO is free software: *
* you can redistribute it and/or modify it under the terms of the *
* GNU General Public License as published by the Free Software *
* Foundation, either version 3 of the License, or (at your option) *
* any later version. *
* *
* CX16-OTHELLO is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty *
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see http://www.gnu.org/licenses/. *
* *
**************************************************************************/

#ifndef _SOUND_LOW_H
#define _SOUND_LOW_H

/**
* @brief Initialize sound engine
*
*/
void __fastcall__ init_sound();

/**
* @brief Start background music
*
*/
void __fastcall__ start_bgmusic();

/**
* @brief Stop background music
*
*/
void __fastcall__ stop_bgmusic();

/**
* @brief Rewind background music
*
*/
void __fastcall__ rewind_bgmusic();

/**
* @brief Fill sound buffers
*
*/
void __fastcall__ sound_fill_buffers_asm();

/**
* @brief Play short sound when placing down a stone
*
*/
void __fastcall__ play_thumb();

#endif // _SOUND_LOW_H
Loading

0 comments on commit 7af94df

Please sign in to comment.