Skip to content

Commit

Permalink
Merge pull request #277 from DigiDwrf/develop
Browse files Browse the repository at this point in the history
Super Scope Example update
  • Loading branch information
alekmaul authored Apr 10, 2024
2 parents 4199b78 + 47e194d commit f39d91d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 42 deletions.
4 changes: 2 additions & 2 deletions snes-examples/input/superscope/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ sprites.pic: sprites.png
@echo convert sprites bitmap ... $(notdir $@)
$(GFXCONV) -s 32 -u 16 -o 48 -t png -i $<

calibration_target.pic: calibration_target.png
aim_adjust_target.pic: aim_adjust_target.png
@echo convert BG map ... $(notdir $@)
$(GFXCONV) -s 8 -u 16 -o 16 -t png -m -i $<

bitmaps : pvsneslibfont.pic sprites.pic calibration_target.pic
bitmaps : pvsneslibfont.pic sprites.pic aim_adjust_target.pic
80 changes: 49 additions & 31 deletions snes-examples/input/superscope/SuperScope.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
extern char tilfont, palfont;

extern unsigned char sprites_map, sprites_map_end, sprites_palette; // Sprites
extern unsigned char cali_target_tileset, cali_target_tileset_end, cali_target_map, cali_target_palette; // BG
extern unsigned char aim_target_tileset, aim_target_tileset_end, aim_target_map, aim_target_palette; // BG

void hideSprites()
{
Expand Down Expand Up @@ -75,7 +75,7 @@ int main(void)
consoleInitText(1, 16 * 2, &tilfont, &palfont);

// Init background
bgInitTileSet(0, &cali_target_tileset, &cali_target_palette, 0, (&cali_target_tileset_end - &cali_target_tileset), 16 * 2, BG_16COLORS, 0x3000);
bgInitTileSet(0, &aim_target_tileset, &aim_target_palette, 0, (&aim_target_tileset_end - &aim_target_tileset), 16 * 2, BG_16COLORS, 0x3000);
bgSetGfxPtr(1, 0x3800);
bgSetMapPtr(1, 0x2000, SC_32x32);

Expand All @@ -98,7 +98,7 @@ int main(void)
bgSetScroll(1, 0, -1);

START_OVER:
bgInitMapSet(0, &cali_target_map, 0x700, SC_32x32, 0x2800);
bgInitMapSet(0, &aim_target_map, 0x700, SC_32x32, 0x2800);

// Draw a wonderful text :P
consoleDrawText(8, 1, "SUPERSCOPE Test");
Expand Down Expand Up @@ -132,7 +132,7 @@ int main(void)
WaitNVBlank(60); // Hold on for one second

ADJUST_AIM:
consoleDrawText(1, 24, " ");
consoleDrawText(9, 24, " ");
consoleDrawText(3, 25, " Shoot center of screen ");
consoleDrawText(3, 26, " to adjust aim ");

Expand Down Expand Up @@ -180,13 +180,10 @@ int main(void)
WaitForVBlank();
}

// Offsets may vary if your code is different, so you can play with this numbers until you find them suitable for your program.
u8 h_offset = 0x8A;
u8 v_offset = 0x74;

// Start aim adjust process: it stores scope's raw values relative to the center of screen, so shot matches superscope's physical aim.
scope_centerh = scope_shothraw - h_offset;
scope_centerv = scope_shotvraw - v_offset;
// Start aim adjust process: it stores scope's raw values relative to the center of screen, so shot matches superscope's physical aim
// We also move our scope's center to the center of screen
scope_centerh = 0x80 - scope_shothraw;
scope_centerv = 0x70 - scope_shotvraw;

if (pause_adjust)
consoleDrawText(1, 3, " ");
Expand Down Expand Up @@ -233,22 +230,15 @@ int main(void)
WaitForVBlank();
}

