From 6870625fd60a5487742cbcbd3d5ce6637101109c Mon Sep 17 00:00:00 2001 From: SemvdH Date: Mon, 21 Jun 2021 21:24:57 +0200 Subject: [PATCH] [ADD] main character, smoke particle when shooting, fire effect to player --- CMakeLists.txt | 1 + Makefile | 155 +++++++++++++++++++++++++++--------------- cmake_install.cmake | 9 ++- src/main.c | 66 +++++++++++++----- src/sprites/sprites.c | 36 ++++++++-- src/sprites/sprites.h | 61 +++++++++++++---- src/toolbox/toolbox.c | 9 +++ src/toolbox/toolbox.h | 13 ++++ 8 files changed, 256 insertions(+), 94 deletions(-) create mode 100644 src/toolbox/toolbox.c create mode 100644 src/toolbox/toolbox.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d5d0c60..5a356ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,7 @@ add_executable(${PROJECT_NAME} src/sprites/sprites.c src/system/timing.c src/system/control_input.c + src/toolbox/toolbox.c ../common/debugScreen.c ) diff --git a/Makefile b/Makefile index a9dcd60..dc6cb49 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # CMAKE generated file: DO NOT EDIT! -# Generated by "Unix Makefiles" Generator, CMake Version 3.16 +# Generated by "Unix Makefiles" Generator, CMake Version 3.18 # Default target executed when no arguments are given to make. default_target: all @@ -17,15 +17,34 @@ default_target: all .SUFFIXES: -# Remove some rules from gmake that .SUFFIXES does not remove. -SUFFIXES = +# Disable VCS-based implicit rules. +% : %,v + + +# Disable VCS-based implicit rules. +% : RCS/% + + +# Disable VCS-based implicit rules. +% : RCS/%,v + + +# Disable VCS-based implicit rules. +% : SCCS/s.% + + +# Disable VCS-based implicit rules. +% : s.% + .SUFFIXES: .hpux_make_needs_suffix_list -# Suppress display of executed commands. -$(VERBOSE).SILENT: +# Command-line flag to silence nested $(MAKE). +$(VERBOSE)MAKESILENT = -s +#Suppress display of executed commands. +$(VERBOSE).SILENT: # A target that is always out of date. cmake_force: @@ -42,16 +61,16 @@ SHELL = /bin/sh CMAKE_COMMAND = /usr/bin/cmake # The command to remove a file. -RM = /usr/bin/cmake -E remove -f +RM = /usr/bin/cmake -E rm -f # Escaping for special characters. EQUALS = = # The top-level source directory on which CMake was run. -CMAKE_SOURCE_DIR = /home/semtex99/vita/samples/cybershot-PSVita +CMAKE_SOURCE_DIR = /home/semtex/samples/cybershot-PSVita # The top-level build directory on which CMake was run. -CMAKE_BINARY_DIR = /home/semtex99/vita/samples/cybershot-PSVita +CMAKE_BINARY_DIR = /home/semtex/samples/cybershot-PSVita #============================================================================= # Targets provided globally by CMake. @@ -59,7 +78,7 @@ CMAKE_BINARY_DIR = /home/semtex99/vita/samples/cybershot-PSVita # Special rule for the target rebuild_cache rebuild_cache: @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." - /usr/bin/cmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) + /usr/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) .PHONY : rebuild_cache # Special rule for the target rebuild_cache @@ -80,14 +99,14 @@ edit_cache/fast: edit_cache # The main all target all: cmake_check_build_system - $(CMAKE_COMMAND) -E cmake_progress_start /home/semtex99/vita/samples/cybershot-PSVita/CMakeFiles /home/semtex99/vita/samples/cybershot-PSVita/CMakeFiles/progress.marks - $(MAKE) -f CMakeFiles/Makefile2 all - $(CMAKE_COMMAND) -E cmake_progress_start /home/semtex99/vita/samples/cybershot-PSVita/CMakeFiles 0 + $(CMAKE_COMMAND) -E cmake_progress_start /home/semtex/samples/cybershot-PSVita/CMakeFiles /home/semtex/samples/cybershot-PSVita//CMakeFiles/progress.marks + $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 all + $(CMAKE_COMMAND) -E cmake_progress_start /home/semtex/samples/cybershot-PSVita/CMakeFiles 0 .PHONY : all # The main clean target clean: - $(MAKE) -f CMakeFiles/Makefile2 clean + $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 clean .PHONY : clean # The main clean target @@ -97,12 +116,12 @@ clean/fast: clean # Prepare targets for installation. preinstall: all - $(MAKE) -f CMakeFiles/Makefile2 preinstall + $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall .PHONY : preinstall # Prepare targets for installation. preinstall/fast: - $(MAKE) -f CMakeFiles/Makefile2 preinstall + $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall .PHONY : preinstall/fast # clear depends @@ -115,12 +134,12 @@ depend: # Build rule for target. cybershot.vpk: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 cybershot.vpk + $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 cybershot.vpk .PHONY : cybershot.vpk # fast build rule for target. cybershot.vpk/fast: - $(MAKE) -f CMakeFiles/cybershot.vpk.dir/build.make CMakeFiles/cybershot.vpk.dir/build + $(MAKE) $(MAKESILENT) -f CMakeFiles/cybershot.vpk.dir/build.make CMakeFiles/cybershot.vpk.dir/build .PHONY : cybershot.vpk/fast #============================================================================= @@ -128,12 +147,12 @@ cybershot.vpk/fast: # Build rule for target. cybershot.self: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 cybershot.self + $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 cybershot.self .PHONY : cybershot.self # fast build rule for target. cybershot.self/fast: - $(MAKE) -f CMakeFiles/cybershot.self.dir/build.make CMakeFiles/cybershot.self.dir/build + $(MAKE) $(MAKESILENT) -f CMakeFiles/cybershot.self.dir/build.make CMakeFiles/cybershot.self.dir/build .PHONY : cybershot.self/fast #============================================================================= @@ -141,40 +160,40 @@ cybershot.self/fast: # Build rule for target. cybershot: cmake_check_build_system - $(MAKE) -f CMakeFiles/Makefile2 cybershot + $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 cybershot .PHONY : cybershot # fast build rule for target. cybershot/fast: - $(MAKE) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/build + $(MAKE) $(MAKESILENT) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/build .PHONY : cybershot/fast -home/semtex99/vita/samples/common/debugScreen.obj: home/semtex99/vita/samples/common/debugScreen.c.obj +home/semtex/samples/common/debugScreen.obj: home/semtex/samples/common/debugScreen.c.obj -.PHONY : home/semtex99/vita/samples/common/debugScreen.obj +.PHONY : home/semtex/samples/common/debugScreen.obj # target to build an object file -home/semtex99/vita/samples/common/debugScreen.c.obj: - $(MAKE) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/home/semtex99/vita/samples/common/debugScreen.c.obj -.PHONY : home/semtex99/vita/samples/common/debugScreen.c.obj +home/semtex/samples/common/debugScreen.c.obj: + $(MAKE) $(MAKESILENT) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/home/semtex/samples/common/debugScreen.c.obj +.PHONY : home/semtex/samples/common/debugScreen.c.obj -home/semtex99/vita/samples/common/debugScreen.i: home/semtex99/vita/samples/common/debugScreen.c.i +home/semtex/samples/common/debugScreen.i: home/semtex/samples/common/debugScreen.c.i -.PHONY : home/semtex99/vita/samples/common/debugScreen.i +.PHONY : home/semtex/samples/common/debugScreen.i # target to preprocess a source file -home/semtex99/vita/samples/common/debugScreen.c.i: - $(MAKE) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/home/semtex99/vita/samples/common/debugScreen.c.i -.PHONY : home/semtex99/vita/samples/common/debugScreen.c.i +home/semtex/samples/common/debugScreen.c.i: + $(MAKE) $(MAKESILENT) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/home/semtex/samples/common/debugScreen.c.i +.PHONY : home/semtex/samples/common/debugScreen.c.i -home/semtex99/vita/samples/common/debugScreen.s: home/semtex99/vita/samples/common/debugScreen.c.s +home/semtex/samples/common/debugScreen.s: home/semtex/samples/common/debugScreen.c.s -.PHONY : home/semtex99/vita/samples/common/debugScreen.s +.PHONY : home/semtex/samples/common/debugScreen.s # target to generate assembly for a file -home/semtex99/vita/samples/common/debugScreen.c.s: - $(MAKE) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/home/semtex99/vita/samples/common/debugScreen.c.s -.PHONY : home/semtex99/vita/samples/common/debugScreen.c.s +home/semtex/samples/common/debugScreen.c.s: + $(MAKE) $(MAKESILENT) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/home/semtex/samples/common/debugScreen.c.s +.PHONY : home/semtex/samples/common/debugScreen.c.s src/main.obj: src/main.c.obj @@ -182,7 +201,7 @@ src/main.obj: src/main.c.obj # target to build an object file src/main.c.obj: - $(MAKE) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/main.c.obj + $(MAKE) $(MAKESILENT) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/main.c.obj .PHONY : src/main.c.obj src/main.i: src/main.c.i @@ -191,7 +210,7 @@ src/main.i: src/main.c.i # target to preprocess a source file src/main.c.i: - $(MAKE) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/main.c.i + $(MAKE) $(MAKESILENT) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/main.c.i .PHONY : src/main.c.i src/main.s: src/main.c.s @@ -200,7 +219,7 @@ src/main.s: src/main.c.s # target to generate assembly for a file src/main.c.s: - $(MAKE) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/main.c.s + $(MAKE) $(MAKESILENT) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/main.c.s .PHONY : src/main.c.s src/sprites/sprites.obj: src/sprites/sprites.c.obj @@ -209,7 +228,7 @@ src/sprites/sprites.obj: src/sprites/sprites.c.obj # target to build an object file src/sprites/sprites.c.obj: - $(MAKE) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/sprites/sprites.c.obj + $(MAKE) $(MAKESILENT) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/sprites/sprites.c.obj .PHONY : src/sprites/sprites.c.obj src/sprites/sprites.i: src/sprites/sprites.c.i @@ -218,7 +237,7 @@ src/sprites/sprites.i: src/sprites/sprites.c.i # target to preprocess a source file src/sprites/sprites.c.i: - $(MAKE) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/sprites/sprites.c.i + $(MAKE) $(MAKESILENT) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/sprites/sprites.c.i .PHONY : src/sprites/sprites.c.i src/sprites/sprites.s: src/sprites/sprites.c.s @@ -227,7 +246,7 @@ src/sprites/sprites.s: src/sprites/sprites.c.s # target to generate assembly for a file src/sprites/sprites.c.s: - $(MAKE) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/sprites/sprites.c.s + $(MAKE) $(MAKESILENT) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/sprites/sprites.c.s .PHONY : src/sprites/sprites.c.s src/system/control_input.obj: src/system/control_input.c.obj @@ -236,7 +255,7 @@ src/system/control_input.obj: src/system/control_input.c.obj # target to build an object file src/system/control_input.c.obj: - $(MAKE) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/system/control_input.c.obj + $(MAKE) $(MAKESILENT) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/system/control_input.c.obj .PHONY : src/system/control_input.c.obj src/system/control_input.i: src/system/control_input.c.i @@ -245,7 +264,7 @@ src/system/control_input.i: src/system/control_input.c.i # target to preprocess a source file src/system/control_input.c.i: - $(MAKE) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/system/control_input.c.i + $(MAKE) $(MAKESILENT) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/system/control_input.c.i .PHONY : src/system/control_input.c.i src/system/control_input.s: src/system/control_input.c.s @@ -254,7 +273,7 @@ src/system/control_input.s: src/system/control_input.c.s # target to generate assembly for a file src/system/control_input.c.s: - $(MAKE) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/system/control_input.c.s + $(MAKE) $(MAKESILENT) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/system/control_input.c.s .PHONY : src/system/control_input.c.s src/system/timing.obj: src/system/timing.c.obj @@ -263,7 +282,7 @@ src/system/timing.obj: src/system/timing.c.obj # target to build an object file src/system/timing.c.obj: - $(MAKE) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/system/timing.c.obj + $(MAKE) $(MAKESILENT) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/system/timing.c.obj .PHONY : src/system/timing.c.obj src/system/timing.i: src/system/timing.c.i @@ -272,7 +291,7 @@ src/system/timing.i: src/system/timing.c.i # target to preprocess a source file src/system/timing.c.i: - $(MAKE) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/system/timing.c.i + $(MAKE) $(MAKESILENT) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/system/timing.c.i .PHONY : src/system/timing.c.i src/system/timing.s: src/system/timing.c.s @@ -281,23 +300,50 @@ src/system/timing.s: src/system/timing.c.s # target to generate assembly for a file src/system/timing.c.s: - $(MAKE) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/system/timing.c.s + $(MAKE) $(MAKESILENT) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/system/timing.c.s .PHONY : src/system/timing.c.s +src/toolbox/toolbox.obj: src/toolbox/toolbox.c.obj + +.PHONY : src/toolbox/toolbox.obj + +# target to build an object file +src/toolbox/toolbox.c.obj: + $(MAKE) $(MAKESILENT) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/toolbox/toolbox.c.obj +.PHONY : src/toolbox/toolbox.c.obj + +src/toolbox/toolbox.i: src/toolbox/toolbox.c.i + +.PHONY : src/toolbox/toolbox.i + +# target to preprocess a source file +src/toolbox/toolbox.c.i: + $(MAKE) $(MAKESILENT) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/toolbox/toolbox.c.i +.PHONY : src/toolbox/toolbox.c.i + +src/toolbox/toolbox.s: src/toolbox/toolbox.c.s + +.PHONY : src/toolbox/toolbox.s + +# target to generate assembly for a file +src/toolbox/toolbox.c.s: + $(MAKE) $(MAKESILENT) -f CMakeFiles/cybershot.dir/build.make CMakeFiles/cybershot.dir/src/toolbox/toolbox.c.s +.PHONY : src/toolbox/toolbox.c.s + # Help Target help: @echo "The following are some of the valid targets for this Makefile:" @echo "... all (the default if no target is provided)" @echo "... clean" @echo "... depend" - @echo "... rebuild_cache" @echo "... edit_cache" - @echo "... cybershot.vpk" + @echo "... rebuild_cache" @echo "... cybershot.self" + @echo "... cybershot.vpk" @echo "... cybershot" - @echo "... home/semtex99/vita/samples/common/debugScreen.obj" - @echo "... home/semtex99/vita/samples/common/debugScreen.i" - @echo "... home/semtex99/vita/samples/common/debugScreen.s" + @echo "... home/semtex/samples/common/debugScreen.obj" + @echo "... home/semtex/samples/common/debugScreen.i" + @echo "... home/semtex/samples/common/debugScreen.s" @echo "... src/main.obj" @echo "... src/main.i" @echo "... src/main.s" @@ -310,6 +356,9 @@ help: @echo "... src/system/timing.obj" @echo "... src/system/timing.i" @echo "... src/system/timing.s" + @echo "... src/toolbox/toolbox.obj" + @echo "... src/toolbox/toolbox.i" + @echo "... src/toolbox/toolbox.s" .PHONY : help diff --git a/cmake_install.cmake b/cmake_install.cmake index 9630e57..c4d9445 100644 --- a/cmake_install.cmake +++ b/cmake_install.cmake @@ -1,4 +1,4 @@ -# Install script for directory: /home/semtex99/vita/samples/cybershot-PSVita +# Install script for directory: /home/semtex/samples/cybershot-PSVita # Set the install prefix if(NOT DEFINED CMAKE_INSTALL_PREFIX) @@ -32,6 +32,11 @@ if(NOT DEFINED CMAKE_CROSSCOMPILING) set(CMAKE_CROSSCOMPILING "TRUE") endif() +# Set default install directory permissions. +if(NOT DEFINED CMAKE_OBJDUMP) + set(CMAKE_OBJDUMP "/usr/local/vitasdk/bin/arm-vita-eabi-objdump") +endif() + if(CMAKE_INSTALL_COMPONENT) set(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt") else() @@ -40,5 +45,5 @@ endif() string(REPLACE ";" "\n" CMAKE_INSTALL_MANIFEST_CONTENT "${CMAKE_INSTALL_MANIFEST_FILES}") -file(WRITE "/home/semtex99/vita/samples/cybershot-PSVita/${CMAKE_INSTALL_MANIFEST}" +file(WRITE "/home/semtex/samples/cybershot-PSVita/${CMAKE_INSTALL_MANIFEST}" "${CMAKE_INSTALL_MANIFEST_CONTENT}") diff --git a/src/main.c b/src/main.c index 97438b1..8b37ad2 100644 --- a/src/main.c +++ b/src/main.c @@ -20,16 +20,18 @@ #define SCREEN_HEIGTH 544 #define SCREEN_WIDTH 940 -size_t running = 1; +size_t running = 1, drawing_circle = 0; stick_data left_stick = {0, 0}, right_stick = {0, 0}; SceCtrlData pad; uint8_t cross_pressed = 0; -size_t bullet_count = 0; uint8_t current_bullet = 0; BULLET bullets[255]; +uint8_t current_smoke_particle = 0; +SMOKE_PARTICLE smoke_particles[255]; + vita2d_pgf *pgf; vita2d_pvf *pvf; @@ -39,7 +41,7 @@ timing_timer bullet_timer = {0, 250, 0}; // 0 as starting time, 400 ms timeout, timer_t bullt = 0; -float x1_pos = 300, y1_pos = 50, x2_pos = 400, y2_pos = 50; +float player_x = 300, player_y = 50, x2_pos = 400, y2_pos = 50, radius = 5.0; /** * @brief should be called when an unhandlable exception or error occurs. Triggers coredump. @@ -57,12 +59,22 @@ void generate_bullet() { // {1, x1_pos, y1_pos, RGBA8(100, 100, 0, 255)}; bullets[current_bullet].active = 1; - bullets[current_bullet].x = x1_pos; - bullets[current_bullet].y = y1_pos; + bullets[current_bullet].x = player_x; + bullets[current_bullet].y = player_y - SHIP_HEIGHT; bullets[current_bullet].color = RGBA8(255, 100, 0, 255); current_bullet = (current_bullet + 1) % 254; } +void generate_smoke_particle() +{ + smoke_particles[current_smoke_particle].active = 1; + smoke_particles[current_smoke_particle].x = player_x; + smoke_particles[current_smoke_particle].y = player_y - SHIP_HEIGHT; + smoke_particles[current_smoke_particle].radius = SMOKE_START_RADIUS; + smoke_particles[current_smoke_particle].explosion_direction = 1; + current_smoke_particle = (current_smoke_particle + 1) % 254; +} + void init() { /* to enable analog sampling */ @@ -81,6 +93,12 @@ void init() BULLET temp = {0, 0, 100, RGBA8(0, i, 255, 255), 300.0}; bullets[i] = temp; } + + for (int i = 0; i < 255; i++) + { + SMOKE_PARTICLE s = {0, 0, 0, SMOKE_START_RADIUS}; + smoke_particles[i] = s; + } } void update() @@ -101,20 +119,21 @@ void update() timing_check_timer_elapsed(&bullet_timer); ctrl_input_get_leftstick(&pad, &left_stick); + // ctrl_input_get_rightstick(&pad, &right_stick); if (abs(left_stick.x) > 15) - x1_pos += ctrl_input_calc_value(left_stick.x, deltaTime); + player_x += ctrl_input_calc_value(left_stick.x, deltaTime); if (abs(left_stick.y) > 15) - y1_pos += ctrl_input_calc_value(left_stick.y, deltaTime); + player_y += ctrl_input_calc_value(left_stick.y, deltaTime); - if (x1_pos <= 0) - x1_pos = 0; - if (x1_pos >= SCREEN_WIDTH) - x1_pos = SCREEN_WIDTH - 1; - if (y1_pos <= 0) - y1_pos = 0; - if (y1_pos >= SCREEN_HEIGTH) - y1_pos = SCREEN_HEIGTH - 1; + if (player_x <= 0) + player_x = 0; + if (player_x >= SCREEN_WIDTH) + player_x = SCREEN_WIDTH - 1; + if (player_y <= 0) + player_y = 0; + if (player_y >= SCREEN_HEIGTH) + player_y = SCREEN_HEIGTH - 1; if (cross_pressed) { @@ -122,16 +141,26 @@ void update() { generate_bullet(); bullet_timer.elapsed = 0; + generate_smoke_particle(); } } - // TODO move to seperate file for (int i = 0; i < 255; i++) { bullets[i].y -= bullets[i].movement_speed * (deltaTime / 1000.0); if (bullets[i].y <= 0) + { bullets[i].active = 0; + } + + smoke_particles[i].radius += smoke_particles[i].explosion_direction * (SMOKE_DISSAPPEAR_SPEED * (deltaTime / 1000.0)) * (SMOKE_MAX_RADIUS/smoke_particles[i].radius); + + if (smoke_particles[i].radius >= SMOKE_MAX_RADIUS) + smoke_particles[i].explosion_direction = -1; + + if (smoke_particles[i].radius <= 0) + smoke_particles[i].active = 0; } } @@ -140,8 +169,8 @@ void draw() vita2d_start_drawing(); vita2d_clear_screen(); - vita2d_draw_rectangle(x1_pos, y1_pos, (float)10, (float)10, RGBA8(100, 100, 100, 255)); - vita2d_draw_rectangle(x2_pos, y2_pos, (float)10, (float)10, RGBA8(169, 60, 23, 255)); + sprites_draw_player(player_x, player_y, 3.0); + // vita2d_draw_rectangle(x2_pos, y2_pos, (float)10, (float)10, RGBA8(169, 60, 23, 255)); char text[80] = "process time: "; sprintf(text, "%lld ms", deltaTime); @@ -160,6 +189,7 @@ void draw() for (int i = 0; i < 255; i++) { sprites_draw_bullet(&bullets[i]); + sprites_draw_smoke_circle(&smoke_particles[i]); } vita2d_end_drawing(); diff --git a/src/sprites/sprites.c b/src/sprites/sprites.c index 773b005..7dbbd5a 100644 --- a/src/sprites/sprites.c +++ b/src/sprites/sprites.c @@ -1,8 +1,3 @@ -#include -#include - -#include - #include "sprites.h" #define printf psvDebugScreenPrintf @@ -11,6 +6,35 @@ void sprites_draw_bullet(BULLET *bullet) { if (bullet->active) { - vita2d_draw_rectangle(bullet->x, bullet->y, (float)5, (float)10, bullet->color); + vita2d_draw_rectangle(bullet->x, bullet->y, (float)3, (float)8, bullet->color); } +} + +void sprites_draw_smoke_circle(SMOKE_PARTICLE *smoke_particle) +{ + if (smoke_particle->active) + { + vita2d_draw_fill_circle(smoke_particle->x, smoke_particle->y, smoke_particle->radius, RGBA8(232, 232, 232, 200)); + } +} + +void sprites_draw_player(float x, float y, float scale) +{ + + // bottom fire + float random_size = toolbox_random_float(scale, 5.0 * scale); + vita2d_draw_line(x - 1.0 * scale, y, x, y + random_size, RGBA8(255, 0, 0, 200)); + vita2d_draw_line(x, y + random_size, x + 1.0 * scale, y, RGBA8(255, 0, 0, 200)); + + //left side + vita2d_draw_line(x - 2.0 * scale, y, x + 2.0 * scale, y, SHIP_PRIMARY_COLOR); + vita2d_draw_line(x - 2.0 * scale, y, x - 1.0 * scale, y - 2.0 * scale, SHIP_PRIMARY_COLOR); + vita2d_draw_line(x - 1.0 * scale, y - 2.0 * scale, x - 1.0 * scale, y - 4.0 * scale, SHIP_PRIMARY_COLOR); + vita2d_draw_line(x - 1.0 * scale, y - 4.0 * scale, x, y - 5.0 * scale, SHIP_PRIMARY_COLOR); + + //right side + vita2d_draw_line(x, y - 5.0 * scale, x + 1.0 * scale, y - 4.0 * scale, SHIP_PRIMARY_COLOR); + vita2d_draw_line(x + 1.0 * scale, y - 4.0 * scale, x + 1.0 * scale, y - 2.0 * scale, SHIP_PRIMARY_COLOR); + vita2d_draw_line(x + 1.0 * scale, y - 2.0 * scale, x + 2.0 * scale, y, SHIP_PRIMARY_COLOR); + } \ No newline at end of file diff --git a/src/sprites/sprites.h b/src/sprites/sprites.h index 3778a58..aea1dd6 100644 --- a/src/sprites/sprites.h +++ b/src/sprites/sprites.h @@ -1,16 +1,24 @@ #ifndef SPRITES_H #define SPRITES_H -//TODO draw main player sprite -/** - * @brief struct that holds the info for drawing the player - * - */ -typedef struct player_sprite_t -{ - /* data to be added, pos, active (?)*/ -} PLAYER; +#include +#include +#include + +#include + +#include "../toolbox/toolbox.h" + +#define SHIP_SECONDARY_COLOR RGBA8(153, 153, 153, 255) +#define SHIP_PRIMARY_COLOR RGBA8(0, 255, 195, 255) + +#define SHIP_WIDTH 12; // 3 * 4 +#define SHIP_HEIGHT 15; // 3 * 5 + +#define SMOKE_START_RADIUS 8.0 +#define SMOKE_MAX_RADIUS 10.0 +#define SMOKE_DISSAPPEAR_SPEED 35.0 /** * @brief a struct that holds a bullet sprite, basically a rectangle @@ -18,14 +26,22 @@ typedef struct player_sprite_t */ typedef struct bullet_sprite_t { - size_t active; // whether or not the bullet should be drawn (0 or 1) - float x; // the x position - float y; // the y position - unsigned int color; // color of the bullet - float movement_speed; // speed of the bullet (how much it should move each frame) + size_t active; // whether or not the bullet should be drawn (0 or 1) + float x; // the x position + float y; // the y position + unsigned int color; // color of the bullet + float movement_speed; // speed of the bullet (how much it should move each frame) } BULLET; - +typedef struct smoke_particle_t +{ + size_t active; // whether or not to draw the smoke circle (0 or 1) + float x; // x position + float y; // y position + float radius; // radius of circle + int8_t explosion_direction; // wether the explosion is expanding or shrinking. + // 1 = expanding, -1 = shrinking +} SMOKE_PARTICLE; /** * @brief function that draws the given bullet, if it is active @@ -34,5 +50,20 @@ typedef struct bullet_sprite_t */ void sprites_draw_bullet(BULLET *bullet); +/** + * @brief draws the player sprite + * + * @param x the x position of the player + * @param y the y position of the player + * @param scale the scale of the ship + */ +void sprites_draw_player(float x, float y, float scale); + +/** + * @brief draws a smoke particle + * + * @param smoke_particle the smoke particle to draw + */ +void sprites_draw_smoke_circle(SMOKE_PARTICLE *smoke_particle); #endif \ No newline at end of file diff --git a/src/toolbox/toolbox.c b/src/toolbox/toolbox.c new file mode 100644 index 0000000..345d5bc --- /dev/null +++ b/src/toolbox/toolbox.c @@ -0,0 +1,9 @@ +#include "toolbox.h" + +float toolbox_random_float(float a, float b) +{ + float random = ((float)rand()) / (float)RAND_MAX; + float diff = b - a; + float r = random * diff; + return a + r; +} \ No newline at end of file diff --git a/src/toolbox/toolbox.h b/src/toolbox/toolbox.h new file mode 100644 index 0000000..1eaa7d4 --- /dev/null +++ b/src/toolbox/toolbox.h @@ -0,0 +1,13 @@ +#ifndef TOOLBOX_H + +#include + +/** + * @brief generates a random float between the given floats + * + * @param a the minumum value (inclusive) + * @param b the maximum value (inclusive) + */ +float toolbox_random_float(float a, float b); + +#endif // !TOOLBOX_H \ No newline at end of file