mirror of
https://github.com/wassname/phaser.git
synced 2026-07-25 13:20:14 +08:00
Final 1.0.5 release.
This commit is contained in:
@@ -1,236 +0,0 @@
|
||||
{"frames": [
|
||||
|
||||
{
|
||||
"filename": "ball_1.png",
|
||||
"frame": {"x":218,"y":38,"w":16,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":16,"h":16},
|
||||
"sourceSize": {"w":16,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "ball_2.png",
|
||||
"frame": {"x":218,"y":20,"w":16,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":16,"h":16},
|
||||
"sourceSize": {"w":16,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "ball_3.png",
|
||||
"frame": {"x":218,"y":2,"w":16,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":16,"h":16},
|
||||
"sourceSize": {"w":16,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "ball_4.png",
|
||||
"frame": {"x":200,"y":38,"w":16,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":16,"h":16},
|
||||
"sourceSize": {"w":16,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "ball_5.png",
|
||||
"frame": {"x":200,"y":20,"w":16,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":16,"h":16},
|
||||
"sourceSize": {"w":16,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "brick_1_1.png",
|
||||
"frame": {"x":98,"y":21,"w":32,"h":17},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":17},
|
||||
"sourceSize": {"w":32,"h":17}
|
||||
},
|
||||
{
|
||||
"filename": "brick_1_2.png",
|
||||
"frame": {"x":98,"y":2,"w":32,"h":17},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":17},
|
||||
"sourceSize": {"w":32,"h":17}
|
||||
},
|
||||
{
|
||||
"filename": "brick_1_3.png",
|
||||
"frame": {"x":270,"y":17,"w":30,"h":13},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":1,"y":1,"w":30,"h":13},
|
||||
"sourceSize": {"w":32,"h":17}
|
||||
},
|
||||
{
|
||||
"filename": "brick_1_4.png",
|
||||
"frame": {"x":54,"y":52,"w":24,"h":9},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":4,"y":4,"w":24,"h":9},
|
||||
"sourceSize": {"w":32,"h":17}
|
||||
},
|
||||
{
|
||||
"filename": "brick_2_1.png",
|
||||
"frame": {"x":236,"y":19,"w":32,"h":15},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":15},
|
||||
"sourceSize": {"w":32,"h":15}
|
||||
},
|
||||
{
|
||||
"filename": "brick_2_2.png",
|
||||
"frame": {"x":236,"y":2,"w":32,"h":15},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":15},
|
||||
"sourceSize": {"w":32,"h":15}
|
||||
},
|
||||
{
|
||||
"filename": "brick_2_3.png",
|
||||
"frame": {"x":270,"y":2,"w":30,"h":13},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":1,"y":0,"w":30,"h":13},
|
||||
"sourceSize": {"w":32,"h":15}
|
||||
},
|
||||
{
|
||||
"filename": "brick_2_4.png",
|
||||
"frame": {"x":236,"y":50,"w":24,"h":11},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":4,"y":3,"w":24,"h":11},
|
||||
"sourceSize": {"w":32,"h":15}
|
||||
},
|
||||
{
|
||||
"filename": "brick_3_1.png",
|
||||
"frame": {"x":166,"y":20,"w":32,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":16},
|
||||
"sourceSize": {"w":32,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "brick_3_2.png",
|
||||
"frame": {"x":166,"y":2,"w":32,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":16},
|
||||
"sourceSize": {"w":32,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "brick_3_3.png",
|
||||
"frame": {"x":236,"y":36,"w":30,"h":12},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":1,"y":2,"w":30,"h":12},
|
||||
"sourceSize": {"w":32,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "brick_3_4.png",
|
||||
"frame": {"x":28,"y":52,"w":24,"h":10},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":4,"y":3,"w":24,"h":10},
|
||||
"sourceSize": {"w":32,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "one.png",
|
||||
"frame": {"x":66,"y":2,"w":30,"h":48},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":1,"y":16,"w":30,"h":48},
|
||||
"sourceSize": {"w":32,"h":64}
|
||||
},
|
||||
{
|
||||
"filename": "paddle_big.png",
|
||||
"frame": {"x":98,"y":40,"w":48,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":48,"h":16},
|
||||
"sourceSize": {"w":48,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "paddle_small.png",
|
||||
"frame": {"x":148,"y":38,"w":32,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":16},
|
||||
"sourceSize": {"w":32,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "power_down.png",
|
||||
"frame": {"x":200,"y":2,"w":16,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":16,"h":16},
|
||||
"sourceSize": {"w":16,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "power_up.png",
|
||||
"frame": {"x":182,"y":38,"w":16,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":16,"h":16},
|
||||
"sourceSize": {"w":16,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "brick_4_1.png",
|
||||
"frame": {"x":132,"y":20,"w":32,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":16},
|
||||
"sourceSize": {"w":32,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "brick_4_2.png",
|
||||
"frame": {"x":132,"y":2,"w":32,"h":16},
|
||||
"rotated": false,
|
||||
"trimmed": false,
|
||||
"spriteSourceSize": {"x":0,"y":0,"w":32,"h":16},
|
||||
"sourceSize": {"w":32,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "brick_4_3.png",
|
||||
"frame": {"x":270,"y":32,"w":30,"h":12},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":1,"y":2,"w":30,"h":12},
|
||||
"sourceSize": {"w":32,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "brick_4_4.png",
|
||||
"frame": {"x":2,"y":52,"w":24,"h":10},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":4,"y":3,"w":24,"h":10},
|
||||
"sourceSize": {"w":32,"h":16}
|
||||
},
|
||||
{
|
||||
"filename": "three.png",
|
||||
"frame": {"x":34,"y":2,"w":30,"h":48},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":1,"y":0,"w":30,"h":48},
|
||||
"sourceSize": {"w":32,"h":48}
|
||||
},
|
||||
{
|
||||
"filename": "two.png",
|
||||
"frame": {"x":2,"y":2,"w":30,"h":48},
|
||||
"rotated": false,
|
||||
"trimmed": true,
|
||||
"spriteSourceSize": {"x":1,"y":16,"w":30,"h":48},
|
||||
"sourceSize": {"w":32,"h":64}
|
||||
}],
|
||||
"meta": {
|
||||
"app": "http://www.texturepacker.com",
|
||||
"version": "1.0",
|
||||
"image": "breakout.png",
|
||||
"format": "RGBA8888",
|
||||
"size": {"w":302,"h":64},
|
||||
"scale": "1",
|
||||
"smartupdate": "$TexturePacker:SmartUpdate:c510ff2f709e8d175b059cd1cbe64773$"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.4 KiB |
@@ -55,8 +55,11 @@
|
||||
|
||||
function render() {
|
||||
|
||||
game.debug.renderRectangle(sprite1.body);
|
||||
game.debug.renderRectangle(sprite2.body);
|
||||
game.debug.renderSpriteInfo(sprite1, 32, 32);
|
||||
game.debug.renderSpriteCollision(sprite1, 32, 400);
|
||||
|
||||
game.debug.renderSpriteBody(sprite1);
|
||||
game.debug.renderSpriteBody(sprite2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
+134
-14
@@ -7,21 +7,37 @@
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.atlas('breakout', 'assets/sprites/breakout.png', 'assets/sprites/breakout.json');
|
||||
game.load.atlas('breakout', 'assets/games/breakout/breakout.png', 'assets/games/breakout/breakout.json');
|
||||
game.load.image('starfield', 'assets/misc/starfield.jpg');
|
||||
|
||||
}
|
||||
|
||||
var ball;
|
||||
var paddle;
|
||||
var bricks;
|
||||
|
||||
var ballOnPaddle = true;
|
||||
|
||||
var lives = 3;
|
||||
var score = 0;
|
||||
|
||||
var scoreText;
|
||||
var livesText;
|
||||
var introText;
|
||||
|
||||
var s;
|
||||
|
||||
function create() {
|
||||
|
||||
// We do this so the ball can still rebound with the world bounds, but it will look like it has gone off the bottom of the screen
|
||||
game.world.height = 620;
|
||||
|
||||
s = game.add.tileSprite(0, 0, 800, 600, 'starfield');
|
||||
|
||||
var brick;
|
||||
bricks = game.add.group();
|
||||
|
||||
@@ -35,15 +51,22 @@
|
||||
}
|
||||
}
|
||||
|
||||
ball = game.add.sprite(game.world.centerX, 534, 'breakout', 'ball_1.png');
|
||||
paddle = game.add.sprite(game.world.centerX, 500, 'breakout', 'paddle_big.png');
|
||||
paddle.anchor.setTo(0.5, 0.5);
|
||||
paddle.body.collideWorldBounds = true;
|
||||
paddle.body.bounce.setTo(1, 1);
|
||||
paddle.body.immovable = true;
|
||||
|
||||
ball = game.add.sprite(game.world.centerX, paddle.y - 16, 'breakout', 'ball_1.png');
|
||||
ball.anchor.setTo(0.5, 0.5);
|
||||
ball.body.collideWorldBounds = true;
|
||||
ball.body.bounce.setTo(1, 1);
|
||||
ball.animations.add('spin', [ 'ball_1.png', 'ball_2.png', 'ball_3.png', 'ball_4.png', 'ball_5.png' ], 50, true, false);
|
||||
|
||||
paddle = game.add.sprite(game.world.centerX, 550, 'breakout', 'paddle_big.png');
|
||||
paddle.body.collideWorldBounds = true;
|
||||
paddle.body.bounce.setTo(1, 1);
|
||||
paddle.body.immovable = true;
|
||||
scoreText = game.add.text(32, 550, 'score: 0', { font: "20px Arial", fill: "#ffffff", align: "left" });
|
||||
livesText = game.add.text(680, 550, 'lives: 3', { font: "20px Arial", fill: "#ffffff", align: "left" });
|
||||
introText = game.add.text(game.world.centerX, 400, '- click to start -', { font: "40px Arial", fill: "#ffffff", align: "center" });
|
||||
introText.anchor.setTo(0.5, 0.5);
|
||||
|
||||
game.input.onDown.add(releaseBall, this);
|
||||
|
||||
@@ -51,36 +74,133 @@
|
||||
|
||||
function update () {
|
||||
|
||||
// Fun, but a little sea-sick inducing :) Uncomment if you like!
|
||||
// s.tilePosition.x += (game.input.speed.x / 2);
|
||||
|
||||
paddle.x = game.input.x;
|
||||
|
||||
if (paddle.x < 24)
|
||||
{
|
||||
paddle.x = 24;
|
||||
}
|
||||
else if (paddle.x > game.width - 24)
|
||||
{
|
||||
paddle.x = game.width - 24;
|
||||
}
|
||||
|
||||
if (ballOnPaddle)
|
||||
{
|
||||
ball.x = paddle.x + 16;
|
||||
ball.x = paddle.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
game.physics.collide(paddle, ball);
|
||||
game.physics.collide(ball, paddle, ballHitPaddle, null, this);
|
||||
game.physics.collide(ball, bricks, ballHitBrick, null, this);
|
||||
}
|
||||
|
||||
// Out?
|
||||
if (ball.y > 600 && ballOnPaddle == false)
|
||||
{
|
||||
ballLost();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function releaseBall () {
|
||||
|
||||
ballOnPaddle = false;
|
||||
ball.body.velocity.y = -300;
|
||||
ball.body.velocity.x = -75;
|
||||
ball.animations.play('spin');
|
||||
if (ballOnPaddle)
|
||||
{
|
||||
ballOnPaddle = false;
|
||||
ball.body.velocity.y = -300;
|
||||
ball.body.velocity.x = -75;
|
||||
ball.animations.play('spin');
|
||||
introText.visible = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function ballLost () {
|
||||
|
||||
lives--;
|
||||
|
||||
if (lives == 0)
|
||||
{
|
||||
gameOver();
|
||||
}
|
||||
else
|
||||
{
|
||||
livesText.text = 'lives: ' + lives;
|
||||
ballOnPaddle = true;
|
||||
ball.body.velocity.setTo(0, 0);
|
||||
ball.x = paddle.x + 16;
|
||||
ball.y = paddle.y - 16;
|
||||
ball.animations.stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function gameOver () {
|
||||
|
||||
ball.body.velocity.setTo(0, 0);
|
||||
|
||||
introText.text = "Game Over!";
|
||||
introText.visible = true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function ballHitBrick (_ball, _brick) {
|
||||
|
||||
_brick.kill();
|
||||
|
||||
score += 10;
|
||||
|
||||
scoreText.text = 'score: ' + score;
|
||||
|
||||
// Are they any bricks left?
|
||||
if (bricks.countLiving() == 0)
|
||||
{
|
||||
// New level starts
|
||||
score += 1000;
|
||||
scoreText.text = 'score: ' + score;
|
||||
introText = '- Next Level -';
|
||||
|
||||
// Let's move the ball back to the paddle
|
||||
ballOnPaddle = true;
|
||||
ball.body.velocity.setTo(0, 0);
|
||||
ball.x = paddle.x + 16;
|
||||
ball.y = paddle.y - 16;
|
||||
ball.animations.stop();
|
||||
|
||||
// And bring the bricks back from the dead :)
|
||||
bricks.callAll('revive', this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render () {
|
||||
function ballHitPaddle (_ball, _paddle) {
|
||||
|
||||
var diff = 0;
|
||||
|
||||
if (_ball.x < _paddle.x)
|
||||
{
|
||||
// Ball is on the left-hand side of the paddle
|
||||
diff = _paddle.x - _ball.x;
|
||||
_ball.body.velocity.x = (-10 * diff);
|
||||
}
|
||||
else if (_ball.x > _paddle.x)
|
||||
{
|
||||
// Ball is on the right-hand side of the paddle
|
||||
diff = _ball.x -_paddle.x;
|
||||
_ball.body.velocity.x = (10 * diff);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ball is perfectly in the middle
|
||||
// Add a little random X to stop it bouncing straight up!
|
||||
_ball.body.velocity.x = 2 + Math.random() * 8;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
$title = "Invaders";
|
||||
require('../head.php');
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
|
||||
|
||||
function preload() {
|
||||
|
||||
game.load.image('phaser', 'assets/sprites/phaser-dude.png');
|
||||
game.load.image('bullet', 'assets/misc/bullet0.png');
|
||||
game.load.image('alien', 'assets/sprites/space-baddie.png');
|
||||
game.load.image('ship', 'assets/sprites/shmup-ship.png');
|
||||
|
||||
}
|
||||
|
||||
var player;
|
||||
var aliens;
|
||||
var bullets;
|
||||
var bulletTime = 0;
|
||||
|
||||
var pickle;
|
||||
|
||||
function create() {
|
||||
|
||||
player = game.add.sprite(400, 500, 'ship');
|
||||
player.anchor.setTo(0.5, 0.5);
|
||||
|
||||
aliens = game.add.group(null, 'aliens');
|
||||
|
||||
for (var y = 0; y < 4; y++)
|
||||
{
|
||||
for (var x = 0; x < 10; x++)
|
||||
{
|
||||
aliens.create(170 + x * 48, 100 + y * 50, 'alien');
|
||||
}
|
||||
}
|
||||
|
||||
// Shows off a known bug:
|
||||
// aliens.x = 100;
|
||||
// aliens.y = 50;
|
||||
|
||||
bullets = game.add.group(null, 'bullets');
|
||||
|
||||
for (var i = 0; i < 10; i++)
|
||||
{
|
||||
var b = bullets.create(0, 0, 'bullet');
|
||||
b.name = 'bullet' + i;
|
||||
b.exists = false;
|
||||
b.visible = false;
|
||||
b.events.onOutOfBounds.add(resetBullet, this);
|
||||
}
|
||||
|
||||
// Shows off a known bug:
|
||||
// var tween = game.add.tween(aliens).to({x: 200}, 3000, Phaser.Easing.Linear.None, true, 0, 1000, true);
|
||||
// tween.onComplete.add(descend, this);
|
||||
|
||||
}
|
||||
|
||||
function overAlien () {
|
||||
console.log('over pickle');
|
||||
}
|
||||
|
||||
function descend() {
|
||||
aliens.y += 10;
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
player.velocity.x = 0;
|
||||
player.velocity.y = 0;
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
player.velocity.x = -200;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
player.velocity.x = 200;
|
||||
}
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR))
|
||||
{
|
||||
fireBullet();
|
||||
}
|
||||
|
||||
game.physics.collide(bullets, aliens, collisionHandler, null, this);
|
||||
|
||||
}
|
||||
|
||||
function fireBullet () {
|
||||
|
||||
if (game.time.now > bulletTime)
|
||||
{
|
||||
bullet = bullets.getFirstExists(false);
|
||||
|
||||
if (bullet)
|
||||
{
|
||||
bullet.reset(player.x + 6, player.y - 8);
|
||||
bullet.velocity.y = -300;
|
||||
bulletTime = game.time.now + 250;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Called if the bullet goes out of the screen
|
||||
function resetBullet (bullet) {
|
||||
bullet.kill();
|
||||
}
|
||||
|
||||
function collisionHandler (bullet, alien) {
|
||||
|
||||
bullet.kill();
|
||||
alien.kill();
|
||||
|
||||
}
|
||||
|
||||
function render () {
|
||||
|
||||
aliens.forEach(renderBounds, this);
|
||||
|
||||
game.debug.renderQuadTree(game.physics.quadTree);
|
||||
|
||||
}
|
||||
|
||||
function renderBounds(s) {
|
||||
game.debug.renderSpriteBounds(s, 'rgba(0,0,255,0.4)', true);
|
||||
}
|
||||
|
||||
})();
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require('../foot.php');
|
||||
?>
|
||||
@@ -12,11 +12,11 @@
|
||||
var s;
|
||||
|
||||
function preload() {
|
||||
game.load.image('disk', 'assets/misc/starfield.jpg');
|
||||
game.load.image('starfield', 'assets/misc/starfield.jpg');
|
||||
}
|
||||
|
||||
function create() {
|
||||
s = game.add.tileSprite(0, 0, 800, 600, 'disk');
|
||||
s = game.add.tileSprite(0, 0, 800, 600, 'starfield');
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
Reference in New Issue
Block a user