vencinachev

Game

Nov 23rd, 2021 (edited)
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict'
  2. const Game = new Phaser.Game(1500, 1200, Phaser.AUTO, 'game-canvas', { preload, create, update })
  3.  
  4. let mycar;
  5. let keys;
  6. let speed = 50;
  7.  
  8. function preload() {
  9.     Game.stage.backgroundColor = "#681526";
  10.     Game.load.image('mycar', "images/bmw.png");
  11.     keys = Game.input.keyboard.createCursorKeys();
  12. }
  13.  
  14. function create() {
  15.     mycar = Game.add.sprite(0, 0, 'mycar');
  16.     mycar.x = 1000;
  17.     mycar.y = 20;
  18.     mycar.height = 100;
  19.     mycar.width = 200;
  20.  
  21. }
  22.  
  23. function update() {
  24.     if (keys.right.isDown){
  25.         mycar.x += speed;
  26.     }
  27.     else if (keys.left.isDown){
  28.         mycar.x -= speed;  
  29.     }
  30.     else if (keys.up.isDown){
  31.         mycar.y -= speed;  
  32.     }
  33.     else if (keys.down.isDown){
  34.         mycar.y += speed;  
  35.     }
  36. }
Add Comment
Please, Sign In to add comment