stupid nub question for stupid meh :/

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
Nexos
Posts: 6
Joined: Wed Aug 18, 2004 1:17 am

stupid nub question for stupid meh :/

Post by Nexos »

Code: Select all

#include <windows.h>
#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#pragma comment(lib, "Irrlicht.lib")

	IrrlichtDevice *device = 0;
	IVideoDriver* driver;

	s32 cnt = 0; 

	int ballx = 250;
	int bally = 150;
	int balmx = 1;
	int balmy = 0;
	int speed = 1;

	int slide = 100;
	int slidey = 150;

	int slider = 100;

	int aiskill = 1;
	int aidirection = 1;

class MyEmenu : public IEventReceiver
{
public:
	virtual bool OnEvent(SEvent event)
	{
		if (event.EventType == EET_GUI_EVENT)
		{
			s32 id = event.GUIEvent.Caller->getID();
			switch(event.GUIEvent.EventType)
				{			
			case EGET_BUTTON_CLICKED:
				break;
}
		}
		return false;
	}
};

INT WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, INT)
{
	MyEmenu receiver;
	IrrlichtDevice *device =
		createDevice(EDT_OPENGL, dimension2d<s32>(500, 300), 32, false, false, &receiver);
	IGUIEnvironment* guienv = device->getGUIEnvironment();
	IGUIImage* img = guienv->addImage(rect<int>(0,0,500,300));
	IVideoDriver* driver = device->getVideoDriver();
	device->setWindowCaption(L"Nexy Pongy - Alpha v0.1");
	void ball(void);
	void ai(void);
	while(device->run())
	{
		IGUIEnvironment* guienv = device->getGUIEnvironment();
		driver->beginScene(true, true, SColor(0,100,100,100));
		img->setImage(driver->getTexture("bg.jpg"));
		position2d<s32> m = device->getCursorControl()->getPosition();
		slidey = (m.Y - 50);
		slide = (m.Y - 50);
		ai();
		guienv->drawAll();
		ball();
		driver->draw2DImage (driver->getTexture("ball.jpg"), position2d<s32>(ballx,bally));
		driver->draw2DImage (driver->getTexture("slider.jpg"), position2d<s32>(30,slide));
		driver->draw2DImage (driver->getTexture("slider.jpg"), position2d<s32>(470,slider));
		driver->endScene();
	}
	device->drop();
	return 0;
}

void ai(void)
{
	if (slider >= 250)
	{
		aidirection = 1;
	}
	if (slider >= 50)
	{
		aidirection = 3;
	}

	if (aidirection = 1)
	{
		slider = (slider + speed);
	}
	else if (aidirection = 3)
	{
		slider = (slider - speed);
	}
}

void ball(void)
{
	if ((ballx <= 50) && ((bally <= (slidey + 50)) && ( bally >= (slidey - 50))))
	{
		balmx = 1;
	}
	if (ballx >= 490)
	{
		balmx = 0;
	}
	if (ballx < 0)
	{
		balmx = 1;
	}
	if (bally >= 290)
	{
		balmy = 0;
	}
	if (bally <= 0)
	{
		balmy = 1;
	}
	if (balmx == 0)
	{
		ballx = (ballx - speed);
	}
	else 
	{
		ballx = (ballx + speed);
	}
	if (balmy == 0)
	{
		bally = (bally - speed);
	}
	else 
	{
		bally = (bally + speed);
	}
}
the only provlem i have right now is that the ai function dont work im puzzled the slider just stays still :( and wont move, i gather this isnt vry informative but ill see what u say :D
GAV(at uni)

Post by GAV(at uni) »

   if (aidirection = 1)
   {
      slider = (slider + speed);
   }
   else if (aidirection = 3)
   {
      slider = (slider - speed);
   }


you need to use == for comparison rather than = which sets the value to the right hand side :wink:

so at the moment, the first if statement sets the aidirection as 1, and is true because it cant be false. .. . so it adds speed to slider

then in the second statement it sets direction to 3, then subtracts speed from slider.
slider+speed-speed is the same as slider!!

so there is why it's not moving :)

PS I hope im right im a very newb programmer myself!!!!
Nexos
Posts: 6
Joined: Wed Aug 18, 2004 1:17 am

Post by Nexos »

lol yey some1 answer ill ave a look now :D

:D it worked just had 2 change one more thing ty
Post Reply