-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWatermelonShooterPriceRectangle.cpp
More file actions
51 lines (45 loc) · 2.21 KB
/
Copy pathWatermelonShooterPriceRectangle.cpp
File metadata and controls
51 lines (45 loc) · 2.21 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
#include "WatermelonShooterPriceRectangle.h"
const int COOL_DOWN_TIME = 10;
const std::string PIC_PATH = "extrafile/5.png";
const std::string COOL_DOWN_PIC_PATH = "extrafile/5dark.png";
const float RECTANGLE_SCALE = .9f;
const int FIRST_RECTANGLE_X = 60;
const int FIRST_RECTANGLE_Y = 80;
const int RECTANGLE_NUM = 4;
WatermelonShooterPriceRectangle::WatermelonShooterPriceRectangle(){
coolDownTime = COOL_DOWN_TIME;
picturePath = PIC_PATH;
coolDownPicPath = COOL_DOWN_PIC_PATH;
}
void WatermelonShooterPriceRectangle::render(sf::RenderTarget& target){
if(clock.getElapsedTime().asSeconds() >= coolDownTime){
sf::Texture watermelonShooterCost;
watermelonShooterCost.loadFromFile(picturePath);
sf::Sprite watermelonShooterCostSprite;
watermelonShooterCostSprite.setTexture(watermelonShooterCost);
watermelonShooterCostSprite.setScale(RECTANGLE_SCALE , RECTANGLE_SCALE);
watermelonShooterCostSprite.setOrigin(watermelonShooterCost.getSize().x/2 , watermelonShooterCost.getSize().y/2);
watermelonShooterCostSprite.setPosition(FIRST_RECTANGLE_X ,FIRST_RECTANGLE_Y + RECTANGLE_NUM * watermelonShooterCost.getSize().y);
this->sprite = watermelonShooterCostSprite;
target.draw(watermelonShooterCostSprite);
}
else{
sf::Texture watermelonShooterCost;
watermelonShooterCost.loadFromFile(coolDownPicPath);
sf::Sprite watermelonShooterCostSprite;
watermelonShooterCostSprite.setTexture(watermelonShooterCost);
watermelonShooterCostSprite.setScale(RECTANGLE_SCALE , RECTANGLE_SCALE);
watermelonShooterCostSprite.setOrigin(watermelonShooterCost.getSize().x/2 , watermelonShooterCost.getSize().y/2);
watermelonShooterCostSprite.setPosition(FIRST_RECTANGLE_X ,FIRST_RECTANGLE_Y + RECTANGLE_NUM * watermelonShooterCost.getSize().y);
target.draw(watermelonShooterCostSprite);
}
}
bool WatermelonShooterPriceRectangle::isAbleToAdd(){
return clock.getElapsedTime().asSeconds() >= coolDownTime;
}
void WatermelonShooterPriceRectangle::startCoolDown(){
this->clock.restart();
}
bool WatermelonShooterPriceRectangle::isContains(sf::Vector2f addr){
return this->sprite.getGlobalBounds().contains(addr);
}