mirror of
https://github.com/wassname/phaser.git
synced 2026-08-12 12:20:38 +08:00
First push to github
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
// The first parameter to your function should always be 'game' which is an instance of the Game object.
|
||||
FakeGame = function (game) {
|
||||
|
||||
// Store the reference and then use it through-out your code
|
||||
this.game = game;
|
||||
|
||||
this.car;
|
||||
this.bigCam;
|
||||
|
||||
};
|
||||
|
||||
FakeGame.prototype = {
|
||||
|
||||
init: function () {
|
||||
|
||||
this.game.loader.addImageFile('track', '../../assets/games/f1/track.png');
|
||||
this.game.loader.addImageFile('car', '../../assets/games/f1/car1.png');
|
||||
|
||||
this.game.loader.load();
|
||||
|
||||
},
|
||||
|
||||
create: function () {
|
||||
|
||||
this.game.camera.setBounds(0, 0, this.game.stage.width, this.game.stage.height);
|
||||
this.game.createSprite(0, 0, 'track');
|
||||
|
||||
this.car = this.game.createSprite(180, 298, 'car');
|
||||
this.car.rotation = 180;
|
||||
this.car.maxVelocity.setTo(150, 150);
|
||||
|
||||
this.bigCam = this.game.createCamera(640, 0, 100, 200);
|
||||
this.bigCam.follow(this.car, Camera.STYLE_LOCKON);
|
||||
this.bigCam.setBounds(0, 0, this.game.stage.width, this.game.stage.height);
|
||||
this.bigCam.showBorder = true;
|
||||
this.bigCam.borderColor = 'rgb(0,0,0)';
|
||||
this.bigCam.scale.setTo(2, 2);
|
||||
|
||||
},
|
||||
|
||||
update: function () {
|
||||
|
||||
if (this.game.input.keyboard.isDown(Keyboard.LEFT))
|
||||
{
|
||||
this.car.rotation -= 4;
|
||||
}
|
||||
else if (this.game.input.keyboard.isDown(Keyboard.RIGHT))
|
||||
{
|
||||
this.car.rotation += 4;
|
||||
}
|
||||
|
||||
if (this.game.input.keyboard.isDown(Keyboard.UP))
|
||||
{
|
||||
this.car.velocity.copyFrom(this.game.math.velocityFromAngle(this.car.angle, 150));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.car.velocity.copyFrom(this.game.math.velocityFromAngle(this.car.angle, 60));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
// The first parameter to your function should always be 'game' which is an instance of the Game object.
|
||||
MainMenu = function (game) {
|
||||
|
||||
// Store the reference and then use it through-out your code
|
||||
this.game = game;
|
||||
|
||||
this.monster;
|
||||
this.isFalling = false;
|
||||
|
||||
this.hasClicked = false;
|
||||
|
||||
};
|
||||
|
||||
MainMenu.prototype = {
|
||||
|
||||
init: function () {
|
||||
|
||||
this.game.loader.addImageFile('car', '../../assets/pics/supercars_parsec.png');
|
||||
this.game.loader.addSpriteSheet('monster', '../../assets/sprites/metalslug_monster39x40.png', 39, 40);
|
||||
|
||||
this.game.loader.load();
|
||||
|
||||
},
|
||||
|
||||
create: function () {
|
||||
|
||||
this.game.camera.backgroundColor = 'rgb(85,85,85)';
|
||||
|
||||
this.game.createSprite(80, 150, 'car');
|
||||
|
||||
this.monster = this.game.createSprite(80, 60, 'monster');
|
||||
|
||||
this.monster.animations.add('walk');
|
||||
this.monster.animations.play('walk', 30, true);
|
||||
this.monster.velocity.x = 50;
|
||||
|
||||
},
|
||||
|
||||
update: function () {
|
||||
|
||||
if (this.monster.x >= 710 && this.isFalling == false)
|
||||
{
|
||||
this.isFalling = true;
|
||||
this.monster.velocity.x = 20;
|
||||
this.monster.acceleration.y = 200;
|
||||
this.monster.angularAcceleration = 100;
|
||||
this.monster.animations.stop('walk');
|
||||
}
|
||||
|
||||
if (this.game.input.mouse.isDown && this.hasClicked == false)
|
||||
{
|
||||
this.hasClicked = true;
|
||||
this.game.switchState(FakeGame);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
render: function () {
|
||||
|
||||
this.game.stage.context.fillStyle = 'rgb(0,0,0)';
|
||||
|
||||
this.game.stage.context.font = 'bold 48px Arial';
|
||||
this.game.stage.context.textAlign = 'center';
|
||||
this.game.stage.context.fillText('Super Racer', this.game.stage.centerX, 60);
|
||||
|
||||
this.game.stage.context.font = 'bold 22px Arial';
|
||||
this.game.stage.context.textAlign = 'center';
|
||||
this.game.stage.context.fillText('Click to "Play"', this.game.stage.centerX, 370);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="initial-scale=1 maximum-scale=1 user-scalable=0" />
|
||||
<title>Phaser Test Runner : JS State Test 1</title>
|
||||
<link rel="stylesheet" href="../../phaser.css" type="text/css" />
|
||||
<script src="../../phaser.js"></script>
|
||||
<script src="MainMenu.js"></script>
|
||||
<script src="FakeGame.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="game"></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var myGame = new Game(this, 'game', 840, 400);
|
||||
|
||||
myGame.switchState(MainMenu);
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user