-
Notifications
You must be signed in to change notification settings - Fork 0
/
buttonblock.cpp
51 lines (44 loc) · 1.02 KB
/
buttonblock.cpp
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
#include "buttonblock.h"
#include "robotgame.h"
ButtonBlock::ButtonBlock(const ButtonBlock& other) : Block(other)
{
this->state = other.state;
}
std::string ButtonBlock::GetDescription()
{
return "Button block. Returns 0 or 1 on its output depending on whether it's being pressed or not";
}
std::shared_ptr<olc::Sprite> ButtonBlock::GetDefaultSprite()
{
return this->sm->GetSprite("button");
}
ButtonBlock* ButtonBlock::Clone()
{
return new ButtonBlock(*this);
}
void ButtonBlock::HandleInput(bool isPointedAt, InputState* input)
{
if (isPointedAt)
this->state = input->lmb.bHeld;
else
this->state = false;
}
void ButtonBlock::Update(float timedelta)
{
Block::Update(timedelta);
if (this->state)
{
this->SetSprite("button_pressed");
this->ports["btn_value"]->Update(true);
}
else
{
this->SetSprite("button");
this->ports["btn_value"]->Update(false);
}
}
void ButtonBlock::Stop()
{
this->state = false;
this->SetSprite("button");
}