Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <head>
- <meta charset="UTF-8" />
- <title>Simple game</title>
- <script src="phaser.min.js"></script>
- </head>
- <body>
- <script type="text/javascript">
- var game = new Phaser.Game(1000, 800, Phaser.AUTO, '', { preload: preload, create: create, update: update });
- var cursors;
- var player;
- var nextCarY = 20
- var random = 4
- var cars;
- var cars2;
- var speed = 5;
- var carSpeed = 2;
- function preload() {
- game.load.image('zaba', 'image/frogFrame1.png');
- game.load.image('auto', 'image/car.png');
- cursors = game.input.keyboard.createCursorKeys();
- }
- function create() {
- player = game.add.sprite(450, 550, 'zaba');
- player.scale.setTo(1.5, 1.5);
- cars = game.add.group();
- cars.enableBody = true;
- cars2 = game.add.group();
- cars2.enableBody = true;
- random = Math.random() * (0 - 10) + 10;
- //Random();
- game.time.events.repeat(Phaser.Timer.SECOND * 2, 100, createCar, this);
- //game.time.events.repeat(Phaser.Timer.SECOND * 3, 100, createCar2, this);
- //auto1 = game.add.sprite(577, 500, 'auto1');
- //auto1.scale.setTo(0.25, 0.25);
- }
- function update() {
- //game.time.events.repeat(Phaser.Timer.SECOND * random, 100, createCar, this);
- if(cursors.left.isDown && player.x>0){
- player.x -= speed;
- }
- if(cursors.right.isDown && player.x<800){
- player.x += speed;
- }
- if (cursors.down.isDown && player.y<605){
- player.y += speed;
- }
- if (cursors.up.isDown && player.y>0){
- player.y -= speed;
- }
- }
- function createCar () {
- this.game.time.events.add(Phaser.Timer.SECOND *random,createCar, this )
- var car = cars.create(1300,495,'auto');
- car.scale.setTo(2, 2);
- Random();
- moveIndividual(car);
- }
- function createCar2 () {
- var car2 = cars2.create(-100,460,'auto');
- car2.scale.setTo(2, 2);
- //cout++;
- moveIndividual2(car2);
- }
- function moveIndividual(moved)
- {
- moved.body.velocity.x = -700;
- }
- function Random()
- {
- random = Math.random() * (4 - 10) + 10;
- console.log(random);
- }
- function moveIndividual2(moved)
- {
- moved.body.velocity.x = 700;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement