EKA_JUMP_UP problem

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
cemedias
Posts: 17
Joined: Mon Jun 11, 2007 9:58 pm

EKA_JUMP_UP problem

Post by cemedias »

I'm having a problem with a FPS camera I put in my game. When I press space to jump, it doesnt stop jumping (as if the space key were stuck [which it isn't])

I made a custom keyMap for the camera, heres the code:

Code: Select all

	irr::SKeyMap keyMap[9];
    keyMap[0].Action = EKA_MOVE_FORWARD;
    keyMap[0].KeyCode = KEY_UP;
	keyMap[1].Action = EKA_MOVE_FORWARD;
	keyMap[1].KeyCode = KEY_KEY_W;

	keyMap[2].Action = EKA_MOVE_BACKWARD;
	keyMap[2].KeyCode = KEY_DOWN;
	keyMap[3].Action = EKA_MOVE_BACKWARD;
	keyMap[3].KeyCode = KEY_KEY_S;

	keyMap[4].Action = EKA_STRAFE_LEFT;
	keyMap[4].KeyCode = KEY_LEFT;
	keyMap[5].Action = EKA_STRAFE_LEFT;
	keyMap[5].KeyCode = KEY_KEY_A;

	keyMap[6].Action = EKA_STRAFE_RIGHT;
	keyMap[6].KeyCode = KEY_RIGHT;
	keyMap[7].Action = EKA_STRAFE_RIGHT;
	keyMap[7].KeyCode = KEY_KEY_D;

	keyMap[8].Action = EKA_JUMP_UP;
	keyMap[8].KeyCode = KEY_SPACE;



	scene::ICameraSceneNode* camera = 	
		smgr->addCameraSceneNodeFPS(0,100.0f,300.0f, -1, keyMap, 9, false, .5f);
	camera->setPosition(core::vector3df(0,0,0));
	
	// camera collision animation
	scene::ISceneNodeAnimator* anim =
		smgr->createCollisionResponseAnimator(
		selector, camera, core::vector3df(30,150,30),
		core::vector3df(0,-1.f,0),
		core::vector3df(0,50,0));
		camera->addAnimator(anim);
	anim->drop();
Any help would be greatly appreciated. Thanks.

P.S. I've been experimenting with the Irrlicht Engine, so I'm not very advanced at it and I wouldn't be surprised if it is something really simple that I forgot lol. (Hopefully it is simple ;) )
cemedias
Posts: 17
Joined: Mon Jun 11, 2007 9:58 pm

Post by cemedias »

Ooops. I'm really sorry, I fixed it. I just realized that I had some code in the OnEvent() to make it jump, and I forgot to remove that before I made my keyMap to do it. But it works now. Thanks.
cemedias
Posts: 17
Joined: Mon Jun 11, 2007 9:58 pm

Post by cemedias »

I have one more question. Is there anyway I can use my FPS camera, and make it so that when I hold down the spacebar it only jumps once?

BTW: sorry for the tripple post.
Dances
Posts: 454
Joined: Sat Jul 02, 2005 1:45 am
Location: Canada
Contact:

Post by Dances »

have a boolean value somewhere in a higher scope:

bool hasJumped = false;

if(hasJumped == false)
{
//jump code here
hasJumped = true;
}

and in your key stuff set hasJumped to false when the key is released.
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

or when user touches ground ;)
cemedias
Posts: 17
Joined: Mon Jun 11, 2007 9:58 pm

Post by cemedias »

Thanks for your posts.

I did what you said Dances, but then it does what I described in my first post, when the camera jumps continuously like the jump button is stuck. Here is some code
:

Keymap and Camera code:

Code: Select all

	irr::SKeyMap keyMap[9];
    keyMap[0].Action = EKA_MOVE_FORWARD;
    keyMap[0].KeyCode = KEY_UP;
	keyMap[1].Action = EKA_MOVE_FORWARD;
	keyMap[1].KeyCode = KEY_KEY_W;

	keyMap[2].Action = EKA_MOVE_BACKWARD;
	keyMap[2].KeyCode = KEY_DOWN;
	keyMap[3].Action = EKA_MOVE_BACKWARD;
	keyMap[3].KeyCode = KEY_KEY_S;

	keyMap[4].Action = EKA_STRAFE_LEFT;
	keyMap[4].KeyCode = KEY_LEFT;
	keyMap[5].Action = EKA_STRAFE_LEFT;
	keyMap[5].KeyCode = KEY_KEY_A;

	keyMap[6].Action = EKA_STRAFE_RIGHT;
	keyMap[6].KeyCode = KEY_RIGHT;
	keyMap[7].Action = EKA_STRAFE_RIGHT;
	keyMap[7].KeyCode = KEY_KEY_D;
	if(stw::hasJumped == false)
	{
		keyMap[8].Action = EKA_JUMP_UP;
		keyMap[8].KeyCode = KEY_SPACE;
		hasJumped = true;
	}
	
	scene::ICameraSceneNode* camera = 	
		smgr->addCameraSceneNodeFPS(0,100.0f,300.0f, -1, keyMap, 9, false, 1.f);
	camera->setPosition(core::vector3df(0,0,0));
	
	// camera collision animation
	scene::ISceneNodeAnimator* anim =
		smgr->createCollisionResponseAnimator(
		selector, camera, core::vector3df(30,150,30),
		core::vector3df(0,-3.f,0),
		core::vector3df(0,50,0));
		camera->addAnimator(anim);
	anim->drop();
OnEvent():

Code: Select all

	if(event.EventType == EET_KEY_INPUT_EVENT &&
		event.KeyInput.Key == KEY_SPACE &&
		event.KeyInput.PressedDown == false)
	{
		stw::hasJumped = false;
		return true;
	}

And I set hasJumped to false in my constructor of my class. I might not have understood your post correctly because i'm still pretty new to Irrlicht and programming in general. And I might have done something wrong with my class because I just started experimenting with them. Any help would be great, thanks!
cemedias
Posts: 17
Joined: Mon Jun 11, 2007 9:58 pm

Post by cemedias »

bump :)
cemedias
Posts: 17
Joined: Mon Jun 11, 2007 9:58 pm

Post by cemedias »

Please, if anyone knows why this isnt working i would appreciate it.
Dances
Posts: 454
Joined: Sat Jul 02, 2005 1:45 am
Location: Canada
Contact:

Post by Dances »

When I read "so he only jumps once" I thought you meant only once, and then you have to hit the key again. Not so that he doesn't fly up in the air.

You need to check that hes touching the ground. You don't actually need hasJumped at all for this.

If you want him to not bunny hop when you hold the key you also need to make sure that your event receiver is setting hasJumped to false when the key is let up, not setting it false when the character jumps.
dennisbarnes
Posts: 12
Joined: Sun Aug 19, 2007 1:11 am
Location: Atlanta Ga U.S.A

Post by dennisbarnes »

Hello I try to you the code posted but i have two error can some one help me fix this


// w,s,a,d and arrow key movement
keyMap[0].Action = EKA_MOVE_FORWARD;
keyMap[0].KeyCode = KEY_UP;
keyMap[1].Action = EKA_MOVE_FORWARD;
keyMap[1].KeyCode = KEY_KEY_W;

keyMap[2].Action = EKA_MOVE_BACKWARD;
keyMap[2].KeyCode = KEY_DOWN;
keyMap[3].Action = EKA_MOVE_BACKWARD;
keyMap[3].KeyCode = KEY_KEY_S;

keyMap[4].Action = EKA_STRAFE_LEFT;
keyMap[4].KeyCode = KEY_LEFT;
keyMap[5].Action = EKA_STRAFE_LEFT;
keyMap[5].KeyCode = KEY_KEY_A;

