Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by Adomas on 14.5.1.
- */
- var game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.CANVAS, 'proc', { preload: preload, create: create, update: update, render: render });
- var car;
- var Keys;
- var speed = 4;
- var style = 'STYLE_TOPDOWN';
- var currentSpeed = 0;
- function preload() {
- game.load.image('car','assets/car.png');
- game.load.image('road','assets/road.png');
- game.load.image('box','assets/box.png')
- }
- function create() {
- game.world.setBounds(0, 0, 4096, 4096);
- game.stage.backgroundColor = '#ff0000';
- game.add.tileSprite(0,0,4096,4096,'road');
- box = game.add.sprite(400, 400, 'box');
- car = game.add.sprite(250, 250, 'car');
- car.anchor.setTo(0.5, 0.5);
- game.physics.enable([ car, box ], Phaser.Physics.ARCADE);
- car.body.drag.set(0.2);
- car.body.maxVelocity.setTo(400, 400);
- car.body.velocity.setTo(0);
- car.body.collideWorldBounds = true;
- box.body.immovable = true;
- box.body.setSize(128, 128, 0, 0);
- game.camera.follow(car);
- }
- function update() {
- if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
- {
- car.angle -= 4;
- }
- if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
- {
- car.angle += 4;
- }
- if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
- {
- currentSpeed = 300;
- }
- if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
- {
- if (currentSpeed > 0)
- {
- currentSpeed -= 7;
- }
- }
- else
- {
- if (currentSpeed > 0)
- {
- currentSpeed -= 2;
- }
- }
- if (currentSpeed > 0)
- {
- game.physics.arcade.velocityFromRotation(car.rotation, currentSpeed, car.body.velocity);
- }
- game.physics.arcade.collide(car, box, null, null, this);
- }
- function render () {
- game.debug.text('/bin/proc initialized...', 32, 32);
- game.debug.text('current style of camera ' + style, 32, 64);
- game.debug.text('Take control UP, RIGHT, LEFT', 32, 96);
- game.debug.text('Current Speed:' + currentSpeed, 32, 128);
- game.debug.body(car);
- game.debug.body(box);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement