]>
Dogcows Code - chaz/yoink/blob - src/GameLayer.cc
2035248115869afdb4a42cb16647be34f29014d0
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>
33 #include <Moof/Video.hh>
35 #include "GameLayer.hh"
42 GameLayer::GameLayer() :
46 music
.setLooping(true);
47 music
.enqueue("NightFusionLoop");
50 heroine
= Heroine::alloc();
51 heroine
->animation
.startSequence("FlyDiagonallyUp");
53 Mf::Scalar a
[6] = {0.0, 1.5, -0.5, 3.0, -2.0, 1.0};
54 interp
.init(a
, 2.0, Mf::Interpolator::OSCILLATE
);
56 scene
= Scene::alloc("Classic");
64 void GameLayer::pushed(Mf::Engine
& engine
)
70 void GameLayer::update(Mf::Scalar t
, Mf::Scalar dt
)
73 heroine
->update(t
, dt
);
75 //camera.lookAt(heroine->getSphere().point);
76 camera
.setPosition(Mf::Vector3(-heroine
->current
.position
[0],
77 -heroine
->current
.position
[1], -256));
79 //Mf::Vector3 heroinePosition = Mf::promote(heroine->current.position);
80 //Mf::Sound::setListenerPosition(heroinePosition);
83 hud
->setBar1Progress(interp
.getState(dt
));
84 hud
->setBar2Progress(1.0 - interp
.getState(dt
));
88 void GameLayer::draw(Mf::Scalar alpha
) const
93 Mf::Texture::resetBind();
95 glEnableClientState(GL_VERTEX_ARRAY
);
96 glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
98 scene
->drawIfVisible(alpha
, camera
.getFrustum());
100 heroine
->draw(alpha
);
103 bool GameLayer::handleEvent(const Mf::Event
& event
)
108 if (event
.key
.keysym
.sym
== SDLK_SPACE
)
110 heroine
->animation
.startSequence("Flattened");
111 Mf::logInfo("thump!");
115 else if (event
.key
.keysym
.sym
== SDLK_p
)
120 else if (event
.key
.keysym
.sym
== SDLK_y
)
122 Mf::Engine::getInstance().pop();
127 return heroine
->handleEvent(event
);
129 case SDL_MOUSEMOTION
:
130 case SDL_MOUSEBUTTONDOWN
:
131 camera
.handleEvent(event
);
134 case SDL_VIDEORESIZE
:
135 setProjection(Mf::Scalar(event
.resize
.w
), Mf::Scalar(event
.resize
.h
));
143 void GameLayer::setProjection()
145 Mf::Video
& video
= Mf::Engine::getInstance().getVideo();
146 setProjection(video
.getWidth(), video
.getHeight());
149 void GameLayer::setProjection(Mf::Scalar width
, Mf::Scalar height
)
151 camera
.setProjection(cml::rad(60.0), width
/ height
, 32.0, 2500.0);
155 /** vim: set ts=4 sw=4 tw=80: *************************************************/
This page took 0.040546 seconds and 4 git commands to generate.