Skip to content

Instantly share code, notes, and snippets.

@DCubix
Created December 9, 2016 03:40
Show Gist options
  • Save DCubix/57a2b86afa8af1210e789fba28e434d1 to your computer and use it in GitHub Desktop.
Save DCubix/57a2b86afa8af1210e789fba28e434d1 to your computer and use it in GitHub Desktop.
class Game : public GameWindow {
public:
Game()
: GameWindow(640, 480, "Test Game")
{
}
void OnLoad() override {
GetCurrentScene()->GetSpriteBatch()->SetAmbientColor(Color(0.01f, 0.02f, 0.07f));
diff = Texture::CreateImageTexture("megaman_diff.png");
norm = Texture::CreateImageTexture("megaman_norm.png");
// Creates a basic Sprite
spr = new SpriteNode(diff, norm);
GetCurrentScene()->GetRootNode()->AddChild(spr);
spr->SetPosition(Vector2(320.0f, 240.0f));
spr->SetOrigin(Vector2(0.5f));
spr->SetScale(Vector2(4.0f));
// Creates a point Light
l = new LightNode();
GetCurrentScene()->GetRootNode()->AddChild(l);
l->SetZ(0.25f);
l->SetIntensity(1.5f);
l->SetRadius(1.2f);
l->SetColor(Color(1.0f, 0.1f, 0.1f));
// Loads the "blinker" script
// and attach it to the Light
FileStream fs("blink.lua");
l->SetScript(GetLua()->RunFile(fs));
fs.Close();
// Creates a Spot light
LightNode* sl = new LightNode();
sl->SetLightType(LightType::Spot);
sl->SetCutOff(0.4f);
sl->SetIntensity(2.0f);
sl->SetRadius(0.4f);
sl->SetPosition(Vector2(0.0f, 240.0f));
sl->SetZ(0.2f);
sl->SetRotation(-M_PI);
GetCurrentScene()->GetRootNode()->AddChild(sl);
}
void OnUpdate(float deltaTime) override {
t += deltaTime;
if (t >= M_PI*2.0f) {
t = 0.0f;
}
// Move the point light to the cursor position
Vector2 mp = Input::GetMousePosition();
l->SetPosition(Vector2(mp.x, mp.y));
l->SetZ(0.1f);
}
float t;
Ptr<Texture> diff, norm;
SpriteNode* spr;
LightNode* l;
};
int main(int argc, char** argv) {
Game game;
return game.Run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment