Raylib C++, Doesn't get past loading an instance of a class

0

I've been trying to rewrite my code in order for it to be Object Oriented. However, when I make the object mainNPC from the class NPC it doesn't seem to get past that.

When loading the code it doesn't get to the part I labelled "Point 4" and the console says "Process returned -1073741819 (0xC0000005)"

Any ideas where i went wrong?

Thanks

#include "raylib.h"
#include <iostream>

using namespace std;

//Declares the screen resolution early so that the NPC class is able to use it
int screenWidth = 1280;
int screenHeight = 720;

float midpointX = screenWidth/2;
float midpointY = screenHeight/2;

class NPC
{
public:
    //Determines the spawn location of the NPC
    float spawnX = (GetRandomValue(100, screenWidth-100));
    float spawnY = (GetRandomValue(100, screenHeight-100));

    //Loads the sprite's texture
    Texture2D sprite = LoadTexture("resources/sprite.png");

    //Determines the points at which the sprite can be clicked for it to be positive
    float minX = spawnX;
    float maxX = spawnX + sprite.width;
    float minY = spawnY;
    float maxY = spawnY + sprite.height;

    //Creates variable for mouse position. Only required for the target.
    float mouseX;
    float mouseY;

    //Creates boolean for checking whether or not the player was correct when choosing the location.
    bool isCorrect = false;
    //cout << "point 1" << endl;

    void checkCorrect()
    {
        mouseX = GetMouseX();
        mouseY = GetMouseY();
        cout << "point 2" << endl;

        //Go through some mad process to determine if it is within the ranges above.
        if (minX < mouseX)
        {
            if (mouseX < maxX)
            {
                if(minY < mouseY)
                {
                    if (mouseY < maxY)
                    {
                        isCorrect= true;
                        cout << "correct" << endl;
                    }
                }
            }
        }

        if (isCorrect){
            DrawText("Correct", midpointX, midpointY, 60, GREEN);
            isCorrect = false;
        }
    }

    void drawNPC()
    {
        DrawTexture(sprite, spawnX, spawnY, WHITE);
        cout << "point 3" << endl;
    }




};

int main()
{

    cout << "point 1" << endl;
    NPC mainNPC;

    cout << "point 4" << endl;

    InitWindow(screenWidth, screenHeight, "Test");
    SetTargetFPS(60);

    cout << "point 5" << endl;

    while(!WindowShouldClose())
    {
        BeginDrawing();
            ClearBackground(RAYWHITE);
            mainNPC.drawNPC();

            if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) mainNPC.checkCorrect();
        EndDrawing();
    }

    CloseWindow();
    return 0;
}
c++
raylib
asked on Stack Overflow Aug 14, 2020 by cddesignsuk

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0