keyMap[6].Action = EKA_STRAFE_RIGHT;
keyMap[6].KeyCode = KEY_RIGHT;
keyMap[7].Action = EKA_STRAFE_RIGHT;
keyMap[7].KeyCode = KEY_KEY_D;


if (stw::hawJumped == false)
{

keyMap[8].Action = EKA_JUMP_UP;
keyMap[8].KeyCode = KEY_KEY_SPACE;
hasJumped = true;


return keyMap;
}




if (event.EventType == EET_KEY_INPUT_EVENT &&

event.KeyInput . KEY == KEY_SPACE &&
event.KeyInput.PressDown == false);
{
stw:: hasJumped = false;
return true ;
}




c:\irrlicht\source\myproject\source\ai\gamepather.h(311) : warning C4311: 'type cast' : pointer truncation from 'void *' to 'unsigned int'
c:\irrlicht\source\myproject\source\core\gamemanager.cpp(247) : error C2059: syntax error : 'if'
c:\irrlicht\source\myproject\source\core\gamemanager.cpp(251) : error C2447: '{' : missing function header (old-style formal list?)
Build log was saved at "file://c:\irrlicht\source\myProject\Debug\BuildLog.htm"
myProject - 2 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Do you expect us to guess which lines in your source actually correspond to those errors?

Sigh.

OK, I'll guess.

gamemanager.cpp(247) is this line:

if (event.EventType == EET_KEY_INPUT_EVENT &&

It's causing an error because it's appearing outside any other function/method. It should be inside a function or method.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Yes, you should really tell us which errors correspond to each line seeing as that information is provided by the bug, but we cant do that as we dont know the line numbers of the code, you do ;)

I notice your last if statement is a bit strange as it ends in a ; instead of the opening bracket on the line below.
Image Image Image
dennisbarnes
Posts: 12
Joined: Sun Aug 19, 2007 1:11 am
Location: Atlanta Ga U.S.A

Post by dennisbarnes »

Hello I reposted the code i have two error can some one help me fix this
Thank you


/////////////////////////////////////////////////////////////////////////////////////
GameManager.cpp
/////////////////////////////////////////////////////////////////////////////////////
#include "GameState.h"
#include "GameManager.h"
#include "../game/GameIntroState.h"
#include "GamePlayer.h"
#include "../engine/GameEnemyManager.h"
#include "GameItemManager.h"
#include "../engine/GameWeaponManager.h"
#include "GameFXManager.h"
#include "../sound/GameSoundManager.h"
#include "../sound/AudiereSoundManager.h"
#include "../sound/FmodSoundManager.h"

#include "../ai/GamePathManager.h"


//! Default constructor
CGameManager::CGameManager()
{
// Irrlicht device
CreateDevice();
Init();
ClearKeys();
// by default, we start with the introduction mode...
m_pGameState = 0;
ChangeState( CGameIntroState::Instance() );
}

//! Default destructor
CGameManager::~CGameManager()
{
}

//! Changes the game state, calls the existing states Clear
//! function before the next states Init function
void CGameManager::ChangeState(CGameState * pState)
{
if (m_pGameState)
m_pGameState->Clear(this);
if ( pState != m_pGameState )
{
m_pGameState = pState;
m_pGameState->Init(this);
}
}

//! Holds a pointer to the current states, (level) Update function
//! The Update will be the game loop for the current state
void CGameManager::Update()
{

m_pGameState->Update(this);
}

//! Creates the Irrlicht device and get pointers to the main subsytems
//! for later use, the Game manager is the central interface point to
//! the rendering engine
void CGameManager::CreateDevice()
{
config= new CConfigManager();


// now use CConfigManager to create device, values stored in config.xml
m_pDevice=createDevice(config->getDriverType(), config->getScreenResolution(), config->getBitsperPixel(),
config->getFullscreen(), config->getStencilbuffer(), config->getVsync(), this);

m_pDriver = m_pDevice->getVideoDriver();
m_pSceneManager = m_pDevice->getSceneManager();
m_pGUIEnvironment = m_pDevice->getGUIEnvironment();

console=new CConsole(m_pDevice,config->getScreenResolution().Width);



}

//! Returns a pointer to the Irrlicht Device subsystem
inline IrrlichtDevice* CGameManager::getDevice()
{
return m_pDevice;
}

//! Returns a pointer to the Irrlicht Driver subsystem
inline IVideoDriver* CGameManager::getDriver()
{
return m_pDriver;
}

//! Returns a pointer to the Irrlicht SceneManager subsystem
inline ISceneManager* CGameManager::getSceneManager()
{
return m_pSceneManager;
}

//! Returns a pointer to the Irrlicht GUI subsystem
IGUIEnvironment* CGameManager::getGUIEnvironment()
{
return m_pGUIEnvironment;
}

//! Gets an instance of the Enemy Manager
CGameEnemyManager* CGameManager::getEnemyManager()
{
return m_pEnemyManager;
}

//! Gets an instance of the Item Manager
CGameItemManager* CGameManager::getItemManager()
{
return m_pItemManager;
}

//! Gets an instance of the Path Manager
CGamePathManager* CGameManager::getPathManager()
{
return m_pPathManager;
}

//! Gets an instance of the Weapon Manager
CGameWeaponManager* CGameManager::getWeaponManager()
{
return m_pWeaponManager;
}

//! Gets an instance of the FX (Special Effects) Manager
CGameFXManager* CGameManager::getFXManager()
{
return m_pFXManager;
}

//! Gets an instance of the Audiere Sound Manager
CGameSoundManager* CGameManager::getSoundManager()
{
return m_pSoundManager;
}

//! Returns the Config manager
CConfigManager* CGameManager::getConfigManager()
{
return config;
}

//! Returns an array of keys, used to detect keyboard presses.
//! Each key can be toggled on or off
bool CGameManager::getKey(char key)
{
return m_bKeys[key];
}

//! Clear keys, set all keys to off
void CGameManager::ClearKeys()
{
for(int x=0; x<irr::KEY_KEY_CODES_COUNT; x++) m_bKeys[x] = false;
}

//! Returns mouse event
char CGameManager::getMouse()
{
return m_cMouse;
}

//! Returns a pointer to the Player
CGamePlayer* CGameManager::getPlayer()
{
return m_pPlayer;
}

//! Get Main Meta selector, where all collison triangle selcetors are added
irr::scene::IMetaTriangleSelector* CGameManager::getMetaSelector()
{
return m_pMetaSelector;
}

//! Sets the MetaTriangleSelector
void CGameManager::setMetaSelector()
{
m_pMetaSelector = this->getSceneManager()->createMetaTriangleSelector();
}

//! Main event handler derived from IEventHandler, this
//! will be passed down to the current states keyboard handler.
//! The state controls its own keyboard events

bool CGameManager::OnEvent(SEvent event)
{
if (!m_pDriver)
return false;

if (event.EventType == EET_KEY_INPUT_EVENT)
{

if(event.KeyInput.PressedDown){
// if we the console is visible write


if(event.KeyInput.Key==KEY_F2){
if(console->isVisible())
console->setVisible(false);
else
console->setVisible(true);
return true;

}
else if(console->isVisible() ){
console->OnEvent(event);
return true;
}
else{
m_bKeys[event.KeyInput.Key] = event.KeyInput.PressedDown;

// Pass input down to the specific game state keyboard handler
m_pGameState->KeyboardEvent(this);

}
}

}

if (event.EventType == EET_KEY_INPUT_EVENT &&
event.KeyInput.Key == KEY_KEY_J &&
event.KeyInput.PressedDown == false)


{
stw::hasJumped = false;
return true;
}




if (event.EventType == EET_MOUSE_INPUT_EVENT)
{
// Pass input down to the specific game state mouse handler
m_cMouse = event.MouseInput.Event;
m_pGameState->MouseEvent(this);
}
return false;
}

//! Game manager genral Initialisation function. Also initialise or
//! load each of the plugable managers
void CGameManager::Init()
{
// set initial Font
m_pFont = this->getGUIEnvironment()->getFont("media/font_lucida.bmp");

// load in resourses from archive
this->getDevice()->getFileSystem()->addZipFileArchive("media/map-20kdm2.pk3");
this->getDevice()->getFileSystem()->addZipFileArchive("media/media.zip");
this->getDriver();

// initialise Player
m_pPlayer = new CGamePlayer(0);
m_pPlayer->Init(this);

// initialise Enemy manager
m_pEnemyManager = new CGameEnemyManager();
m_pEnemyManager->Init();

// initialise Item manager
m_pItemManager = new CGameItemManager();
m_pItemManager->Init();

// initialise Path manager
m_pPathManager = new CGamePathManager();
m_pPathManager->Init();

// initialise Weapon manager
m_pWeaponManager = new CGameWeaponManager();
m_pWeaponManager->Init();

// Load FX (Special Effects) Manager
m_pFXManager = new CGameFXManager();
m_pFXManager->Load(this);

// Load Audiere Sound Manager Base on Config.xml sound tag
switch (getConfigManager()->getSoundDevice()){
case AUDIERE :
m_pSoundManager = new CAudiereSoundManager();
break;
case NULLDEVICE:
m_pSoundManager =new CGameSoundManager();
break;
//If we like o use FMod Sound System
#if USEFMOD
case FMODSYSTEM:
m_pSoundManager = new CFmodSoundManager();
break;
//if Not we use Audiere as Default
#else
default:
m_pSoundManager = new CAudiereSoundManager();
break;

#endif

}
m_pSoundManager->Load(this);

}

//! Get Console Manager
CConsole *CGameManager::getConsole(){
return console;
}


//! Gets a Global soft coded Int variable for a specified name, used to pass
//! data accross games states
int CGameManager::getGlobalInt(std::wstring name)
{
std::map<std::wstring,int>::iterator it = m_mIntCache.begin(), stop = m_mIntCache.end();
for( ; it != stop; it ++ )
if (it->first == name)
return it->second;

return -1;
}

//! Sets a Global Int value to the value given. Used to pass data across states.
void CGameManager::setGlobalInt(std::wstring name, int value)
{
m_mIntCache.erase(name);
m_mIntCache.insert(std::pair<std::wstring,int>(name, value));
}

//! Gets a Global soft coded String variable used to pass data between states.
std::wstring CGameManager::getGlobalString(std::wstring name)
{
std::map<std::wstring,std::wstring>::iterator it = m_mStringCache.begin(), stop = m_mStringCache.end();
for( ; it != stop; it ++ )
if (it->first == name)
return it->second;

return (L"");
}

//! Sets a Global soft coded String variable used to pass data between states.
void CGameManager::setGlobalString(std::wstring name, std::wstring value)
{
m_mStringCache.erase(name);
m_mStringCache.insert(std::pair<std::wstring,std::wstring>(name, value));
}

//! Sets global font
void CGameManager::setFont(irr::gui::IGUIFont* font)
{
m_pFont = font;
}

//! Gets global font
irr::gui::IGUIFont* CGameManager::getFont()
{
return m_pFont;
}



/////////////////////////////////////////////////////////////////////////////////////
GamePlayState.cpp
/////////////////////////////////////////////////////////////////////////////////////

#include "GamePlayState.h"
#include "GameCreditsState.h"
#include "../engine/GameWeaponOwnedStates.h"

CGamePlayState CGamePlayState::m_PlayState;


//! Default constructor
CGamePlayState::CGamePlayState()
{

}

//! Default destructor
CGamePlayState::~CGamePlayState()
{

}

CGamePlayState* CGamePlayState::Instance()
{
return ( &m_PlayState );
}

//! Keyboard event for state, main keyboard events
//! passed down by Game manager
void CGamePlayState::KeyboardEvent(CGameManager * pManager)
{
// override in child class
}

//! Mouse event handler passed down by CGameManager
void CGamePlayState::MouseEvent(CGameManager* pManager)
{
switch(pManager->getMouse())
{
case EMIE_LMOUSE_PRESSED_DOWN: // left mouse pressed, FIRE!!!
if (!pManager->getWeaponManager()->isWeaponLocked() && pManager->getPlayer()->getAmmo() > 0)
pManager->getWeaponManager()->getActiveWeapon()->ChangeState(WeaponStateShoot::Instance());
break;

case EMIE_RMOUSE_PRESSED_DOWN: // right mouse pressed, RELOAD!!!
if (pManager->getPlayer()->getAmmo() <= 0)
pManager->getPlayer()->setAmmo(100); // 100% full
break;
case EMIE_MOUSE_WHEEL: // change weapon
if (!pManager->getWeaponManager()->isWeaponLocked())
pManager->getWeaponManager()->getActiveWeapon()->ChangeState(WeaponStateChange::Instance());
break;
}
}
//! Initialisation, loads data required for state. Generic game play
//! initialisation performed here, level specific initialisation should
//! be performed by the sub-classed level
void CGamePlayState::Init(CGameManager* pManager)
{
// text position and colour
m_pPlayStateText = pManager->getGUIEnvironment()->addStaticText(L"ESC Quit\n Left Mouse Button Fire\n Right Mouse Button Reload",
rect<int>(10,30,300,160), false);
m_displayText = pManager->getGUIEnvironment()->addStaticText(L"",
rect<int>(10,10,200,30), false);
m_iconText = pManager->getGUIEnvironment()->addStaticText(L"",
rect<int>(355,735,370,745), false);
m_displayText->setOverrideColor(video::SColor(255,255,255,255));
m_iconText->setOverrideColor(video::SColor(255,255,255,255));
m_pPlayStateText->setOverrideColor(video::SColor(255,255,0,0));

// load cross hair
m_pCrossHair = pManager->getDriver()->getTexture("media/crosshair.bmp");
pManager->getDriver()->makeColorKeyTexture(m_pCrossHair,core::position2d<s32>(0,0));

// load ammo bar
m_pAmmoBar = pManager->getDriver()->getTexture("media/hud.jpg");
pManager->getDriver()->makeColorKeyTexture(m_pAmmoBar,core::position2d<s32>(0,0));

// load health bar
m_pHealthBar = pManager->getDriver()->getTexture(".media/healthbar.jpg");
pManager->getDriver()->makeColorKeyTexture(m_pHealthBar,core::position2d<s32>(0,0));

// load key icons
m_pIcons = pManager->getDriver()->getTexture("media/key.tga");
pManager->getDriver()->makeColorKeyTexture(m_pIcons,core::position2d<s32>(0,0));

}

//! Update, moves and renders screen. Generic game play updates performed here,
//! level specific updates should be performed by the sub-classed level.
void CGamePlayState::Update(CGameManager * pManager)
{
// overide in child class
pManager->getDriver()->beginScene(true, true, video::SColor(0,100,100,100));
pManager->getSceneManager()->drawAll();
pManager->getGUIEnvironment()->drawAll();
pManager->getEnemyManager()->Update();
pManager->getWeaponManager()->Update();
pManager->getItemManager()->Update(pManager);

displayCrossHair(pManager);
displayAmmoBar(pManager, pManager->getPlayer()->getAmmo());
displayHealthBar(pManager, pManager->getPlayer()->getHealth());
displayIcons(pManager);
pManager->getDriver()->endScene();
if (pManager->getPlayer()->getHealth() <= 0)
if (pManager->getPlayer()->Death(pManager))
ChangeState(pManager, CGameCreditsState::Instance());


}