oamSetXY(0, scope_shoth - 0x12, scope_shotv - 0x0C); // Draw spot in the center if the aim was on the center during aim adjustment, this means our aim is good.
// To finish aim adjust we store coords relative to the center of screen
oamSetXY(0, scope_shoth - 0x08, scope_shotv - 0x08); // Draw spot aligned with our aim if the aim was on the center on first shot, this means our aim is adjusted.

WaitNVBlank(60); // Hold on for one second

s8 shot_diff_x = scope_shoth - scope_shothraw; // difference between raw horizontal value and adjusted shot.
s8 shot_diff_y = scope_shotv - scope_shotvraw; // difference between raw vertical value and adjusted shot.

if ((shot_diff_x + shot_diff_y) == 0) // no difference between adjusted shot coords and raw coords, this means we have a perfect aim adjustment
consoleDrawText(12, 24, "PERFECT!");
else if ((shot_diff_x > -4) && (shot_diff_x < 4) && (shot_diff_y > -4) && (shot_diff_y < 4)) // Aim in range (8px x 8px)
consoleDrawText(14, 24, "Nice."); // inside 8x8 range, displays a good message
else
consoleDrawText(2, 24, "You can do better. Try again?"); // More than 8x8, we think is too much
consoleDrawText(9, 24, "Are you ready?");
if (pause_adjust)
{
consoleDrawText(4, 25, "Press PAUSE to return");
consoleDrawText(5, 25, "Press PAUSE to return");
consoleDrawText(3, 26, "Press CURSOR to adjust aim");
}
else
Expand Down Expand Up @@ -336,8 +326,8 @@ int main(void)
}

// We also have to setup Fire rate
scope_holddelay = max_rate; // How much time we need to consider a button has been held
scope_repdelay = max_rate; // Fire rate
scope_holddelay = 60; // We wait a secont until we want to consider that the button has been held
scope_repdelay = slow_fire_rate; // Fire rate

setFadeEffect(FADE_OUT);

Expand Down Expand Up @@ -365,15 +355,15 @@ int main(void)
consoleDrawText(8, 1, " ");
consoleDrawText(1, 3, " ");
consoleDrawText(8, 4, " ");
consoleDrawText(1, 24, " ");
consoleDrawText(9, 24, " ");
consoleDrawText(4, 25, " ");
consoleDrawText(3, 26, " ");

setPaletteColor(0, 0x7FFF); // Let's use a white BACK
setPaletteColor(17, 0x0000); // and black for texts

WaitForVBlank();
dmaFillVram(&cali_target_map, 0x2800, 0x700); // Wipe screen
dmaFillVram(&aim_target_map, 0x2800, 0x700); // Wipe screen
oamInitGfxAttr(0x0000, OBJ_SIZE32_L64); // Set to bigger sprites

setScreenOn();
Expand Down Expand Up @@ -421,14 +411,33 @@ int main(void)

if (enable_fire)
{
if (scope_held & SSC_FIRE)
if (scope_held & SSC_FIRE) // We're using scope_held to swap from a normal fire rate to a slower firerate
if (cool_down < 2)
cool_down++;

if ((scope_down & SSC_FIRE) == 0)
cool_down = 0;

if (((scope_held & SSC_FIRE) && (cool_down == 2)) || ((scope_down & SSC_FIRE) && (ready_to_fire == normal_fire_rate)))
{
bullet_id++;
if (bullet_id == 32)
bullet_id = 0;

bullet_x[bullet_id] = scope_shoth - 0x1A;
bullet_y[bullet_id] = scope_shotv - 0x14;
if (scope_shoth < 0x110)
{
bullet_x[bullet_id] = scope_shoth - 0x10;
if (scope_shotv < 0xE0)
bullet_y[bullet_id] = scope_shotv - 0x10;
else
bullet_y[bullet_id] = 0xE0;
}
else
{
bullet_x[bullet_id] = 0x110;
bullet_y[bullet_id] = 0xE0;
}

bullet_frame[bullet_id] = 0;
bullet_draw[bullet_id] = 0;

Expand All @@ -440,8 +449,17 @@ int main(void)
difuse_y[bullet_id] = ((rand() & 0xF0) >> 4) - 8;

shot_bullets++; // incease shot bullets by one
ready_to_fire = 0;
}

if (cool_down < 2)
{
if (ready_to_fire < normal_fire_rate)
ready_to_fire++; // This will prevent lag if we shoot too fast
}
else
ready_to_fire = 0;

for (bullet_num = 0; bullet_num < shot_bullets; bullet_num++)
{
s8 id = bullet_id - bullet_num;
Expand Down Expand Up @@ -495,7 +513,7 @@ int main(void)
consoleDrawText(13, 13, " ");
consoleDrawText(10, 14, " ");

setPalette(&cali_target_palette, 0, 2); // Restore blue BACK
setPalette(&aim_target_palette, 0, 2); // Restore blue BACK
setPaletteColor(17, 0x7FFF); // Restore white text

hideSprites();
Expand Down Expand Up @@ -596,7 +614,7 @@ int main(void)
setFadeEffect(FADE_OUT);

resetGame();
setPalette(&cali_target_palette, 0, 2); // Restore blue BACK
setPalette(&aim_target_palette, 0, 2); // Restore blue BACK
setPaletteColor(17, 0x7FFF); // Restore white text
goto START_OVER;
}
Expand Down
5 changes: 4 additions & 1 deletion snes-examples/input/superscope/SuperScope.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#ifndef SUPERSCOPE_H
#define SUPERSCOPE_H

#define max_rate 10 // To put some limit to turbo mode, so we're gonna fire every 10 frames
#define normal_fire_rate 10 // To put some limit to turbo mode, so we're gonna fire every 10 frames
#define slow_fire_rate 20 // To put some limit to turbo mode, so we're gonna fire every 20 frames

#define max_bullets 32
#define max_targets 64
Expand All @@ -10,6 +11,8 @@ bool sscope_disconnected = false; // if SuperScope is disconnected during gamepl
bool pause_adjust = false; // If we pause during game, will lead us to calibration screen, but we will be able to continue our game

// Let's declare some usefull variables to animate our fantastic blue bullets :D
u8 ready_to_fire = 0;
u8 cool_down = 0;
u8 bullet_id = 0; // bullet id, we're going to use a maximum of 32 bullets, and then they reset to 0
u8 bullet_num = 0; // bullet number, this will help us to draw multiple bullets on screen at the same time
u8 shot_bullets = 0; // the number of bullets we have shot and need to be drawn on screen. Every time a bullet dissapears, this number will decrease by one.
Expand Down
14 changes: 7 additions & 7 deletions snes-examples/input/superscope/data.asm
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
sprites_palette:
.incbin "sprites.pal"

cali_target_tileset:
.incbin "calibration_target.pic"
aim_target_tileset:
.incbin "aim_adjust_target.pic"

cali_target_tileset_end:
aim_target_tileset_end:

cali_target_map:
.incbin "calibration_target.map"
aim_target_map:
.incbin "aim_adjust_target.map"

cali_target_palette:
.incbin "calibration_target.pal"
aim_target_palette:
.incbin "aim_adjust_target.pal"

.ends
2 changes: 1 addition & 1 deletion snes-examples/input/superscope/hdr.asm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
.SNESHEADER
ID "SNES" ; 1-4 letter string, just leave it as "SNES"

NAME "LIBSNES S.SCOPE INPUT" ; Program Title - can't be over 21 bytes,
NAME "LIBSNES SUPER SCOPE I" ; Program Title - can't be over 21 bytes,
; "123456789012345678901" ; use spaces for unused bytes of the name.

SLOWROM
Expand Down

0 comments on commit f39d91d

Please sign in to comment.