Collisions in Raylib C++

your text#include “raylib.h”
your text#include <stdio.h>
your text
your textstruct square
your text{
your text // Variables
your text float x, y;
your text float w, h;
your text float gravity;
your text float velocity;
your text
your text Rectangle GetRectangle() { // x w h
your text return Rectangle{ x – w / 2, y – h / x, 80, 80 };
your text }
your text int drawsquare() {
your text DrawRectangleRec(GetRectangle(), RED);
your text return 0;
your text }
your text};
your textstruct obby
your text{
your text // Variables
your text float x, y;
your text float w, h;
your text
your text Rectangle GetRectangle() {
your text return Rectangle{ x, y, w, h };
your text }
your text int drawobby() {
your text DrawRectangleRec(GetRectangle(), BROWN);
your text return 0;
your text }
your text};
your text
your textint currentLevel = 1;
your text
your textint main(void)
your text{
your text InitWindow(1100, 700, “Basic Platformer”);
your text
your text SetWindowState(FLAG_VSYNC_HINT);
your text
your text // Player Attributes
your text square player;
your text player.x = 100;
your text player.y = 400;
your text player.w = 80;
your text player.h = 80;
your text player.gravity = 0.0f;
your text player.velocity = 0.15f;
your text
your text // Floor Attributes
your text obby floor1;
your text floor1.x = 50;
your text floor1.y = 575;
your text floor1.w = 160;
your text floor1.h = 30;
your text
your text // DeltaTime
your text float deltaTime = GetFrameTime();
your text
your text // Sets the FPS
your text SetTargetFPS(60);
your text
your text // While Window is Open
your text while (!WindowShouldClose())
your text {
your text // Player Gravity / Physics
your text player.gravity += player.velocity;
your text player.y += player.gravity;
your text
your text // Collisions
your text if (CheckCollisionRecs(player.GetRectangle(), floor1.GetRectangle())) {
your text player.y = floor1.y – 80;
your text player.gravity = 0;
your text }
your text
your text // Input
your text if (IsKeyPressed(KEY_W)) {
your text player.gravity = -5;
your text }
your text else if (IsKeyDown(KEY_A)) {
your text player.x -= 4;
your text }
your text else if (IsKeyDown(KEY_D)) {
your text player.x += 4;
your text currentLevel = 2;
your text }
your text
your text BeginDrawing();
your text
your text // Level 1
your text if (currentLevel == 1) {
your text void Level1(void);
your text {
your text floor1.drawobby();
your text }
your text }
your text
your text // Level 2
your text if (currentLevel == 2) {
your text void Level1(void);
your text {
your text
your text }
your text }
your text
your text // Level 3
your text if (currentLevel == 3) {
your text void Level1(void);
your text {
your text
your text }
your text }
your text
your text ClearBackground(GRAY);
your text player.drawsquare();
your text
your text EndDrawing();
your text
your text // DeltaTime
your text deltaTime = GetFrameTime();
your text }
your text
your text
your text CloseWindow();
your text
your text return 0;
your text}

So Im making this simple platform game on Raylib C++, and I can’t nail down the collisions. I’ve searched many tutorials for collisions but I haven’t found one that fits my situation. I have tried to implement my own collisions but it only works for the top of the floor object my player is trying to stand on. Also, don’t worry about the Level voids those are just there for the future.

New contributor

ayden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật