Skip to content

Commit

Permalink
Fix visual glitch in demo game
Browse files Browse the repository at this point in the history
This was only happening on Mega Drive, not
the emalators... anyway, fixed now
  • Loading branch information
yujiyokoo committed Dec 8, 2022
1 parent f0f9acc commit c6d80fa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
14 changes: 9 additions & 5 deletions src/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def scroll_wait
break if (pad_state & 0x80 & ~prev) != 0 # start
break if (pad_state & 0x40 & ~prev) != 0 # a
prev = pad_state
wait_vblank(false)
wait_vblank(@show_timer)
end
end

Expand All @@ -396,6 +396,8 @@ def demo_game
v_vel = 0
prev = MegaMrbc.read_joypad
spike_pos = 0
MegaMrbc.show_spikes(spike_pos)
MegaMrbc.show_runner(v_pos)
while true do
MegaMrbc.scroll_game
spike_pos -= 6
Expand All @@ -411,8 +413,8 @@ def demo_game
v_pos += v_vel
v_pos = v_vel = 0 if v_pos >= 0
prev = pad_state
MegaMrbc.show_spikes(spike_pos)
MegaMrbc.show_runner(v_pos)
MegaMrbc.set_spike_pos(spike_pos)
MegaMrbc.set_runner_pos(v_pos)
if collided?(v_pos, spike_pos)
MegaMrbc.sleep_raw(150)
game_over
Expand All @@ -430,7 +432,7 @@ def game_over
MegaMrbc.play_death_se
while i < 30 do
v_pos += 2
MegaMrbc.show_runner(v_pos)
MegaMrbc.set_runner_pos(v_pos)
wait_vblank(false)
i += 1
end
Expand All @@ -444,8 +446,10 @@ def title_screen
state = 0
count = 0
prev = MegaMrbc.read_joypad
MegaMrbc.render_start_bg
[0, 1].each do |dash|
MegaMrbc.render_start(dash)
wait_vblank(false)
MegaMrbc.render_start_logo(dash)
while true do
MegaMrbc.scroll_title
if count / 30 >= 1 # switch every 0.5s
Expand Down
28 changes: 20 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ Sprite* elephant0_obj;
Sprite* elephant1_obj;
Sprite* spikes_obj;

static void render_sky_bg() {
static void c_megamrbc_render_start_bg(mrb_vm *vm, mrb_value *v, int argc) {
PAL_setPaletteDMA(PAL0, sky_bg.palette->data);
VDP_drawImageEx(
BG_B, &sky_bg,
Expand All @@ -336,15 +336,10 @@ static void render_sky_bg() {
);
}

static void c_megamrbc_render_start_screen(mrb_vm *vm, mrb_value *v, int argc) {
static void c_megamrbc_render_start_logo(mrb_vm *vm, mrb_value *v, int argc) {
bool render_dash = mrbc_integer(v[1]);
Image logo_image = main_logo;

// sprintf(buf, "colour_id: %d, colour_val: %d", colour_id, colour_val);
char str[40];
sprintf(str, "value: %d\n", render_dash);
KLog(str);
render_sky_bg();
// use elephant palette which includes main logo palette
VDP_setPalette(PAL1, elephant0.palette->data);
if(render_dash) {
Expand Down Expand Up @@ -394,6 +389,13 @@ static void c_megamrbc_show_runner(mrb_vm *vm, mrb_value *v, int argc) {
SPR_setVisibility(ninja32black_obj, VISIBLE);
}

// This has been moved out because calling show_spikes and show_runner every frame causes flickering on the actual unit, but not emulator
// TODO: remove position from show_spikes / show_runner
static void c_megamrbc_set_runner_pos(mrb_vm *vm, mrb_value *v, int argc) {
uint16_t v_pos = mrbc_integer(v[1]);
SPR_setPosition(ninja32black_obj, 130, 180 + v_pos);
}

static void c_megamrbc_show_spikes(mrb_vm *vm, mrb_value *v, int argc) {
uint16_t spike_location = mrbc_integer(v[1]);
// ninjas' shared pallette
Expand All @@ -402,6 +404,13 @@ static void c_megamrbc_show_spikes(mrb_vm *vm, mrb_value *v, int argc) {
SPR_setVisibility(spikes_obj, VISIBLE);
}

// This has been moved out because calling show_spikes and show_runner every frame causes flickering on the actual unit, but not emulator
// TODO: remove position from show_spikes / show_runner
static void c_megamrbc_set_spike_pos(mrb_vm *vm, mrb_value *v, int argc) {
uint16_t spike_location = mrbc_integer(v[1]);
SPR_setPosition(spikes_obj, 320 + spike_location, 200);
}

static void c_megamrbc_hide_spikes(mrb_vm *vm, mrb_value *v, int argc) {
SPR_setVisibility(spikes_obj, HIDDEN);
}
Expand Down Expand Up @@ -826,11 +835,14 @@ void make_class(mrb_vm *vm)
mrbc_define_method(vm, cls, "clear_screen", c_megamrbc_clear_screen);
// mrbc_define_method(vm, cls, "is_word?", c_megamrbc_is_word);
mrbc_define_method(vm, cls, "call_rand", c_megamrbc_call_rand);
mrbc_define_method(vm, cls, "render_start", c_megamrbc_render_start_screen);
mrbc_define_method(vm, cls, "render_start_bg", c_megamrbc_render_start_bg);
mrbc_define_method(vm, cls, "render_start_logo", c_megamrbc_render_start_logo);
mrbc_define_method(vm, cls, "show_game_bg", c_megamrbc_show_game_bg);
mrbc_define_method(vm, cls, "show_runner", c_megamrbc_show_runner);
mrbc_define_method(vm, cls, "set_runner_pos", c_megamrbc_set_runner_pos);
mrbc_define_method(vm, cls, "hide_runner", c_megamrbc_hide_runner);
mrbc_define_method(vm, cls, "show_spikes", c_megamrbc_show_spikes);
mrbc_define_method(vm, cls, "set_spike_pos", c_megamrbc_set_spike_pos);
mrbc_define_method(vm, cls, "hide_spikes", c_megamrbc_hide_spikes);
// Maybe not needed???
mrbc_define_method(vm, cls, "read_content_line", c_megamrbc_read_content_line);
Expand Down

0 comments on commit c6d80fa

Please sign in to comment.