1 | // |
---|
2 | // Orbital |
---|
3 | // |
---|
4 | // Copyright: (c) 2012 Various People |
---|
5 | // |
---|
6 | |
---|
7 | #if defined HAVE_CONFIG_H |
---|
8 | # include "config.h" |
---|
9 | #endif |
---|
10 | |
---|
11 | #if defined _WIN32 |
---|
12 | # include <direct.h> |
---|
13 | #endif |
---|
14 | |
---|
15 | #if USE_SDL && defined __APPLE__ |
---|
16 | # include <SDL_main.h> |
---|
17 | #endif |
---|
18 | |
---|
19 | #include "core.h" |
---|
20 | #include "loldebug.h" |
---|
21 | |
---|
22 | using namespace std; |
---|
23 | using namespace lol; |
---|
24 | |
---|
25 | #include "orbital.h" |
---|
26 | |
---|
27 | Orbital::Orbital() |
---|
28 | { |
---|
29 | for (int j = 0; j < 20; j++) |
---|
30 | { |
---|
31 | for (int i = 0; i < 20; i++) |
---|
32 | { |
---|
33 | m.SendCommand(((i + j) % 2) ? "sc.2,.6,.7,1,scb.2,.6,.7,1" |
---|
34 | : "sc.2,.2,.6,1,scb.2,.2,.6,1"); |
---|
35 | m.SendCommand("ac4,2,44,40,0,0,ty-1,ad4,40,0,ry45"); |
---|
36 | m.Scale(vec3(std::sqrt(0.5f))); |
---|
37 | m.Translate(vec3(i * 44 - 440, 0, j * 44 - 440)); |
---|
38 | m.Flush(); |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | /* Yellow sphere */ |
---|
43 | m.SendCommand("sc1,1,0,1,asph10,30,20,24"); |
---|
44 | m.SendCommand("t0,0,60,fl"); |
---|
45 | |
---|
46 | /* Pink box */ |
---|
47 | m.SendCommand("sc1,0,1,1,afcb10,10,10,1,rx45,rz45"); |
---|
48 | m.SendCommand("t-20,20,0,fl"); |
---|
49 | |
---|
50 | /* Large meteor */ |
---|
51 | m.SendCommand("sc0,0,0.3,1,afcb30,30,30,5,ry45,rx45,afcb30,30,30,5"); |
---|
52 | m.SendCommand("t40,40,0,fl"); |
---|
53 | |
---|
54 | /* Grey/red bonus */ |
---|
55 | m.SendCommand("sc0.6,0.7,0.8,1,afcb7,4,7,0.6,sc1,0,0.3,1,afcb4,7,4,0.6"); |
---|
56 | m.SendCommand("t-40,20,-30,fl"); |
---|
57 | |
---|
58 | /* Orange/white alien */ |
---|
59 | m.SendCommand("sc1,0.7,0,1,afcb12,3,10,0.4,tz3,sc1,1,1,1,afcb2,10,10,0.4"); |
---|
60 | m.SendCommand("rx20,ry30,t0,40,-20,fl"); |
---|
61 | |
---|
62 | /* Orange fire */ |
---|
63 | m.SendCommand("sc1,1,0,1,scb1,0,0,0,at4,1,s1.5,1,4,tz-13,ad6,5.8,1"); |
---|
64 | m.SendCommand("t-40,40,0,fl"); |
---|
65 | |
---|
66 | /* Lasers */ |
---|
67 | m.SendCommand("sc1,1,1,1,scb0,0,0,1,aq8,1,sx0.25,tx-3,sc1,0,0,1,scb0,0,0,1,aq8,1,tx4,sz50,sx0.3,tz-200,mx,as10,12,8,1,1,ty60,fl"); |
---|
68 | |
---|
69 | //m_particlesystem = new ParticleSystem(); |
---|
70 | //Ticker::Ref(m_particlesystem); |
---|
71 | |
---|
72 | /* Create a camera that matches the settings of XNA Orbital */ |
---|
73 | m_camera = new Camera(vec3(0, 50, 0), |
---|
74 | vec3(0, 0, 0), |
---|
75 | vec3(0, 0, -1)); |
---|
76 | m_camera->SetOrtho(1280.f / 3, 960.f / 3, -1000.f, 1000.f); |
---|
77 | Ticker::Ref(m_camera); |
---|
78 | |
---|
79 | /* Add tanks */ |
---|
80 | for (int j = 0; j < 10; j++) |
---|
81 | for (int i = 0; i < 10; i++) |
---|
82 | { |
---|
83 | m_tanks << new Tank(); |
---|
84 | m_tanks.Last()->m_position = vec3(i * 40.f - 250.f, 0, j * 40.f - 100.f); |
---|
85 | m_tanks.Last()->SetTarget(vec3(i * 80.f - 200.f, 0, j * 80.f - 130.f)); |
---|
86 | Ticker::Ref(m_tanks.Last()); |
---|
87 | } |
---|
88 | |
---|
89 | /* Add player */ |
---|
90 | for (int i = 0; i < 1; i++) |
---|
91 | { |
---|
92 | m_players << new Player(); |
---|
93 | Ticker::Ref(m_players.Last()); |
---|
94 | } |
---|
95 | |
---|
96 | m_auto_cam_timer = 0.0f; |
---|
97 | |
---|
98 | m_angle = vec3(0.f); |
---|
99 | m_angular_velocity = vec3(0.f); |
---|
100 | |
---|
101 | m_ready = false; |
---|
102 | } |
---|
103 | |
---|
104 | void Orbital::TickGame(float seconds) |
---|
105 | { |
---|
106 | WorldEntity::TickGame(seconds); |
---|
107 | |
---|
108 | if (Input::GetButtonState(27 /*SDLK_ESCAPE*/)) |
---|
109 | Ticker::Shutdown(); |
---|
110 | |
---|
111 | #if 0 |
---|
112 | if (m_auto_cam_timer > 0.0f) |
---|
113 | m_auto_cam_timer -= seconds; |
---|
114 | |
---|
115 | //Doing the query with actual values, cause I want to stay SDL-free for now. |
---|
116 | |
---|
117 | int HMovement = Input::GetButtonState(275 /*SDLK_RIGHT*/) - Input::GetButtonState(276 /*SDLK_LEFT*/); |
---|
118 | int VMovement = Input::GetButtonState(274 /*SDLK_DOWN*/) - Input::GetButtonState(273 /*SDLK_UP*/); |
---|
119 | int RMovement = Input::GetButtonState(280 /*SDLK_PAGEUP*/) - Input::GetButtonState(281 /*SDLK_PAGEDOWN*/); |
---|
120 | |
---|
121 | vec3 new_angular_velocity = vec3(0.0f); |
---|
122 | |
---|
123 | if (VMovement != 0 || HMovement != 0 || RMovement != 0) |
---|
124 | { |
---|
125 | new_angular_velocity = vec3(HMovement, VMovement, RMovement) * 50.0f; |
---|
126 | m_auto_cam_timer = 2.0f; |
---|
127 | } |
---|
128 | else if (m_auto_cam_timer <= 0.0f) |
---|
129 | { |
---|
130 | /* Order is yaw, pitch, roll */ |
---|
131 | new_angular_velocity = clamp(-m_angle, vec3(40.f, -20.f, -40.f), |
---|
132 | vec3(40.f, 20.f, 40.f)); |
---|
133 | } |
---|
134 | |
---|
135 | m_angular_velocity += (new_angular_velocity - m_angular_velocity) |
---|
136 | * (seconds / (seconds + 0.3f)); |
---|
137 | m_angle += m_angular_velocity * seconds; |
---|
138 | |
---|
139 | /* TODO: implement "vec3 % float" or "fmod(vec3, float)" */ |
---|
140 | for (int n = 0; n < 3; n++) |
---|
141 | { |
---|
142 | if (m_angle[n] > 180.f) |
---|
143 | m_angle[n] -= 360.f; |
---|
144 | else if (m_angle[n] < -180.f) |
---|
145 | m_angle[n] += 360.f; |
---|
146 | } |
---|
147 | |
---|
148 | /* Yaw around Y, Pitch around X, Roll around Z. Since it's the camera |
---|
149 | * we want to move, use the inverse transform. */ |
---|
150 | mat4 anim = mat4(1.f / quat::fromeuler_yxz(m_angle)); |
---|
151 | #endif |
---|
152 | |
---|
153 | m_model = mat4(1.f); |
---|
154 | } |
---|
155 | |
---|
156 | void Orbital::TickDraw(float seconds) |
---|
157 | { |
---|
158 | WorldEntity::TickDraw(seconds); |
---|
159 | |
---|
160 | if (!m_ready) |
---|
161 | { |
---|
162 | m.SendCommand("irb"); |
---|
163 | |
---|
164 | /* FIXME: this object never cleans up */ |
---|
165 | m_ready = true; |
---|
166 | } |
---|
167 | |
---|
168 | Video::SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f)); |
---|
169 | |
---|
170 | m.Render(m_model); |
---|
171 | } |
---|
172 | |
---|
173 | Orbital::~Orbital() |
---|
174 | { |
---|
175 | for (int i = 0; i < m_tanks.Count(); i++) |
---|
176 | Ticker::Unref(m_tanks[i]); |
---|
177 | for (int i = 0; i < m_players.Count(); i++) |
---|
178 | Ticker::Unref(m_players[i]); |
---|
179 | //Ticker::Unref(m_particlesystem); |
---|
180 | Ticker::Unref(m_camera); |
---|
181 | } |
---|
182 | |
---|
183 | int main(int argc, char **argv) |
---|
184 | { |
---|
185 | Application app("Orbital", ivec2(800, 600), 60.0f); |
---|
186 | |
---|
187 | #if defined _MSC_VER && !defined _XBOX |
---|
188 | _chdir(".."); |
---|
189 | #elif defined _WIN32 && !defined _XBOX |
---|
190 | _chdir("../.."); |
---|
191 | #endif |
---|
192 | |
---|
193 | new DebugFps(5, 5); |
---|
194 | new Orbital(); |
---|
195 | app.ShowPointer(false); |
---|
196 | |
---|
197 | app.Run(); |
---|
198 | |
---|
199 | return EXIT_SUCCESS; |
---|
200 | } |
---|
201 | |
---|