Repository navigation
Expand file tree
/
Copy pathcursor.cpp
More file actions
95 lines (73 loc) · 1.83 KB
/
Copy pathcursor.cpp
File metadata and controls
95 lines (73 loc) · 1.83 KB
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
#include"cursor.h"
#include <iostream>
cursor::cursor() {
std::cout << "default constructor obsolete, please call cursor(const sf::Texture * image_)\n";
}
cursor::cursor(const sf::Texture * image_){
tileSprite = sf::Sprite();
tileSprite.setTexture(*image_);
posX = posY = 0;
tileSprite.setPosition(posX, posY);
movCooldown = true;
stackInd = 0;
}
cursor::cursor(const cursor& A) {
tileSprite = A.tileSprite;
posX = A.posX;
posY = A.posY;
movCooldown = A.movCooldown;
cursTimer = A.cursTimer;
cursTrigger = A.cursTrigger;
stackInd = A.stackInd;
}
cursor::~cursor(){
std::cout << "cursor deletion called\n";
}
cursor * cursor::clone() {
return new cursor(*this);
}
void cursor::print() {
std::cout << "cursor print called\n";
}
bool cursor::getCooldown() {
return movCooldown;
}
bool cursor::burnCooldown() {
movCooldown = false;
cursTimer = std::chrono::duration_cast<std::chrono::nanoseconds>(cursTimer).zero();
}
void cursor::moveX(int64_t moveX) {
uint64_t newX = moveX + posX;
if (movCooldown && newX >= 0 && newX <= 384-16) {
tileSprite.setPosition(newX, posY);
posX += moveX;
burnCooldown();
}
}
void cursor::moveY(int64_t moveY) {
uint64_t newY = moveY + posY;
if (movCooldown && newY >= 0 && newY <= 384-16) {
tileSprite.setPosition(posX, newY);
posY = newY;
burnCooldown();
}
}
// an absolute variant to be used by buisness logic, not ui directly as it doesnt use cooldowns.
void cursor::moveXAbs(int64_t moveX) {
if(moveX >= 0) {
posX = moveX;
}
}
//an absolute variant
void cursor::moveYAbs(int64_t moveY) {
if(moveY >= 0) {
posY = moveY;
}
}
void cursor::updateTimer(std::chrono::nanoseconds timer) {
cursTimer += timer;
if ( cursTimer >= cursTrigger && !movCooldown) {
movCooldown = true;
cursTimer = std::chrono::duration_cast<std::chrono::nanoseconds>(cursTimer).zero();
}
}