-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectileObject.cpp
More file actions
75 lines (63 loc) · 1.79 KB
/
Copy pathProjectileObject.cpp
File metadata and controls
75 lines (63 loc) · 1.79 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
#include "ProjectileObject.h"
#include <iostream>
#include "Animation.h"
#include "GameLevel.h"
#include "GameObject.h"
#include "EventDispatcher.h"
#include "GameObjectTerrainCollision.h"
#include "GameObjectTerrainCollision.h"
ProjectileObject::ProjectileObject(ProjectileType::Type type, CollidesWith::Type collisionType, GameObject* owner)
: m_Type( type )
, m_Owner( owner )
{
m_MovementEnabled = true;
setCollisionRect(sf::IntRect(0,0,10,10));
m_CollidesWith = collisionType;
}
ProjectileObject::~ProjectileObject()
{
if(m_LightSource)
{
m_GameLevel->getLightManager()->destroyLight(m_LightSource);
}
}
void ProjectileObject::update(float tick_ms, GameLevel* level)
{
m_Sprite.setPosition(m_Location);
getCurrentAnimation()->update(tick_ms);
updateLightLocation((int)getLocation().x,(int) getLocation().y);
if( m_GameLevel->isLocationInLevel( m_Location ) )
{
GameObjectTerrainCollision gotc(this);
m_Dispatcher->dispatchEvent(&gotc);
}
else
{
updateLocation(tick_ms, level, true); // has to be last, can cause ourselves to be deleted (oh my :o)
}
}
void ProjectileObject::init(EventDispatcher* dispatcher, GameLevel* game_level)
{
((GameObject*)(this))->init(dispatcher, game_level);
switch(m_Type)
{
case ProjectileType::PROJECTILE_BASIC:
{
registerAnimation("shot", "proj_basic");
setCurrentAnimation("shot");
break;
}
}
m_LightSource = LightSource::createRadialLightSource(sf::IntRect((int) getLocation().x, (int) getLocation().y, 50, 50), sf::Color::White);
m_LightSource->setOffset(-128, -84);
m_GameLevel->addLightSource(m_LightSource);
}
void ProjectileObject::notify(GameEvent* event)
{
switch(event->getEventType())
{
case Event::EVENT_GAMEOBJECT_TERRAIN_COLLISION:
{
}
}
}