Skip to content

Commit

Permalink
Implement title screen
Browse files Browse the repository at this point in the history
Merge pull request #6 from haroldo-ok/title-screen
  • Loading branch information
haroldo-ok authored Dec 12, 2021
2 parents 8427cee + c9d4f8f commit e8209be
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 9 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ OBJS := data.rel actor.rel chicken_crossing.rel

all: $(PRJNAME).sms

data.c: data/* data/sprites_tiles.psgcompr data/background_tiles.psgcompr \
data.c: data/* data/sprites_tiles.psgcompr data/background_tiles.psgcompr data/title_tiles.psgcompr \
data/player_1_score.psg data/player_2_score.psg data/player_3_score.psg data/player_4_score.psg
folder2c data data

Expand All @@ -13,6 +13,9 @@ data/sprites_tiles.psgcompr: data/img/sprites.png
data/background_tiles.psgcompr: data/img/background.png
BMP2Tile.exe data/img/background.png -palsms -fullpalette -savetiles data/background_tiles.psgcompr -savetilemap data/background_tilemap.bin -savepalette data/background_palette.bin

data/title_tiles.psgcompr: data/img/title.png
BMP2Tile.exe data/img/title.png -palsms -fullpalette -savetiles data/title_tiles.psgcompr -savetilemap data/title_tilemap.bin -savepalette data/title_palette.bin

data/%.psg: data/deflemask/%.vgm
vgm2psg $< $@ 23

Expand Down
68 changes: 60 additions & 8 deletions chicken_crossing.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "lib/SMSlib.h"
#include "lib/PSGlib.h"
Expand Down Expand Up @@ -264,8 +266,8 @@ void handle_spawners() {
}
}

void draw_background() {
unsigned int *ch = background_tilemap_bin;
void draw_background_map(void *map) {
unsigned int *ch = map;

SMS_setNextTileatXY(0, 0);
for (char y = 0; y != 24; y++) {
Expand All @@ -277,6 +279,10 @@ void draw_background() {
}
}

void draw_background() {
draw_background_map(background_tilemap_bin);
}

char is_touching(actor *act1, actor *act2) {
static actor *collider1, *collider2;
static int r1_tlx, r1_tly, r1_brx, r1_bry;
Expand Down Expand Up @@ -438,18 +444,22 @@ void perform_level_end_sequence() {
level.ending = 0;
}

void clear_scores() {
set_score(score1, 0);
set_score(score2, 0);
set_score(score3, 0);
set_score(score4, 0);
}

char gameplay_loop() {
int frame = 0;
int fish_frame = 0;
int torpedo_frame = 0;
int timer_delay = 30;

animation_delay = 0;

set_score(score1, 0);
set_score(score2, 0);
set_score(score3, 0);
set_score(score4, 0);

clear_scores();
score1->x = 7;
score1->y = 1;
score2->x = 12;
Expand Down Expand Up @@ -566,6 +576,46 @@ char handle_gameover() {
}

char handle_title() {
unsigned int joy = SMS_getKeysStatus();

SMS_waitForVBlank();
SMS_displayOff();
SMS_disableLineInterrupt();

reset_actors_and_player();
clear_sprites();

SMS_loadPSGaidencompressedTiles(title_tiles_psgcompr, 0);
SMS_loadBGPalette(title_palette_bin);
SMS_loadTileMap(0, 0, title_tilemap_bin, title_tilemap_bin_size);

SMS_load1bppTiles(font_1bpp, 352, font_1bpp_size, 0, 12);
SMS_configureTextRenderer(352 - 32);

SMS_setNextTileatXY(3, 16);
puts("Press any button to start");

SMS_setNextTileatXY(3, 18);
puts("Last score:");
SMS_setNextTileatXY(3, 19);
printf("Player 1: %d Player 2: %d", score1->value, score2->value);
SMS_setNextTileatXY(3, 20);
printf("Player 3: %d Player 4: %d", score3->value, score4->value);

SMS_displayOn();

// Wait button press
do {
SMS_waitForVBlank();
joy = SMS_getKeysStatus();
} while (!(joy & (PORT_A_KEY_1 | PORT_A_KEY_2 | PORT_B_KEY_1 | PORT_B_KEY_2)));

// Wait button release
do {
SMS_waitForVBlank();
joy = SMS_getKeysStatus();
} while ((joy & (PORT_A_KEY_1 | PORT_A_KEY_2 | PORT_B_KEY_1 | PORT_B_KEY_2)));

return STATE_GAMEPLAY;
}

Expand All @@ -577,6 +627,8 @@ void main() {
SMS_VDPturnOnFeature(VDPFEATURE_HIDEFIRSTCOL);
SMS_VDPturnOnFeature(VDPFEATURE_LOCKHSCROLL);

clear_scores();

while (1) {
switch (state) {

Expand All @@ -596,6 +648,6 @@ void main() {
}

SMS_EMBED_SEGA_ROM_HEADER(9999,0); // code 9999 hopefully free, here this means 'homebrew'
SMS_EMBED_SDSC_HEADER(0,3, 2021,12,11, "Haroldo-OK\\2021", "Chicken Crossing",
SMS_EMBED_SDSC_HEADER(0,4, 2021,12,12, "Haroldo-OK\\2021", "Chicken Crossing",
"Made for The Honest Jam III - https://itch.io/jam/honest-jam-3.\n"
"Built using devkitSMS & SMSlib - https://github.com/sverx/devkitSMS");
Binary file added data/font.1bpp
Binary file not shown.
Binary file added data/img/jam.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 added data/img/jam.xcf
Binary file not shown.
Binary file added data/img/title.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 added data/img/title.xcf
Binary file not shown.
Binary file added data/title_palette.bin
Binary file not shown.
Binary file added data/title_tilemap.bin
Binary file not shown.
Binary file added data/title_tiles.psgcompr
Binary file not shown.

0 comments on commit e8209be

Please sign in to comment.