Fixed some issues in Tilemap collision, updated the Emitter so x/y controls the point of emission (to stop collision getting out of whack) and fixed the postUpdate in body.

This commit is contained in:
Richard Davey
2013-09-12 20:59:56 +01:00
parent 336de314a1
commit 79dc3566f4
10 changed files with 617 additions and 83 deletions
+7 -14
View File
@@ -12,7 +12,6 @@
(function () {
// var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update, render: render });
var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
function preload() {
@@ -34,20 +33,15 @@
// floor
map.setCollisionRange(80, 97, true, true, true, true);
// pipes
// map.setCollisionRange(31, 32, true, true, true, true);
// map.setCollisionRange(37, 38, true, true, true, true);
// map.setCollisionRange(39, 40, true, true, true, true);
// map.setCollisionRange(45, 46, true, true, true, true);
// map.setCollisionRange(73, 74, true, true, true, true);
// one-ways
map.setCollisionRange(15, 17, true, true, false, true);
p = game.add.sprite(0, 0, 'player');
// p.body.velocity.y = 150;
// p.body.gravity.y = 10;
// p.body.bounce.y = 0.5;
p = game.add.sprite(32, 32, 'player');
p.body.bounce.y = 0.4;
p.body.collideWorldBounds = true;
game.camera.follow(p);
}
@@ -56,12 +50,11 @@
map.collide(p);
p.body.velocity.x = 0;
p.body.acceleration.y = 250;
p.body.acceleration.y = 500;
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
p.body.velocity.x = -150;
// game.camera.x -= 8;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
+103
View File
@@ -0,0 +1,103 @@
<!DOCTYPE HTML>
<html>
<head>
<title>phaser.js - mario party(cles)</title>
<script src="phaser-min.js"></script>
<style type="text/css">
body {
margin: 0;
font-family: sans-serif;
}
p {
padding: 16px;
margin: 0px;
}
</style>
</head>
<body>
<div id="game"></div>
<script type="text/javascript">
(function () {
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'game', { preload: preload, create: create, update: update });
function preload() {
game.load.tilemap('background', 'assets/smb_bg.png', 'assets/smb_bg.json', null, Phaser.Tilemap.JSON);
game.load.tilemap('level1', 'assets/smb_tiles.png', 'assets/smb_level1.json', null, Phaser.Tilemap.JSON);
game.load.spritesheet('balls', 'assets/balls.png', 17, 17);
game.load.image('phaser', 'assets/phaser.png');
}
var p;
var map;
function create() {
game.stage.backgroundColor = '#787878';
game.add.tilemap(0, 0, 'background');
map = game.add.tilemap(0, 0, 'level1');
map.setCollisionByIndex([9,10,11,14,15,16,18,19,22,23,24,32,37,38], true, true, true, true);
p = game.add.emitter(300, 50, 500);
p.bounce = 0.5;
p.makeParticles('balls', [0,1,2,3,4,5], 500, 1);
p.minParticleSpeed.setTo(-150, 150);
p.maxParticleSpeed.setTo(100, 100);
p.gravity = 8;
p.start(false, 5000, 50);
var logo = game.add.sprite(688, 8, 'phaser');
logo.scrollFactor.setTo(0, 0);
game.add.tween(p).to({ x: 4000 }, 7500, Phaser.Easing.Quadratic.InOut, true, 0, 1000, true);
game.input.onDown.add(goFull, this);
}
function goFull() {
game.stage.scale.startFullScreen();
}
function update() {
map.collide(p);
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
game.camera.x -= 8;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
game.camera.x += 8;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
game.camera.y -= 8;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
game.camera.y += 8;
}
}
})();
</script>
<p>Left / Right arrows to scroll the map</p>
<p>Click game to full-screen (if supported)</p>
<p>Highlights a few visual glitches I need to work on :)</p>
<p>Created with <a href="https://github.com/photonstorm/phaser">Phaser 1.0</a> by <a href="https://twitter.com/photonstorm">@photonstorm</a></p>
</body>
</html>
+85
View File
@@ -0,0 +1,85 @@
<!DOCTYPE HTML>
<html>
<head>
<title>phaser.js - a new beginning</title>
<?php
require('js.php');
?>
</head>
<body>
<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.tilemap('mario', 'assets/maps/mario1.png', 'assets/maps/mario1.json', null, Phaser.Tilemap.JSON);
game.load.image('player', 'assets/sprites/phaser-dude.png');
}
var map;
var p;
function create() {
game.stage.backgroundColor = '#787878';
map = game.add.tilemap(0, 0, 'mario');
// floor
map.setCollisionRange(80, 97, true, true, true, true);
// one-ways
map.setCollisionRange(15, 17, true, true, false, true);
p = game.add.sprite(32, 32, 'player');
p.body.bounce.y = 0.4;
p.body.collideWorldBounds = true;
game.camera.follow(p);
}
function update() {
map.collide(p);
p.body.velocity.x = 0;
p.body.acceleration.y = 500;
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
p.body.velocity.x = -150;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
p.body.velocity.x = 150;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
if (p.body.touching.down)
{
p.body.velocity.y = -200;
}
}
}
function render() {
game.debug.renderSpriteCorners(p);
game.debug.renderSpriteCollision(p, 32, 320);
}
})();
</script>
</body>
</html>
+83
View File
@@ -0,0 +1,83 @@
<!DOCTYPE HTML>
<html>
<head>
<title>phaser.js - a new beginning</title>
<?php
require('js.php');
?>
</head>
<body>
<script type="text/javascript">
(function () {
var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.tilemap('background', 'assets/maps/smb_bg.png', 'assets/maps/smb_bg.json', null, Phaser.Tilemap.JSON);
game.load.tilemap('level1', 'assets/maps/smb_tiles.png', 'assets/maps/smb_level1.json', null, Phaser.Tilemap.JSON);
game.load.spritesheet('balls', 'assets/sprites/balls.png', 17, 17);
}
var p;
var map;
var test = [];
var g;
function create() {
game.stage.backgroundColor = '#787878';
game.add.tilemap(0, 0, 'background');
map = game.add.tilemap(0, 0, 'level1');
map.setCollisionByIndex([9,10,11,14,15,16,18,19,22,23,24,32,37,38], true, true, true, true);
p = game.add.emitter(300, 50, 500);
p.bounce = 0.5;
p.makeParticles('balls', [0,1,2,3,4,5], 500, 1);
p.minParticleSpeed.setTo(-150, 150);
p.maxParticleSpeed.setTo(100, 100);
p.gravity = 8;
p.start(false, 5000, 50);
game.add.tween(p).to({ x: 4000 }, 7500, Phaser.Easing.Quadratic.InOut, true, 0, 1000, true);
}
function update() {
map.collide(g);
map.collide(p);
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
{
game.camera.x -= 8;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
{
game.camera.x += 8;
}
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
{
game.camera.y -= 8;
}
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
{
game.camera.y += 8;
}
}
function render() {
}
})();
</script>
</body>
</html>