-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathkeyTile.cpp
More file actions
84 lines (81 loc) · 3.17 KB
/
Copy pathkeyTile.cpp
File metadata and controls
84 lines (81 loc) · 3.17 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
//
// Created by jtorreal on 11/24/20.
//
#include "keyTile.h"
KeyTile::KeyTile(int xP, int yP, char dir){
xPos = xP;
yPos = yP;
tileWidth = 16;
tileHeight = 16;
direction = dir;
clicked = false;
placed = false;
}
KeyTile::KeyTile(){}
int KeyTile::getXPos() {return xPos;}
int KeyTile::getYPos() {return yPos;}
bool KeyTile::isClicked() {return clicked;}
bool KeyTile::isPlaced() {return placed;}
void KeyTile::setIsClicked(bool val) {clicked = val;}
void KeyTile::setIsPlaced(bool val) {placed = val;}
void KeyTile::processInput(float mouseClickX, float mouseClickY, Player* player, Level* currentLevel, float offsetX, float offsetY){
//Update isPlaced and isClicked based on mouseClicked position
if(mouseClickX >= xPos && mouseClickX <= xPos + tileWidth && mouseClickY >= yPos && mouseClickY <= yPos+tileHeight && !clicked){
clicked = true;
}
else{
if(clicked){
if (currentLevel->getTile((int) ((mouseClickX)/tileWidth + offsetX), (int) ((mouseClickY)/tileHeight) + offsetY) == '.') {
currentLevel->setTile((int) ((mouseClickX)/tileWidth + offsetX), (int) ((mouseClickY)/tileHeight) + offsetY, direction);
placed = true;
switch(direction){
case 'l':
player->setXVel(0.0f);
player->setMoveLeft(false);
break;
case 'r':
player->setXVel(0.0f);
player->setMoveRight(false);
break;
case 'j':
player->setCanJump(false);
break;
}
}
}
clicked = false;
}
}
void KeyTile::draw(olc::PixelGameEngine* pge){
olc::Sprite *rightTile;
olc::Sprite *leftTile;
olc::Sprite *upTile;
olc::Sprite *rightClicked;
olc::Sprite *leftClicked;
olc::Sprite *upClicked;
rightTile = new olc::Sprite("/home/jtorreal/CLionProjects/StickyKeys/Images/right.png");
leftTile = new olc::Sprite("/home/jtorreal/CLionProjects/StickyKeys/Images/left.png");
upTile = new olc::Sprite("/home/jtorreal/CLionProjects/StickyKeys/Images/up.png");
rightClicked = new olc::Sprite("/home/jtorreal/CLionProjects/StickyKeys/Images/rightClicked.png");
leftClicked = new olc::Sprite("/home/jtorreal/CLionProjects/StickyKeys/Images/leftClicked.png");
upClicked = new olc::Sprite("/home/jtorreal/CLionProjects/StickyKeys/Images/upClicked.png");
//Check isPlaced and isClicked to determine where to draw
if(!placed && !clicked && direction == 'l'){
pge->DrawSprite(xPos, yPos, leftTile);
}
if(!placed && clicked && direction == 'l'){
pge->DrawSprite(xPos, yPos, leftClicked);
}
if(!placed && !clicked && direction == 'r'){
pge->DrawSprite(xPos, yPos, rightTile);
}
if(!placed && clicked && direction == 'r'){
pge->DrawSprite(xPos, yPos, rightClicked);
}
if(!placed && !clicked && direction == 'j'){
pge->DrawSprite(xPos, yPos, upTile);
}
if(!placed && clicked && direction == 'j'){
pge->DrawSprite(xPos, yPos, upClicked);
}
}