Skip to content

Instantly share code, notes, and snippets.

@JackStouffer
Last active August 29, 2015 14:22
Show Gist options
  • Save JackStouffer/77f0843449a211e76614 to your computer and use it in GitHub Desktop.
Save JackStouffer/77f0843449a211e76614 to your computer and use it in GitHub Desktop.
example for bug report
import std.stdio;
import Dgame.Window;
import Dgame.Graphic;
import Dgame.System.StopWatch;
import Dgame.System.Font;
import Dgame.System.Keyboard;
interface Entity {
void update(ref Window window);
}
class Player : Entity {
int x;
int y;
int speed = 1;
Sprite player_sprite;
this(int x, int y) {
this.x = x;
this.y = y;
Surface player_img = Surface("assets/textures/player.png");
Texture player_texture = Texture(player_img);
this.player_sprite = new Sprite(player_texture);
this.player_sprite.setPosition(this.x, this.y);
}
void update(ref Window window) {
window.draw(this.player_sprite);
}
}
void main() {
Window wnd = Window(640, 480, "Dgame Test", Window.Style.OpenGL | Window.Style.Shown);
wnd.setClearColor(Color4b.Green);
wnd.clear();
StopWatch clock;
Font fnt = Font("assets/fonts/Helvetica.ttf", 22);
Text curFps = new Text(fnt);
curFps.setPosition(0, 0);
Player player = new Player(200, 10);
Surface enemy_img = Surface("assets/textures/enemy.png");
Texture enemy_texture = Texture(enemy_img);
Sprite enemy_sprite = new Sprite(enemy_texture);
enemy_sprite.setPosition(30, 50);
bool running = true;
Event event;
while (running) {
wnd.clear();
while (wnd.poll(&event)) {
switch (event.type) {
case Event.Type.Quit:
writeln("Quit Event");
running = false;
break;
default: break;
}
}
player.update(wnd);
wnd.draw(enemy_sprite);
curFps.format("Current FPS: %d.", clock.getCurrentFPS());
wnd.draw(curFps);
wnd.display();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment