aboutsummaryrefslogtreecommitdiffstats
path: root/src/wp_assaultrifle.cpp
blob: 0be3d5bdb22be7bd74e1f63e0b7880f2bd12915d (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
#include "wp_assaultrifle.hpp"

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

#include "entity.hpp"

wp_assaultrifle::wp_assaultrifle(const char* s, const char* r)
    : AWeapon(300.0f, 1, 30, 0.0, s, r, "ar") {}

int wp_assaultrifle::bang(std::vector<Entity>* enemies, Entity* player) {
    if (barrel == 0) {
        return (1);
    } else {
        Vector2 playerDirection = Vector2Normalize(player->direction);
        playerDirection.x *= range;
        playerDirection.y *= range;
        Vector2 playerPosition = (Vector2){player->posX, player->posY};
        Vector2 rot1 = Vector2Rotate(playerDirection, -0.2f);
        Vector2 rot2 = Vector2Rotate(playerDirection, 0.2f);

        Vector2 add1 = Vector2Add(playerPosition, rot1);
        Vector2 add2 = Vector2Add(playerPosition, rot2);

        Vector2 r;
        barrel--;
        PlaySound(shot);
        t = GetTime();
        // here
        //
        r = playerDirection;
        r.x *= 2;
        r.y *= 2;
        for (auto en = enemies->begin(); en != enemies->end(); en++) {
            if (CheckCollisionPointLine((Vector2){en->posX, en->posY},
                                        playerPosition, add1,
                                        (en->radius * 2)) ||
                CheckCollisionPointLine(
                    (Vector2){en->posX, en->posY}, playerPosition,
                    Vector2Add(playerPosition, r), (en->radius * 2)) ||
                CheckCollisionPointLine((Vector2){en->posX, en->posY},
                                        playerPosition, add2,
                                        (en->radius * 2))) {  // enemy hit
                std::cout << "hit" << std::endl;
                en->hp -= damage;
                if (en->hp == 0) {
                    en->direction.x = (playerDirection.x / 2);
                    en->direction.y = (playerDirection.y / 2);
                    player->victims += 1;
                }
                player->fury += 1;
                break;
            }
        }
        // assaultrifle cone
        DrawLineEx(playerPosition, add1, 10, ORANGE);
        DrawLineEx(playerPosition, Vector2Add(playerPosition, r), 10, ORANGE);
        DrawLineEx(playerPosition, add2, 10, ORANGE);

        //
        // there
        if (barrel == 0) {
            empty = true;
        }
        return (0);
    }
}