Advertisement
Guest User

Untitled

a guest
May 1st, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Created by Adomas on 14.5.1.
  3.  */
  4. var game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.CANVAS, 'proc', { preload: preload, create: create, update: update, render: render });
  5.  
  6. var car;
  7. var Keys;
  8. var speed = 4;
  9. var style = 'STYLE_TOPDOWN';
  10. var currentSpeed = 0;
  11.  
  12. function preload() {
  13.  
  14.     game.load.image('car','assets/car.png');
  15.  
  16.     game.load.image('road','assets/road.png');
  17.  
  18.     game.load.image('box','assets/box.png')
  19.  
  20. }
  21.  
  22. function create() {
  23.  
  24.     game.world.setBounds(0, 0, 4096, 4096);
  25.  
  26.     game.stage.backgroundColor = '#ff0000';
  27.  
  28.     game.add.tileSprite(0,0,4096,4096,'road');
  29.  
  30.     box = game.add.sprite(400, 400, 'box');
  31.  
  32.     car = game.add.sprite(250, 250, 'car');
  33.  
  34.  
  35.     car.anchor.setTo(0.5, 0.5);
  36.  
  37.     game.physics.enable([ car, box ], Phaser.Physics.ARCADE);
  38.  
  39.     car.body.drag.set(0.2);
  40.  
  41.     car.body.maxVelocity.setTo(400, 400);
  42.  
  43.     car.body.velocity.setTo(0);
  44.  
  45.     car.body.collideWorldBounds = true;
  46.  
  47.     box.body.immovable = true;
  48.  
  49.     box.body.setSize(128, 128, 0, 0);
  50.  
  51.  
  52.     game.camera.follow(car);
  53.  
  54. }
  55.  
  56. function update() {
  57.     if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
  58.     {
  59.         car.angle -= 4;
  60.     }
  61.     if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
  62.     {
  63.         car.angle += 4;
  64.     }
  65.  
  66.     if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
  67.     {
  68.             currentSpeed = 300;
  69.     }
  70.     if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
  71.     {
  72.         if (currentSpeed > 0)
  73.         {
  74.             currentSpeed -= 7;
  75.         }
  76.     }
  77.     else
  78.     {
  79.         if (currentSpeed > 0)
  80.         {
  81.             currentSpeed -= 2;
  82.         }
  83.     }
  84.  
  85.     if (currentSpeed > 0)
  86.     {
  87.         game.physics.arcade.velocityFromRotation(car.rotation, currentSpeed, car.body.velocity);
  88.     }
  89.  
  90.     game.physics.arcade.collide(car, box, null, null, this);
  91.  
  92. }
  93.  
  94. function render () {
  95.  
  96.     game.debug.text('/bin/proc initialized...', 32, 32);
  97.     game.debug.text('current style of camera ' + style, 32, 64);
  98.     game.debug.text('Take control UP, RIGHT, LEFT', 32, 96);
  99.     game.debug.text('Current Speed:' + currentSpeed, 32, 128);
  100.  
  101.     game.debug.body(car);
  102.     game.debug.body(box);
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement