source: trunk/orbital/orbital.cpp @ 1354

Last change on this file since 1354 was 1354, checked in by sam, 11 years ago

orbital: add second player, option drone meshes, and animate the drones.

File size: 5.3 KB
Line 
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
22using namespace std;
23using namespace lol;
24
25#include "orbital.h"
26
27Orbital::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.0,.1,.2,1,scb.0,.1,.2,1"
34                                        : "sc.0,.0,.1,1,scb.0,.0,.1,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("t0,40,-20,fl");
61    //m.SendCommand("rx20,ry30,t0,40,-20,fl");
62
63    /* Orange fire */
64    m.SendCommand("sc1,1,0,1,scb1,0,0,0,at4,1,s1.5,1,4,tz-13,ad6,5.8,1");
65    m.SendCommand("t-40,40,0,fl");
66
67    /* Lasers */
68    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");
69
70    //m_particlesystem = new ParticleSystem();
71    //Ticker::Ref(m_particlesystem);
72
73    /* Create a camera that matches the settings of XNA Orbital */
74    m_camera = new Camera(vec3(0.f, 600.f, 50.f),
75                          vec3(0.f, 0.f, 50.f),
76                          vec3(0, 0, -1));
77    m_camera->SetRotation(quat::fromeuler_yxz(0.f, -30.f, 0.f));
78    m_camera->SetOrtho(1280.f / 3, 960.f / 3, -1000.f, 1000.f);
79    Ticker::Ref(m_camera);
80
81    /* Add tanks */
82    for (int j = 0; j < 5; j++)
83    for (int i = 0; i < 5; i++)
84    {
85        m_tanks << new Tank();
86        m_tanks.Last()->m_position = vec3(i * 80.f - 250.f, 0, j * 80.f - 100.f);
87        m_tanks.Last()->SetTarget(vec3(i * 160.f - 200.f, 0, j * 160.f - 130.f));
88        Ticker::Ref(m_tanks.Last());
89    }
90
91    /* Add player */
92    for (int i = 0; i < 2; i++)
93    {
94        m_players << new Player(i);
95        Ticker::Ref(m_players.Last());
96    }
97
98    m_auto_cam_timer = 0.0f;
99
100    m_angle = vec3(0.f);
101    m_angular_velocity = vec3(0.f);
102
103    m_ready = false;
104}
105
106void Orbital::TickGame(float seconds)
107{
108    WorldEntity::TickGame(seconds);
109
110    if (Input::GetButtonState(27 /*SDLK_ESCAPE*/))
111        Ticker::Shutdown();
112
113#if 0
114    if (m_auto_cam_timer > 0.0f)
115        m_auto_cam_timer -= seconds;
116
117    //Doing the query with actual values, cause I want to stay SDL-free for now.
118
119    int HMovement = Input::GetButtonState(275 /*SDLK_RIGHT*/) - Input::GetButtonState(276 /*SDLK_LEFT*/);
120    int VMovement = Input::GetButtonState(274 /*SDLK_DOWN*/) - Input::GetButtonState(273 /*SDLK_UP*/);
121    int RMovement = Input::GetButtonState(280 /*SDLK_PAGEUP*/) - Input::GetButtonState(281 /*SDLK_PAGEDOWN*/);
122
123    vec3 new_angular_velocity = vec3(0.0f);
124
125    if (VMovement != 0 || HMovement != 0 || RMovement != 0)
126    {
127        new_angular_velocity = vec3(HMovement, VMovement, RMovement) * 50.0f;
128        m_auto_cam_timer = 2.0f;
129    }
130    else if (m_auto_cam_timer <= 0.0f)
131    {
132        /* Order is yaw, pitch, roll */
133        new_angular_velocity = clamp(-m_angle, vec3(40.f, -20.f, -40.f),
134                                               vec3(40.f,  20.f,  40.f));
135    }
136
137    m_angular_velocity += (new_angular_velocity - m_angular_velocity)
138                          * (seconds / (seconds + 0.3f));
139    m_angle += m_angular_velocity * seconds;
140
141    /* TODO: implement "vec3 % float" or "fmod(vec3, float)" */
142    for (int n = 0; n < 3; n++)
143    {
144        if (m_angle[n] > 180.f)
145            m_angle[n] -= 360.f;
146        else if (m_angle[n] < -180.f)
147            m_angle[n] += 360.f;
148    }
149
150    /* Yaw around Y, Pitch around X, Roll around Z. Since it's the camera
151     * we want to move, use the inverse transform. */
152    mat4 anim = mat4(1.f / quat::fromeuler_yxz(m_angle));
153#endif
154
155    m_model = mat4(1.f);
156}
157
158void Orbital::TickDraw(float seconds)
159{
160    WorldEntity::TickDraw(seconds);
161
162    if (!m_ready)
163    {
164        m.SendCommand("irb");
165
166        /* FIXME: this object never cleans up */
167        m_ready = true;
168    }
169
170    Video::SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));
171
172    m.Render(m_model);
173}
174
175Orbital::~Orbital()
176{
177    for (int i = 0; i < m_tanks.Count(); i++)
178        Ticker::Unref(m_tanks[i]);
179    for (int i = 0; i < m_players.Count(); i++)
180        Ticker::Unref(m_players[i]);
181    //Ticker::Unref(m_particlesystem);
182    Ticker::Unref(m_camera);
183}
184
185int main(int argc, char **argv)
186{
187    Application app("Orbital", ivec2(800, 600), 60.0f);
188
189#if defined _MSC_VER && !defined _XBOX
190    _chdir("..");
191#elif defined _WIN32 && !defined _XBOX
192    _chdir("../..");
193#endif
194
195    new DebugFps(5, 5);
196    new Orbital();
197    app.ShowPointer(false);
198
199    app.Run();
200
201    return EXIT_SUCCESS;
202}
203
Note: See TracBrowser for help on using the repository browser.