From 472fd7ded174be5c57bcbd9f4913fd6a65c9f636 Mon Sep 17 00:00:00 2001 From: Justin Orringer Date: Wed, 7 Dec 2022 17:15:27 -0500 Subject: [PATCH 1/3] Sync --- large.c | 40 +++++++++++++++++++++++++++ large.h | 12 +++++++++ main.c | 48 ++++++++++++++++----------------- maps/pool.gbm | Bin 2716 -> 5976 bytes maps/pool_map.c | 28 +++++++++++++++---- maps/pool_map.h | 6 ++--- scrolling.c | 31 +++++++++++++++++++++ scrolling.h | 4 +++ tiles/german.c | 60 +++++++++++++++++++++++------------------ tiles/german.h | 4 +-- tiles/german_16x16.gbr | Bin 0 -> 10069 bytes 11 files changed, 173 insertions(+), 60 deletions(-) create mode 100644 large.c create mode 100644 large.h create mode 100644 scrolling.c create mode 100644 scrolling.h create mode 100644 tiles/german_16x16.gbr diff --git a/large.c b/large.c new file mode 100644 index 0000000..1556749 --- /dev/null +++ b/large.c @@ -0,0 +1,40 @@ +#include + +// This will be used for bosses and the character +struct Large { + UBYTE sprite_id[4]; + UINT8 x; + UINT8 y; + UINT8 width; + UINT8 height; +}; + +typedef struct Large Large; + +void move_large(Large *large, UINT8 x, UINT8 y) { + large->x = x; + large->y = y; + + move_sprite(large->sprite_id[0], large->x, large->y); + move_sprite(large->sprite_id[1], large->x, large->y + 8); + move_sprite(large->sprite_id[2], large->x + 8, large->y); + move_sprite(large->sprite_id[3], large->x + 8, large->y + 8); +} + +void init_large(Large *large, UBYTE *sprite_ids, UINT8 x, UINT8 y, UINT8 width, UINT8 height) { + large->sprite_id[0] = sprite_ids[0]; + large->sprite_id[1] = sprite_ids[1]; + large->sprite_id[2] = sprite_ids[2]; + large->sprite_id[3] = sprite_ids[3]; + large->x = x; + large->y = y; + large->width = width; + large->height = height; + + set_sprite_tile(large->sprite_id[0], large->sprite_id[0]); + set_sprite_tile(large->sprite_id[1], large->sprite_id[1]); + set_sprite_tile(large->sprite_id[2], large->sprite_id[2]); + set_sprite_tile(large->sprite_id[3], large->sprite_id[3]); + + move_large(large, large->x, large->y); +} diff --git a/large.h b/large.h new file mode 100644 index 0000000..58ac8af --- /dev/null +++ b/large.h @@ -0,0 +1,12 @@ +#include + +typedef struct { + UBYTE sprite_id[4]; + UINT8 x; + UINT8 y; + UINT8 width; + UINT8 height; +} Large; + +void init_large(Large *large, UBYTE *sprite_ids, UINT8 x, UINT8 y, UINT8 width, UINT8 height); +void move_large(Large *large, UINT8 x, UINT8 y); diff --git a/main.c b/main.c index 9f6acf2..ebe7ea8 100644 --- a/main.c +++ b/main.c @@ -2,16 +2,19 @@ #include #include "tiles/pool.h" -#include "tiles/german.h" #include "tiles/ocean.h" +#include "tiles/german.h" #include "maps/pool_map.h" +#include "large.h" +#include "scrolling.h" + void init(); void checkInput(); void updateSwitches(); bool collisionCheck(UINT8 x1, UINT8 y1, UINT8 w1, UINT8 h1, UINT8 x2, UINT8 y2, UINT8 w2, UINT8 h2); -UINT8 player[2]; +Large player; void main() { @@ -26,33 +29,26 @@ void main() { } void init() { - DISPLAY_ON; // Turn on the display set_bkg_data(0, 11, poolTiles); // Load 23 tiles into background memory - set_bkg_tiles(0, 0, poolMapWidth, poolMapHeight, poolMap); - - set_sprite_data(0, 1, oceanTiles); + set_bkg_tiles(0, 0, poolMapWidth, poolMapHeight, poolMap); + set_sprite_data(0, 4, germanTiles); - set_sprite_tile(0, 0); + UINT8 sprite_ids[] = {0, 1, 2, 3}; - player[0] = 32; - player[1] = 16; - - move_sprite(0, player[0], player[1]); + init_large(&player, sprite_ids, 32, 16, 16, 16); } void updateSwitches() { - HIDE_WIN; SHOW_SPRITES; SHOW_BKG; - } void checkInput() { - int tempX = player[0]; - int tempY = player[1]; + UINT8 x_mod = 0; + UINT8 y_mod = 0; if (joypad() & J_B) { @@ -61,40 +57,44 @@ void checkInput() { // UP if (joypad() & J_UP) { - tempY = tempY - 1; + y_mod = y_mod - 1; } // DOWN if (joypad() & J_DOWN) { - tempY++; + y_mod++; } // LEFT if (joypad() & J_LEFT) { - tempX = tempX - 1; + x_mod = x_mod - 1; } // RIGHT if (joypad() & J_RIGHT) { - tempX++; + x_mod++; } + UINT8 tempX = player.x + x_mod; + UINT8 tempY = player.y + y_mod; + // Is the player colliding with the left wall? - if(collisionCheck(tempX, tempY, 8, 8, 0, 32, 32, 144) == true) { - // no op + if(collisionCheck(tempX, tempY, 16, 16, 0, 32, 32, 144) == true) { + return; } + if (scroll(player.x + x_mod, x_mod, 0) == true) { + move_large(&player, tempX - x_mod, tempY); + } else { - player[0] = tempX; - player[1] = tempY; - move_sprite(0, player[0], player[1]); + move_large(&player, tempX, tempY); } } diff --git a/maps/pool.gbm b/maps/pool.gbm index 3e065a06eb6ec4730280187479d50cfff29ed757..94805b35333e31da8203b9ffcb454ddd7f471521 100644 GIT binary patch literal 5976 zcmeHJ&ubG=5T0z(CXH2#ASi+a>P3i&y-3JOg3usFTk)bS$V;*$v779gq$Hsr9z5yQ zgGUt)J$Ud>C?2FoPl6W@f>Q5Z`~mTseOY`V$yOS+RovlC-t5f0nK$2iZ`$SDwWa*Z z<-(0CA#y1Waaq)jqSZ?jgq_H(*UYlfbj|xRFQqbrJb9~bWE0hP+s>xbolYlJ5-p=H zQVpY>zE`#D>pt&IqN9S@6lky)P(e}?SWxjW50UQJK_s+L2ZHhM=uUDU)3?ugaRaxjZ z^jqNbgM6I#_$wmzIRah;FMxAj@WT{)w{uoX^!!Jco`T(c50hep^Ko9zp8$Woa87%0 zHK~;fr#{|{zYl$m&QlZ-7ZLrs7A6xuPY@%o_;S1#(0#gl(aEhLpFF32-#w|MvwiGr z&m)Ffh-QfpesrLAjOd`!q3N(=nq-Bm$Jzt4O8g=?*WVXh>Sic1qMN0e5nU8m$+c%t z#TI~j$(JMq9S7(;1cl?|ILi1jpeWa!VCw{uzH>Md>089)T1#3Ow88QY~4Z-30@qb|@dr267 zdu3bNoM&*R=_QAVJcfUfJ(B*lrfGVo+DAv_X>PIS^WcV!G4_8l?}fWsgUBjG0U7}s nDgvq;+zk~C|78Dg4)&}f5a6t$;h!Af>>svj0SOQ& znB`>zVKKyg%wUKCVi5QNG{eg*(Wm+ZkZ}QsK>`ne*uz4YNycA@sk}k`lPcFu#%Jt2 z4D3K7#ev3eU}9#__>jR60yKmLNW;{E3{3c#vH2j=Oh%?nteaz4-ZJuU7G~lAihBfj P`G)u~Gi;7vb727hfY3!* diff --git a/maps/pool_map.c b/maps/pool_map.c index 6a1a103..9e6f236 100644 --- a/maps/pool_map.c +++ b/maps/pool_map.c @@ -7,8 +7,8 @@ Info: Section : Bank : 0 - Map size : 20 x 18 - Tile set : Z:\home\danielagbay\workspace\hackathon\DoggyPaddle\tiles\pool_8x8.gbr + Map size : 30 x 18 + Tile set : Z:\home\jorringe\DoggyPaddle\tiles\pool_8x8.gbr Plane count : 1 plane (8 bits) Plane order : Tiles are continues Tile offset : 0 @@ -18,7 +18,7 @@ */ -#define poolMapWidth 20 +#define poolMapWidth 30 #define poolMapHeight 18 #define poolMapBank 0 @@ -26,39 +26,57 @@ unsigned char poolMap[] = { 0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F, 0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F, + 0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B, 0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F, 0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F, + 0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B, + 0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B, + 0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B, + 0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B, + 0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B, + 0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B, + 0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B, 0x08,0x08,0x06,0x02,0x02,0x02,0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, + 0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x02, 0x09,0x09,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x09,0x09,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x09,0x09,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x09,0x09,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x09,0x09,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x09,0x09,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x09,0x09,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x09,0x09,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x09,0x09,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x09,0x09,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x09,0x09,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x09,0x09,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x09,0x09,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x09,0x09,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x09,0x09,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; diff --git a/maps/pool_map.h b/maps/pool_map.h index 7c9bbb8..ff65de0 100644 --- a/maps/pool_map.h +++ b/maps/pool_map.h @@ -7,8 +7,8 @@ Info: Section : Bank : 0 - Map size : 20 x 18 - Tile set : Z:\home\danielagbay\workspace\hackathon\DoggyPaddle\tiles\pool_8x8.gbr + Map size : 30 x 18 + Tile set : Z:\home\jorringe\DoggyPaddle\tiles\pool_8x8.gbr Plane count : 1 plane (8 bits) Plane order : Tiles are continues Tile offset : 0 @@ -18,7 +18,7 @@ */ -#define poolMapWidth 20 +#define poolMapWidth 30 #define poolMapHeight 18 #define poolMapBank 0 diff --git a/scrolling.c b/scrolling.c new file mode 100644 index 0000000..3036595 --- /dev/null +++ b/scrolling.c @@ -0,0 +1,31 @@ +#include +#include + +// ~40% of the screen width +UINT8 gameplay_x = 55; + +UINT8 level_left = 30 * 8 - 160; + +// pass in sprites to move them with the background +bool scroll(UINT8 player_x, UINT8 x_mod, UINT8 y_mod) { + if (x_mod <= 0) { + return false; + } + + if (player_x < gameplay_x) { + return false; + } + + if (level_left <= 0) { + return false; + } + + // decrement level_left by x_mod + level_left = level_left - x_mod; + + scroll_bkg(x_mod, y_mod); + + return true; + + // scroll all sprites and their collisions except character +} \ No newline at end of file diff --git a/scrolling.h b/scrolling.h new file mode 100644 index 0000000..7e9a3a5 --- /dev/null +++ b/scrolling.h @@ -0,0 +1,4 @@ +#include +#include + +bool scroll(UINT8 player_x, UINT8 x_mod, UINT8 y_mod); diff --git a/tiles/german.c b/tiles/german.c index b1ff7d1..691fce3 100644 --- a/tiles/german.c +++ b/tiles/german.c @@ -9,8 +9,8 @@ Format : Gameboy 4 color. Compression : None. Counter : None. - Tile size : 32 x 32 - Tiles : 0 to 0 + Tile size : 16 x 16 + Tiles : 0 to 4 Palette colors : None. SGB Palette : None. @@ -25,37 +25,45 @@ /* Start of tile array. */ unsigned char germanTiles[] = { + 0x00,0x00,0x00,0x00,0x40,0x40,0xE0,0xA0, + 0xE0,0xA0,0x70,0x50,0x20,0x3F,0x38,0x27, + 0x27,0x38,0x25,0x3A,0x2F,0x30,0x3F,0x27, + 0x78,0x48,0x50,0x70,0x50,0x70,0x20,0x20, + 0x00,0x00,0x00,0x00,0x10,0x10,0x38,0x28, + 0x2E,0x36,0x37,0x29,0x3F,0xC1,0x7E,0x8E, + 0xF0,0x10,0xF0,0x10,0xF0,0x10,0xF0,0xD0, + 0x78,0x48,0x28,0x38,0x28,0x38,0x10,0x10, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x80,0x80,0x80,0x40,0x80,0x40, - 0x80,0xC0,0xC0,0xC0,0x27,0xE7,0xFF,0xFF, - 0x78,0x7F,0x09,0x0E,0x1B,0x1C,0x13,0x1C, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0xFF, - 0x60,0x9F,0xFE,0x01,0xFF,0x00,0xFF,0x00, - 0x17,0x18,0x17,0x18,0x13,0x1C,0x11,0x1E, - 0x09,0x0E,0x07,0x06,0x03,0x02,0x07,0x04, - 0x0B,0x0C,0x17,0x19,0x1E,0x12,0x2C,0x34, - 0x3F,0x23,0x19,0x1F,0x06,0x06,0x00,0x00, - 0xF8,0x07,0xE0,0x1F,0xE0,0x1F,0xFF,0x7F, - 0xE0,0x60,0xE0,0x60,0xC0,0x40,0x80,0x00, - 0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01, - 0x01,0x01,0x07,0x07,0xCC,0xCF,0x38,0xFF, - 0x00,0xFF,0x05,0xFA,0xCF,0x30,0xFE,0x01, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x00,0x00,0x00,0x00,0xC0,0xC0,0x9C,0x1C, - 0xB8,0xB0,0x78,0xF8,0x18,0xFE,0x1C,0xE3, - 0xFF,0x01,0xFF,0x03,0x1C,0xFC,0x20,0xE0, - 0x7E,0x81,0x3C,0xC3,0x18,0xE7,0x1F,0xE7, - 0xDE,0xE2,0x7F,0x61,0x7F,0x70,0x3F,0x3E, - 0x07,0x07,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, - 0x60,0xE0,0x40,0xC0,0xC0,0xC0,0x80,0x80, - 0x00,0x00,0x80,0x80,0xE0,0x60,0xF8,0x18, - 0x88,0xF8,0x70,0x70,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; diff --git a/tiles/german.h b/tiles/german.h index f543a02..832866c 100644 --- a/tiles/german.h +++ b/tiles/german.h @@ -9,8 +9,8 @@ Format : Gameboy 4 color. Compression : None. Counter : None. - Tile size : 32 x 32 - Tiles : 0 to 0 + Tile size : 16 x 16 + Tiles : 0 to 4 Palette colors : None. SGB Palette : None. diff --git a/tiles/german_16x16.gbr b/tiles/german_16x16.gbr new file mode 100644 index 0000000000000000000000000000000000000000..933d666b39846f61dee50a1904d111a29dea4dc0 GIT binary patch literal 10069 zcmeI2K~4fe5JjuH2XG@H@dCZn&8X~fNlb9(#tV$t5fTQBNJcm64Lpx)FX9b6f_8P! z03n#c1sKS$grTec@9M6%o$0hMPnd`v-LI3R_ImVWuKELO&h5B=JGA$%9-&hECor#FS?hC#*+Jrh+Yr!RQDToagO#)<=kM<#Z38PF`o^T_YbGw z2?8Jh0w4eaAOHd&00JNY0w4eaAOHd&00JNY0w4eaAOHd&00JNY0w4ea+e|={q60U8 z`)+~RJ>~m_Zyyx7SLGi;+L{UF`b(nXhIw=KU*sh_)>?YWyYEwlszRRj==1A{TJLQ# slT)g-;*ICg#!p Date: Thu, 8 Dec 2022 10:21:12 -0500 Subject: [PATCH 2/3] Made the pool boundary move --- main.c | 47 ++++++++++++++++++++++++++++------------- scrolling.c | 13 +++++------- scrolling.h | 2 +- tiles/german_16x16.gbr | Bin 10069 -> 10069 bytes 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/main.c b/main.c index b5ce855..f027806 100644 --- a/main.c +++ b/main.c @@ -17,6 +17,9 @@ bool collisionCheck(UINT8 x1, UINT8 y1, UINT8 w1, UINT8 h1, UINT8 x2, UINT8 y2, Large player; +UINT8 level_left = 30 * 8 - 160; +UINT8 scrolled = 0; + void main() { init(); @@ -38,9 +41,9 @@ void init() { set_bkg_data(0, 11, poolTiles); // Load 23 tiles into background memory set_bkg_tiles(0, 0, poolMapWidth, poolMapHeight, poolMap); + set_sprite_data(0, 4, germanTiles); UINT8 sprite_ids[] = {0, 1, 2, 3}; - - init_large(&player, sprite_ids, 32, 16, 16, 16); + init_large(&player, sprite_ids, 16, 16, 16, 16); } void updateSwitches() { @@ -90,33 +93,47 @@ void checkInput() { } UINT8 tileSize = 8; // px + UINT8 playerSize = 16; // px UINT8 tempX = player.x + x_mod; UINT8 tempY = player.y + y_mod; - if( + // push the pool boundary + UINT8 poolBoundary = 32; + if (scrolled > poolBoundary) { + poolBoundary = 0; + } + else { + poolBoundary = poolBoundary - scrolled; + } + + // obstacle boundaries + if ( // left wall (pool boundary) - collisionCheck(tempX, tempY, tileSize, tileSize, 0, 32, 32, 144) - // left wall 2 (left of screen, not pool boundary) - || collisionCheck(tempX, tempY, tileSize, tileSize, 8, 16, 0, 32) + collisionCheck(tempX, tempY, playerSize, playerSize, 0, 48, poolBoundary, 144) + ) + { + playSound(CHANNEL_1, boundaryHit); + return; + } + + // screen boundaries + if( + // left wall (left of screen, not pool boundary) + collisionCheck(tempX, tempY, playerSize, playerSize, 8, 16, 0, 144) // right wall - || collisionCheck(tempX, tempY, tileSize, tileSize, 160+tileSize, 0, 0, 144+8+tileSize) + || collisionCheck(tempX, tempY, playerSize, playerSize, 160+tileSize, 0, 0, 144+8+tileSize) // ceiling - || collisionCheck(tempX, tempY, tileSize, tileSize, 0, 8+tileSize, 160+tileSize, 0) + || collisionCheck(tempX, tempY, playerSize, playerSize, 0, 8+tileSize, 160+tileSize, 0) // floor - || collisionCheck(tempX, tempY, tileSize, tileSize, 0, 144+8+tileSize, 160+tileSize, 0) + || collisionCheck(tempX, tempY, playerSize, playerSize, 0, 144+8+tileSize, 160+tileSize, 0) ) { playSound(CHANNEL_1, boundaryHit); - } - - - // Is the player colliding with the left wall? - if(collisionCheck(tempX, tempY, 16, 16, 0, 32, 32, 144) == true) { return; } - if (scroll(player.x + x_mod, x_mod, 0) == true) { + if (scroll(player.x + x_mod, x_mod, 0, &level_left, &scrolled) == true) { move_large(&player, tempX - x_mod, tempY); } else { diff --git a/scrolling.c b/scrolling.c index 3036595..d224fdd 100644 --- a/scrolling.c +++ b/scrolling.c @@ -4,10 +4,8 @@ // ~40% of the screen width UINT8 gameplay_x = 55; -UINT8 level_left = 30 * 8 - 160; - // pass in sprites to move them with the background -bool scroll(UINT8 player_x, UINT8 x_mod, UINT8 y_mod) { +bool scroll(UINT8 player_x, UINT8 x_mod, UINT8 y_mod, UINT8 *level_left, UINT8 *scrolled) { if (x_mod <= 0) { return false; } @@ -16,16 +14,15 @@ bool scroll(UINT8 player_x, UINT8 x_mod, UINT8 y_mod) { return false; } - if (level_left <= 0) { + if (*level_left <= 0) { return false; } // decrement level_left by x_mod - level_left = level_left - x_mod; + *level_left = *level_left - x_mod; + *scrolled = *scrolled + x_mod; scroll_bkg(x_mod, y_mod); return true; - - // scroll all sprites and their collisions except character -} \ No newline at end of file +} diff --git a/scrolling.h b/scrolling.h index 7e9a3a5..56ecbb4 100644 --- a/scrolling.h +++ b/scrolling.h @@ -1,4 +1,4 @@ #include #include -bool scroll(UINT8 player_x, UINT8 x_mod, UINT8 y_mod); +bool scroll(UINT8 player_x, UINT8 x_mod, UINT8 y_mod, UINT8 *level_left, UINT8 *scrolled); diff --git a/tiles/german_16x16.gbr b/tiles/german_16x16.gbr index 933d666b39846f61dee50a1904d111a29dea4dc0..3f14c5075cbcedc45b1c20042e6d4c512789139a 100644 GIT binary patch delta 135 zcmccWchzr#9;-A{#qacu#>*76qpV^w@^e#Tvhs_HGV{_?V_fpn(<=iKQ&MtLV@fh} zQj25KQ;TvF^YoG@Z)6NLU=9I^F`xp73N#r;kQ$cFor*`9*cCu*k1s$IzHRna=`ER delta 42 vcmccWchzr#9xDR~Y&2e`FnNh$>*NEBs*@Kfif^8!xP=MG`McR$m5T`gK$Q<0 From 05d302de0e7f391cf508f6206c323be2d4614fcd Mon Sep 17 00:00:00 2001 From: Justin Orringer Date: Thu, 8 Dec 2022 10:23:29 -0500 Subject: [PATCH 3/3] Moved large sprite and scrolling to folders --- scrolling.c => internal/scrolling.c | 0 scrolling.h => internal/scrolling.h | 0 main.c | 4 ++-- large.c => movement/large.c | 0 large.h => movement/large.h | 0 5 files changed, 2 insertions(+), 2 deletions(-) rename scrolling.c => internal/scrolling.c (100%) rename scrolling.h => internal/scrolling.h (100%) rename large.c => movement/large.c (100%) rename large.h => movement/large.h (100%) diff --git a/scrolling.c b/internal/scrolling.c similarity index 100% rename from scrolling.c rename to internal/scrolling.c diff --git a/scrolling.h b/internal/scrolling.h similarity index 100% rename from scrolling.h rename to internal/scrolling.h diff --git a/main.c b/main.c index f027806..f95908b 100644 --- a/main.c +++ b/main.c @@ -7,8 +7,8 @@ #include "maps/pool_map.h" #include "sounds/sounds.h" -#include "large.h" -#include "scrolling.h" +#include "movement/large.h" +#include "internal/scrolling.h" void init(); void checkInput(); diff --git a/large.c b/movement/large.c similarity index 100% rename from large.c rename to movement/large.c diff --git a/large.h b/movement/large.h similarity index 100% rename from large.h rename to movement/large.h