Jump to content

uni assignment need help.


brittydoll
 Share

Recommended Posts

hey everyone im in university studying bachelor of inter active media, but that's not the point ..... we need to make a mobile game in phaser for our assignment.... you see my code is super long, i have no idea how to place enemies in my game for my character to kill, or to place health bars, how to have random collectables appear or even how to get a game over screen . right now my game is a player some platforms and some water kinda like mario looking....... i tried using states to get a menu and a game over screen ect.... but my code refused to work. i need help.... some tutorials because my teacher never even showed us how..... here is my code so far any help is welcome. 

 

 

 
var game = new Phaser.Game(960, 540, Phaser.AUTO, 'game', { preload: preload, create: create, update: update });
 
var player;
var Keys = Phaser.Keyboard;
var speed = 4;
var style = 'default';
var cursors;
 
function preload() {
 
    game.load.image('sky', 'images/sky3.png');
game.load.image('sky2', 'images/sky4.png');
  game.load.image('sky3', 'images/sky5.png');
    game.load.image('ground', 'images/platform3.png');
 game.load.image('ground1', 'images/platform4.png');
 game.load.image('ground2', 'images/platform5.png');
 game.load.image('ground3', 'images/platform6.png');
 game.load.image('skyplat', 'images/skyplatform.png');
 game.load.image('skyplat2', 'images/skyplat2.png');
    game.load.image('star', 'images/star.png');
    game.load.spritesheet('dude', 'images/dude.png', 32, 48);
game.load.image('water', 'images/water_back.png');
game.load.image('water1', 'images/water_front.png');
 
 
}
 
 
 
