From a90db3b7b6e87e24c789b5db222f1cef92809bde Mon Sep 17 00:00:00 2001 From: Thomas Guillermo Albers Raviola Date: Fri, 16 Jan 2026 19:38:33 +0100 Subject: Initial commit --- progress/src/colisiones.c | 150 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 progress/src/colisiones.c (limited to 'progress/src/colisiones.c') diff --git a/progress/src/colisiones.c b/progress/src/colisiones.c new file mode 100644 index 0000000..455db40 --- /dev/null +++ b/progress/src/colisiones.c @@ -0,0 +1,150 @@ +#include "main.h" + +void collisionDetect(GameState *gameState) +{ + ///Player 1 + if(gameState->player1.y >= 420) + { + gameState->player1.y = 420; + gameState->player1.dy = 0; + gameState->player1.salto = 0; + } + if(gameState->player1.x <= 0) + { + gameState->player1.x = 0; + gameState->player1.dx = 0; + } + if(gameState->player1.x >= 600) + { + gameState->player1.x = 600; + gameState->player1.dx = 0; + } + for(int i = 0; i < gameState->maxE; i++) + { + float mw = gameState->player1.w, mh = gameState->player1.h; + float mx =gameState->player1.x, my = gameState->player1.y; + float bx = gameState->entidades[i].x, by = gameState->entidades[i].y, bw = gameState->entidades[i].w, bh = gameState->entidades[i].h; + if(mx+mw/2 > bx && mx+mw/2 by) + { + //correct y + gameState->player1.y = by+bh; + my = by+bh; + + //bumped our head, stop any jump velocity + gameState->player1.dy = 0; + } + } + if(mx+mw > bx && mx by && my < by) + { + //correct y + gameState->player1.y = by-mh; + my = by-mh; + + //landed on this ledge, stop any jump velocity + gameState->player1.dy = 0; + gameState->player1.salto = 0; + } + } + + if(my+mh > by && my bx+bw) + { + //correct x + gameState->player1.x = bx+bw; + mx = bx+bw; + + gameState->player1.dx = 0; + } + //rubbing against left edge + else if(mx+mw > bx && mx < bx) + { + //correct x + gameState->player1.x = bx-mw; + mx = bx-mw; + + gameState->player1.dx = 0; + } + } + } + + ///Player 2 + if(gameState->player2.y >= 420) + { + gameState->player2.y = 420; + gameState->player2.dy = 0; + gameState->player2.salto = 0; + } + if(gameState->player2.x <= 0) + { + gameState->player2.x = 0; + gameState->player2.dx = 0; + } + if(gameState->player2.x >= 600) + { + gameState->player2.x = 600; + gameState->player2.dx = 0; + } + for(int i = 0; i < gameState->maxE; i++) + { + float mw = gameState->player2.w, mh = gameState->player2.h; + float mx =gameState->player2.x, my = gameState->player2.y; + float bx = gameState->entidades[i].x, by = gameState->entidades[i].y, bw = gameState->entidades[i].w, bh = gameState->entidades[i].h; + if(mx+mw/2 > bx && mx+mw/2 by) + { + //correct y + gameState->player2.y = by+bh; + my = by+bh; + + //bumped our head, stop any jump velocity + gameState->player2.dy = 0; + } + } + if(mx+mw > bx && mx by && my < by) + { + //correct y + gameState->player2.y = by-mh; + my = by-mh; + + //landed on this ledge, stop any jump velocity + gameState->player2.dy = 0; + gameState->player2.salto = 0; + } + } + + if(my+mh > by && my bx+bw) + { + //correct x + gameState->player2.x = bx+bw; + mx = bx+bw; + + gameState->player2.dx = 0; + } + //rubbing against left edge + else if(mx+mw > bx && mx < bx) + { + //correct x + gameState->player2.x = bx-mw; + mx = bx-mw; + + gameState->player2.dx = 0; + } + } + } +} -- cgit v1.2.3