]>
Dogcows Code - chaz/yoink/blob - src/GameLayer.cc
a80946f6f5ff68fd393ad165734871eaa7ba8cf7
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() :
43 mMusic("BeatTheCube"),
46 mMusic
.setLooping(true);
47 mMusic
.enqueue("NightFusionLoop");
50 mHeroine
= Heroine::alloc();
51 mHeroine
->animation
.startSequence("FlyDiagonallyUp");
53 Mf::Scalar a
[6] = {0.0, 1.5, -0.5, 3.0, -2.0, 1.0};
54 mInterp
.init(a
, 2.0, Mf::Interpolator::OSCILLATE
);
56 mScene
= Scene::alloc("Classic");
64 void GameLayer::pushed(Mf::Engine
& engine
)
70 void GameLayer::update(Mf::Scalar t
, Mf::Scalar dt
)
72 mCamera
.update(t
, dt
);
73 mHeroine
->update(t
, dt
);
75 mScene
->checkForCollision(*mHeroine
);
77 mCamera
.setPosition(Mf::Vector3(-mHeroine
->getState().position
[0],
78 -mHeroine
->getState().position
[1], -256));
79 //mCamera.lookAt(Mf::promote(mHeroine->getState().position));
81 //Mf::Vector3 heroinePosition = Mf::promote(mHeroine->getState().position);
82 //Mf::Sound::setListenerPosition(heroinePosition);
84 mInterp
.update(t
, dt
);
85 mHud
->setBar1Progress(mInterp
.getState(dt
));
86 mHud
->setBar2Progress(1.0 - mInterp
.getState(dt
));
90 void GameLayer::draw(Mf::Scalar alpha
) const
92 mCamera
.uploadToGL(alpha
);
95 Mf::Texture::resetBind();
97 glEnableClientState(GL_VERTEX_ARRAY
);
98 glEnableClientState(GL_TEXTURE_COORD_ARRAY
);
100 mScene
->drawIfVisible(alpha
, mCamera
.getFrustum());
102 mHeroine
->draw(alpha
);
105 bool GameLayer::handleEvent(const Mf::Event
& event
)
110 if (event
.key
.keysym
.sym
== SDLK_SPACE
)
112 mHeroine
->animation
.startSequence("Flattened");
113 Mf::logInfo("thump!");
117 else if (event
.key
.keysym
.sym
== SDLK_p
)
122 else if (event
.key
.keysym
.sym
== SDLK_y
)
124 Mf::Engine::getInstance().pop();
129 return mHeroine
->handleEvent(event
);
131 case SDL_MOUSEMOTION
:
132 case SDL_MOUSEBUTTONDOWN
:
133 mCamera
.handleEvent(event
);
136 case SDL_VIDEORESIZE
:
137 setProjection(Mf::Scalar(event
.resize
.w
), Mf::Scalar(event
.resize
.h
));
145 void GameLayer::setProjection()
147 Mf::Video
& video
= Mf::Engine::getInstance().getVideo();
148 setProjection(video
.getWidth(), video
.getHeight());
151 void GameLayer::setProjection(Mf::Scalar width
, Mf::Scalar height
)
153 mCamera
.setProjection(cml::rad(60.0), width
/ height
, 32.0, 2500.0);
157 /** vim: set ts=4 sw=4 tw=80: *************************************************/
This page took 0.038788 seconds and 4 git commands to generate.