here is my code:
Code: Select all
//this program is to try and make a pong game using irrlicht
//include headers
#include <irrlicht.h>
//link to the irrlicht lib
#pragma comment (lib, "Irrlicht.lib")
//use the irrlicht namespace
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace gui;
using namespace io;
//variables
bool keys[irr::KEY_KEY_CODES_COUNT];
//structs and classes
class MyEventReceiver : public IEventReceiver {
public:
virtual bool OnEvent(const SEvent& event) {
if(event.EventType == irr::EET_KEY_INPUT_EVENT){
keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
return false;
}
return false;
}
};
struct OBJECT
{
s32 x, y;
s32 h, w;
f64 XMomentum, YMomentum;
ITexture* tex;
};
IrrlichtDevice *device = createDevice(EDT_DIRECT3D9);
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
MyEventReceiver rv;
//functions
void Initialize(OBJECT *ob[]);
void Run(OBJECT *ob[]);
int main()
{
//initialize
void Initialize(OBJECT *ob[]);
//game loop
while(device->run() && driver)
{
void Run(OBJECT *ob[]);
}
device->drop();
return 0;
}
void Initialize(OBJECT *ob[])
{
//set the event receiver
device->setEventReceiver(&rv);
//set the window caption
device->setWindowCaption(L"Pong with irrlicht");
//load up the player 1 attributes
ob[0]->tex = driver->getTexture("../../Media/Player1paddle.jpg");
ob[0]->x = 300;
ob[0]->y = 10;
ob[0]->XMomentum = 0;
ob[0]->YMomentum = 0;
ob[0]->h = 16;
ob[0]->w = 45;
}
void Run(OBJECT *ob[])
{
//if the window is active
if (device->isWindowActive())
{
//run the game
u32 time = device->getTimer()->getTime();
driver->beginScene(true, true, SColor(0, 120,102,136));
driver->draw2DImage(ob[0]->tex, position2d<s32>(ob[0]->x,ob[0]->y));
driver->endScene();
}
};