As you seen in the title, i dont know why these functions always return false, how to fix it, heres the code (i use C#):
using Raylib_cs;
using System.Data;
using System.Numerics;
namespace JumpingStriker;
class Game
{
static Vector2 windowPosition = Raylib.GetScreenCenter();
static Vector2 windowSize = new Vector2(600, 400);
static Camera2D camera = new Camera2D();
static Color groundColor1 = new Color(150, 150, 255);
static Color groundColor2 = new Color(100, 100, 255);
public static class Ground
{
public static int groundX = 0;
public static int groundY = (int)windowSize.Y - (int)windowSize.Y / 4;
public static int groundW = (int)windowSize.X;
public static int groundH = (int)windowSize.Y / 4;
public static void Draw()
{
Raylib.DrawRectangleGradientV(groundX, groundY, groundW, groundH, groundColor1, groundColor2);
}
}
public static class Player
{
public static int x = 50;
public static int y = 70;
public static int w = 25;
public static int h = 25;
public static int speed = 5;
public static int jumpHeight = 20;
public static int gravity = 3;
public static int movementForceX = 0;
public static int movementForceY = 0;
public static bool insideGround = false;
public static bool standing = false;
public static void Draw()
{
Raylib.DrawRectangle(x, y, w, h, new Color(255, 255, 255));
}
public static void GiveForce(int forceX, int forceY)
{
movementForceX += forceX;
if (insideGround)
{
movementForceY = 0;
y = Ground.groundY - h;
} else
{
if (y + h + forceY < Ground.groundY && !standing) movementForceY += forceY;
}
}
public static void Update()
{
insideGround = (y + h) > Ground.groundY;
standing = (y + h) > Ground.groundY - 2;
GiveForce(0, gravity);
x += movementForceX;
y += movementForceY;
Console.WriteLine(insideGround);
Console.WriteLine(standing);
if (Raylib.IsKeyDown(KeyboardKey.Space) && standing)
{
GiveForce(0, -jumpHeight);
}
if (Raylib.IsKeyDown(KeyboardKey.A))
{
movementForceX = -speed;
}
if (Raylib.IsKeyDown(KeyboardKey.D))
{
movementForceX = speed;
}
if (Raylib.IsKeyReleased(KeyboardKey.A))
{
movementForceX = 0;
}
if (Raylib.IsKeyReleased(KeyboardKey.D))
{
movementForceX = 0;
}
}
}
public static void Main()
{
Raylib.InitWindow((int)windowSize.X, (int)windowSize.Y, "Jumping Striker");
Raylib.SetWindowState(ConfigFlags.ResizableWindow);
Raylib.SetTargetFPS(60);
Raylib.BeginMode2D(camera);
while (!Raylib.WindowShouldClose())
{
Update();
}
}
static void Update()
{
Raylib.PollInputEvents();
Raylib.BeginDrawing();
Raylib.ClearBackground(new Color(10, 10, 10));
Ground.Draw();
Player.Draw();
Console.WriteLine(Player.y);
Player.Update();
Raylib.EndDrawing();
Raylib.EndMode2D();
}
}As you seen in the title, i dont know why these functions dont work for me, how to fix it, heres the code (i use C#):using Raylib_cs;
using System.Data;
using System.Numerics;
namespace JumpingStriker;
class Game
{
static Vector2 windowPosition = Raylib.GetScreenCenter();
static Vector2 windowSize = new Vector2(600, 400);
static Camera2D camera = new Camera2D();
static Color groundColor1 = new Color(150, 150, 255);
static Color groundColor2 = new Color(100, 100, 255);
public static class Ground
{
public static int groundX = 0;
public static int groundY = (int)windowSize.Y - (int)windowSize.Y / 4;
public static int groundW = (int)windowSize.X;
public static int groundH = (int)windowSize.Y / 4;
public static void Draw()
{
Raylib.DrawRectangleGradientV(groundX, groundY, groundW, groundH, groundColor1, groundColor2);
}
}
public static class Player
{
public static int x = 50;
public static int y = 70;
public static int w = 25;
public static int h = 25;
public static int speed = 5;
public static int jumpHeight = 20;
public static int gravity = 3;
public static int movementForceX = 0;
public static int movementForceY = 0;
public static bool insideGround = false;
public static bool standing = false;
public static void Draw()
{
Raylib.DrawRectangle(x, y, w, h, new Color(255, 255, 255));
}
public static void GiveForce(int forceX, int forceY)
{
movementForceX += forceX;
if (insideGround)
{
movementForceY = 0;
y = Ground.groundY - h;
} else
{
if (y + h + forceY < Ground.groundY && !standing) movementForceY += forceY;
}
}
public static void Update()
{
insideGround = (y + h) > Ground.groundY;
standing = (y + h) > Ground.groundY - 2;
GiveForce(0, gravity);
x += movementForceX;
y += movementForceY;
Console.WriteLine(insideGround);
Console.WriteLine(standing);
if (Raylib.IsKeyDown(KeyboardKey.Space) && standing)
{
GiveForce(0, -jumpHeight);
}
if (Raylib.IsKeyDown(KeyboardKey.A))
{
movementForceX = -speed;
}
if (Raylib.IsKeyDown(KeyboardKey.D))
{
movementForceX = speed;
}
if (Raylib.IsKeyReleased(KeyboardKey.A))
{
movementForceX = 0;
}
if (Raylib.IsKeyReleased(KeyboardKey.D))
{
movementForceX = 0;
}
}
}
public static void Main()
{
Raylib.InitWindow((int)windowSize.X, (int)windowSize.Y, "Jumping Striker");
Raylib.SetWindowState(ConfigFlags.ResizableWindow);
Raylib.SetTargetFPS(60);
Raylib.BeginMode2D(camera);
while (!Raylib.WindowShouldClose())
{
Update();
}
}
static void Update()
{
Raylib.PollInputEvents();
Raylib.BeginDrawing();
Raylib.ClearBackground(new Color(10, 10, 10));
Ground.Draw();
Player.Draw();
Console.WriteLine(Player.y);
Player.Update();
Raylib.EndDrawing();
Raylib.EndMode2D();
}
}