Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import('dart:html');
- main() {
- State state = new State();
- }
- class Point {
- num x=-69;
- num y=-666;
- Point(this.x,this.y);
- }
- class State {
- Point point = new Point(5,5);
- State () {
- display(what: "player", where: point);
- document.on.keyDown.add((event) => _handleKeyDown(event));
- document.on.keyUp.add((event) => _handleKeyUp(event));
- }
- void display({String what, Point where}) {
- var item = window.document.query("#$what");
- item.attributes["cx"] = where.y * 50;
- item.attributes["cy"] = where.x * 50;
- }
- void keyPressed(KeyboardEvent ev) {
- int code = ev.keyCode;
- switch(code) {
- case 37:
- point.y -= 1;
- break;
- case 38:
- point.x -= 1;
- break;
- case 39:
- point.y += 1;
- break;
- case 40:
- point.x += 1;
- break;
- default:
- print("unknown keycode $code");
- }
- display(what: "player", where: point);
- }
- void _handleKeyDown(KeyboardEvent event) {
- //print("Down: ${event.keyCode}");
- keyPressed(event);
- }
- void _handleKeyUp(KeyboardEvent event) {
- print("Up: ${event.keyCode}");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement