-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBall.cpp
More file actions
40 lines (36 loc) · 864 Bytes
/
Ball.cpp
File metadata and controls
40 lines (36 loc) · 864 Bytes
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
/*
* File: Ball.cpp
* Author: iMer
*
* Created on 21. März 2015, 18:23
*/
#include "Ball.hpp"
#include "Engine/Scene.hpp"
#include "Engine/Game.hpp"
#include "LevelScene.hpp"
#include "Engine/util/Random.hpp"
Ball::Ball(engine::Scene* scene): SpriteNode(scene) {
}
Ball::~Ball() {
}
void Ball::OnUpdate(sf::Time interval) {
engine::SpriteNode::OnUpdate(interval);
auto pos = GetGlobalPosition();
if (pos.x < 0) {
((LevelScene*)m_scene)->AddPoint(true);
Delete();
}else if (pos.x > GetScene()->GetGame()->GetWindow()->getSize().x) {
((LevelScene*)m_scene)->AddPoint(false);
Delete();
}
}
bool Ball::initialize(Json::Value& root) {
if (!engine::SpriteNode::initialize(root)) {
return false;
}
engine::util::RandomFloat rand(-1, 1);
b2Vec2 f;
f.x = rand() > 0 ? 100 : -100;
f.y = rand()*100;
GetBody()->ApplyForceToCenter(f, true);
}