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);
}
}