00001
00002 #pragma comment(lib, "../../../irrlicht-0.12.0/lib/Win32-VisualStudio/Irrlicht.lib")
00003 #pragma comment(lib, "../../../cal3d-0.10.0/bin/release/cal3d.lib")
00004
00005 #include <stdlib.h>
00006 #include <iostream>
00007 #include "irrlicht.h"
00008 #include "CCal3DSceneNode.h"
00009
00010 using namespace std;
00011 using namespace irr;
00012 using namespace core;
00013 using namespace scene;
00014 using namespace video;
00015 using namespace io;
00016 using namespace gui;
00017
00018 #define v3 vector3df
00019 #define LEVELPATH "levels/level_04.xml"
00020 #define MEDIAPATH_NUMBERS "media/numbers/" // append e.g. "0.png"
00021 #define MEDIAPATH "media/"
00022 #define MEDIAFILE_END_IMAGE "endImage.jpg"
00023
00024 #define STATE_GAME_START 2
00025 #define STATE_LEVEL_END 4
00026 #define STATE_PREPARENEXT_LEVEL 8
00027 #define STATE_PLAY 16
00028 #define STATE_DEATH 32
00029
00030
00031 extern IrrlichtDevice* device = 0;
00032 extern IVideoDriver* driver = 0;
00033 extern ISceneManager* smgr = 0;
00034 extern IGUIEnvironment* guienv = 0;
00035 extern ICameraSceneNode* cam = 0;
00036 extern ILightSceneNode* light = 0;
00037 extern IGUIStaticText* dbg = 0;
00038
00039 extern ISceneNode* skyBox = 0;
00040 extern ISceneNode* arrow = 0;
00041
00042 extern bool paused = false;
00043 extern bool renderOfflineAnim = false;
00044
00045 struct Obj
00046 {
00047 stringc name;
00048 IMesh* mesh;
00049 ISceneNode* node;
00050 v3 rot;
00051 };
00052 extern list<Obj*> objects;
00053 list<Obj*> objects;
00054
00055 struct SPlayer
00056 {
00057 CCal3DSceneNode* node;
00058 v3 velocity;
00059 v3 acceleration;
00060 CalQuaternion leftBone;
00061 CalQuaternion rightBone;
00062 } player;
00063
00064 extern ITimer* timer = 0;
00065 extern u32 levelTime = 0;
00066 extern u32 oldTime = 0;
00067 extern u32 now = 0;
00068 extern v3 nextRingPosition;
00069 v3 nextRingPosition;
00070 extern float direction = 0;
00071 extern float ydirection = 0;
00072 extern int gameState = STATE_GAME_START;
00073
00074 ITexture* numbers[10] = {0,0,0,0,0,0,0,0,0,0};
00075 IGUIImage* time[3] = {0,0,0};
00076 ITexture* endImgTexture = 0;
00077 IGUIImage* endImg = 0;
00078
00079 #include "tools.h"
00080 #include "controller.h"
00081 #include "level.h"
00082 #include "event.h"
00083
00084
00085
00086 int main()
00087 {
00088 int fps = 0;
00089 int lastFPS = 1;
00090 EventReceiver receiver;
00091
00092 device = createDevice(EDT_OPENGL, dimension2d<s32>(800, 600), 16, false, false, false, &receiver);
00093 driver = device->getVideoDriver();
00094 smgr = device->getSceneManager();
00095 guienv = device->getGUIEnvironment();
00096
00097 while(device->run())
00098 {
00099 switch (gameState)
00100 {
00101 case STATE_GAME_START:
00102 {
00103 reset();
00104 gameState = STATE_PREPARENEXT_LEVEL;
00105 break;
00106 }
00107
00108 case STATE_PREPARENEXT_LEVEL:
00109 {
00110 loadNextLevel();
00111
00112
00113
00114
00115
00116 gameState = STATE_PLAY;
00117 break;
00118 }
00119
00120 case STATE_PLAY:
00121 {
00122 update();
00123
00124 addDbg("----------------------------");
00125 addDbg("move player: MOUSE");
00126 addDbg("reset level: R");
00127 addDbg("pause/unpause game: P");
00128 addDbg("offline Anim on/off: A");
00129 addDbg("exit: ESC");
00130 addDbg("----------------------------");
00131 addDbg("");
00132 addDbg("camPos", cam->getPosition());
00133 addDbg("camRot", cam->getRotation());
00134 addDbg("");
00135 if (player.node)
00136 {
00137 addDbg("playerPos", player.node->getPosition());
00138 addDbg("playerRotation", player.node->getRotation());
00139 addDbg("playerAccel", player.acceleration);
00140 addDbg("playerVelo", player.velocity);
00141 addDbg("");
00142 CalQuaternion q;
00143 q = player.node->getBoneRotation(1);
00144 addDbg("bone right wing qaternion", q);
00145 q = player.node->getBoneRotation(2);
00146 addDbg("bone left wing qaternion", q);
00147 }
00148 addDbg("");
00149 addDbg("drawn triangles", (int) driver->getPrimitiveCountDrawn());
00150 addDbg("cam far points", cam->getFarValue());
00151
00152 guienv->getRootGUIElement()->bringToFront(dbg);
00153
00154 break;
00155 }
00156
00157 case STATE_LEVEL_END:
00158 {
00159 device->getCursorControl()->setVisible(true);
00160 for (int i=0; i<3; i++)
00161 {
00162 time[i]->setVisible(true);
00163 }
00164 endImg->setVisible(true);
00165 break;
00166 }
00167
00168 case STATE_DEATH:
00169 {
00170 break;
00171 }
00172 }
00173
00174
00175 driver->beginScene(true, true, SColor(255,100,101,140));
00176 smgr->drawAll();
00177 guienv->drawAll();
00178
00179 driver->endScene();
00180 clrDbg();
00181
00182 while(paused)
00183 {
00184 _sleep(10);
00185 if (!device->run()) break;
00186 }
00187
00188 fps = driver->getFPS();
00189 if (lastFPS != fps)
00190 {
00191 stringw str = L"Oelle - FPS:";
00192 str += fps;
00193 device->setWindowCaption(str.c_str());
00194 lastFPS = fps;
00195 }
00196 }
00197
00198 device->drop();
00199 return 0;
00200 }
00201