summary refs log tree commit diff
diff options
context:
space:
mode:
authorzlago2024-10-07 19:07:58 +0200
committerzlago2024-10-07 19:07:58 +0200
commitc851581465b9bae8ac679415368d792cefd76de2 (patch)
tree17175c7003ba3a9fc4f88d9858263c9128149582
parentd005a7756f6d15f67a7033a53bae23d00a58af69 (diff)
fixes
-rw-r--r--src/main.c4
-rw-r--r--src/player.c14
-rw-r--r--src/res/particles.asebin0 -> 288 bytes
-rw-r--r--utl/rearrange.c2
4 files changed, 14 insertions, 6 deletions
diff --git a/src/main.c b/src/main.c
index d5f6504..fbbb371 100644
--- a/src/main.c
+++ b/src/main.c
@@ -282,7 +282,7 @@ int main(int const argc, char *const *const argv) {
 		return EXIT_FAILURE;
 	}
 	SDL_StopTextInput();
-	if (scale <= 0) {
+	if (scale <= 0) { // this looks very wrong
 		SDL_DisplayMode dm;
 		if (SDL_GetDesktopDisplayMode(0, &dm) != 0) {
 			SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "couldnt get desktop size", SDL_GetError(), NULL);
@@ -309,6 +309,8 @@ int main(int const argc, char *const *const argv) {
 	if (window == NULL) {
 		goto end;
 	}
+
+	SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl"); // hack, i dont wanna deal with windows discarding render textures
 	renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_TARGETTEXTURE | SDL_RENDERER_PRESENTVSYNC);
 	if (renderer == NULL) {
 		goto end;
diff --git a/src/player.c b/src/player.c
index a6fa86d..f36ae1a 100644
--- a/src/player.c
+++ b/src/player.c
@@ -13,6 +13,9 @@
 #define GRAVITY 1
 #define JUMP 30
 
+#define SLASH_REACH_X 8
+#define SLASH_REACH_Y 6
+
 enum {
 	PLAYER_NONE,
 	PLAYER_IDLE,
@@ -49,6 +52,9 @@ static int slash_update(struct projectile *self) {
 	self->x += self->velocity.x;
 	self->y += self->velocity.y;
 	self->hp--;
+	int x = from_fixed(self->x) + self->facing * sin(self->hp + 0) * SLASH_REACH_X;
+	int y = from_fixed(self->y) - cos(self->hp + 0) * SLASH_REACH_Y;
+	self->hitbox = (struct hitbox) {.left = x, .right = x, .top = y, .bottom = y};
 	#if 0
 		struct particle *part = entities.particle + entities.particles;
 		part->x = self->x + to_fixed(self->facing >= 0? sin(self->hp): -sin(self->hp)) * 6;
@@ -72,9 +78,9 @@ static int slash_draw(struct projectile *self, int camX, int camY) {
 	//SDL_RenderFillRect(renderer, &(SDL_Rect) {from_fixed(self->x) - camX - 8, from_fixed(self->y) - camY - 12, 16, 16});
 	int const x = from_fixed(self->x) - camX, y = from_fixed(self->y) - camY;
 	SDL_Vertex vertices[3] = {
-		{.position = {x + from_fixed(self->velocity.x) + ((self->facing >= 0)? sin(self->hp - 1): -sin(self->hp - 1)) * 8, y - cos(self->hp - 1) * 6}, .color = {255, 127, 0, 255}},
-		{.position = {x + ((self->facing >= 0)? sin(self->hp + 0): -sin(self->hp + 0)) * 8, y - cos(self->hp + 0) * 6}, .color = {255, 127, 0, 255}},
-		{.position = {x - from_fixed(self->velocity.x) + ((self->facing >= 0)? sin(self->hp + 1): -sin(self->hp + 1)) * 8, y - cos(self->hp + 1) * 6}, .color = {255, 127, 0, 255}},
+		{.position = {x + from_fixed(self->velocity.x) + self->facing * sin(self->hp - 1) * SLASH_REACH_X, y - cos(self->hp - 1) * SLASH_REACH_Y}, .color = {255, 127, 0, 255}},
+		{.position = {x + self->facing * sin(self->hp + 0) * SLASH_REACH_X, y - cos(self->hp + 0) * SLASH_REACH_Y}, .color = {255, 127, 0, 255}},
+		{.position = {x - from_fixed(self->velocity.x) + self->facing * sin(self->hp + 1) * SLASH_REACH_X, y - cos(self->hp + 1) * SLASH_REACH_Y}, .color = {255, 127, 0, 255}},
 	};
 	SDL_RenderGeometry(renderer, NULL, vertices, 3, NULL, 0);
 	return 0;
@@ -287,7 +293,7 @@ static int player_hurt(struct entity *self, int damage) {
 				part->x = self->x;
 				part->y = self->y;
 				part->velocity = (struct vec2) {to_fixed(x), to_fixed(y) - 8};
-				part->rect = (SDL_Rect) {0, 0, 4, 4};
+				part->rect = (SDL_Rect) {4, 0, 4, 4};
 				part->acceleration = (struct vec2) {0, 1};
 				part->hp = 30;
 				entities.particles++;
diff --git a/src/res/particles.ase b/src/res/particles.ase
new file mode 100644
index 0000000..5e1762d
--- /dev/null
+++ b/src/res/particles.ase
Binary files differdiff --git a/utl/rearrange.c b/utl/rearrange.c
index 1d82029..a2b7d90 100644
--- a/utl/rearrange.c
+++ b/utl/rearrange.c
@@ -1,5 +1,5 @@
 #include <stdio.h>
-#include <libplum.h>
+#include "libplum.h"
 
 int main(int const argc, char *const *const argv) {
 	if (argc < 3) {