aboutsummaryrefslogtreecommitdiffstats
path: root/src/gameplay.cpp
blob: 3cbc17fd2014d0a391dfb756a9594561bdd069be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "gameplay.hpp"

#include <iostream>


Game::~Game()
{
    delete enemies;
    delete player;
}

Game::Game(void)
{
    // nEnemies = GetRandomValue(5, 15);

    enemies = 3;

    enemies = new std::vector<Entity>(nEnemies);
    player = new Entity;
    player->posX = SCREENWIDTH / 2;
    player->posY = SCREENHEIGHT / 2;
    player->direction.x = 1;
    player->direction.y = 0;
}

void Game::start() const
{
    std::cout << "----- Gameplay: Start -----" << std::endl;
    std::cout << "Gameplay: " << nEnemies << "enemies need to be spawned" << std::endl;
}

void Game::draw() const
{
    for (auto & en : *enemies)
    {
        DrawCircleV((Vector2){en.posX, en.posY}, 10, RED);
    }
    DrawCircleV((Vector2){player->posX, player->posY}, 10, GREEN);
}


void Game::tick() const
{
    for (auto & en : *enemies)
    {
        if (en.posX >= SCREENWIDTH || en.posX <= 0)
        {
            en.direction.x = -en.direction.x;
        }
        if (en.posY >= SCREENHEIGHT || en.posY <= 0)
        {
            en.direction.y = -en.direction.y;
        }
        en.posX += en.direction.x;
        en.posY += en.direction.y;
    }
    player->posX += player->direction.x;
    player->posY += player->direction.y;
}

void Game::getKeys() const
{
    if (IsKeyPressed(KEY_UP)) {
        player->direction.x = 0;
        player->direction.y = -2;
    }
    if (IsKeyPressed(KEY_DOWN)) {
        player->direction.x = 0;
        player->direction.y = 2;
    }
    if (IsKeyPressed(KEY_LEFT)) {
        player->direction.x = -2;
        player->direction.y = 0;
    }
    if (IsKeyPressed(KEY_RIGHT)) {
        player->direction.x = 2;
        player->direction.y = 0;
    }
}