ShadowCaster.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. 'atomic component';
  2. var halfWidth = Atomic.graphics.width * Atomic.PIXEL_SIZE * 0.5;
  3. var halfHeight = Atomic.graphics.height * Atomic.PIXEL_SIZE * 0.5;
  4. //ShadowCaster component
  5. exports.component = function(self) {
  6. //Link to the current node
  7. var node = self.node;
  8. //Create RigidBody2D component on the current node and make its static and cast shadows
  9. var body = node.createComponent("RigidBody2D");
  10. body.bodyType = Atomic.BodyType2D.BT_STATIC;
  11. body.castShadows = true;
  12. //Create circle collision and set its radius
  13. var circle = node.createComponent("CollisionCircle2D");
  14. circle.radius = .35;
  15. //Create sprite
  16. var sprite = node.createComponent("StaticSprite2D");
  17. var sprite2D = Atomic.cache.getResource("Sprite2D", "Sprites/ball" + (Math.round(Math.random() * 7) + 1) + ".png");
  18. sprite.setSprite(sprite2D);
  19. var x = -halfWidth + (halfWidth * 2) * Math.random();
  20. var y = -halfHeight + (halfHeight * 2) * Math.random();
  21. // tolerance towards the middle of screen
  22. x *= .7;
  23. y *= .7;
  24. //Set position of the current node in 2D space
  25. node.position2D = [x, y];
  26. };