source: trunk/mrpigeon/mrpigeon.cpp @ 1300

Last change on this file since 1300 was 1300, checked in by sam, 8 years ago

core: prefix some member variables with m_ for clarity.

  • Property svn:keywords set to Id
File size: 4.8 KB
Line 
1//
2// MrPigeon
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 "debug/fps.h"
21
22using namespace std;
23using namespace lol;
24
25#include "mrpigeon.h"
26#include "player.h"
27#include "enemy.h"
28#include "blueenemy.h"
29#include "redenemy.h"
30
31MrPigeon::MrPigeon() :
32    totaltime(0.0f),
33    railtime(0.0f),
34    backtime(0.0f),
35    speed(1.0f)
36{
37    player = new Player(this);
38    Ticker::Ref(player);
39
40    for (int i = 0; i < 10; i++)
41        enemies[i] = NULL;
42
43    hud_progress = Tiler::Register("mrpigeon/gfx/HUD_timeline.png", ivec2(160,16), ivec2(0));
44    hud_arrow = Tiler::Register("mrpigeon/gfx/HUD_timelineArrow.png", ivec2(16,16), ivec2(0));
45
46    deco_campagneback = Tiler::Register("mrpigeon/gfx/DECO_campagneBack.png", ivec2(144,168), ivec2(0));
47    deco_cityback = Tiler::Register("mrpigeon/gfx/DECO_cityBack3x.png", ivec2(96,96), ivec2(0));
48    deco_citybackdefense = Tiler::Register("mrpigeon/gfx/DECO_cityBackDefense3X.png", ivec2(288,96), ivec2(0));
49    deco_citybackpav = Tiler::Register("mrpigeon/gfx/DECO_cityBackPav3X.png", ivec2(192,96), ivec2(0));
50    deco_floorrails = Tiler::Register("mrpigeon/gfx/DECO_floorRails3x.png", ivec2(72,24), ivec2(0));
51
52    m_position = vec3(0, 0, 0);
53    m_bbox[0] = m_position;
54    m_bbox[1] = vec3(512, 384, 0);
55    Input::TrackMouse(this);
56}
57
58void MrPigeon::TickGame(float deltams)
59{
60    WorldEntity::TickGame(deltams);
61
62    totaltime += deltams;
63
64    if (totaltime > 100000.0f)
65    {
66        speed = 1.8f;
67        active_deco = deco_citybackpav;
68        active_deco_width = 192;
69    }
70    else if (totaltime > 49000.0f)
71    {
72        speed = 1.5f;
73        active_deco = deco_citybackdefense;
74        active_deco_width = 288;
75    }
76    else if (totaltime > 18000.0f)
77    {
78        speed = 1.2f;
79        active_deco = deco_cityback;
80        active_deco_width = 96;
81    }
82    else
83    {
84        speed = 1.0f;
85        active_deco = deco_campagneback;
86        active_deco_width = 144;
87    }
88
89    deltams *= GetSpeed();
90
91    /* Delete enemies that went past us */
92    for (int i = 0; i < 10; i++)
93    {
94        if (enemies[i] && enemies[i]->m_position.x < -100.0f)
95        {
96            Ticker::Unref(enemies[i]);
97            enemies[i] = NULL;
98        }
99    }
100
101    /* Spawn enemies if necessary */
102    spawntime += deltams;
103    if (spawntime > 600.0f)
104    {
105        if (RandF(1.0f) < 0.2f)
106            spawntime -= 300.0f;
107        spawntime -= 600.0f;
108        for (int i = 0; i < 10; i++)
109        {
110            if (enemies[i] == NULL)
111            {
112                if (RandF(1.0f) < 0.4f)
113                    enemies[i] = new BlueEnemy(this);
114                else if (totaltime > 9000.0f && RandF(1.0f) < 0.3f)
115                    enemies[i] = new RedEnemy(this);
116
117                if (enemies[i])
118                    Ticker::Ref(enemies[i]);
119                break;
120            }
121        }
122    }
123
124    /* Scroll background etc. */
125    railtime = fmod(railtime + deltams, 1000.0f);;
126    backtime = fmod(backtime + deltams, 10000.0f / 288 * active_deco_width);;
127
128    ivec3 buttons = Input::GetMouseButtons();
129    if (buttons[0] || buttons[1])
130    {
131        if (!action)
132            player->Action();
133        action = 1;
134    }
135    else
136        action = 0;
137
138    if (buttons[2])
139        Ticker::Shutdown();
140}
141
142void MrPigeon::TickDraw(float deltams)
143{
144    WorldEntity::TickDraw(deltams);
145
146    Video::SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));
147
148    Scene::GetDefault()->AddTile(hud_progress, 0, ivec3(18, 3, 0), 0, vec2(3.0f));
149
150    int n = (int)(totaltime * 372 / 156000.0f);
151    if (n > 372)
152        n = 372;
153    Scene::GetDefault()->AddTile(hud_arrow, 0, ivec3(48 + n, 18, 10), 0, vec2(3.0f));
154
155    for (int i = -(int)(backtime * 288 / 5000.0f); i < 512 + active_deco_width; i += active_deco_width)
156        Scene::GetDefault()->AddTile(active_deco, 0, ivec3(i, 300, 0), 0, vec2(1.0f));
157
158    for (int i = -(int)(railtime * 72 / 1000.0f); i < 512 + 72; i += 72)
159        Scene::GetDefault()->AddTile(deco_floorrails, 0, ivec3(i, 57, 0), 0, vec2(1.0f));
160}
161
162MrPigeon::~MrPigeon()
163{
164    Tiler::Deregister(hud_progress);
165    Tiler::Deregister(hud_arrow);
166
167    Tiler::Deregister(deco_campagneback);
168    Tiler::Deregister(deco_cityback);
169    Tiler::Deregister(deco_citybackdefense);
170    Tiler::Deregister(deco_citybackpav);
171    Tiler::Deregister(deco_floorrails);
172
173    Ticker::Unref(player);
174    for (int i = 0; i < 10; i++)
175        if (enemies[i])
176            Ticker::Unref(enemies[i]);
177
178    Input::UntrackMouse(this);
179}
180
181int main(int argc, char **argv)
182{
183    Application app("MrPigeon", ivec2(512,384), 60.0f);
184
185#if defined _WIN32 && !defined _XBOX
186    _chdir(".."); /* Temporary Win32 hack */
187#endif
188
189    new DebugFps(2, 370);
190    new MrPigeon();
191    app.ShowPointer(false);
192    app.Run();
193
194    return EXIT_SUCCESS;
195}
196
Note: See TracBrowser for help on using the repository browser.