Code: Select all
#include <iostream>
#include "irrlicht.h"
#include <windows.h>
#define PI 3.14159265
#define PATH "D:/projetos/CuteKiller/"
using namespace std;
using namespace irr;
using namespace gui;
using namespace core;
using namespace scene;
using namespace video;
int x=0,
y=0,
z=0,
mp=0,
sr=0,
rtt=0,
ree=0,
veloc=0,
velocl=1,
v=10,
zoom = 40;
bool mouseDownL;
bool mouseDownM;
bool mouseDownR;
f32 lastWheelMovement;
f32 LastMouseX;
position2d<f32> cursor;
bool keys[KEY_KEY_CODES_COUNT];
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent (const SEvent &event )
{
if ( event.EventType == EET_KEY_INPUT_EVENT )
{
keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
return true;
}
if (event.EventType == EET_MOUSE_INPUT_EVENT)
{
// left mouse button state check
if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) mouseDownL = true;
if(event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP) mouseDownL = false;
// middle mouse button state check
//if(event.MouseInput.Event == EMIE_MMOUSE_PRESSED_DOWN) mouseDownM = true;
//if(event.MouseInput.Event == EMIE_MMOUSE_LEFT_UP) mouseDownM = false;
// mouse wheel
if(event.MouseInput.Event == EMIE_MOUSE_WHEEL)
{
//while(EMIE_MOUSE_WHEEL){
lastWheelMovement = event.MouseInput.Wheel;
//}
/*zoom -= -event.MouseInput.Wheel * (zoom / 20) * 2;
if(zoom < 10) zoom = 10;
if(zoom > 300) zoom = 300;*/
}
// right mouse button state check
if(event.MouseInput.Event == EMIE_RMOUSE_PRESSED_DOWN)
{
/*mouseDownR = true;
cursorOld.X = event.MouseInput.X;
cursorOld.Y = event.MouseInput.Y;
cursorDelta.X = 0;
cursorDelta.Y = 0;
cameraOrbitOld = cameraOrbit;
cameraAngleOld = cameraAngle;*/
}
//endroit ou mettre la remise a zéro de la position
if(event.MouseInput.Event == EMIE_RMOUSE_LEFT_UP) mouseDownR = false;
// mouse move check
if(event.MouseInput.Event == EMIE_MOUSE_MOVED)
{
//cursor.X = 0;
cursor.X = event.MouseInput.X;
// add condition that right mouse button be down
if(mouseDownR == true)
{
/*cursor.X = event.MouseInput.X;
cursor.Y = event.MouseInput.Y;
cursorDelta.X = cursor.X - cursorOld.X;
cursorDelta.Y = cursor.Y - cursorOld.Y;
if(cursorDelta.Y > 100) cursorDelta.Y = 100;
if(cursorDelta.Y < -100) cursorDelta.Y = -100;
cameraOrbit = (int)(cameraOrbitOld + cursorDelta.X) % 360;
cameraAngle = (int)(cameraAngleOld + cursorDelta.Y) % 360;
if(cameraAngle > 88) cameraAngle = 88;
if(cameraAngle < -88) cameraAngle = -88;*/
}
}
return false;
}
return false;
}
};
void mouseread(){
}
int main()
{
veloc=velocl;
IrrlichtDevice *device =
createDevice(EDT_BURNINGSVIDEO, dimension2d<s32>(800, 600), 6, false, true);
MyEventReceiver receiver;
device->setEventReceiver(&receiver);
device->setWindowCaption(L"Green 3D");
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
IAnimatedMesh* mesh = smgr->getMesh(PATH"sydney.md2");
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
if (node) {
node->setMaterialFlag(EMF_LIGHTING, true);
node->setMD2Animation ( scene::EMAT_STAND );
node->setMaterialTexture( 0, driver->getTexture(PATH"sydney.bmp"));
}
if (node)
node->setPosition(core::vector3df(0,-40,0));
node->addShadowVolumeSceneNode(0,true,100.0f);
smgr->setShadowColor(video::SColor(220,0,0,0));
device->getFileSystem()->addZipFileArchive(PATH"map-20kdm2.pk3");
scene::IAnimatedMesh* meshmap = smgr->getMesh(PATH"20kdm2.bsp");
scene::ISceneNode* nodemap = 0;
if (meshmap) nodemap = smgr->addOctTreeSceneNode(meshmap->getMesh(0));
if (nodemap) nodemap->setPosition(core::vector3df(-1300,-144,-1249));
scene::ITriangleSelector* selector = 0;
if (nodemap)
{
nodemap->setPosition(core::vector3df(-1350,-130,-1400));
selector = smgr->createOctTreeTriangleSelector(meshmap->getMesh(0), nodemap, 128);
nodemap->setTriangleSelector(selector);
selector->drop();
}
if (node)
{
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
selector, node, core::vector3df(10,25,10),
core::vector3df(0,-2,0), // gravidade
core::vector3df(0,0,0));
node->addAnimator(anim);
anim->drop();
node->setLoopMode(true);
}
ICameraSceneNode* principalcam;
principalcam = smgr->addCameraSceneNode(node,core::vector3df(-100,zoom,0),core::vector3df(0,0,0));
ISceneNode * light = smgr->addLightSceneNode( 0, vector3df( 30, 140,0), SColorf(1.f, 1.f, 1.f,0.f), 600.f);
light->setParent(node);
while(device->run())
{
driver->beginScene(true, true, SColor(255,100,101,140));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
rtt--;
cout << cursor.X << "\n";
if(mp!=0)
{
if(rtt<=1)
{
node->setMD2Animation ( scene::EMAT_STAND );
mp=0;
}
}
if(veloc>1)
veloc--;
if(cursor.X > 420)
{
if(veloc<2)
{
sr+=v;
veloc=velocl/2;
}
}
if(cursor.X < 380)
{
if(veloc<2)
{
sr-=v;
veloc=velocl/2;
}
}
if(keys[KEY_KEY_W])
{
if(veloc<2)
{
vector3df vr = node->getRotation();
vector3df vp = node->getPosition();
vp.X += v*cos(vr.Y*PI/180);
vp.Z -= v*sin(vr.Y*PI/180);
node->setPosition(vp);
veloc=velocl;
}
rtt=3;
if(mp!=1)
{
node->setMD2Animation ( scene::EMAT_RUN );
mp=1;
}
}
if(keys[KEY_KEY_S])
{
if(veloc<2)
{
vector3df vr = node->getRotation();
vector3df vp = node->getPosition();
vp.X -= cos(vr.Y*PI/180);
vp.Z += sin(vr.Y*PI/180);
node->setPosition(vp);
veloc=velocl;
}
rtt=3;
if(mp!=1)
{
node->setMD2Animation ( scene::EMAT_RUN );
mp=1;
}
}
if(keys[KEY_SPACE])
{
rtt=10;
if(mp!=3)
{
node->setMD2Animation ( scene::EMAT_JUMP );
mp=3;
}
}
if(keys[KEY_BACK])
{
cout << "OI" << zoom << " " << lastWheelMovement << "\n";
}
if (EMIE_MOUSE_WHEEL){
if(lastWheelMovement > 0){
cout << "OI" << zoom << " " << EMIE_MOUSE_WHEEL << "\n";
zoom-= 20;
if (zoom <= 15) zoom = 15;
principalcam = smgr->addCameraSceneNode(node,core::vector3df(-100,zoom,0),core::vector3df(0,0,0));
lastWheelMovement = 0;
}
if(lastWheelMovement < 0){
cout << "OI" << zoom << " " << EMIE_MOUSE_WHEEL << "\n";
zoom+= 20;
if (zoom >= 100) zoom = 100;
principalcam = smgr->addCameraSceneNode(node,core::vector3df(-100,zoom,0),core::vector3df(0,0,0));
lastWheelMovement = 0;
}
}
node->setRotation(core::vector3df(0,sr,0));
principalcam->setTarget(node->getPosition());
}
device->drop();
return 0;
}