Angular Physics re-implemented, most tests now working as expected.

This commit is contained in:
photonstorm
2014-01-03 04:50:31 +00:00
parent f7329e0661
commit c3183dcea9
5 changed files with 164 additions and 100 deletions
+11 -8
View File
@@ -19,7 +19,7 @@ var launchVelocity = 0;
function create() {
// set global gravity
game.physics.gravity.setTo(0,8);
game.physics.gravity.y = 100;
game.stage.backgroundColor = '#0072bc';
var graphics = game.add.graphics(0,0);
@@ -42,7 +42,7 @@ function create() {
ball.anchor.setTo(0.5, 0.5);
ball.body.collideWorldBounds = true;
ball.body.bounce.setTo(0.9, 0.9);
ball.body.drag.setTo(50, 50);
ball.body.drag.setTo(10, 0);
// Enable input.
ball.inputEnabled = true;
@@ -66,10 +66,10 @@ function launch() {
arrow.alpha = 0;
analog.alpha = 0;
Xvector = (arrow.x - ball.x) * 4.1;
Yvector = (arrow.y - ball.y) * 4.1;
Xvector = (arrow.x - ball.x) * 3;
Yvector = (arrow.y - ball.y) * 3;
ball.body.allowGravity = true;
ball.body.velocity.setTo(Xvector,Yvector);
ball.body.velocity.setTo(Xvector, Yvector);
}
@@ -85,7 +85,7 @@ function update() {
arrow.alpha = 1;
analog.alpha = 0.5;
analog.rotation = arrow.rotation - 3.14/2;
analog.rotation = arrow.rotation - 3.14 / 2;
analog.height = game.physics.distanceToPointer(arrow);
launchVelocity = analog.height;
}
@@ -95,7 +95,10 @@ function update() {
function render() {
game.debug.renderText("Drag the ball and release to launch", 32, 32);
game.debug.renderSpriteInfo(ball, 32, 64);
game.debug.renderText("Launch Velocity: " + parseInt(launchVelocity), 32, 250);
game.debug.renderBodyInfo(ball, 32, 64);
// game.debug.renderSpriteInfo(ball, 32, 64);
// game.debug.renderText("Launch Velocity: " + parseInt(launchVelocity), 32, 250);
}
+35 -11
View File
@@ -4,6 +4,7 @@ var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload:
function preload() {
game.load.image('chunk', 'assets/sprites/chunk.png');
game.load.image('arrow', 'assets/sprites/asteroids_ship.png');
}
@@ -12,25 +13,36 @@ var bmd;
function create() {
game.stage.backgroundColor = '#2384e7';
game.stage.backgroundColor = '#124184';
bmd = game.add.bitmapData(800, 600);
bmd.fillStyle('#ffffff');
game.add.sprite(0, 0, bmd);
var bg = game.add.sprite(0, 0, bmd);
bg.body.moves = false;
sprite = game.add.sprite(732, 0, 'chunk');
game.physics.gravity.y = 100;
// sprite = game.add.sprite(732, 0, 'chunk');
// sprite = game.add.sprite(32, 450, 'chunk');
sprite = game.add.sprite(32, 450, 'arrow');
sprite.anchor.setTo(0.5, 0.5);
sprite.body.collideWorldBounds = true;
sprite.body.bounce.setTo(0.5, 0.5);
// sprite.body.bounce.setTo(0.5, 0.5);
sprite.body.bounce.setTo(0.8, 0.8);
//sprite.body.drag.setTo(0, -20);
sprite.body.drag.setTo(5, 0);
sprite.body.drag.setTo(10, 10);
// sprite.body.sleepMin.setTo(-50, -20);
// sprite.body.sleepMax.setTo(50, 20);
// sprite.body.sleepDuration = 1000;
sprite.body.sleepMin.setTo(0, -5);
sprite.body.sleepMax.setTo(0, 5);
sprite.body.sleepDuration = 1000;
sprite.body.sleepMin.setTo(-5, -5);
sprite.body.sleepMax.setTo(5, 5);
sprite.body.sleepDuration = 500;
// sprite.body.canSleep = false;
game.input.onDown.add(launch, this);
@@ -38,20 +50,32 @@ function create() {
function launch() {
sprite.body.velocity.setTo(-100, 300);
// up and to the right
sprite.body.velocity.setTo(200, -300);
sprite.body.gravity.setTo(0, -100);
// sprite.body.velocity.setTo(-100, 300);
// sprite.body.gravity.setTo(0, -100);
// sprite.body.gravity.setTo(0, -100);
}
function update() {
sprite.rotation = sprite.body.angle;
// console.log(sprite.body.velocity.x);
bmd.fillStyle('#ffffff');
bmd.fillRect(sprite.x, sprite.y, 2, 2);
// bmd.fillStyle('#ff0000');
// bmd.fillRect(sprite.body.x, sprite.body.y, 2, 2);
}
function render() {
game.debug.renderBodyInfo(sprite, 16, 16);
game.debug.renderBodyInfo(sprite, 16, 24);
}