Last active
December 20, 2015 14:19
-
-
Save keithpitt/6145768 to your computer and use it in GitHub Desktop.
Full screening bug in Polycode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "HelloPolycodeApp.h" | |
HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : EventHandler() { | |
core = new POLYCODE_CORE(view, 1400,900,true,true,0,0,90); | |
x = 0, leftVelocity = 0, rightVelocity = 0; | |
y = 0, yVelocity = 0; | |
speed = 10; | |
gravity = 1.2; | |
quit = false; | |
falling = true; | |
CoreServices::getInstance()->getResourceManager()->addArchive("Resources/default.pak"); | |
CoreServices::getInstance()->getResourceManager()->addDirResource("default", false); | |
Screen * screen = new Screen(); | |
image = new ScreenImage("Resources/polycode_logo.png"); | |
screen->addChild(image); | |
label = new ScreenLabel("Hello, Polycode!", 32); | |
screen->addChild(label); | |
core->getInput()->addEventListener(this, InputEvent::EVENT_KEYDOWN); | |
core->getInput()->addEventListener(this, InputEvent::EVENT_KEYUP); | |
} | |
HelloPolycodeApp::~HelloPolycodeApp() { | |
} | |
void HelloPolycodeApp::handleEvent(Event *e) { | |
if(e->getDispatcher() == core->getInput()) { | |
InputEvent *inputEvent = (InputEvent*)e; | |
switch(e->getEventCode()) { | |
case InputEvent::EVENT_KEYDOWN: | |
switch (inputEvent->keyCode()) { | |
case KEY_LEFT: | |
leftVelocity = speed * -1; | |
break; | |
case KEY_RIGHT: | |
rightVelocity = speed; | |
break; | |
case KEY_SPACE: | |
if(!falling) { | |
yVelocity = -20; | |
falling = true; | |
} | |
break; | |
case KEY_ESCAPE: | |
quit = true; | |
break; | |
case KEY_f : | |
core->setVideoMode(1024, 768, !core->isFullscreen(), true, 1, 1); | |
break; | |
} | |
break; | |
case InputEvent::EVENT_KEYUP: | |
switch (inputEvent->keyCode()) { | |
case KEY_LEFT: | |
leftVelocity = 0; | |
break; | |
case KEY_RIGHT: | |
rightVelocity = 0; | |
break; | |
break; | |
} | |
break; | |
} | |
} | |
} | |
bool HelloPolycodeApp::Update() { | |
if(quit) { | |
core->Shutdown(); | |
} | |
Number elapsed = core->getElapsed(); | |
if(rightVelocity != 0) { | |
image->setRotation(image->getRotation()+(elapsed*150)); | |
}else if(leftVelocity != 0) { | |
image->setRotation(image->getRotation()-(elapsed*150)); | |
} | |
x += leftVelocity + rightVelocity; | |
if(falling) { | |
yVelocity += gravity; | |
y += yVelocity; | |
} | |
int floor = 900 - image->getHeight(); | |
if(y >= floor) { | |
y = floor; | |
falling = false; | |
} | |
image->setPosition(x, y); | |
label->setText(String::NumberToString(core->getFPS())); | |
return core->updateAndRender(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Polycode.h> | |
#include "PolycodeView.h" | |
using namespace Polycode; | |
class HelloPolycodeApp : public EventHandler { | |
public: | |
HelloPolycodeApp(PolycodeView *view); | |
~HelloPolycodeApp(); | |
void handleEvent(Event *e); | |
bool Update(); | |
int x; | |
int y; | |
int leftVelocity; | |
int rightVelocity; | |
int yVelocity; | |
int speed; | |
int gravity; | |
bool falling; | |
bool quit; | |
private: | |
ScreenImage *image; | |
Core *core; | |
ScreenLabel *label; | |
};% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment