-
Notifications
You must be signed in to change notification settings - Fork 2
/
player.cpp.t13468
72 lines (65 loc) · 2.06 KB
/
player.cpp.t13468
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
#include "player.h"
#include "game.h"
#include "aabb.h"
#include <QDebug>
Player::Player(Game *game, int x, int y) : Entity(game, x, y, 32, 48)
{
speed = 2;
health = 5;
}
void Player::draw(QPainter *gl)
{
QRect texture;
QRectF bounds = boundingRect();
if(dx == 0 && dy==0){
texture = QRect(16*(game->STEPS/15%1), 6, 16, 24);
}
if(dy == 1 || (dy == 0 && ldy == 1)){
texture = QRect(16*(game->STEPS/15%(dy == 0 ? 1 : 4)), 6, 16, 24);
}
if(dy == -1 || (dy == 0 && ldy == -1)){
texture = QRect(16*(game->STEPS/15%(dy == 0 ? 1 : 4)), 69, 16, 24);
}
if(dx == 1 || (dx == 0 && ldx == 1)){
texture = QRect(16*(game->STEPS/15%(dx == 0 ? 1 : 4)), 38, 16, 24);
}
if(dx == -1|| (dx == 0 && ldx == -1)){
texture = QRect(16*(game->STEPS/15%(dx == 0 ? 1 : 4)), 102, 16, 24);
}
if((swing > 0 && dy == 0 && dx == 0 && ldx == 0 && ldy == 0) || (swing > 0 && (dy == 1 || ldy == 1))){
bounds=QRectF(-16,-2, 64,52);
texture = QRect(31*(3 - (swing/8%4)), 134, 32, 26);
}
if(swing > 0 && (dy == -1 || ldy == -1)){
bounds=QRectF(-16,-2, 64,52);
texture = QRect(31*(3 - (swing/8%4)), 166, 32, 26);
}
if(swing > 0 && (dx == 1 || ldx == 1)){
bounds=QRectF(-16,-2, 64,52);
texture = QRect(31*(3 - (swing/8%4)), 199, 32, 26);
}
if(swing > 0 && (dx == -1 || ldx == -1)){
bounds=QRectF(-16,-2, 64,52);
texture = QRect(31*(3 - (swing/8%4)), 230, 32, 26);
}
gl->drawImage(bounds, game->resource->player, texture);
}
void Player::update()
{
if(swing > 0)
swing--;
// Důležité pro pohyb (každý druh pohybu by měl mít vlastní funkci v entitě)
updateMove();
}
void Player::attack()
{
swing = 32;
QRect swingBox(x, y+height/2, width, height);
for(int i = 0; i < game->world->entities->count(); i++){
Entity *entity = game->world->entities->at(i);
AABB collision(swingBox, entity->collisionRect());
if(collision.collide){
qDebug() << "Koliduje";
}
}
}