-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPUTileMapData.cpp
More file actions
86 lines (77 loc) · 2.23 KB
/
Copy pathCPUTileMapData.cpp
File metadata and controls
86 lines (77 loc) · 2.23 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
#include "CPUTileMapData.h"
#include <iostream>
CPUTileMapData::CPUTileMapData() {
Quit = false; // Game loop is initially on (hence this is false)
V = std::vector<uint8_t>(16); // 16 empty registers
// Initialise all values in keys array to false
for (std::size_t i = 0; i < 16; i++) {
keysDown[i] = false;
}
resetKeyUps(); // Initialise all key ups to true
}
// Check if user clicked to exit
bool CPUTileMapData::getExitStatus() {
return Quit;
}
// Set quit to its new status (user may have chose to close game)
void CPUTileMapData::setExitStatus(bool quitStatus) {
Quit = quitStatus;
}
// Get one of the chosen variable registers (0-F)
uint8_t CPUTileMapData::getVRegister(std::size_t vRegister) {
if (0 <= vRegister && vRegister < 16) {
return V[vRegister];
}
else {
std::cout << "Error: Invalid variable register access in get method" << "\n";
return 0;
}
}
// Set one of the registers to its new value
void CPUTileMapData::setVRegister(std::size_t vRegister, uint8_t registerData) {
if (0 <= vRegister && vRegister < 16) {
V[vRegister] = registerData;
}
else {
std::cout << "Error: Invalid variable register access in set method" << "\n";
}
}
// Get current key status (if pressed or not)
bool CPUTileMapData::getKeyPress(std::size_t keyPressIndex) {
if (0 <= keyPressIndex && keyPressIndex < 16) {
return keysDown[keyPressIndex];
}
else {
std::cout << "Error: Invalid key access in get method" << "\n";
return 0;
}
}
// Set key to true or false if pressed
void CPUTileMapData::setKeyPress(std::size_t keyPressIndex, bool keyPress) {
if (0 <= keyPressIndex && keyPressIndex < 16) {
// set to true if user released key
if (keyPress == false) {
keysUp[keyPressIndex] = true;
}
keysDown[keyPressIndex] = keyPress;
}
else {
std::cout << "Error: Invalid key access in set method" << "\n";
}
}
// Reset all keys that have been released after sometime
void CPUTileMapData::resetKeyUps() {
for (std::size_t i = 0; i < 16; i++) {
keysUp[i] = false;
}
}
// check if key has been released
uint8_t CPUTileMapData::checkKeyUp(std::size_t keyUpIndex) {
if (0 <= keyUpIndex && keyUpIndex < 16) {
return keysUp[keyUpIndex];
}
else {
std::cout << "Error: Invalid key access in key up method" << "\n";
return 0;
}
}