function create() {
 
  game.world.setBounds(0, 0, 960*10, 540);
 game.add.tileSprite(0, 0, 960*5, 540, 'sky');
 
game.add.sprite(4800, 0, 'sky2');
 game.add.tileSprite(6406, 0, 960*5, 540, 'sky3');
   
    
ground = game.add.sprite(0, 396, 'ground');
    game.physics.arcade.enable(ground);
ground.scale.setTo(2, 1);
 ground.body.immovable = true;
 
 skyplat = game.add.sprite(500, 290, 'skyplat');
    game.physics.arcade.enable(skyplat);
skyplat.scale.setTo(1, 1);
 skyplat.body.immovable = true;
 
 
 skyplat2 = game.add.sprite(700, 250, 'skyplat');
    game.physics.arcade.enable(skyplat2);
skyplat2.scale.setTo(1, 1);
 skyplat2.body.immovable = true;
 
  skyplat3 = game.add.sprite(1050, 215, 'skyplat');
    game.physics.arcade.enable(skyplat3);
skyplat3.scale.setTo(1, 1);
 skyplat3.body.immovable = true;
 
 skyplat4 = game.add.sprite(1300, 215, 'skyplat');
    game.physics.arcade.enable(skyplat4);
skyplat4.scale.setTo(2, 1);
 skyplat4.body.immovable = true;
 
  skyplat5 = game.add.sprite(2150, 344, 'skyplat');
    game.physics.arcade.enable(skyplat5);
skyplat5.scale.setTo(2, 1);
 skyplat5 .body.immovable = true;
 
  skyplat6 = game.add.sprite(2250, 295, 'skyplat');
    game.physics.arcade.enable(skyplat6);
skyplat6.scale.setTo(1, 1);
 skyplat6 .body.immovable = true;
 
 
  
 
 ground2 = game.add.sprite(1150, 396, 'ground');
    game.physics.arcade.enable(ground2);
ground2.scale.setTo(1, 1);
 ground2.body.immovable = true;
 
 ground3 = game.add.sprite(1800, 396, 'ground');
    game.physics.arcade.enable(ground3);
ground3.scale.setTo(2, 1);
 ground3.body.immovable = true;
 
 
  ground4 = game.add.sprite(2950, 396, 'ground1');
    game.physics.arcade.enable(ground4);
ground4.scale.setTo(1, 1);
 ground4.body.immovable = true;
 
 
   ground5 = game.add.sprite(3250, 396, 'ground1');
    game.physics.arcade.enable(ground5);
ground5.scale.setTo(1, 1);
 ground5.body.immovable = true;
 
   ground6 = game.add.sprite(3600, 396, 'ground1');
    game.physics.arcade.enable(ground6);
ground6.scale.setTo(1, 1);
 ground6.body.immovable = true;
 
 
  ground7 = game.add.sprite(3900, 396, 'ground');
    game.physics.arcade.enable(ground7);
ground7.scale.setTo(2, 1);
 ground7.body.immovable = true;
 
 skyplat7 = game.add.sprite(4200, 290, 'skyplat');
    game.physics.arcade.enable(skyplat7);
skyplat7.scale.setTo(1, 1);
 skyplat7.body.immovable = true;
 
 
 skyplat8 = game.add.sprite(4400, 250, 'skyplat');
    game.physics.arcade.enable(skyplat8);
skyplat8.scale.setTo(1, 1);
 skyplat8.body.immovable = true;
 
 skyplat9 = game.add.sprite(4600, 290, 'skyplat');
    game.physics.arcade.enable(skyplat9);
skyplat9.scale.setTo(1, 1);
 skyplat9.body.immovable = true;
 
 
 
   ground8 = game.add.sprite(5000, 396, 'ground');
    game.physics.arcade.enable(ground8);
ground8.scale.setTo(1, 1);
 ground8.body.immovable = true;
 
 ground9 = game.add.sprite(5500, 396, 'ground2');
    game.physics.arcade.enable(ground9);
ground9.scale.setTo(1.5, 1);
 ground9.body.immovable = true;
 
 skyplat10 = game.add.sprite(5700, 290, 'skyplat2');
    game.physics.arcade.enable(skyplat10);
skyplat10.scale.setTo(1, 1);
 skyplat10.body.immovable = true;
 
 
 skyplat11 = game.add.sprite(5900, 250, 'skyplat2');
    game.physics.arcade.enable(skyplat11);
skyplat11.scale.setTo(1, 1);
 skyplat11.body.immovable = true;
 
  skyplat12 = game.add.sprite(6250, 215, 'skyplat2');
    game.physics.arcade.enable(skyplat12);
skyplat12.scale.setTo(1, 1);
 skyplat12.body.immovable = true;
 
 skyplat13 = game.add.sprite(6500, 215, 'skyplat2');
    game.physics.arcade.enable(skyplat13);
skyplat13.scale.setTo(2, 1);
 skyplat13.body.immovable = true;
 
  skyplat14 = game.add.sprite(7350, 344, 'skyplat2');
    game.physics.arcade.enable(skyplat14);
skyplat14.scale.setTo(2, 1);
 skyplat14 .body.immovable = true;
 
  skyplat15 = game.add.sprite(7450, 295, 'skyplat2');
    game.physics.arcade.enable(skyplat15);
skyplat15.scale.setTo(1, 1);
 skyplat15 .body.immovable = true;
 
 
 ground10 = game.add.sprite(6350, 396, 'ground2');
    game.physics.arcade.enable(ground10);
ground10.scale.setTo(1, 1);
 ground10.body.immovable = true;
 
 ground11 = game.add.sprite(7000, 396, 'ground2');
    game.physics.arcade.enable(ground11);
ground11.scale.setTo(2, 1);
 ground11.body.immovable = true;
 
 
  ground12 = game.add.sprite(8150, 396, 'ground3');
    game.physics.arcade.enable(ground12);
ground12.scale.setTo(1, 1);
 ground12.body.immovable = true;
 
 
   ground13 = game.add.sprite(8450, 396, 'ground3');
    game.physics.arcade.enable(ground13);
ground13.scale.setTo(1, 1);
 ground13.body.immovable = true;
 
   ground14 = game.add.sprite(8800, 396, 'ground3');
    game.physics.arcade.enable(ground14);
ground14.scale.setTo(1, 1);
 ground14.body.immovable = true;
 
  ground15 = game.add.sprite(9100, 396, 'ground2');
    game.physics.arcade.enable(ground15);
ground15.scale.setTo(2, 1);
 ground15.body.immovable = true;
 
   ground16 = game.add.sprite(10200, 396, 'ground2');
    game.physics.arcade.enable(ground16);
ground16.scale.setTo(1, 1);
 ground16.body.immovable = true;
 
 
water = game.add.tileSprite(0, 470, 960*10, 540, 'water');
game.physics.arcade.enable(water);
    water.body.setSize(960, 20, 0, 0);
water.scale.setTo(2, 1);
 water.body.immovable = true;
 
water = game.add.tileSprite(0, 435, 960*10, 540, 'water');
game.physics.arcade.enable(water);
    water.body.setSize(960, 20, 0, 0);
water.scale.setTo(2, 1);
 water.body.immovable = true;
 
 
 
 
// player 
 
player = game.add.sprite(0, 340, 'dude');
 
    //  We need to enable physics on the player
    game.physics.arcade.enable(player);
 
    //  Player physics properties. Give the little guy a slight bounce.
    player.body.bounce.y = 0.2;
    player.body.gravity.y = 300;
    player.body.collideWorldBounds = true;
 
    player.animations.add('left', [0, 1, 2, 3], 10, true);
    player.animations.add('right', [5, 6, 7, 8], 10, true);
 
game.camera.follow(player);
 
 
 
}
 
 
 
