Advertisement
Guest User

Untitled

a guest
May 2nd, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. /*
  2. var Crafty = require('craftyjs');
  3.  
  4. Crafty.init(600, 300);
  5. Crafty.background('rgb(127,127,127)');
  6. //Paddles
  7. Crafty.e("Paddle, 2D, DOM, Color, Multiway")
  8. .color('rgb(255,0,0)')
  9. .attr({ x: 20, y: 100, w: 10, h: 100 })
  10. .multiway(4, { W: -90, S: 90 });
  11. Crafty.e("Paddle, 2D, DOM, Color, Multiway")
  12. .color('rgb(0,255,0)')
  13. .attr({ x: 580, y: 100, w: 10, h: 100 })
  14. .multiway(4, { UP_ARROW: -90, DOWN_ARROW: 90 });
  15. //Ball
  16. Crafty.e("2D, DOM, Color, Collision")
  17. .color('rgb(0,0,255)')
  18. .attr({ x: 300, y: 150, w: 10, h: 10,
  19. dX: Crafty.math.randomInt(2, 5),
  20. dY: Crafty.math.randomInt(2, 5) })
  21. .bind('EnterFrame', function () {
  22. //hit floor or roof
  23. if (this.y <= 0 || this.y >= 290)
  24. this.dY *= -1;
  25.  
  26. if (this.x > 600) {
  27. this.x = 300;
  28. Crafty("LeftPoints").each(function () {
  29. this.text(++this.points + " Points") });
  30. }
  31. if (this.x < 10) {
  32. this.x = 300;
  33. Crafty("RightPoints").each(function () {
  34. this.text(++this.points + " Points") });
  35. }
  36.  
  37. this.x += this.dX;
  38. this.y += this.dY;
  39. })
  40. .onHit('Paddle', function () {
  41. this.dX *= -1;
  42. })
  43.  
  44. //Score boards
  45. Crafty.e("LeftPoints, DOM, 2D, Text")
  46. .attr({ x: 20, y: 20, w: 100, h: 20, points: 0 })
  47. .text("0 Points");
  48. Crafty.e("RightPoints, DOM, 2D, Text")
  49. .attr({ x: 515, y: 20, w: 100, h: 20, points: 0 })
  50. .text("0 Points");
  51. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement