From 2682bc5d1d864341aaeb42a449db73c3ecd16d70 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Wed, 30 Dec 2020 19:07:31 +0000 Subject: Initial import --- game/src/main.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 game/src/main.c (limited to 'game/src/main.c') diff --git a/game/src/main.c b/game/src/main.c new file mode 100644 index 0000000..1405356 --- /dev/null +++ b/game/src/main.c @@ -0,0 +1,143 @@ +#include + +#include "ubox.h" +#include "mplayer.h" + +#include "aux.h" +#include "game.h" + +#define LOCAL +#include "main.h" + +// generated +#include "tiles.h" + +void draw_menu() +{ + uint8_t i; + + ubox_disable_screen(); + + ubox_fill_screen(WHITESPACE_TILE); + + // game logo; starts in tile 32 and it is 10 x 3 tiles + for (i = 0; i < 10; ++i) + { + ubox_put_tile(11 + i, 6, 32 + i); + ubox_put_tile(11 + i, 7, 64 + i); + ubox_put_tile(11 + i, 8, 96 + i); + } + + put_text(11, 11, "PRESS FIRE"); + + put_text(7, 2, "UBOX MSX LIB DEMO!"); + put_text(4, 16, "CODE, GRAPHICS AND SOUND"); + put_text(8, 17, "JUAN J. MARTINEZ"); + // 037 is ASCII 31 in octal, our Copyright sign + put_text(8, 21, "\0372020 USEBOX.NET"); + + ubox_enable_screen(); +} + +void draw_end_game() +{ + ubox_disable_screen(); + + ubox_fill_screen(WHITESPACE_TILE); + + put_text(3, 9, "WELL DONE!"); + put_text(3, 10, "YOU HAVE FINISHED THE DEMO."); + put_text(3, 12, "NOW GO AND MAKE GAMES :)"); + + put_text(3, 14, "(PRESS ESC)"); + + ubox_enable_screen(); + + // wait until ESC is pressed + while (1) + { + if (ubox_read_keys(7) == UBOX_MSX_KEY_ESC) + break; + + ubox_wait(); + } +} + +void draw_game_over() +{ + ubox_disable_screen(); + + ubox_fill_screen(WHITESPACE_TILE); + put_text(11, 10, "GAME OVER"); + + ubox_enable_screen(); + + // play game over music + mplayer_init(SONG, SONG_GAME_OVER); + + wait_for(128); +} + +void main() +{ + // PAL: 50/2 = 25 FPS + // NTSC: 60/2 = 30 FPS + ubox_init_isr(2); + + // set screen 2 + ubox_set_mode(2); + // all black + ubox_set_colors(1, 1, 1); + + // avoid showing garbage on the screen + // while setting up the tiles + ubox_disable_screen(); + + // upload our tileset + ubox_set_tiles(tiles); + // and the colour information + ubox_set_tiles_colors(tiles_colors); + + // clear the screen + ubox_fill_screen(WHITESPACE_TILE); + + ubox_enable_screen(); + + // reg 1: activate sprites, v-blank int on, 16x16 sprites + ubox_wvdp(1, 0xe2); + + // init the player + mplayer_init(SONG, SONG_SILENCE); + mplayer_init_effects(EFFECTS); + + // we don't need anything in our ISR + // other than the play function, so we + // use that! + ubox_set_user_isr(mplayer_play); + +redraw_menu: + draw_menu(); + + // whait until fire is pressed + // can be space (control will be cursors), or any fire button on a joystick + while (1) + { + ctl = ubox_select_ctl(); + if (ctl != UBOX_MSX_CTL_NONE) + { + mplayer_play_effect_p(EFX_START, EFX_CHAN_NO, 0); + wait_for(16); + + // play the game + run_game(); + + if (!lives) + draw_game_over(); + else if (!batteries) + draw_end_game(); + + goto redraw_menu; + } + ubox_wait(); + } +} -- cgit v1.2.3