Skip to content

Commit

Permalink
Patch 1.2.0 (#2)
Browse files Browse the repository at this point in the history
* Expanding menu

* Disconnecting mouse cursor from keyboard cursor

* Initial commit ingame help

* Integrating help

* Replacing example image
  • Loading branch information
ifilot authored Jun 1, 2024
1 parent 7af0079 commit 63c8c0f
Show file tree
Hide file tree
Showing 19 changed files with 556 additions and 96 deletions.
Binary file modified assets/tiles/tiles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/tiles/tiles.pyxel
Binary file not shown.
Binary file modified img/cx16-othello.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ PYTHON=python3

make: OTHELLO.PRG

OTHELLO.PRG: *.c *.h *.s FONTMAP.DAT TILES.DAT OTHELLO.ZSM TILE.ZSM
OTHELLO.PRG: *.c *.h *.s FONTMAP.DAT TILES.DAT OTHELLO.ZSM TILE.ZSM HELP.DAT
$(CC) -O -o OTHELLO.PRG -t cx16 -C othello.cfg *.c *.s *.lib

HELP.DAT: help.hlp
$(PYTHON) help.py

TILES.DAT:
$(PYTHON) ../assets/scripts/convert_tilemap.py TILES.DAT

Expand Down
8 changes: 6 additions & 2 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
#define TILE_BLACK 0x03
#define TILE_WHITE 0x04
#define TILE_MOUSE_CURSOR 0x0F
#define TILE_BLACK_CURSOR 0x13
#define TILE_WHITE_CURSOR 0x14
#define TILE_HIGHLIGHT 0x12

// board offsets
#define BOARD_WOOD 0x20
Expand All @@ -63,6 +62,7 @@
// sprites
#define SPRITE_MOUSE_CURSOR 0x00
#define SPRITE_TILE_CURSOR 0x65
#define SPRITE_HIGHLIGHT 0x66

// stone colors
#define STONE_RED 0x03
Expand Down Expand Up @@ -95,6 +95,8 @@
#define GAME_STOP 0x00
#define GAME_RUN 0x01
#define GAME_MENU 0x02
#define GAME_SETTINGS 0x03
#define GAME_HELP 0x04

#define PLAYER_HUMAN 0x00
#define PLAYER_CPU 0x01
Expand All @@ -110,4 +112,6 @@
#define SCROLL_BACKGROUND 1
#define SCROLLSPEED 50

#define HELPPAGES 6

#endif // _CONSTANTS_H
34 changes: 13 additions & 21 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 Expand Up @@ -155,10 +156,6 @@ void set_stone(uint8_t y, uint8_t x, uint8_t stone) {
* @param x board x position
*/
void set_cursor(uint8_t y, uint8_t x) {
uint8_t tile = board[cury * boardsize + curx];
uint8_t edge = edgefield[cury * boardsize + curx];
uint32_t map_base_addr = 0x0000;

set_sprite(SPRITE_TILE_CURSOR, board_offset_y + y, board_offset_x + x);

// update cursor positions
Expand Down Expand Up @@ -280,9 +277,6 @@ uint8_t place_stone(uint8_t y, uint8_t x, uint8_t probe, uint8_t player) {
// change turn
swap_turn();

// reset cursor
set_cursor(y, x);

// display current number of stones
count_stones(COUNT_NO_GAME_END);

Expand Down Expand Up @@ -567,21 +561,19 @@ void human_turn() {
ccurx = (*mouse_x >> 4) - board_offset_x;
ccury = (*mouse_y >> 4) - board_offset_y;
if(ccurx >= 0 && ccurx < boardsize && ccury >=0 && ccury < boardsize) {
set_cursor(ccury, ccurx);
}

if(mouse_buttons & 1) {
// wait until mouse button is released
while(mouse_buttons != 0x00) {
asm("ldx #2");
asm("jsr $FF6B");
asm("sta %v", mouse_buttons);

sound_fill_buffers();
update_background_diagonal();
if(mouse_buttons & 1) {
// wait until mouse button is released
while(mouse_buttons != 0x00) {
asm("ldx #2");
asm("jsr $FF6B");
asm("sta %v", mouse_buttons);

sound_fill_buffers();
update_background_diagonal();
}
// place stone in current mouse location
place_stone(ccury, ccurx, PROBE_NO, current_player);
}
// place stone in current mouse location
place_stone(cury, curx, PROBE_NO, current_player);
}
}

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
26 changes: 26 additions & 0 deletions src/help.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**************************************************************************
* *
* 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 _HELP_H
#define _HELP_H

void __fastcall__ load_help_assets();

#endif // _HELP_H
88 changes: 88 additions & 0 deletions src/help.hlp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#
# Generalized HELP file, any lines starting with "#" will be ignored
# in the parsing
#
# All pages are 320x240 pixels or 20 x 15 characters (16x16 font size)
# Writeable area is however 20x12 characters as first line and bottom two
# lines are already used.
#
|PAGE1|
____________________
Othello for the
Commander X16 is a
modern adaptation
of the classic
strategy board game,
tailored for the
retro charm of the
X16 platform.
|ENDPAGE|
|PAGE2|
____________________
Known for its simple
yet strategic
gameplay, Othello
challenges players
to outmaneuver their
opponent by flipping
discs (stones) on
the playing board.
|ENDPAGE|
|PAGE3|
____________________
The objective is to
have the majority
of stones in your
color when the
board is filled.
|ENDPAGE|
|PAGE4|
____________________
Keyboard, joystick
and mouse can all
be used to play the
game.
When playing with
the keyboard, use
the arrow keys to
move the cursor and
press SPACE to place
a disc.
|ENDPAGE|
|PAGE5|
____________________
When playing with
the joystick, use the
d-pad to move the
cursor and press the
B key (yellow key on
SNES controller) to
place a disc.
|ENDPAGE|
|PAGE6|
____________________
When playing with
the mouse, simply
move the cursor
above the tile and
press the left mouse
key to place a disc.
The cursor position
is ignored when
playing with the
mouse.
|ENDPAGE|
#|PAGE|
#____________________
#____________________
#____________________
#____________________
#____________________
#____________________
#____________________
#____________________
#____________________
#____________________
#____________________
#____________________
#|ENDPAGE|
36 changes: 36 additions & 0 deletions src/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# parse .hlp file into binary file that can be parsed by the Othello game

def main():
pages = []
with open('help.hlp') as f:
lines = f.readlines()

for line in lines:
if line.startswith('#'):
continue

if line.startswith('|PAGE'):
parsing = True
curpage = bytearray()
continue

if line.startswith('|ENDPAGE|'):
parsing = False
curpage.extend([0x20] * (20 * 12 - len(curpage)))
pages.append(curpage)
continue

if parsing:
line = line.strip()
line = line.replace('_', ' ')
if len(line) > 20:
curpage += line[0:20].encode('ascii')
else:
curpage += line.encode('ascii') + bytearray([0x20] * (20 - len(line)))

with open('HELP.DAT', 'wb') as f:
for page in pages:
f.write(page)

if __name__ == '__main__':
main()
60 changes: 60 additions & 0 deletions src/help.s
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/.
;
;

.include "x16.inc"

.export _load_help_assets

.code
;
; Start the sound engine
;
.proc _load_help_assets: near

; set ram bank
lda #2 ; use bank 2, bank 1 is used for sound
sta $00 ; set ram bank 2

; assign file name
lda #$08 ; filename length
ldx #<filename ; low byte filename pointer
ldy #>filename ; high byte filename pointer
jsr X16::Kernal::SETNAM

; set file pointer
lda #2 ; file index
ldx #8 ; SD-card
ldy #2 ; headerless load
jsr X16::Kernal::SETLFS

; load file into memory
lda #0 ; load file into system memory
ldx #$00
ldy #$A0 ; banked memory
jsr X16::Kernal::LOAD

; reset ram bank
lda #0 ; reset ram bank
sta $00

rts
.endproc

filename: .asciiz "help.dat"
16 changes: 15 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "menu.h"
#include "mouse.h"
#include "sound.h"
#include "help.h"

unsigned char keycode;

Expand All @@ -39,14 +40,27 @@ void main() {
init_sound();
start_bgmusic();

// load help assets
load_help_assets();

// enable mouse
init_mouse();
set_mouse_pointer(TILE_MOUSE_CURSOR);

while(1) {
while(gamestate == GAME_MENU) {
clear_screen();
game_menu();
game_title();
}

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

while(gamestate == GAME_HELP) {
clear_screen();
game_help();
}

while(gamestate == GAME_RUN) {
Expand Down
Loading

0 comments on commit 63c8c0f

Please sign in to comment.