Advertisement
fuxoft

Dart SVG animation test

Oct 21st, 2012
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. #import('dart:html');
  2.  
  3. main() {
  4. State state = new State();
  5. }
  6.  
  7. class Point {
  8. num x=-69;
  9. num y=-666;
  10.  
  11. Point(this.x,this.y);
  12. }
  13.  
  14. class State {
  15. Point point = new Point(5,5);
  16.  
  17. State () {
  18. display(what: "player", where: point);
  19. document.on.keyDown.add((event) => _handleKeyDown(event));
  20. document.on.keyUp.add((event) => _handleKeyUp(event));
  21. }
  22.  
  23. void display({String what, Point where}) {
  24. var item = window.document.query("#$what");
  25. item.attributes["cx"] = where.y * 50;
  26. item.attributes["cy"] = where.x * 50;
  27. }
  28.  
  29. void keyPressed(KeyboardEvent ev) {
  30. int code = ev.keyCode;
  31. switch(code) {
  32. case 37:
  33. point.y -= 1;
  34. break;
  35. case 38:
  36. point.x -= 1;
  37. break;
  38. case 39:
  39. point.y += 1;
  40. break;
  41. case 40:
  42. point.x += 1;
  43. break;
  44. default:
  45. print("unknown keycode $code");
  46. }
  47. display(what: "player", where: point);
  48. }
  49.  
  50. void _handleKeyDown(KeyboardEvent event) {
  51. //print("Down: ${event.keyCode}");
  52. keyPressed(event);
  53. }
  54.  
  55. void _handleKeyUp(KeyboardEvent event) {
  56. print("Up: ${event.keyCode}");
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement