-
Notifications
You must be signed in to change notification settings - Fork 0
/
UFOParticleSystem.cpp
97 lines (76 loc) · 2.58 KB
/
UFOParticleSystem.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <iostream>
#include <ctime>
#include <sstream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include "SOIL.h"
#include "skilLib.h"
#include "systems.h"
#include "components.h"
#include "messages.h"
#include <math.h>
#include "ld33.h"
extern Engine* theEngine;
const float PI = 3.141592654;
UFOParticleSystem::UFOParticleSystem(){
id = LD33_UFOPARTICLESYSTEM;
ufox = 0;
ufoy = 0;
toggleBeam = false;
toggleEngine = false;
beamActive = false;
engineActive = false;
}
void UFOParticleSystem::update(float delta){
for(int iterator = 0; iterator < numEntities(); iterator++){
Entity *ent = entityAt(iterator);
if(ent->hasComponent(LD33_ISUFOCOMPONENT)){
engineActive = ent->hasComponent(LD33_UFOFLYINGCOMPONENT);
beamActive = ent->hasComponent(LD33_UFOBEAMINGCOMPONENT);
Position* pos = static_cast<Position*>(ent->getComponent(COMPONENT_POSITION));
ufox = pos->getX();
ufoy = pos->getY();
}
if(engineActive && !toggleEngine){
Entity *tmpBurner = new Entity();
tmpBurner->addComponent(new Position(ufox, ufoy-5, -1));
tmpBurner->addComponent(new Dimensions(18, 11));
tmpBurner->addComponent(new Color(.85, 0, 0, .4));
tmpBurner->addComponent(new Property(LD33_UFOENGINEEFFECTCOMPONENT));
theEngine->addEntity(tmpBurner);
Entity *tmpBurner2 = new Entity();
tmpBurner2->addComponent(new Position(ufox, ufoy-5, -1));
tmpBurner2->addComponent(new Dimensions(12, 8));
tmpBurner2->addComponent(new Color(.85, .85, 0, .6));
tmpBurner2->addComponent(new Property(LD33_UFOENGINEEFFECTCOMPONENT));
theEngine->addEntity(tmpBurner2);
}
if(beamActive && !toggleBeam){
Entity *tmpBurner = new Entity();
tmpBurner->addComponent(new Position(ufox, ufoy-32, -1));
tmpBurner->addComponent(new Dimensions(18, 64));
tmpBurner->addComponent(new Color(.25, .85, 1, .4));
tmpBurner->addComponent(new Property(LD33_UFOBEAMEFFECTCOMPONENT));
theEngine->addEntity(tmpBurner);
}
toggleEngine = engineActive;
toggleBeam = beamActive;
if(ent->hasComponent(LD33_UFOBEAMEFFECTCOMPONENT) && !beamActive){
theEngine->removeEntity(iterator);
iterator--;
}
if(ent->hasComponent(LD33_UFOENGINEEFFECTCOMPONENT)){
Position *pos = static_cast<Position*>(ent->getComponent(COMPONENT_POSITION));
pos->setX(ufox);
pos->setY(ufoy-5);
}
if(ent->hasComponent(LD33_UFOENGINEEFFECTCOMPONENT) && !engineActive){
std::cout<<"Removed Engine";
theEngine->removeEntity(iterator);
iterator--;
}
}
}