collisions happen properly now
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
// src/game/collision.h
|
||||
#pragma once
|
||||
#include "../render/player_positioning.h"
|
||||
#include "../render/player.h"
|
||||
#include "../assets/character_walk_frames.h"
|
||||
#include "../assets/character_run_frames.h"
|
||||
#include "../assets/character_crawl_frames.h"
|
||||
@@ -18,9 +17,13 @@ struct Obstacle {
|
||||
inline bool check_collision(const CharacterPosition& player,
|
||||
MovementType movement,
|
||||
const Obstacle& obs) {
|
||||
int player_x = player.x;
|
||||
int player_y = (VIEW_HEIGHT - player.y) - CHARACTER_WALK_FRAME_HEIGHT;
|
||||
int box_x = 0, box_w = 0, box_h = 0;
|
||||
|
||||
// Player is given in bottom-based world coordinates (0 = bottom line)
|
||||
const int player_x = player.x;
|
||||
const int player_bottom = player.y;
|
||||
int box_x = 0;
|
||||
int box_w = 0;
|
||||
int box_h = 0;
|
||||
|
||||
switch (movement) {
|
||||
case MovementType::Walk:
|
||||
@@ -46,19 +49,18 @@ inline bool check_collision(const CharacterPosition& player,
|
||||
}
|
||||
|
||||
// Player's bounding box
|
||||
int player_left = box_x;
|
||||
int player_right = player_left + box_w;
|
||||
int player_top = player_y;
|
||||
int player_bottom = player_top + box_h;
|
||||
const int player_left = box_x;
|
||||
const int player_right = player_left + box_w;
|
||||
const int player_top = player_bottom + box_h;
|
||||
|
||||
// Obstacle bounding box
|
||||
int obs_left = obs.x;
|
||||
int obs_right = obs.x + obs.width;
|
||||
int obs_top = obs.y;
|
||||
int obs_bottom = obs.y + obs.height;
|
||||
const int obs_left = obs.x;
|
||||
const int obs_right = obs.x + obs.width;
|
||||
const int obs_bottom = obs.y;
|
||||
const int obs_top = obs_bottom + obs.height;
|
||||
|
||||
// Simple overlap check
|
||||
bool horizontal = player_left < obs_right && player_right > obs_left;
|
||||
bool vertical = player_top < obs_bottom && player_bottom > obs_top;
|
||||
bool vertical = player_bottom < obs_top && player_top > obs_bottom;
|
||||
return horizontal && vertical;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user