-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
158 lines (135 loc) · 3.94 KB
/
main.cpp
File metadata and controls
158 lines (135 loc) · 3.94 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
Name: Martin Cardozo
Copyright:
Author: Martin Cardozo
Date: 12/06/08 11:17
Description: Clase usada para testear a la clase ParticleSystem.h
*/
/************************
INCLUDES/GLOBAL STATICS
************************/
#include <allegro.h>
using namespace std;
#include "MathHelper.h"
//STATICS
MathHelper MathFunc;
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
#include "ParticleSystem.h"
/************************
PRIVATE VARIABLES
************************/
//FUNCTIONS
void init();
void deinit();
void checkInput();
//VARIABLES
ParticleSystem* Particulas;
int XInicial;
int deltaX;
int YInicial;
int deltaY;
int difX;
int difY;
//KEY VARIABLES
bool CONTROL;
bool MINUS;
bool PLUS;
bool Z;
bool X;
bool Q;
bool W;
bool S;
/************************
TIMER
************************/
//volatile double elapsed_time = 0;
//void __inc_elapsed_time() { elapsed_time += .001; }
//END_OF_FUNCTION(__inc_elapsed_time);
/************************
MAIN FUNCTION
************************/
int main() {
init();
Particulas = new ParticleSystem(0, 0, 0, 0, 0, 0, SCREEN_WIDTH, 50, SCREEN_HEIGHT, 5, 30, 1);
//maxParticles, X, Y, force, amplitude, minX, maxX, minY, maxY, elasticity, life, size
Particulas->start();
while (!key[KEY_ESC]) {
checkInput();
Particulas->draw();
}
deinit();
return 0;
};
END_OF_MAIN()
/************************
PRIVATE FUNCTIONS
************************/
void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1);
}
install_timer();
install_keyboard();
install_mouse();
//LOCK_VARIABLE(elapsed_time);
//LOCK_FUNCTION(__inc_elapsed_time);
//install_int_ex(__inc_elapsed_time, BPS_TO_TIMER(10));
};
void deinit() {
clear_keybuf();
};
void checkInput(){
//INCREMENTS/DECREMENTS
if (key[KEY_PLUS_PAD] && !PLUS){Particulas->incrementLifeTime();}
if (key[KEY_MINUS_PAD] && !MINUS){Particulas->decrementLifeTime();}
if (key[KEY_Z] && !Z){Particulas->decrementElasticity(); Z = true;}
if (key[KEY_X] && !X){Particulas->incrementElasticity(); X = true;}
if (key[KEY_Q] && !Q){Particulas->decrementSize(); Q = true;}
if (key[KEY_W] && !W){Particulas->incrementSize(); W = true;}
//- RELEASE KEY -//
if (!key[KEY_PLUS_PAD]){PLUS = false;}
if (!key[KEY_MINUS_PAD]){MINUS = false;}
if (!key[KEY_Z]){Z = false;}
if (!key[KEY_X]){X = false;}
if (!key[KEY_Q]){Q = false;}
if (!key[KEY_W]){W = false;}
//KILL
if (key[KEY_A]){Particulas->kill();}
//COLOR
if (key[KEY_S]){if (!S){Particulas->changeColor();S = true;}}
if (!key[KEY_S]){S = false;}
//RESIZE SCREEN/CHANGE PARAMETERS
if (key[KEY_LCONTROL]){CONTROL = true;}
if (!key[KEY_LCONTROL]){CONTROL = false;}
if (mouse_b & 1){ //RIGHT CLICK
Particulas->changePointer(0);
Particulas->incrementMaxParticles();
Particulas->setNewLocation(mouse_x, mouse_y);
}
if (mouse_b & 2){ //LEFT CLICK
Particulas->changePointer(1);
if (!XInicial) {XInicial = mouse_x;}
if (!YInicial) {YInicial = mouse_y;}
deltaX = (XInicial - mouse_x)+ difX;
deltaY = (YInicial - mouse_y)+ difY;
if (CONTROL){Particulas->setBounds(deltaX,deltaX,0,SCREEN_HEIGHT);}
Particulas->setAmplitude(deltaX);
Particulas->setForce(deltaY);
}
if (!mouse_b & 1){
Particulas->changePointer(0);
Particulas->setNewLocation(mouse_x, mouse_y);
difX = deltaX;
difY = deltaY;
XInicial = 0;
YInicial = 0;
}
};