function update() {
game.physics.arcade.collide(player, ground);
 
game.physics.arcade.collide(player, ground2);
game.physics.arcade.collide(player, ground3);
game.physics.arcade.collide(player, ground4);
game.physics.arcade.collide(player, ground5);
game.physics.arcade.collide(player, ground6);
game.physics.arcade.collide(player, ground7);
game.physics.arcade.collide(player, ground8);
game.physics.arcade.collide(player, ground9);
 
game.physics.arcade.collide(player, ground10);
game.physics.arcade.collide(player, ground11);
game.physics.arcade.collide(player, ground12);
game.physics.arcade.collide(player, ground13);
game.physics.arcade.collide(player, ground14);
game.physics.arcade.collide(player, ground15);
game.physics.arcade.collide(player, ground16);
 
game.physics.arcade.collide(player, skyplat);
game.physics.arcade.collide(player, skyplat2);
game.physics.arcade.collide(player, skyplat3);
game.physics.arcade.collide(player, skyplat4);
game.physics.arcade.collide(player, skyplat5); 
game.physics.arcade.collide(player, skyplat6);
game.physics.arcade.collide(player, skyplat7);
game.physics.arcade.collide(player, skyplat8);
game.physics.arcade.collide(player, skyplat9);
game.physics.arcade.collide(player, skyplat10);
game.physics.arcade.collide(player, skyplat11);
game.physics.arcade.collide(player, skyplat12);
game.physics.arcade.collide(player, skyplat13);
game.physics.arcade.collide(player, skyplat14);
game.physics.arcade.collide(player, skyplat15);
 
 
 
 
cursors = game.input.keyboard.createCursorKeys();
player.body.velocity.x = 0;
 
    if (cursors.left.isDown)
    {
        //  Move to the left
        player.body.velocity.x = -150;
 
        player.animations.play('left');
    }
    else if (cursors.right.isDown)
    {
        //  Move to the right
        player.body.velocity.x = 150;
 
        player.animations.play('right');
    }
    else
    {
        //  Stand still
        player.animations.stop();
 
        player.frame = 4;
    }
 
    //  Allow the player to jump if they are touching the ground.
    if (cursors.up.isDown && player.body.touching.down)
       {
        player.body.velocity.y = -250;
    }
 
 
 
 
 
}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...