I'm trying to make custom 2d collisions for 2 rectangles in macroquad but I keep running into the same error.
heres my code:
use macroquad::prelude::*;
#[derive(Debug, Clone)]
struct rectangle {
x: f32,
y: f32,
w: f32,
h: f32,
color: macroquad::prelude::Color, // should be <T>, I don't wanna deal with the custom color type, but macroquad has some bugs
speed: f32, // should be <U> , I want users to have more customiazation over speed, but macroquad has some bugs with this...
}
#[macroquad::main("InputKeys")]
async fn main() {
let mut x: f32 = screen_width() / 2.0_f32;
let mut y: f32 = screen_width() / 2.0_f32;
let mut gravity_speed: f32 = 1.0_f32;
let speed: f32 = 3.5_f32;
let mut gameover: bool = false;
let player_rect = rectangle { x: x, y: y, w: 5.0_f32, h: 5.0_f32, color: GREEN, speed: 3.5_f32 };
let obstacle_rect = rectangle { x: 100.0_f32, y: 100.0_f32, w: 7.0_f32, h: 7.0_f32, color: RED, speed: 0.0_f32 };
loop {
clear_background(GRAY);
if is_key_down(KeyCode::W) {
y -= player_rect.speed;
}
if is_key_down(KeyCode::A) {
x -= player_rect.speed;
}
if is_key_down(KeyCode::D) {
x += player_rect.speed;
}
if is_key_down(KeyCode::S) {
y += player_rect.speed
}
draw_rectangle(player_rect.x, player_rect.y, player_rect.w, player_rect.h, player_rect.color);
draw_rectangle(obstacle_rect.x, obstacle_rect.y, obstacle_rect.w, obstacle_rect.h, obstacle_rect.color);
rectangle_collisions(player_rect, obstacle_rect);
/*if gameover == true {
clear_background(GRAY);
draw_text("YOU LOST",20.0, 105.0, 150.0, BLACK);
}*/
next_frame().await;
}
}
fn rectangle_collisions(rect1: rectangle, rect2: rectangle2) {
if rect1.x < rect2.x + rect2.w && rect1.x + rect1.w > rect2.x && rect1.y < rect2.y + rect2.h && rect1.h + rect1.y > rect2.y {
println!("COLLISSSSIOOONNNN DETECTED!!!!!")
}
}