//! Clear, generic tidy up here, level specific house keeping should be
//! performed by the level specific subclass. Resources that have been
//! initialised should be destroyed also.
void CGamePlayState::Clear(CGameManager* pManager)
{
if (m_pPlayStateText) m_pPlayStateText->remove();
if (m_displayText) m_displayText->remove(); // crashes as leaves state, Visual Studio only, investigate!
if (m_iconText) m_iconText->remove(); // possible swprintf overflow protection. see DsiplayFPS()
pManager->getSceneManager()->clear();
pManager->getEnemyManager()->clear();
pManager->getItemManager()->clear();
pManager->getWeaponManager()->clear();
pManager->getFXManager()->Clear();
pManager->getPathManager()->Clear();
pManager->ClearKeys();

}

//! Displays Renderer, FPS and poly count on the screen
void CGamePlayState::displayFPS(CGameManager* pManager)
{

}
//! Loads the specified Game level (Quake3 .bsp, 3DS Max .3ds or DirectX .x file)
//! and performs general map initialisation. Map position only
void CGamePlayState::loadMap(CGameManager* pManager, const c8* map, core::vector3df mapPosition)
{
loadMap(pManager, map, mapPosition, vector3df(0,0,0));
}

//! Loads the specified Game level (Quake3 .bsp, 3DS Max .3ds or DirectX .x file)
//! and performs general map initialisation. Map and camera position
void CGamePlayState::loadMap(CGameManager* pManager, const c8* map, core::vector3df mapPosition, core::vector3df camPosition)
{
// Load in game Level from resources
m_Selector = 0;
scene::IAnimatedMesh* mesh = pManager->getSceneManager()->getMesh(map);scene::ISceneNode* node = 0;
if (mesh)
node = pManager->getSceneManager()->addOctTreeSceneNode(mesh->getMesh(0));
if (node)
{
node->setPosition(mapPosition);
m_Selector = pManager->getSceneManager()->createOctTreeTriangleSelector(
mesh->getMesh(0), node, 128);
node->setTriangleSelector(m_Selector);
m_Selector->drop();
}
pManager->setMetaSelector();
pManager->getMetaSelector()->addTriangleSelector(m_Selector);

// fog for effect
node->setMaterialFlag(EMF_FOG_ENABLE,true);
pManager->getDriver()->setFog(SColor(0,0,30,0),true, 0,1300);
pManager->getDriver()->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);

// set FPS camera and Node Animator for collison detection
scene::ICameraSceneNode* camera = pManager->getSceneManager()->addCameraSceneNodeFPS(0,100.0f,300.0f,-1, loadKeyBindings(), 9);
camera->setPosition(camPosition);
scene::ISceneNodeAnimator* m_pAnim = pManager->getSceneManager()->createCollisionResponseAnimator(
pManager->getMetaSelector(), camera, irr::core::vector3df(30,50,30), irr::core::vector3df(0,-3, 0), irr::core::vector3df(0,35,0));
camera->addAnimator(m_pAnim);
m_pAnim->drop();

// Skybox
loadSkyBox(pManager);

// fade in and disable cursor
pManager->getDevice()->getCursorControl()->setVisible(false);
m_inOutFader = pManager->getDevice()->getGUIEnvironment()->addInOutFader();
m_backColour.set(255,0,0,0); //255 90 90 156
m_inOutFader->setColor(m_backColour);
m_inOutFader->fadeIn(1000);
}

//! Load Key bindings
SKeyMap* CGamePlayState::loadKeyBindings()
{


// w,s,a,d and arrow key movement
keyMap[0].Action = EKA_MOVE_FORWARD;
keyMap[0].KeyCode = KEY_UP;
keyMap[1].Action = EKA_MOVE_FORWARD;
keyMap[1].KeyCode = KEY_KEY_W;

keyMap[2].Action = EKA_MOVE_BACKWARD;
keyMap[2].KeyCode = KEY_DOWN;
keyMap[3].Action = EKA_MOVE_BACKWARD;
keyMap[3].KeyCode = KEY_KEY_S;

keyMap[4].Action = EKA_STRAFE_LEFT;
keyMap[4].KeyCode = KEY_LEFT;
keyMap[5].Action = EKA_STRAFE_LEFT;
keyMap[5].KeyCode = KEY_KEY_A;

keyMap[6].Action = EKA_STRAFE_RIGHT;
keyMap[6].KeyCode = KEY_RIGHT;
keyMap[7].Action = EKA_STRAFE_RIGHT;
keyMap[7].KeyCode = KEY_KEY_D;
if(stw::hasJumped == false)
{

keyMap[8].Action = EKA_JUMP_UP;
keyMap[8].KeyCode = KEY_KEY_J;
hasJumped = true;
}

return keyMap;
}

