]>
Dogcows Code - chaz/yoink/blob - src/GameLayer.cc
dfdadaa5f2c19fbe809193f9eebcc971569adfd6
2 /*******************************************************************************
4 Copyright (c) 2009, Charles McGarvey
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
10 * Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *******************************************************************************/
29 #include <Moof/Engine.hh>
30 #include <Moof/Log.hh>
31 #include <Moof/Math.hh>
32 #include <Moof/OpenGL.hh>
34 #include "GameLayer.hh"
41 GameLayer::GameLayer() :
42 music("NightFusionIntro"),
45 music
.setLooping(true);
46 music
.enqueue("NightFusionLoop");
49 heroine
= Character::alloc("RobotTrooper");
50 heroine
->getAnimation().startSequence("Run");
52 Mf::Scalar a
[6] = {0.0, 1.5, -0.5, 3.0, -2.0, 1.0};
53 interp
.init(a
, 2.0, Mf::Interpolator::OSCILLATE
);
55 Mf::Scalar b
[2] = {1.0, 0.0};
58 octree
= Mf::loadScene("Classic");
59 heroine
->treeNode
= octree
->insert(heroine
);
61 camera
.setProjection(cml::rad(60.0), 1.33333, 32.0, 2500.0);
62 camera
.uploadProjectionToGL();
66 void GameLayer::pushed(Mf::Engine
& engine
)
69 engine
.pushLayer(hud
);
73 void GameLayer::update(Mf::Scalar t
, Mf::Scalar dt
)
79 heroine
->update(t
, dt
);
82 heroine
->treeNode
= octree
->reinsert(heroine
, heroine
->treeNode
);
83 octree
->print(heroine
->treeNode
);
85 //camera.lookAt(heroine->getSphere().point);
86 camera
.setPosition(Mf::Vector3(-heroine
->current
.position
[0],
87 -heroine
->current
.position
[1], -256));
89 Mf::Vector3 heroinePosition
;
90 Mf::promoteVector(heroinePosition
, heroine
->current
.position
);
91 Mf::Sound::setListenerPosition(heroinePosition
);
94 hud
->setBar1Progress(interp
.getState(dt
));
95 hud
->setBar2Progress(1.0 - interp
.getState(dt
));
99 void GameLayer::draw(Mf::Scalar alpha
) const
101 glMatrixMode(GL_MODELVIEW
);
102 glLoadMatrix(camera
.getModelviewMatrix().data());
105 Mf::Texture::resetBind();
107 glEnableClientState(GL_VERTEX_ARRAY
);
108 glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
110 octree
->drawIfVisible(alpha
, camera
.getFrustum());
112 //heroine->draw(alpha);
113 heroine
->getAabb().draw();
117 glMatrixMode(GL_PROJECTION
);
120 glMatrixMode(GL_MODELVIEW
);
123 glColor4f(0.0f
, 0.0f
, 0.0f
, fadeIn
.getState(alpha
));
124 Mf::Texture::resetBind();
126 //glRectf(-1.0f, -1.0f, 1.0f, 1.0f);
128 glVertex3f(-1.0, -1.0, -0.1);
129 glVertex3f(1.0, -1.0, -0.1);
130 glVertex3f(1.0, 1.0, -0.1);
131 glVertex3f(-1.0, 1.0, -0.1);
136 glMatrixMode(GL_PROJECTION
);
138 glMatrixMode(GL_MODELVIEW
);
142 bool GameLayer::handleEvent(const Mf::Event
& event
)
147 if (event
.key
.keysym
.sym
== SDLK_SPACE
)
149 heroine
->getAnimation().startSequence("Punch");
150 Mf::logInfo("thump!");
154 else if (event
.key
.keysym
.sym
== SDLK_p
)
159 else if (event
.key
.keysym
.sym
== SDLK_y
)
161 Mf::Engine::getInstance().popLayer();
166 heroine
->handleEvent(event
);
169 case SDL_MOUSEMOTION
:
170 case SDL_MOUSEBUTTONDOWN
:
171 camera
.handleEvent(event
);
174 case SDL_VIDEORESIZE
:
175 glViewport(0, 0, event
.resize
.w
, event
.resize
.h
);
176 camera
.setProjection(cml::rad(60.0),
177 double(event
.resize
.w
) / double(event
.resize
.h
), 32.0, 2500.0);
178 camera
.uploadProjectionToGL();
186 /** vim: set ts=4 sw=4 tw=80: *************************************************/
This page took 0.043477 seconds and 3 git commands to generate.