I'm trying to get my collision detection to work. I'm new to programming and am just testing some stuff out. The problem I'm getting is when I'm putting in the two different rectangles that are supposed to detect collisions with each other. I've marked the problem with //THIS IS WHERE I GET THE ERROR!
ERROR CODE IS "(local variable) Rectangle player01 'player01' is not null here.
Argument 1: cannot convert from 'Grunder.Rectangle' to 'Raylib_cs.Rectangle' [labyrint0]"
using Raylib_cs;
namespace Grunder
{
class Program
{
static void Main(string[] args)
{
Rectangle floor01 = new Rectangle(50, 500, 700, 50, Color.WHITE);
Rectangle player01 = new Rectangle(300, 300, 50, 50, Color.DARKBLUE);
// Start graficMotor
Raylib.InitWindow(800, 600, "My Raylib Window");
Raylib.SetTargetFPS(60);
while (!Raylib.WindowShouldClose())
{
Raylib.BeginDrawing();
Raylib.ClearBackground(Color.BEIGE);
floor01.Draw();
player01.Draw();
player01.IsPlayer();
Raylib.EndDrawing();
if (Raylib.CheckCollisionRecs(player01, floor01)) //THIS IS WHERE I GET THE ERROR!
{
Raylib.DrawText("Kollision", 100, 50, 50, Color.ORANGE);
}
}
}
}
public class Rectangle
{
public int posX;
public int posY;
public int length;
public int width;
Color color;
int playerSpeed = 5;
bool collisionRight;
bool collsiionLeft;
bool collisionUp;
bool collisionDown;
public Rectangle(int _posX, int _posY, int _length, int _width, Color _color)
{
posX = _posX;
posY = _posY;
length = _length;
width = _width;
color = _color;
}
public void Draw()
{
Raylib.DrawRectangle(posX, posY, length, width, color);
}
public void IsPlayer()
{
// Not used: int playerMaxSpeed = 5;
if (Raylib.IsKeyDown(KeyboardKey.KEY_RIGHT))
{
posX += playerSpeed;
}
if (Raylib.IsKeyDown(KeyboardKey.KEY_LEFT))
{
posX -= playerSpeed;
}
if (Raylib.IsKeyDown(KeyboardKey.KEY_UP))
{
posY -= playerSpeed;
}
if (Raylib.IsKeyDown(KeyboardKey.KEY_DOWN))
{
posY += playerSpeed;
}
}
}
}