Skip to content

Commit

Permalink
atari basic collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
tian2992 committed Jan 25, 2015
1 parent ba189fb commit f171e5c
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
this.game.bondel.cuca = this.game.add.existing(
new Cuca(this.game, this.game.width/2, this.game.height - 16)
);


//this.game.bondel.cuca.scale = new PIXI.Point(0.5,0.5);

this.game.bondel.muebles = this.game.add.tileSprite(0, 0, this.cameraWidth, this.cameraHeight, 'muebles');
Expand All @@ -59,19 +61,22 @@
this.game.input.activePointer.y = this.game.height/2 - 100;
this.game.camera.follow(this.game.bondel.cuca);

this.game.time.events.loop(Phaser.Timer.SECOND * 4, addItem, this);

//this.game.time.events.loop(Phaser.Timer.SECOND * 4, addItem, this);
addItem();

this.game.camera.deadzone= new Phaser.Rectangle( Math.ceil( this.camera.width*0.25 ), Math.ceil( this.camera.height*0.25 ), Math.ceil(this.camera.width*0.5), Math.ceil(this.camera.height*0.5) );

this.game.add.existing(new Phaser.Button(this.game, 10,10, 'pasos', function() {
var paso = new Pasos(this.game,100,100,1);
this.game.bondel.pasos = this.game.add.existing(paso);
}), this );


};

// The update() method is called every frame
GameState.prototype.update = function() {
game.physics.arcade.collide(atari, game.bondel.cuca);
};

var Pasos = function(game, x, y, dir) {
Expand All @@ -97,6 +102,8 @@

// Enable physics on the missile
this.game.physics.enable(this, Phaser.Physics.ARCADE);
this.body.collideWorldBounds = true;
this.body.immovable = true;

// Define constants that affect motion
this.SPEED = 200; // missile speed pixels/second
Expand All @@ -107,19 +114,15 @@
// Create a variable called wobble that tweens back and forth between
// -this.WOBBLE_LIMIT and +this.WOBBLE_LIMIT forever
this.wobble = this.WOBBLE_LIMIT;
this.game.add.tween(this)
.to(
{ wobble: -this.WOBBLE_LIMIT },
this.WOBBLE_SPEED, Phaser.Easing.Sinusoidal.InOut, true, 0,
Number.POSITIVE_INFINITY, true
);
};

// Cuca are a type of Phaser.Sprite
Cuca.prototype = Object.create(Phaser.Sprite.prototype);
Cuca.prototype.constructor = Cuca;

var i = 0;
var atari;

Cuca.prototype.update = function() {
// Calculate the angle from the missile to the mouse cursor game.input.x
// and game.input.y are the mouse position; substitute with whatever
Expand Down Expand Up @@ -175,7 +178,15 @@
};

var addItem = function(){
game.add.sprite(0, 0, 'atari');
atari = game.add.sprite(0, 0, 'atari');

game.physics.enable(atari, Phaser.Physics.ARCADE);
atari.body.velocity.setTo(200,200);
// This makes the game world bounce-able
atari.body.collideWorldBounds = true;

atari.body.bounce.set(1);

}

var game = new Phaser.Game(GameState.width, GameState.height, Phaser.AUTO, '');
Expand Down

0 comments on commit f171e5c

Please sign in to comment.