mirror of
https://github.com/wassname/phaser.git
synced 2026-08-06 13:31:05 +08:00
Lots of new examples :)
Lots of new examples, the wip/examples folder can be destoryed I think
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
$title = "Motion";
|
||||
require('../head.php');
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update});
|
||||
|
||||
function preload() {
|
||||
game.load.image('car', 'assets/sprites/car90.png');
|
||||
game.load.image('ship', 'assets/sprites/xenon2_ship.png');
|
||||
game.load.image('baddie', 'assets/sprites/space-baddie.png');
|
||||
}
|
||||
|
||||
var car;
|
||||
var ship;
|
||||
var total;
|
||||
var aliens;
|
||||
|
||||
function create() {
|
||||
|
||||
aliens = [];
|
||||
|
||||
for (var i = 0; i < 50; i++)
|
||||
{
|
||||
var s = game.add.sprite(game.world.randomX, game.world.randomY, 'baddie');
|
||||
s.name = 'alien' + s;
|
||||
s.body.collideWorldBounds = true;
|
||||
s.body.bounce.setTo(1, 1);
|
||||
s.body.velocity.setTo(10 + Math.random() * 40, 10 + Math.random() * 40);
|
||||
aliens.push(s);
|
||||
}
|
||||
|
||||
car = game.add.sprite(400, 300, 'car');
|
||||
car.anchor.setTo(0.5, 0.5);
|
||||
car.body.collideWorldBounds = true;
|
||||
car.body.bounce.setTo(0.5, 0.5);
|
||||
car.body.allowRotation = true;
|
||||
|
||||
ship = game.add.sprite(400, 400, 'ship');
|
||||
ship.body.collideWorldBounds = true;
|
||||
ship.body.bounce.setTo(0.5, 0.5);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
car.body.velocity.x = 0;
|
||||
car.body.velocity.y = 0;
|
||||
car.body.angularVelocity = 0;
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
car.body.angularVelocity = -200;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
car.body.angularVelocity = 200;
|
||||
}
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
car.body.velocity.copyFrom(game.physics.velocityFromAngle(car.angle, 300));
|
||||
}
|
||||
|
||||
game.physics.collide(aliens);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require('../foot.php');
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
$title = "Motion";
|
||||
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('fuji', 'assets/pics/atari_fujilogo.png');
|
||||
}
|
||||
|
||||
var fuji,
|
||||
b;
|
||||
|
||||
function create() {
|
||||
|
||||
game.stage.backgroundColor = 'rgb(0,0,100)';
|
||||
|
||||
fuji = game.add.sprite(game.world.centerX, game.world.centerY, 'fuji');
|
||||
fuji.anchor.setTo(0, 0.5);
|
||||
fuji.angle = 34;
|
||||
|
||||
b = new Phaser.Rectangle(fuji.center.x, fuji.center.y, fuji.width, fuji.height);
|
||||
|
||||
//Remember that the sprite is rotating around its anchor
|
||||
game.add.tween(fuji).to({ angle: 360 }, 20000, Phaser.Easing.Linear.None, true, 0, true);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
if (game.input.activePointer.justPressed()){
|
||||
fuji.centerOn(game.input.x, game.input.y);
|
||||
}
|
||||
|
||||
b.x = fuji.center.x - fuji.halfWidth;
|
||||
b.y = fuji.center.y - fuji.halfHeight;
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
//Phaser.DebugUtils.renderSpriteWorldViewBounds(fuji);
|
||||
//Phaser.DebugUtils.renderSpriteBounds(fuji);
|
||||
game.debug.renderSpriteCorners(fuji);
|
||||
//Phaser.DebugUtils.renderSpriteWorldView(fuji, 32, 32);
|
||||
game.debug.renderRectangle(b, 'rgba(0,20,91,1)');
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require('../foot.php');
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user