diff options
Diffstat (limited to 'src/engine')
-rw-r--r-- | src/engine/bullet.c | 39 | ||||
-rw-r--r-- | src/engine/bullet.h | 14 | ||||
-rw-r--r-- | src/engine/draw_screen.c | 50 | ||||
-rw-r--r-- | src/engine/draw_screen.h | 5 | ||||
-rw-r--r-- | src/engine/engine.c | 1 | ||||
-rw-r--r-- | src/engine/entity.c | 4 | ||||
-rw-r--r-- | src/engine/player_controller.c | 13 |
7 files changed, 2 insertions, 124 deletions
diff --git a/src/engine/bullet.c b/src/engine/bullet.c deleted file mode 100644 index eafd4e7..0000000 --- a/src/engine/bullet.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "bullet.h" -#include "engine/sprite_controller.h" - -void shootBullet(vec2 playerPos, Bullet* bullet){ - // Set bullet's x and y coordinates to player's coordinates - bullet->x = playerPos.x; - bullet->y = playerPos.y; - // Set bullet's velocity to a fixed value - bullet->velocity = 1; - // Set bullet's status to active - bullet->isActive = true; -} -void updateBullet(Bullet* bullet, int deltaTime){ - // Only update bullet if it is active - static int latestLocationBullet = 0; - if (bullet->isActive) { - // Move bullet based on velocity and deltaTime - bullet->x += bullet->velocity * deltaTime; - drawBullet(bullet); - // Check if bullet has moved 16 pixels - if (bullet->x - latestLocationBullet > 16) { - // Set bullet's status to inactive - bullet->isActive = false; - } - } - else{ - latestLocationBullet = bullet->x; - } -} -void drawBullet(Bullet* bullet){ - - hh_ppu_update_foreground(1, (hh_s_ppu_loc_fam_entry) - { - .horizontal_flip = false, - .vertical_flip = false, - .palette_index = 7, - .tilemap_index = 2, // change tilemap to the correct foreground index; - }); -} diff --git a/src/engine/bullet.h b/src/engine/bullet.h deleted file mode 100644 index f119829..0000000 --- a/src/engine/bullet.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include "player_controller.h" - -typedef struct { - int x; - int y; - int velocity; - int isActive; -} Bullet; - -//Bullet* createBullet(float x, float y, float velocity, float direction); -void shootBullet(vec2 playerPos, Bullet* bullet); -void updateBullet(Bullet* bullet, int deltaTime); -void drawBullet(Bullet* bullet); diff --git a/src/engine/draw_screen.c b/src/engine/draw_screen.c index 43d3cd4..c4f3389 100644 --- a/src/engine/draw_screen.c +++ b/src/engine/draw_screen.c @@ -19,6 +19,7 @@ uint8_t hh_world_to_tile(vec2 pos){ return tile; } + // remeber old value to know which part to update. vec2 previousViewport = { .x = 0, .y = 0 }; void hh_draw_screen(vec_cor viewport){ @@ -59,52 +60,3 @@ void hh_setup_screen(){ } free(tile); } - -void hh_setup_startingScreen(){ - return; - int size = 300; // 40 x as tiles 30 y as tiles - FILE* level = fopen("../test/bin/startingScreen.bin", "rb"); /* open binary file */ - if (!level) { /* check if file opened successfully */ - fprintf(stderr, "Error: Failed to open file. AAAA\n"); - return; - } - fseek(level, (0* sizeof(int)) + sizeof(int), SEEK_SET); - int* tile = (int*)malloc(size*sizeof(int)); - fread(tile, sizeof(int), size, level); // read 1 tile from binary - - fclose(level); - - for(int BAM_index = 0; BAM_index < size; BAM_index++){ - hh_ppu_update_background(BAM_index, (hh_s_ppu_loc_bam_entry){ - .horizontal_flip = false, - .vertical_flip = false, - .palette_index = hh_get_palette(tile[BAM_index]), - .tilemap_index = tile[BAM_index], - }); - } - free(tile); -} - -void hh_setup_shopScreen(){ - int size = 300; // 40 x as tiles 30 y as tiles - FILE* level = fopen("../test/bin/shopScreen.bin", "rb"); /* open binary file */ - if (!level) { /* check if file opened successfully */ - fprintf(stderr, "Error: Failed to open file.\n"); - return; - } - fseek(level, (0* sizeof(int)) + sizeof(int), SEEK_SET); - int* tile = (int*)malloc(size*sizeof(int)); - fread(tile, sizeof(int), size, level); // read 1 tile from binary - - fclose(level); - - for(int BAM_index = 0; BAM_index < size; BAM_index++){ - hh_ppu_update_background(BAM_index, (hh_s_ppu_loc_bam_entry){ - .horizontal_flip = false, - .vertical_flip = false, - .palette_index = hh_get_palette(tile[BAM_index]), - .tilemap_index = tile[BAM_index], - }); - } - free(tile); -} diff --git a/src/engine/draw_screen.h b/src/engine/draw_screen.h index bfe8bf8..b181108 100644 --- a/src/engine/draw_screen.h +++ b/src/engine/draw_screen.h @@ -19,8 +19,3 @@ uint8_t hh_world_to_tile(vec2 pos); void hh_draw_screen(vec2 viewport); /** @brief send data to BAM memory from binary level */ void hh_setup_screen(); -/** @brief send starting screen data to BAM memory from binary level */ -void hh_setup_startingScreen(); - -/** @brief send shop screen data to BAM memory from binary level */ -void hh_setup_shopScreen(); diff --git a/src/engine/engine.c b/src/engine/engine.c index d852a99..799ee7c 100644 --- a/src/engine/engine.c +++ b/src/engine/engine.c @@ -1,5 +1,4 @@ #include "engine/draw_screen.h" -#include "engine/bullet.h" #include "engine/level.h" #include "engine/maths.h" #include "engine/sprite_controller.h" diff --git a/src/engine/entity.c b/src/engine/entity.c index 888539a..153e7e1 100644 --- a/src/engine/entity.c +++ b/src/engine/entity.c @@ -3,10 +3,6 @@ #include "engine/entity.h" #include "engine/maths.h" -#ifdef HH_TARGET_DESKTOP -#include <stdio.h> -#endif - /* PLAYER: (pos on X) ,___, diff --git a/src/engine/player_controller.c b/src/engine/player_controller.c index f938844..22f6eb6 100644 --- a/src/engine/player_controller.c +++ b/src/engine/player_controller.c @@ -3,7 +3,7 @@ #include "engine/draw_screen.h" #include "engine/sprite_controller.h" #include "engine/player_controller.h" -#include "engine/bullet.h" + #include "input.h" void hh_player_actions() { @@ -29,17 +29,6 @@ void hh_player_actions() { // hh_input_read(); player.vel = (vec2){.x = (-1 * g_hh_controller_p1.dpad_left) + (1 * g_hh_controller_p1.dpad_right), .y = (-1 * g_hh_controller_p1.dpad_up) + (1 * g_hh_controller_p1.dpad_down) }; - - // shooting code - static Bullet bullet; - if(g_hh_controller_p1.button_primary){ - bullet.isActive = false; - shootBullet(player.vel, &bullet); - } - else{ - updateBullet(&bullet, 1); - - } // const int8_t maa = 3; // const int8_t mbb = -3; // if (g_hh_controller_p1.dpad_up) |