aboutsummaryrefslogtreecommitdiff
path: root/src/demo.c
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-03-10 13:16:16 +0100
committerlonkaars <loek@pipeframe.xyz>2023-03-10 13:16:16 +0100
commitc37397234534e9888dfeed9b1728c46646c33b58 (patch)
treec0e97dcccb1fce5bcd4550db243a67949a42ea1a /src/demo.c
parentbf8c5fdb43ae2446a502227a95f17167c3dcda33 (diff)
`clang-format`
Diffstat (limited to 'src/demo.c')
-rw-r--r--src/demo.c182
1 files changed, 81 insertions, 101 deletions
diff --git a/src/demo.c b/src/demo.c
index c4e4d7a..b9bba17 100644
--- a/src/demo.c
+++ b/src/demo.c
@@ -1,36 +1,36 @@
#include <math.h>
#include "demo.h"
-#include "ppu/ppu.h"
-#include "input.h"
#include "entity.h"
+#include "input.h"
+#include "ppu/ppu.h"
#define HH_DEMO_BALL_COUNT 1
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,
- .speed = 1,
+ .pos_x = 31000, // 0b0000 0001 0011 0110
+ .pos_y = 21000,
+ .radius = 8,
+ .speed = 1,
.direction_x = 1,
- .rotation = 8,
- .in_air = false,
+ .rotation = 8,
+ .in_air = false,
};
-void playerMovement();
+void hh_player_movement();
-uint16_t pos_x; //0b0000 0001 0011 0110
-uint16_t pos_y;
-uint8_t left = 0;
-uint8_t right = 0;
-uint8_t up = 0;
-uint8_t down = 0;
-uint8_t pos_x_bit[2];
-uint8_t pos_y_bit[2];
-uint8_t data_send[3];
-int tileX;
-int tileY;
+uint16_t g_hh_pos_x; // 0b0000 0001 0011 0110
+uint16_t g_hh_pos_y;
+uint8_t g_hh_left = 0;
+uint8_t g_hh_right = 0;
+uint8_t g_hh_up = 0;
+uint8_t g_hh_down = 0;
+uint8_t g_hh_pos_x_bit[2];
+uint8_t g_hh_pos_y_bit[2];
+uint8_t g_hh_data_send[3];
+int g_hh_tile_x;
+int g_hh_tile_y;
void hh_demo_setup() {
// load sprites
@@ -38,55 +38,54 @@ void hh_demo_setup() {
hh_ppu_update_sprite(1, HH_DBG_SPRITE_CHECKERBOARD);
// background pattern
- hh_ppu_update_color(0, 1, (hh_ppu_rgb_color_t) {0x4, 0x4, 0x4});
+ 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,
- });
+ 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});
+ 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;
+ 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) {
- playerMovement();
+ 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;
- //adjust map size
- pos_x = g_hh_player_1.pos_x / 100;
- pos_y = g_hh_player_1.pos_y / 100;
-
// input testing (no hitbox stuff)
// pos_x += (-1 * g_hh_controller_p1.dpad_left) + (1 * g_hh_controller_p1.dpad_right); // -1 = L || 1 == R
// pos_y += (-1 * g_hh_controller_p1.dpad_up) + (1 * g_hh_controller_p1.dpad_down); // -1 = D || 1 == U
// update player sprite on ppu
- g_hh_demo_balls[0].position_x = pos_x;
- g_hh_demo_balls[0].position_y = pos_y;
+ g_hh_demo_balls[0].position_x = g_hh_pos_x;
+ g_hh_demo_balls[0].position_y = g_hh_pos_y;
hh_ppu_update_foreground(0, g_hh_demo_balls[0]);
-
// set background pattern position
- hh_ppu_update_aux((hh_s_ppu_loc_aux) {
+ 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,
+ .fg_fetch = 0,
+ .sysreset = 0,
});
}
@@ -95,91 +94,77 @@ void hh_demo_loop(unsigned long frame) {
// bitData[2] = data & 0xff;
// bitData[1] = (data >> 8);
// bitData[0] = address; // first byte is address
-//
+//
// HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_RESET);
// HAL_SPI_Transmit(&hspi1, bitData, 3, 100); //2*8 bit data
// HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_SET);
// }
-void playerMovement() {
+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_down) + (1 * g_hh_controller_p1.dpad_up); // -1 = D || 1 == U
+ int8_t directionY = (-1 * g_hh_controller_p1.dpad_down) + (1 * g_hh_controller_p1.dpad_up); // -1 = D || 1 == U
- uint8_t i,j;
+ uint8_t i, j;
uint8_t rotation = 0; // 0-7
- //rotation calc
- for(i = -1; i < 2;i++)
- {
- for(j = -1; j < 2; j++)
- {
- if(directionX == i)
- {
- if(directionY == j)
- {
- if(i != 0 && j != 0) //dont update when player idle
+ // rotation calc
+ for (i = -1; i < 2; i++) {
+ for (j = -1; j < 2; j++) {
+ if (directionX == i) {
+ if (directionY == j) {
+ if (i != 0 && j != 0) // dont update when player idle
{
g_hh_player_1.rotation = rotation;
}
}
}
- rotation++;
+ rotation++;
}
}
- //direction calc
- if(directionX != 0) //update direction if player is not idle
+ // direction calc
+ if (directionX != 0) // update direction if player is not idle
{
g_hh_player_1.direction_x = directionX;
}
- //collision map x-axis
+ // collision map x-axis
- //tile calc including radius and direction for background coliision
+ // 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 = (g_hh_player_1.pos_y / 100) / 16;
+ ;
// 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 ) / 20;
- modTileX = ( g_hh_player_1.pos_x + ( 100 * g_hh_player_1.radius ) ) % 2000;
+ 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) / 20;
+ modTileX = (g_hh_player_1.pos_x + (100 * g_hh_player_1.radius)) % 2000;
+ } else if (directionX == -1) {
+ tileColX = ((g_hh_player_1.pos_x / 100) - g_hh_player_1.radius) / 20;
+ modTileX = (g_hh_player_1.pos_x - (100 * g_hh_player_1.radius)) % 2000;
}
- else if(directionX == -1)
- {
- tileColX = ( ( g_hh_player_1.pos_x / 100) - g_hh_player_1.radius ) / 20;
- modTileX = ( g_hh_player_1.pos_x - ( 100 * g_hh_player_1.radius ) ) % 2000;
+
+ 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
}
- if(HH_DEMO_HITBOX_TILEMAP[tileColY][tileColX + directionX] != 1)
- {
+ else if (HH_DEMO_HITBOX_TILEMAP[tileColY][tileColX + directionX] == 1) {
+ if (modTileX < g_hh_player_1.speed) {
+ g_hh_player_1.pos_x = g_hh_player_1.pos_x + (directionX * 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
}
+ }
- else if(HH_DEMO_HITBOX_TILEMAP[tileColY][tileColX + directionX] == 1)
- {
- if(modTileX < g_hh_player_1.speed)
- {
- g_hh_player_1.pos_x = g_hh_player_1.pos_x + (directionX * 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
- }
- }
-
- }
- else //if in air different all borders have to be checked
+ } else // if in air different all borders have to be checked
{
-
}
- //collision map floor (y-axis) (falling)
- // if falling no jump press (implement)
+ // 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;
@@ -189,10 +174,5 @@ void playerMovement() {
//playerStat = falling; //for later use of graphics/sound
}
*/
- //else if(HH_DEMO_HITBOX_TILEMAP[])
-
-
-
-
-
+ // else if(HH_DEMO_HITBOX_TILEMAP[])
}