Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Klasa Player

Antek Bizon edited this page Mar 5, 2022 · 1 revision

Klasa Player

Odpowiada za tworzenie, ruch, rysowanie, odpowiednie reagowanie na kolizje grywalnej postaci. Wywołuje także funkcje AddWeapon tworzącą broń. Rozmiary Playera rozłożone są na rozmiar tekstury oraz rozmiar HitBoxa.

class Player : public Sprite {
public:
    Player(Game* game, Position position);
    Player(Game* game, std::ifstream&);
    virtual void Draw();
    virtual void Move();
    virtual void Collision(Sprite*);
    virtual void Save(std::ofstream&);
    void Shooting();
    bool timeLeft();
    int frameCounter;

private:
    Vector2 speed;
    Color color = WHITE;
    Texture2D spriteSheet;
    Rectangle moveRightRec;
    Rectangle moveLeftRec;
    Rectangle standRec;
    Rectangle moveUpRec;
    Rectangle hurtRec;
    int cooldown = 0;
    bool climbing = false;
    bool collision = false;
    bool onIce = false;
    short int changeColor = 0;
};

Player::Player(Game *game, Position position)
    : Sprite(game, Position(position), Type::PLAYER), speed({ 0, 0 }) {
    spriteSheet = game->textures[PLAYER];
    moveRightRec = { 0.0f, 11 * 64.0f, 64.0f, 64.0f };
    moveLeftRec = { 0.0f, 9 * 64.0f, 64.0f, 64.0f };
    standRec = { 0.0f, 2 * 64.0f, 64.0f, 64.0f };
    moveUpRec = { 0.0f, 8 * 64.0f, 64.0f, 64.0f };
    hurtRec = { 0.0f, 20 * 64.0f, 64.0f, 64.0f };
}

Player::Player(Game *game, std::ifstream& s)
    : Sprite(game, Position(s), Type::PLAYER) {
    Read(s, &speed.x);
    Read(s, &speed.y);
    Read(s, &climbing);
    Read(s, &onIce);
    Read(s, &frameCounter);
    spriteSheet = game->textures[PLAYER];
    moveRightRec = { 0.0f, 11 * 64.0f, 64.0f, 64.0f };
    moveLeftRec = { 0.0f, 9 * 64.0f, 64.0f, 64.0f };
    standRec = { 0.0f, 2 * 64.0f, 64.0f, 64.0f };
    moveUpRec = { 0.0f, 8 * 64.0f, 64.0f, 64.0f };
    hurtRec = { 0.0f, 20 * 64.0f, 64.0f, 64.0f };
}
Clone this wiki locally