//! Load skybox
ISceneNode* CGamePlayState::loadSkyBox(CGameManager* pManager)
{
m_pSkyBox = pManager->getSceneManager()->addSkyBoxSceneNode(
pManager->getDriver()->getTexture("media/skybox_up.jpg"),
pManager->getDriver()->getTexture("media/skybox_dn.jpg"),
pManager->getDriver()->getTexture("media/skybox_lf.jpg"),
pManager->getDriver()->getTexture("media/skybox_rt.jpg"),
pManager->getDriver()->getTexture("media/skybox_ft.jpg"),
pManager->getDriver()->getTexture("media/skybox_bk.jpg"));
return m_pSkyBox;
}

//! Display cross hair in center of screen
void CGamePlayState::displayCrossHair(CGameManager* pManager)
{
pManager->getDriver()->draw2DImage(m_pCrossHair, core::position2d<s32>(512, 384),
core::rect<s32>(0,0,16,16), 0, video::SColor(255,255,255,255), true);
}

//! Display horizontal ammo bar. Ammo as a percentage is shown
//! 100 max ammo, zero none
void CGamePlayState::displayAmmoBar(CGameManager* pManager, irr::s32 percent)
{
irr::core::rect< irr::s32 > clip(20, 650, 20 + (256 * percent/100) , 650 + 64);
pManager->getDriver()->draw2DImage(m_pAmmoBar, irr::core::position2d< irr::s32 >(20,650),
irr::core::rect< irr::s32 >(0,0,256,128),
&clip, irr::video::SColor(255, 255, 255, 255), true);
}

//! Display horizontal health bar. Players health as a percentage is shown
//! 100 max health, zero none
void CGamePlayState::displayHealthBar(CGameManager* pManager, irr::s32 percent)
{
irr::core::rect< irr::s32 > clip(20, 730, 20 + (256 * percent/100) , 730 + 16);
pManager->getDriver()->draw2DImage(m_pHealthBar, irr::core::position2d< irr::s32 >(20,730),
irr::core::rect< irr::s32 >(0,0,256,16),
&clip, irr::video::SColor(255, 255, 255, 255), true);
}
//! Dispaly key icons
void CGamePlayState::displayIcons(CGameManager* pManager)
{
//pManager->getDriver()->draw2DImage(m_pIcons, irr::core::position2d< irr::s32 >(320,710));
//swprintf(m_tmp2, 9, L"%d", pManager->getPlayer()->getLives());
//m_iconText->setText(m_tmp2);
}





GamePlayState.cpp
c:\irrlicht\source\myproject\source\ai\gamepather.h(311) : warning C4311: 'type cast' : pointer truncation from 'void *' to 'unsigned int'
c:\irrlicht\source\myproject\source\game\gameplaystate.cpp(221) : error C2653: 'stw' : is not a class or namespace name
c:\irrlicht\source\myproject\source\game\gameplaystate.cpp(221) : error C2065: 'hasJumped' : undeclared identifier
Build log was saved at "file://c:\irrlicht\source\myProject\Debug\BuildLog.htm"
myProject - 2 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

What lines do those errors correspond to? That's an easy thing for you to tell us and then you can just post that line, along with the error and we can probably see what the problem is.

Also, what's stw? I couldn't see anywhere that it was defined.
Image Image Image
Post Reply