00001 00002 00003 00004 00005 00006 00007
00008
00009
00010 #ifndef DEMOACTIONENGINE_H
00011 #define DEMOACTIONENGINE_H
00012
00013 #include <PalmOS.h>
00014
00015 #include "Customization.h"
00016
00017 #include "ActionEngine.h"
00018 #include "Canvas.h"
00019 #include "HardKeyManager.h"
00020 #include "SpriteEngine.h"
00021 #include "SoundEngine.h"
00022
00023 00024 00025 00026 00027
00028 class DemoActionEngine : public ActionEngine
00029 {
00030 public:
00031
00032 DemoActionEngine() : ActionEngine()
00033 {
00034 sprite1 = new Sprite(2000, 2001, 42,75, true, Sprite::optBUFFER);
00035 sprite2 = new Sprite(2000, 2001, 42,75, true, Sprite::optBUFFER);
00036
00037 spriteGroup = new SpriteGroup(2);
00038 spriteGroup->addSprite(*sprite1);
00039 spriteGroup->addSprite(*sprite2);
00040 }
00041
00042
00043 ~DemoActionEngine()
00044 {
00045 }
00046
00047
00048 void restart()
00049 {
00050 state.periodCounter = state.lastMoved = 0;
00051 state.xCoord = 20;
00052 state.yCoord = 20;
00053 state.targetXCoord = -1;
00054
00055 SoundEngine::playSong(0);
00056 }
00057
00058
00059 void nextPeriod()
00060 {
00061 state.periodCounter++;
00062
00063
00064 if (state.targetXCoord != -1)
00065 {
00066 state.lastMoved = state.periodCounter;
00067
00068 state.xCoord = state.targetXCoord;
00069 state.yCoord = state.targetYCoord;
00070
00071 state.targetXCoord = -1;
00072 }
00073
00074
00075
00076 UInt32 keyState = HardKeyManager::getCurrentState();
00077
00078 if (keyState & (keyBitHard1 | keyBitHard2 | keyBitHard3 | keyBitHard4 | keyBitPageDown | keyBitPageUp))
00079 {
00080 state.lastMoved = state.periodCounter;
00081
00082 if (keyState & keyBitHard1)
00083 state.xCoord -= 5;
00084 else if (keyState & keyBitHard2)
00085 state.xCoord += 5;
00086
00087 if (keyState & keyBitPageDown)
00088 state.yCoord += 5;
00089 else if (keyState & keyBitPageUp)
00090 state.yCoord -= 5;
00091
00092
00093 if (keyState & keyBitHard3)
00094 {
00095 SoundEngine::playFx(0);
00096 sprite1->setVisibility(!(sprite1->isVisible()));
00097 }
00098
00099 if (keyState & keyBitHard4)
00100 sprite2->setVisibility(!(sprite2->isVisible()));
00101 }
00102
00103
00104
00105 if ((state.periodCounter - state.lastMoved) > 200)
00106 state.xCoord += 3;
00107
00108
00109
00110 state.xCoord %= 200;
00111 state.yCoord %= 200;
00112
00113 sprite1->move(state.xCoord, state.yCoord);
00114 sprite2->move(100 - state.xCoord, state.yCoord + 10);
00115 }
00116
00117
00118 WinLockInitType getWinLockMode() const
00119 {
00120 return winLockErase;
00121 }
00122
00123
00124 void draw(RectangleType *bounds) const
00125 {
00126
00127 spriteGroup->draw(bounds);
00128 }
00129
00130
00131 void receiveEvent(const EventType* evtPtr)
00132 {
00133 00134 00135 00136 00137
00138 }
00139
00140
00141
00142
00143 void* getRestoreStateBuffer()
00144 {
00145 return &state;
00146 }
00147
00148 void releaseRestoreStateBuffer(void* ) const
00149 {
00150
00151 }
00152
00153 void* getSaveStateBuffer()
00154 {
00155 return &state;
00156 }
00157
00158 void releaseSaveStateBuffer(void* ) const
00159 {
00160
00161 }
00162
00163 Int16 getStateBufferSize() const
00164 {
00165 return sizeof(state);
00166 }
00167
00168 void restoreState(void *stateBuffer)
00169 {
00170 ErrFatalDisplayIf(stateBuffer != &state, "State buffer mismatch!");
00171
00172 sprite1->move(state.xCoord, state.yCoord);
00173 sprite2->move(100 - state.xCoord, state.yCoord + 10);
00174 }
00175
00176
00177 private:
00178
00179 struct
00180 {
00181 UInt32 periodCounter;
00182 UInt32 lastMoved;
00183
00184 Coord xCoord;
00185 Coord yCoord;
00186
00187 Coord targetXCoord;
00188 Coord targetYCoord;
00189 } state;
00190
00191
00192 Sprite *sprite1;
00193 Sprite *sprite2;
00194 SpriteGroup *spriteGroup;
00195 };
00196
00197
00198 #endif