-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlyingLogs.cpp
More file actions
43 lines (38 loc) · 1.47 KB
/
FlyingLogs.cpp
File metadata and controls
43 lines (38 loc) · 1.47 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
//
// Created by c on 6/19/24.
//
#include "FlyingLogs.h"
#include <iostream>
//Textures is taken from the website with free assets - https://gamecodeschool.com/gamemaker-studio/buiding-a-timberman-game-in-gamemaker-studio-2/
FlyingLogs::FlyingLogs(sf::RenderWindow &windowRef) :window(windowRef){
if(!logTexture.loadFromFile("assets/log.png"))
std::cerr << "ERROR: Log picture didn't open." << std::endl;
logWidth=120;
logHeight=75;
startPositionX=static_cast<float>(window.getSize().x)/2.0f;
startPositionY=static_cast<float>(window.getSize().y)-120-logHeight/2.0f;
velocityX=30.0f;
velocityY=5.0f;
}
void FlyingLogs::addLog(Side moveSide) {
logStruct tmp;
tmp.side=moveSide;
tmp.log.setSize(sf::Vector2f(logWidth,logHeight));
tmp.log.setPosition(startPositionX,startPositionY);
tmp.log.setOrigin(logWidth/2.0f,logHeight/2.0f);
tmp.log.setTexture(&logTexture);
logsVector.push_back(tmp);
}
void FlyingLogs::updateAndDraw() {
if(!logsVector.empty()) {
float firstLogPositionX=logsVector[0].log.getPosition().x;
if(firstLogPositionX<-logWidth*1.5 or firstLogPositionX>window.getSize().x+logWidth*1.5)
logsVector.erase(logsVector.begin());
}
for(auto it=logsVector.begin(); it!=logsVector.end(); ++it){
if(it->side==RIGHT) it->log.move(velocityX,-velocityY);
if(it->side==LEFT) it->log.move(-velocityX,-velocityY);
it->log.rotate(10);
window.draw(it->log);
}
}