aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/c_cpp_properties.json3
-rw-r--r--.vscode/launch.json2
-rw-r--r--.vscode/tasks.json69
-rw-r--r--src/demo.c272
-rw-r--r--src/entity.h17
-rw-r--r--src/ppusim/input.c2
6 files changed, 289 insertions, 76 deletions
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
index 51f5ad0..3a0c430 100644
--- a/.vscode/c_cpp_properties.json
+++ b/.vscode/c_cpp_properties.json
@@ -2,7 +2,8 @@
"configurations": [
{
"name": "src",
- "compileCommands": "${workspaceFolder}/src/compile_commands.json"
+ "compileCommands": "${workspaceFolder}/src/compile_commands.json",
+ "configurationProvider": "ms-vscode.makefile-tools"
}
],
"version": 4
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 2f7561c..4ff91bb 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -12,7 +12,7 @@
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
- "preLaunchTask": "client/build",
+ "preLaunchTask": "build",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
index 8404cfa..a670b0f 100644
--- a/.vscode/tasks.json
+++ b/.vscode/tasks.json
@@ -16,13 +16,19 @@
"isDefault": false,
"kind": "build"
},
- "options": { "cwd": "${workspaceFolder}/src" },
+ "options": {
+ "cwd": "${workspaceFolder}/src"
+ },
"windows": {
"command": "make -j",
- "args": [ "" ],
+ "args": [
+ ""
+ ]
},
"command": "make",
- "args": [ "-j" ],
+ "args": [
+ "-j"
+ ],
"type": "shell"
},
{
@@ -32,13 +38,20 @@
"isDefault": false,
"kind": "test"
},
- "options": { "cwd": "${workspaceFolder}/src" },
+ "options": {
+ "cwd": "${workspaceFolder}/src"
+ },
"windows": {
"command": "make -j flash",
- "args": [ "" ],
+ "args": [
+ ""
+ ]
},
"command": "make",
- "args": [ "-j", "flash" ],
+ "args": [
+ "-j",
+ "flash"
+ ],
"type": "shell"
},
{
@@ -48,13 +61,19 @@
"isDefault": false,
"kind": "test"
},
- "options": { "cwd": "${workspaceFolder}/src" },
+ "options": {
+ "cwd": "${workspaceFolder}/src"
+ },
"windows": {
"command": "make compile_commands.json",
- "args": [ "" ],
+ "args": [
+ ""
+ ]
},
"command": "make",
- "args": [ "compile_commands.json" ],
+ "args": [
+ "compile_commands"
+ ],
"type": "shell"
},
{
@@ -64,14 +83,40 @@
"isDefault": false,
"kind": "test"
},
- "options": { "cwd": "${workspaceFolder}" },
+ "options": {
+ "cwd": "${workspaceFolder}"
+ },
"windows": {
"command": "make clean",
- "args": [ "" ],
+ "args": [
+ ""
+ ]
},
"command": "make",
- "args": [ "clean" ],
+ "args": [
+ "clean"
+ ],
"type": "shell"
+ },
+ {
+ "type": "cppbuild",
+ "label": "C/C++: gcc.exe build active file",
+ "command": "C:\\msys64\\mingw64\\bin\\gcc.exe",
+ "args": [
+ "-fdiagnostics-color=always",
+ "-g",
+ "${file}",
+ "-o",
+ "${fileDirname}\\${fileBasenameNoExtension}.exe"
+ ],
+ "options": {
+ "cwd": "C:\\msys64\\mingw64\\bin"
+ },
+ "problemMatcher": [
+ "$gcc"
+ ],
+ "group": "build",
+ "detail": "compiler: C:\\msys64\\mingw64\\bin\\gcc.exe"
}
]
}
diff --git a/src/demo.c b/src/demo.c
index 95347cb..f5d2e71 100644
--- a/src/demo.c
+++ b/src/demo.c
@@ -1,31 +1,40 @@
#include <math.h>
#include "demo.h"
-#include "input.h"
#include "entity.h"
+#include "input.h"
#include "ppu/ppu.h"
-#include "engine/maths.h"
-#include "engine/camera.h"
-#include "engine/entity.h"
-#include "engine/draw_screen.h"
-#include "engine/player_controller.h"
-#include "engine/sprite_controller.h"
-
-
+#define HH_DEMO_BALL_COUNT 2
+hh_s_ppu_loc_fam_entry g_hh_demo_balls[HH_DEMO_BALL_COUNT];
hh_s_entity_player g_hh_player_1 = {
- .pos_x = 31000, // 0b0000 0001 0011 0110
- .pos_y = 21000,
- .radius = 8,
+ .pos_x = 11000,
+ .pos_y = 5000,
+ .radius = 4,
.speed = 100,
+ .air_speed = 80,
.direction_x = 1,
+ .accelY = 0,
.rotation = 8,
.in_air = false,
};
+hh_s_entity_enemy g_hh_enemy_1 = {
+ .pos_x = 16000,
+ .pos_y = 20000,
+ .radius = 4,
+ .speed = 100,
+ .direction_x = 1,
+ .accelY = 0,
+ .in_air = false,
+};
+
void hh_player_movement();
+int hh_background_collision_x(hh_s_entity_player tempEntity);
+hh_s_entity_player hh_background_collision_y_player(hh_s_entity_player tempEntity);
+
uint16_t g_hh_pos_x; // 0b0000 0001 0011 0110
uint16_t g_hh_pos_y;
uint8_t g_hh_left = 0;
@@ -38,26 +47,66 @@ uint8_t g_hh_data_send[3];
int g_hh_tile_x;
int g_hh_tile_y;
-typedef struct {
- vec2 pos;
- uint8_t idx;
-}hh_s_tiles;
-
-
-hh_entity hh_g_player, hh_g_player_new;
void hh_demo_setup() {
+ // load sprites
+ hh_ppu_update_sprite(0, HH_DBG_SPRITE_BALL);
+ hh_ppu_update_sprite(1, HH_DBG_SPRITE_CHECKERBOARD);
- hh_setup_palettes();
- hh_setup_screen();
+ // background pattern
+ hh_ppu_update_color(0, 1, (hh_ppu_rgb_color_t){0x4, 0x4, 0x4});
+ for (unsigned i = 0; i < HH_PPU_BG_CANVAS_TILES_H * HH_PPU_BG_CANVAS_TILES_V; i++) {
+ hh_ppu_update_background(i, (hh_s_ppu_loc_bam_entry){
+ .horizontal_flip = false,
+ .vertical_flip = false,
+ .palette_index = 0,
+ .tilemap_index = 1,
+ });
+ }
+
+ // cool colors
+ hh_ppu_update_color(1, 1, (hh_ppu_rgb_color_t){0xf, 0x0, 0xf});
+ hh_ppu_update_color(2, 1, (hh_ppu_rgb_color_t){0xf, 0xf, 0xf});
+ hh_ppu_update_color(3, 1, (hh_ppu_rgb_color_t){0xf, 0x0, 0x0});
+ hh_ppu_update_color(4, 1, (hh_ppu_rgb_color_t){0x0, 0xf, 0xf});
+ hh_ppu_update_color(5, 1, (hh_ppu_rgb_color_t){0x0, 0x0, 0xf});
+ // balls
+ for (unsigned i = 0; i < HH_DEMO_BALL_COUNT; i++) {
+ g_hh_demo_balls[i].horizontal_flip = false;
+ g_hh_demo_balls[i].vertical_flip = false;
+ g_hh_demo_balls[i].palette_index = i + 1;
+ g_hh_demo_balls[i].tilemap_index = 0;
+ }
}
void hh_demo_loop(unsigned long frame) {
+ hh_player_movement();
+ // input testing (no hitbox stuff)
+ // g_hh_player_1.pos_x += ((-1 * g_hh_controller_p1.dpad_left) + (1 * g_hh_controller_p1.dpad_right)) * g_hh_player_1.speed; // -1 = L || 1 == R
+ g_hh_player_1.pos_y += ((-1 * g_hh_controller_p1.dpad_up) + (1 * g_hh_controller_p1.dpad_down)) * g_hh_player_1.speed; // -1 = D || 1 == U
+
- // hh_player_movement();
+ // adjust map size
+ g_hh_pos_x = g_hh_player_1.pos_x / 100;
+ g_hh_pos_y = g_hh_player_1.pos_y / 100;
- hh_player_actions();
+ // update player sprite on ppu
+ g_hh_demo_balls[0].position_x = g_hh_pos_x;
+ g_hh_demo_balls[0].position_y = g_hh_pos_y;
+
+ g_hh_demo_balls[1].position_x = 220;
+ g_hh_demo_balls[1].position_y = 220;
+ hh_ppu_update_foreground(0, g_hh_demo_balls[0]);
+ hh_ppu_update_foreground(1, g_hh_demo_balls[1]);
+
+ // set background pattern position
+ hh_ppu_update_aux((hh_s_ppu_loc_aux){
+ .bg_shift_x = (frame / 2) % HH_PPU_SPRITE_WIDTH,
+ .bg_shift_y = (frame / 8) % HH_PPU_SPRITE_HEIGHT,
+ .fg_fetch = 0,
+ .sysreset = 0,
+ });
}
// void sendData(uint8_t address, uint16_t data) {
@@ -75,6 +124,12 @@ void hh_player_movement() {
int8_t directionX = (-1 * g_hh_controller_p1.dpad_left) + (1 * g_hh_controller_p1.dpad_right); // -1 = L || 1 == R
int8_t directionY = (-1 * g_hh_controller_p1.dpad_up) + (1 * g_hh_controller_p1.dpad_down); // -1 = D || 1 == U
+ if(g_hh_controller_p1.button_primary == 1 && g_hh_player_1.accelY == 0 && g_hh_player_1.in_air == false)
+ {
+ g_hh_player_1.accelY = 25;
+ }
+
+
uint8_t i, j;
uint8_t rotation = 0; // 0-7
@@ -92,63 +147,162 @@ void hh_player_movement() {
rotation++;
}
}
- // direction calc
- if (directionX != 0) // update direction if player is not idle
+ // X-axis calc
+ if (directionX != 0) // update direction and position if player is not idle
{
g_hh_player_1.direction_x = directionX;
+ g_hh_player_1.pos_x = hh_background_collision_x(g_hh_player_1);
}
- // collision map x-axis
+
+ g_hh_player_1 = hh_background_collision_y_player(g_hh_player_1);
+
+}
+
+
+int hh_background_collision_x(hh_s_entity_player tempEntity){
// tile calc including radius and direction for background coliision
uint16_t tileColX;
- uint16_t tileColY = (g_hh_player_1.pos_y / 100) / 16;
+ uint16_t tileColY = (tempEntity.pos_y / 100) / 8;
;
// remaining space between grid and exact
uint8_t modTileX;
- uint8_t modTileY;
-
- if (g_hh_player_1.in_air == false && directionX != 0) {
- if (directionX == 1) {
- tileColX = ((g_hh_player_1.pos_x / 100) + g_hh_player_1.radius) / 16;
- modTileX = (g_hh_player_1.pos_x + (100 * g_hh_player_1.radius)) % 1600;
- } else if (directionX == -1) {
- tileColX = ((g_hh_player_1.pos_x / 100) - g_hh_player_1.radius) / 16;
- modTileX = (g_hh_player_1.pos_x - (100 * g_hh_player_1.radius)) % 1600;
- }
- if (HH_DEMO_HITBOX_TILEMAP[tileColY][tileColX + directionX] != 1) {
- g_hh_player_1.pos_x = g_hh_player_1.pos_x + (directionX * g_hh_player_1.speed); // NEW x set
- }
- else if (HH_DEMO_HITBOX_TILEMAP[tileColY][tileColX + directionX] == 1) {
+
+ if (tempEntity.direction_x == 1) {
+ tileColX = ((tempEntity.pos_x / 100) + tempEntity.radius) / 8;
+ modTileX = 800 -((tempEntity.pos_x + (100 * tempEntity.radius)) % 800);
+ } else if (tempEntity.direction_x == -1) {
+ tileColX = ((tempEntity.pos_x / 100) - tempEntity.radius )/ 8;
+ modTileX = (tempEntity.pos_x - (100 * tempEntity.radius)) % 800;
+ }
+
+ tileColY = (( tempEntity.pos_y / 100) + tempEntity.radius) / 8; //bottom of player box
+
+ if (HH_DEMO_HITBOX_TILEMAP[tileColY][tileColX + tempEntity.direction_x] != 1) {
+ tileColY = (( tempEntity.pos_y / 100) - tempEntity.radius) / 8; //bottom of player box
+ if (HH_DEMO_HITBOX_TILEMAP[tileColY][tileColX + tempEntity.direction_x] != 1) {
+ if(tempEntity.in_air== true){
+ tempEntity.pos_x= tempEntity.pos_x + (tempEntity.direction_x * tempEntity.air_speed); // 80% of max speed if in air
+ } else {
+ tempEntity.pos_x= tempEntity.pos_x + (tempEntity.direction_x * tempEntity.speed); // 80% of max speed if in air
+ }
+ } else {
+ if(tempEntity.in_air == true){
+ if (modTileX < tempEntity.air_speed) {
+ tempEntity.pos_x = tempEntity.pos_x + (tempEntity.direction_x * modTileX); // NEW x set
+ } else {
+ tempEntity.pos_x= tempEntity.pos_x + (tempEntity.direction_x * tempEntity.air_speed); //
+ }
+ } else {
+ if (modTileX < g_hh_player_1.speed) {
+ tempEntity.pos_x= tempEntity.pos_x + (tempEntity.direction_x * modTileX); // NEW x set
+ } else {
+ tempEntity.pos_x = tempEntity.pos_x + (tempEntity.direction_x * tempEntity.speed); //
+ }
+ }
+ }
+ } else if (HH_DEMO_HITBOX_TILEMAP[tileColY][tileColX + tempEntity.direction_x] == 1) {
+ if(tempEntity.in_air == true){
+ if (modTileX < tempEntity.air_speed) {
+ tempEntity.pos_x = tempEntity.pos_x + (tempEntity.direction_x * modTileX); // NEW x set
+ } else {
+ tempEntity.pos_x = tempEntity.pos_x + (tempEntity.direction_x * tempEntity.air_speed); //
+ }
+ } else {
if (modTileX < g_hh_player_1.speed) {
- g_hh_player_1.pos_x = g_hh_player_1.pos_x + (directionX * modTileX); // NEW x set
+ tempEntity.pos_x = tempEntity.pos_x + (tempEntity.direction_x * modTileX); // NEW x set
} else {
- g_hh_player_1.pos_x = g_hh_player_1.pos_x + (directionX * g_hh_player_1.speed); // NEW x set
+ tempEntity.pos_x= tempEntity.pos_x + (tempEntity.direction_x * tempEntity.speed); //
}
}
-
- } else // if in air different all borders have to be checked
- {
}
+
+ return tempEntity.pos_x;
- if(directionY != 0)
+}
+
+hh_s_entity_player hh_background_collision_y_player(hh_s_entity_player tempEntity){
+
+ uint16_t tileColX;
+ uint16_t tileColY;
+
+
+ // remaining space between grid and exact
+ uint8_t modTileY;
+
+ if(g_hh_controller_p1.button_primary == 1 && tempEntity.accelY == 0 && tempEntity.in_air == false)
{
- // g_hh_player_1.pos_y = g_hh_player_1.pos_y + (directionY * g_hh_player_1.speed * 2); // NEW x set
+// tempEntity.accelY = 25;
}
- // collision map floor (y-axis) (falling)
- // if falling no jump press (implement)
- /*
- tileColY = (( g_hh_player_1.pos_y / 100) + g_hh_player_1.radius) / 16; //bottom of player box
- modTileY = 1;
- if(HH_DEMO_HITBOX_TILEMAP[tileColY+1][tileColX] != 1) //rework after jumping
- {
- g_hh_player_1.pos_y = g_hh_player_1.pos_y + 5 ;// NEW y set //makew var gravity
- //playerStat = falling; //for later use of graphics/sound
+
+ tileColY = (( tempEntity.pos_y / 100) + tempEntity.radius) / 8; //bottom of player box
+ tileColX = ((tempEntity.pos_x / 100) + tempEntity.radius) / 8; //right of player
+ modTileY = ((tempEntity.pos_y + (100 * tempEntity.radius)) % 800); //bottom of box
+
+ //rework arfter jumping
+ if(tempEntity.accelY <= 0){ //falling
+ if(HH_DEMO_HITBOX_TILEMAP[tileColY+1][tileColX] != 1) {//check bottom right first
+ tileColX = ((tempEntity.pos_x / 100) - tempEntity.radius) / 8;
+ if(HH_DEMO_HITBOX_TILEMAP[tileColY+1][tileColX] != 1) {
+ tempEntity.in_air = true;
+ tempEntity.pos_y = tempEntity.pos_y - (tempEntity.accelY * 8) ;// NEW y set
+ if (tempEntity.accelY > -35){
+ tempEntity.accelY--;
+ }
+ }
+ else {
+ if(modTileY < tempEntity.accelY * -8) {
+ tempEntity.pos_y = tempEntity.pos_y + (modTileY) ;// NEW y set
+ } else {
+ tempEntity.pos_y = tempEntity.pos_y - (tempEntity.accelY * 8) ;// NEW y set
+ }
+ tempEntity.in_air = false;
+ tempEntity.accelY = 0;
+ }
+ }
+ else {
+ if(modTileY < tempEntity.accelY * -8) {
+ tempEntity.pos_y = tempEntity.pos_y + (modTileY) ;// NEW y set
+ } else {
+ tempEntity.pos_y = tempEntity.pos_y - (tempEntity.accelY * 8) ;// NEW y set
+ }
+ tempEntity.in_air = false;
+ tempEntity.accelY = 0;
+ }
+ }
+ else{ //jumping
+ tileColY = (( tempEntity.pos_y / 100) - tempEntity.radius) / 8; //top of player box
+ modTileY = 800 -((tempEntity.pos_y + (100 * tempEntity.radius)) % 800); //top of box
+ if(HH_DEMO_HITBOX_TILEMAP[tileColY-1][tileColX] != 1) {//check bottom right first
+ tileColX = ((tempEntity.pos_x / 100) - tempEntity.radius) / 8;
+ if(HH_DEMO_HITBOX_TILEMAP[tileColY-1][tileColX] != 1) {
+ tempEntity.pos_y = tempEntity.pos_y - (tempEntity.accelY * 8) ;// NEW y set
+ tempEntity.in_air = true;
+ tempEntity.accelY--;
+ } else {
+ if(modTileY < tempEntity.accelY * -8) {
+ tempEntity.pos_y = tempEntity.pos_y - (modTileY) ;// NEW y set
+ } else {
+ tempEntity.pos_y = tempEntity.pos_y - (tempEntity.accelY * 8) ;
+ }
+ tempEntity.accelY = 0;
+ }
+ }
+ else {
+ if(modTileY < tempEntity.accelY * -8) {
+ tempEntity.pos_y = tempEntity.pos_y - (modTileY) ;// NEW y set //makew var gravity
+ } else {
+ tempEntity.pos_y = tempEntity.pos_y - (tempEntity.accelY * 8) ;// NEW y set //makew var gravity
+ }
+ tempEntity.accelY = 0;
+ }
+
}
- */
- // else if(HH_DEMO_HITBOX_TILEMAP[])
+
+ return tempEntity;
}
diff --git a/src/entity.h b/src/entity.h
index 181182b..3684252 100644
--- a/src/entity.h
+++ b/src/entity.h
@@ -8,7 +8,20 @@ typedef struct {
uint16_t pos_y;
uint8_t radius;
uint8_t rotation; //45 degrees steps 0 == right 2 == down 4 == left 6 == up
- uint8_t direction_x; //direction where its looking at in case no input;
- int8_t speed; //10 default L/R MODifier
+ int8_t direction_x; //direction where its looking at in case no input;
+ int8_t accelY;
+ int16_t speed; // default L/R MODifier
+ int16_t air_speed; // air L/R MODifier
bool in_air;
} hh_s_entity_player;
+
+typedef struct {
+ uint16_t pos_x;
+ uint16_t pos_y;
+ uint8_t radius;
+ uint8_t direction_x; //direction where its walking towards;
+ int8_t accelY;
+ int16_t speed; // default L/R MODifier
+ int16_t air_speed;
+ bool in_air;
+} hh_s_entity_enemy;
diff --git a/src/ppusim/input.c b/src/ppusim/input.c
index 5323fb1..4491a63 100644
--- a/src/ppusim/input.c
+++ b/src/ppusim/input.c
@@ -12,5 +12,5 @@ void hh_input_read() {
g_hh_controller_p1.dpad_down = kb[SDL_SCANCODE_S];
g_hh_controller_p1.dpad_left = kb[SDL_SCANCODE_A];
g_hh_controller_p1.dpad_right = kb[SDL_SCANCODE_D];
- g_hh_controller_p1.button_primary = kb[SDL_SCANCODE_SPACE];
+ g_hh_controller_p1.button_primary = kb[SDL_SCANCODE_K];
}