In this code, the dog is meant to “eat” the bone, but instead of the bone being eaten, the dog moves away from the bone! I think this game is trolling me.
<code>#include "raylib.h"
#include <stdio.h>
#include <stdlib.h>
#include "raymath.h"
#include <time.h>
#define HEIGHT 500
#define WIDTH 700
Color extraDarkGreen = {10,30,20,255};
int main(void)
{
InitWindow(WIDTH, HEIGHT, "Random");
Image doge = LoadImage("/home/neraan/C/rand/Doge.png");
ImageResize(&doge, 75, 75);
Texture2D dogeTex = LoadTextureFromImage(doge);
Image Bone = LoadImage("/home/neraan/C/rand/Bone.png");
ImageResize(&Bone, 75, 75);
Texture2D BoneTex = LoadTextureFromImage(Bone);
Vector2 DogePos = {50,50};
Vector2 BonePos = {GetRandomValue(10, WIDTH-10),GetRandomValue(10, HEIGHT-10)};
SetTargetFPS(60);
here's an image of the output:
[](https://i.sstatic.net/02UXjFCY.png)
while (!WindowShouldClose())
{
Rectangle DogeHit = {DogePos.x,DogePos.y,20,20};
Rectangle BoneHit = {BonePos.x,BonePos.y,20,20};
BeginDrawing();
ClearBackground(extraDarkGreen);
DrawTexture(dogeTex, DogePos.x, DogePos.y,GREEN);
DrawTexture(BoneTex, BonePos.x, BonePos.y,GREEN);
EndDrawing();
DogePos.x += GetRandomValue(1.0f,2.0f);
DogePos.x -= GetRandomValue(1.0f,2.0f);
DogePos.y -= GetRandomValue(1.0f,2.0f);
DogePos.y += GetRandomValue(1.0f,2.0f);
if (IsKeyDown(KEY_RIGHT)) DogePos.x += 4.0f;
if (IsKeyDown(KEY_LEFT)) DogePos.x -= 4.0f;
if (IsKeyDown(KEY_UP)) DogePos.y -= 4.0f;
if (IsKeyDown(KEY_DOWN)) DogePos.y += 4.0f;
if (CheckCollisionRecs(DogeHit,BoneHit))
{
SetRandomSeed((unsigned int)time(NULL));
Vector2 BonePos = {GetRandomValue(10, WIDTH-10),GetRandomValue(10, HEIGHT-10)};
puts("Lets GOOOO");
}
}
CloseWindow();
return 0;
}
</code>
<code>#include "raylib.h"
#include <stdio.h>
#include <stdlib.h>
#include "raymath.h"
#include <time.h>
#define HEIGHT 500
#define WIDTH 700
Color extraDarkGreen = {10,30,20,255};
int main(void)
{
InitWindow(WIDTH, HEIGHT, "Random");
Image doge = LoadImage("/home/neraan/C/rand/Doge.png");
ImageResize(&doge, 75, 75);
Texture2D dogeTex = LoadTextureFromImage(doge);
Image Bone = LoadImage("/home/neraan/C/rand/Bone.png");
ImageResize(&Bone, 75, 75);
Texture2D BoneTex = LoadTextureFromImage(Bone);
Vector2 DogePos = {50,50};
Vector2 BonePos = {GetRandomValue(10, WIDTH-10),GetRandomValue(10, HEIGHT-10)};
SetTargetFPS(60);
here's an image of the output:
[](https://i.sstatic.net/02UXjFCY.png)
while (!WindowShouldClose())
{
Rectangle DogeHit = {DogePos.x,DogePos.y,20,20};
Rectangle BoneHit = {BonePos.x,BonePos.y,20,20};
BeginDrawing();
ClearBackground(extraDarkGreen);
DrawTexture(dogeTex, DogePos.x, DogePos.y,GREEN);
DrawTexture(BoneTex, BonePos.x, BonePos.y,GREEN);
EndDrawing();
DogePos.x += GetRandomValue(1.0f,2.0f);
DogePos.x -= GetRandomValue(1.0f,2.0f);
DogePos.y -= GetRandomValue(1.0f,2.0f);
DogePos.y += GetRandomValue(1.0f,2.0f);
if (IsKeyDown(KEY_RIGHT)) DogePos.x += 4.0f;
if (IsKeyDown(KEY_LEFT)) DogePos.x -= 4.0f;
if (IsKeyDown(KEY_UP)) DogePos.y -= 4.0f;
if (IsKeyDown(KEY_DOWN)) DogePos.y += 4.0f;
if (CheckCollisionRecs(DogeHit,BoneHit))
{
SetRandomSeed((unsigned int)time(NULL));
Vector2 BonePos = {GetRandomValue(10, WIDTH-10),GetRandomValue(10, HEIGHT-10)};
puts("Lets GOOOO");
}
}
CloseWindow();
return 0;
}
</code>
#include "raylib.h"
#include <stdio.h>
#include <stdlib.h>
#include "raymath.h"
#include <time.h>
#define HEIGHT 500
#define WIDTH 700
Color extraDarkGreen = {10,30,20,255};
int main(void)
{
InitWindow(WIDTH, HEIGHT, "Random");
Image doge = LoadImage("/home/neraan/C/rand/Doge.png");
ImageResize(&doge, 75, 75);
Texture2D dogeTex = LoadTextureFromImage(doge);
Image Bone = LoadImage("/home/neraan/C/rand/Bone.png");
ImageResize(&Bone, 75, 75);
Texture2D BoneTex = LoadTextureFromImage(Bone);
Vector2 DogePos = {50,50};
Vector2 BonePos = {GetRandomValue(10, WIDTH-10),GetRandomValue(10, HEIGHT-10)};
SetTargetFPS(60);
here's an image of the output:
[](https://i.sstatic.net/02UXjFCY.png)
while (!WindowShouldClose())
{
Rectangle DogeHit = {DogePos.x,DogePos.y,20,20};
Rectangle BoneHit = {BonePos.x,BonePos.y,20,20};
BeginDrawing();
ClearBackground(extraDarkGreen);
DrawTexture(dogeTex, DogePos.x, DogePos.y,GREEN);
DrawTexture(BoneTex, BonePos.x, BonePos.y,GREEN);
EndDrawing();
DogePos.x += GetRandomValue(1.0f,2.0f);
DogePos.x -= GetRandomValue(1.0f,2.0f);
DogePos.y -= GetRandomValue(1.0f,2.0f);
DogePos.y += GetRandomValue(1.0f,2.0f);
if (IsKeyDown(KEY_RIGHT)) DogePos.x += 4.0f;
if (IsKeyDown(KEY_LEFT)) DogePos.x -= 4.0f;
if (IsKeyDown(KEY_UP)) DogePos.y -= 4.0f;
if (IsKeyDown(KEY_DOWN)) DogePos.y += 4.0f;
if (CheckCollisionRecs(DogeHit,BoneHit))
{
SetRandomSeed((unsigned int)time(NULL));
Vector2 BonePos = {GetRandomValue(10, WIDTH-10),GetRandomValue(10, HEIGHT-10)};
puts("Lets GOOOO");
}
}
CloseWindow();
return 0;
}
Here’s an image of the output:
I have absolutely no idea what even to try. Stack Overflow wants me to add more text, as “there’s only code here!” but I literally don’t know what to add. So, let me just tell you that I’m unsure EXACTLY what is wrong here. To me, all the logic checks out! It SHOULD work, and, for goodness sake, WHY DOES THE DOG MOVE, NOT THE BONE!