summaryrefslogtreecommitdiff
path: root/Player.cpp
blob: 9ab733ef70bdd2d6e062609d854b7c797455b81a (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
#include "Player.h"

Player::Player() {
    health = 100;
    sprint = false;
    crouch = 0;
    numWeapons = 0;
    setWeapon(0);
}

void Player::jump() {
    if (!yVel) {
        incYVel(-JUMP_STRENGTH);
    }
}

void Player::kill() {
    health = 0;
    // Do resetting stuff
}

void Player::setSprint(bool s) {
    sprint = s;
}

bool Player::getSprint() {
    return sprint;
}

int Player::getXVel() {
    if (sprint)
        return xVel * SPRINT_MULTIPLYER;
    else
        return xVel;
}

/* Set crouching state
   0 = default, not crouching
   1 = attempting to stop crouching
   2 = crouching */
void Player::setCrouch(int c) {
    if (c == 2) {
        crouch = 2;
        setY(getY() + MARCUS_HEIGHT - CROUCH_HEIGHT);
    } else if (c == 1) {
        crouch = 1;
    } else if (c == 0) {
        crouch = 0;
        setY(getY() - MARCUS_HEIGHT + CROUCH_HEIGHT);
    }
}

// Override orient to give player crouching
void Player::orient() {
    if (crouch > 0)
        clipNo = ORIENT_CROUCH;
    else if (xVel < 0)
        clipNo = ORIENT_LEFT;
    else if (xVel > 0)
        clipNo = ORIENT_RIGHT;
    else if (yVel < 0)
        clipNo = ORIENT_BACK;
    else
        clipNo = ORIENT_FRONT;
}

int Player::getCrouch() {
    return crouch;
}

void Player::setWeapon(int weaponNo) {
    // Set the current active weapon
    weapon = weapons[weaponNo];
}

void Player::obtainWeapon(int weaponNo) {
    // Add a new weapon to the available weapons
    if (numWeapons < 10) {
        switch (weaponNo) {
            case 0:
                weapons[numWeapons] = new Weapon();
                break;
            case 1:
                weapons[numWeapons] = new Shotgun();
        }
        weapon = weapons[numWeapons];
        numWeapons++;
    }
}

void Player::attack() {
    // Perform an attack with the current weapon
    weapon->attack();
}