Skip to content

Commit

Permalink
Merge pull request #3 from justinorringer/scrolling_dog
Browse files Browse the repository at this point in the history
Scrolling Dog
  • Loading branch information
justinorringer authored Dec 8, 2022
2 parents 997350c + 05d302d commit 4096343
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 67 deletions.
28 changes: 28 additions & 0 deletions internal/scrolling.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <gb/gb.h>
#include <stdbool.h>

// ~40% of the screen width
UINT8 gameplay_x = 55;

// pass in sprites to move them with the background
bool scroll(UINT8 player_x, UINT8 x_mod, UINT8 y_mod, UINT8 *level_left, UINT8 *scrolled) {
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;
*scrolled = *scrolled + x_mod;

scroll_bkg(x_mod, y_mod);

return true;
}
4 changes: 4 additions & 0 deletions internal/scrolling.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include <gb/gb.h>
#include <stdbool.h>

bool scroll(UINT8 player_x, UINT8 x_mod, UINT8 y_mod, UINT8 *level_left, UINT8 *scrolled);
85 changes: 54 additions & 31 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@
#include <stdbool.h>

#include "tiles/pool.h"
#include "tiles/german.h"
#include "tiles/ocean.h"
#include "tiles/german.h"
#include "maps/pool_map.h"
#include "sounds/sounds.h"

#include "movement/large.h"
#include "internal/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;

UINT8 level_left = 30 * 8 - 160;
UINT8 scrolled = 0;

void main() {

Expand All @@ -27,35 +33,28 @@ void main() {
}

void init() {
// display
DISPLAY_ON;

DISPLAY_ON; // Turn on the display

// sound
initSound();

set_bkg_data(0, 11, poolTiles);
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_sprite_tile(0, 0);

player[0] = 8;
player[1] = 16;

move_sprite(0, player[0], player[1]);
set_sprite_data(0, 4, germanTiles);
UINT8 sprite_ids[] = {0, 1, 2, 3};
init_large(&player, sprite_ids, 16, 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_A) {

Expand All @@ -68,53 +67,77 @@ 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 tileSize = 8; // px
UINT8 playerSize = 16; // px

if(
UINT8 tempX = player.x + x_mod;
UINT8 tempY = player.y + y_mod;

// 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);
return;
}

if (scroll(player.x + x_mod, x_mod, 0, &level_left, &scrolled) == 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);
}
}

Expand Down
Binary file modified maps/pool.gbm
Binary file not shown.
28 changes: 23 additions & 5 deletions maps/pool_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,47 +18,65 @@
*/

#define poolMapWidth 20
#define poolMapWidth 30
#define poolMapHeight 18
#define poolMapBank 0

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
};

Expand Down
6 changes: 3 additions & 3 deletions maps/pool_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,7 +18,7 @@
*/

#define poolMapWidth 20
#define poolMapWidth 30
#define poolMapHeight 18
#define poolMapBank 0

Expand Down
40 changes: 40 additions & 0 deletions movement/large.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <gb/gb.h>

// 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);
}
12 changes: 12 additions & 0 deletions movement/large.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <gb/gb.h>

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);
Loading

0 comments on commit 4096343

Please sign in to comment.