mirror of
https://github.com/wassname/phaser.git
synced 2026-08-15 12:45:11 +08:00
Merged N+ physics in and tidied up the Docs folder and logos.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
function init() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('atari', 'assets/sprites/atari800xl.png');
|
||||
game.load.start();
|
||||
}
|
||||
var atari;
|
||||
function create() {
|
||||
atari = game.add.sprite(200, 300, 'atari');
|
||||
atari.texture.alpha = 0.5;
|
||||
//atari.scale.setTo(1.5, 1.5);
|
||||
//atari.physics.shape.setSize(150, 50);
|
||||
//atari.physics.shape.offset.setTo(50, 25);
|
||||
//atari.physics.gravity.setTo(0, 2);
|
||||
atari.body.bounce.setTo(0.7, 0.7);
|
||||
atari.body.drag.setTo(10, 10);
|
||||
}
|
||||
function update() {
|
||||
atari.body.acceleration.x = 0;
|
||||
atari.body.acceleration.y = 0;
|
||||
if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
atari.body.acceleration.x = -150;
|
||||
} else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
atari.body.acceleration.x = 150;
|
||||
}
|
||||
if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
atari.body.acceleration.y = -150;
|
||||
} else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
||||
atari.body.acceleration.y = 150;
|
||||
}
|
||||
}
|
||||
function render() {
|
||||
atari.body.renderDebugInfo(16, 16);
|
||||
Phaser.DebugUtils.renderSpritePhysicsBody(atari);
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,64 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
|
||||
function init() {
|
||||
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('atari', 'assets/sprites/atari800xl.png');
|
||||
game.load.start();
|
||||
|
||||
}
|
||||
|
||||
var atari: Phaser.Sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
atari = game.add.sprite(200, 300, 'atari');
|
||||
atari.texture.alpha = 0.5;
|
||||
//atari.scale.setTo(1.5, 1.5);
|
||||
|
||||
//atari.physics.shape.setSize(150, 50);
|
||||
//atari.physics.shape.offset.setTo(50, 25);
|
||||
|
||||
//atari.physics.gravity.setTo(0, 2);
|
||||
atari.body.bounce.setTo(0.7, 0.7);
|
||||
atari.body.drag.setTo(10, 10);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
atari.body.acceleration.x = 0;
|
||||
atari.body.acceleration.y = 0;
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
atari.body.acceleration.x = -150;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
atari.body.acceleration.x = 150;
|
||||
}
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
atari.body.acceleration.y = -150;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
{
|
||||
atari.body.acceleration.y = 150;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
atari.body.renderDebugInfo(16, 16);
|
||||
Phaser.DebugUtils.renderSpritePhysicsBody(atari);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,50 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
function init() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('atari', 'assets/sprites/atari800xl.png');
|
||||
game.load.image('card', 'assets/sprites/mana_card.png');
|
||||
game.load.start();
|
||||
}
|
||||
var atari;
|
||||
var card;
|
||||
function create() {
|
||||
//atari = game.add.sprite(350, 100, 'atari');
|
||||
//atari = game.add.sprite(350, 500, 'atari');
|
||||
atari = game.add.sprite(0, 310, 'atari');
|
||||
card = game.add.sprite(400, 300, 'card');
|
||||
//card.body.immovable = true;
|
||||
//atari.texture.alpha = 0.5;
|
||||
//atari.scale.setTo(1.5, 1.5);
|
||||
//atari.body.shape.setSize(150, 50);
|
||||
//atari.body.shape.offset.setTo(50, 25);
|
||||
//atari.body.gravity.setTo(0, 2);
|
||||
atari.body.bounce.setTo(1, 1);
|
||||
//atari.body.drag.setTo(10, 10);
|
||||
card.body.bounce.setTo(0.7, 0.7);
|
||||
//card.body.velocity.x = -50;
|
||||
}
|
||||
function update() {
|
||||
atari.body.acceleration.x = 0;
|
||||
atari.body.acceleration.y = 0;
|
||||
if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
atari.body.acceleration.x = -150;
|
||||
} else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
atari.body.acceleration.x = 150;
|
||||
}
|
||||
if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
atari.body.acceleration.y = -150;
|
||||
} else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
||||
atari.body.acceleration.y = 150;
|
||||
}
|
||||
// collide?
|
||||
game.collide(atari, card);
|
||||
}
|
||||
function render() {
|
||||
atari.body.renderDebugInfo(16, 16);
|
||||
card.body.renderDebugInfo(200, 16);
|
||||
Phaser.DebugUtils.renderSpritePhysicsBody(atari);
|
||||
Phaser.DebugUtils.renderSpritePhysicsBody(card);
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,81 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
|
||||
function init() {
|
||||
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('atari', 'assets/sprites/atari800xl.png');
|
||||
game.load.image('card', 'assets/sprites/mana_card.png');
|
||||
game.load.start();
|
||||
|
||||
}
|
||||
|
||||
var atari: Phaser.Sprite;
|
||||
var card: Phaser.Sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
//atari = game.add.sprite(350, 100, 'atari');
|
||||
//atari = game.add.sprite(350, 500, 'atari');
|
||||
atari = game.add.sprite(0, 310, 'atari');
|
||||
card = game.add.sprite(400, 300, 'card');
|
||||
|
||||
//card.body.immovable = true;
|
||||
|
||||
//atari.texture.alpha = 0.5;
|
||||
//atari.scale.setTo(1.5, 1.5);
|
||||
|
||||
//atari.body.shape.setSize(150, 50);
|
||||
//atari.body.shape.offset.setTo(50, 25);
|
||||
|
||||
//atari.body.gravity.setTo(0, 2);
|
||||
atari.body.bounce.setTo(1, 1);
|
||||
//atari.body.drag.setTo(10, 10);
|
||||
|
||||
card.body.bounce.setTo(0.7, 0.7);
|
||||
//card.body.velocity.x = -50;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
atari.body.acceleration.x = 0;
|
||||
atari.body.acceleration.y = 0;
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
atari.body.acceleration.x = -150;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
atari.body.acceleration.x = 150;
|
||||
}
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
atari.body.acceleration.y = -150;
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
{
|
||||
atari.body.acceleration.y = 150;
|
||||
}
|
||||
|
||||
// collide?
|
||||
game.collide(atari, card);
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
atari.body.renderDebugInfo(16, 16);
|
||||
card.body.renderDebugInfo(200, 16);
|
||||
|
||||
Phaser.DebugUtils.renderSpritePhysicsBody(atari);
|
||||
Phaser.DebugUtils.renderSpritePhysicsBody(card);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,139 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/physics/advanced/Manager.ts" />
|
||||
/// <reference path="../../Phaser/physics/advanced/shapes/Box.ts" />
|
||||
/// <reference path="../../Phaser/physics/advanced/shapes/Circle.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
function init() {
|
||||
game.load.image('xatari', 'assets/sprites/atari800xl.png');
|
||||
game.load.image('card', 'assets/sprites/mana_card.png');
|
||||
game.load.image('atari', 'assets/sprites/shinyball.png');
|
||||
game.load.start();
|
||||
}
|
||||
var debug;
|
||||
var atari;
|
||||
var card;
|
||||
var physics;
|
||||
var circle;
|
||||
var walls;
|
||||
var t;
|
||||
function create() {
|
||||
//atari = game.add.sprite(200, 100, 'atari');
|
||||
// need to get the physics bounds around the sprite center, regardless of origin
|
||||
//atari.transform.origin.setTo(0.5, 0.5);
|
||||
//card = game.add.sprite(500, 300, 'card');
|
||||
physics = new Phaser.Physics.Advanced.Manager(game);
|
||||
//Phaser.Physics.Advanced.Manager.debug = debug;
|
||||
walls = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_STATIC, 0, 0);
|
||||
walls.game = game;
|
||||
//walls.addBox(250, 200, 500, 20, 0, 1, 1);
|
||||
//staticBody.addShape(new ShapeBox(0, 0.2, 20.48, 0.4));
|
||||
// * 0.02 p2m
|
||||
// * 50 m2p
|
||||
walls.addBox(0, 500, 1024, 20, 0, 1, 1);
|
||||
//walls.transform.setRotation(game.math.degreesToRadians(4));
|
||||
//walls.fixedRotation = true;
|
||||
// position is in relation to the containing body! don't forget this
|
||||
//ground = walls.addShape(new Phaser.Physics.Advanced.Shapes.Box(400, 500, 500, 20));
|
||||
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(0, 0.2, 20.48, 0.4));
|
||||
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(0, 15.16, 20.48, 0.4));
|
||||
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(-10.04, 7.68, 0.4, 14.56));
|
||||
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(10.04, 7.68, 0.4, 14.56));
|
||||
//walls.resetMassData();
|
||||
physics.space.addBody(walls);
|
||||
// Add a circle
|
||||
//circle = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_DYNAMIC, 200, 100);
|
||||
//circle.game = game;
|
||||
//circle.addCircle(32, 0, 0, 0.5);
|
||||
//physics.space.addBody(circle);
|
||||
t = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_DYNAMIC, 300, 100);
|
||||
//t.fixedRotation = true;
|
||||
t.game = game;
|
||||
t.addBox(0, 0, 20, 20, 0.5, 1, 1);
|
||||
//t.addCircle(32, 0, 0, 0.8);
|
||||
//t.addTriangle(0, 0, 1, 1, 2, 2);
|
||||
//t.addPoly([{ x: -0.8, y: 0.48 }, { x: -0.8, y: 0 }, { x: 0.8, y: 0 }, { x: 0.8, y: 0.32 }, { x: 0, y: 0.84 }, { x: -0.56, y: 0.84 }], 1, 1, 6);
|
||||
//t.addPoly([{ x: -0.8, y: 0.48 }, { x: -0.8, y: 0 }, { x: 0.8, y: 0 }, { x: 0.8, y: 0.32 }, { x: 0, y: 0.84 }, { x: -0.56, y: 0.84 }], 0.5, 1, 1);
|
||||
//t.transform.setRotation(game.math.degreesToRadians(45));
|
||||
//t.fixedRotation = true;
|
||||
physics.space.addBody(t);
|
||||
game.input.onTap.add(step, this);
|
||||
}
|
||||
function step() {
|
||||
physics.update();
|
||||
}
|
||||
function update() {
|
||||
//if (physics.space.stepCount < 90)
|
||||
//{
|
||||
physics.update();
|
||||
//}
|
||||
//atari.x = physics.metersToPixels(circle.position.x);
|
||||
//atari.y = physics.metersToPixels(circle.position.y);
|
||||
//atari.rotation = physics.metersToPixels(circle.angle);
|
||||
// force moves without rotating
|
||||
if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
circle.applyAngularImpulse(-0.02);
|
||||
} else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
circle.applyAngularImpulse(0.02);
|
||||
}
|
||||
/*
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
circle.applyForceToCenter(new Phaser.Vec2(-8, 0));
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
circle.applyForceToCenter(new Phaser.Vec2(8, 0));
|
||||
}
|
||||
*/
|
||||
if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
circle.applyForceToCenter(new Phaser.Vec2(0, -10));
|
||||
} else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
||||
circle.applyForceToCenter(new Phaser.Vec2(0, 5));
|
||||
}
|
||||
//console.log(circle.velocity.x, circle.velocity.y);
|
||||
//console.log('p', circle.position.x, circle.position.y);
|
||||
}
|
||||
function renderBounds(body) {
|
||||
game.stage.context.fillStyle = 'rgba(0,255,200,0.2)';
|
||||
game.stage.context.fillRect(body.bounds.x, body.bounds.y, body.bounds.width, body.bounds.height);
|
||||
}
|
||||
function renderCircle(shape) {
|
||||
game.stage.context.beginPath();
|
||||
game.stage.context.arc(shape.tc.x * 50, shape.tc.y * 50, shape.radius * 50, 0, Math.PI * 2, false);
|
||||
if(shape.body.isAwake) {
|
||||
game.stage.context.fillStyle = 'rgba(0,255,0, 0.3)';
|
||||
} else {
|
||||
game.stage.context.fillStyle = 'rgba(100,100,100, 0.1)';
|
||||
}
|
||||
game.stage.context.fill();
|
||||
game.stage.context.closePath();
|
||||
}
|
||||
function drawPolygon(ctx, shape, lineWidth, fillStyle) {
|
||||
var verts = shape.tverts;
|
||||
var body = shape.body;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(body.position.x + verts[0].x * 50, body.position.y + verts[0].y * 50);
|
||||
for(var i = 0; i < verts.length; i++) {
|
||||
ctx.lineTo(body.position.x + verts[i].x * 50, body.position.y + verts[i].y * 50);
|
||||
}
|
||||
ctx.lineTo(body.position.x + verts[verts.length - 1].x * 50, body.position.y + verts[verts.length - 1].y * 50);
|
||||
ctx.closePath();
|
||||
ctx.fillStyle = fillStyle;
|
||||
ctx.fill();
|
||||
}
|
||||
function render() {
|
||||
//game.stage.context.fillStyle = 'rgb(255,255,0)';
|
||||
//game.stage.context.fillText('x: ' + t.position.x + ' y: ' + t.position.y, 32, 32);
|
||||
//game.stage.context.fillText('vx: ' + t.velocity.x + ' vy: ' + t.velocity.y, 32, 64);
|
||||
//game.stage.context.fillText('x: ' + t.bounds.x + ' y: ' + t.bounds.y, 32, 32);
|
||||
//game.stage.context.fillText('vx: ' + t.velocity.x + ' vy: ' + t.velocity.y, 32, 64);
|
||||
//renderCircle(circle.shapes[0]);
|
||||
//renderBounds(circle);
|
||||
drawPolygon(game.stage.context, walls.shapes[0], 1, 'rgb(0,255,255)');
|
||||
//drawPolygon(game.stage.context, walls.shapes[1], 1, 'rgb(0,255,255)');
|
||||
//renderCircle(t.shapes[0]);
|
||||
drawPolygon(game.stage.context, t.shapes[0], 1, 'rgb(255,255,255)');
|
||||
//renderBounds(t);
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,206 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
/// <reference path="../../Phaser/physics/advanced/Manager.ts" />
|
||||
/// <reference path="../../Phaser/physics/advanced/shapes/Box.ts" />
|
||||
/// <reference path="../../Phaser/physics/advanced/shapes/Circle.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
|
||||
function init() {
|
||||
|
||||
game.load.image('xatari', 'assets/sprites/atari800xl.png');
|
||||
game.load.image('card', 'assets/sprites/mana_card.png');
|
||||
game.load.image('atari', 'assets/sprites/shinyball.png');
|
||||
game.load.start();
|
||||
|
||||
}
|
||||
|
||||
var debug: HTMLTextAreaElement;
|
||||
var atari: Phaser.Sprite;
|
||||
var card: Phaser.Sprite;
|
||||
var physics: Phaser.Physics.Advanced.Manager;
|
||||
var circle: Phaser.Physics.Advanced.Body;
|
||||
var walls: Phaser.Physics.Advanced.Body;
|
||||
var t: Phaser.Physics.Advanced.Body;
|
||||
|
||||
function create() {
|
||||
|
||||
//atari = game.add.sprite(200, 100, 'atari');
|
||||
|
||||
// need to get the physics bounds around the sprite center, regardless of origin
|
||||
//atari.transform.origin.setTo(0.5, 0.5);
|
||||
//card = game.add.sprite(500, 300, 'card');
|
||||
|
||||
physics = new Phaser.Physics.Advanced.Manager(game);
|
||||
//Phaser.Physics.Advanced.Manager.debug = debug;
|
||||
|
||||
walls = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_STATIC, 0, 0);
|
||||
walls.game = game;
|
||||
|
||||
//walls.addBox(250, 200, 500, 20, 0, 1, 1);
|
||||
|
||||
//staticBody.addShape(new ShapeBox(0, 0.2, 20.48, 0.4));
|
||||
|
||||
// * 0.02 p2m
|
||||
// * 50 m2p
|
||||
|
||||
walls.addBox(0, 500, 1024, 20, 0, 1, 1);
|
||||
|
||||
//walls.transform.setRotation(game.math.degreesToRadians(4));
|
||||
//walls.fixedRotation = true;
|
||||
|
||||
// position is in relation to the containing body! don't forget this
|
||||
//ground = walls.addShape(new Phaser.Physics.Advanced.Shapes.Box(400, 500, 500, 20));
|
||||
|
||||
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(0, 0.2, 20.48, 0.4));
|
||||
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(0, 15.16, 20.48, 0.4));
|
||||
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(-10.04, 7.68, 0.4, 14.56));
|
||||
//walls.addShape(new Phaser.Physics.Advanced.ShapeBox(10.04, 7.68, 0.4, 14.56));
|
||||
//walls.resetMassData();
|
||||
|
||||
physics.space.addBody(walls);
|
||||
|
||||
// Add a circle
|
||||
//circle = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_DYNAMIC, 200, 100);
|
||||
//circle.game = game;
|
||||
//circle.addCircle(32, 0, 0, 0.5);
|
||||
//physics.space.addBody(circle);
|
||||
|
||||
t = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_DYNAMIC, 300, 100);
|
||||
//t.fixedRotation = true;
|
||||
t.game = game;
|
||||
t.addBox(0, 0, 20, 20, 0.5, 1, 1);
|
||||
//t.addCircle(32, 0, 0, 0.8);
|
||||
//t.addTriangle(0, 0, 1, 1, 2, 2);
|
||||
//t.addPoly([{ x: -0.8, y: 0.48 }, { x: -0.8, y: 0 }, { x: 0.8, y: 0 }, { x: 0.8, y: 0.32 }, { x: 0, y: 0.84 }, { x: -0.56, y: 0.84 }], 1, 1, 6);
|
||||
//t.addPoly([{ x: -0.8, y: 0.48 }, { x: -0.8, y: 0 }, { x: 0.8, y: 0 }, { x: 0.8, y: 0.32 }, { x: 0, y: 0.84 }, { x: -0.56, y: 0.84 }], 0.5, 1, 1);
|
||||
//t.transform.setRotation(game.math.degreesToRadians(45));
|
||||
//t.fixedRotation = true;
|
||||
physics.space.addBody(t);
|
||||
|
||||
game.input.onTap.add(step, this);
|
||||
|
||||
}
|
||||
|
||||
function step() {
|
||||
|
||||
physics.update();
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
//if (physics.space.stepCount < 90)
|
||||
//{
|
||||
physics.update();
|
||||
//}
|
||||
|
||||
//atari.x = physics.metersToPixels(circle.position.x);
|
||||
//atari.y = physics.metersToPixels(circle.position.y);
|
||||
//atari.rotation = physics.metersToPixels(circle.angle);
|
||||
|
||||
// force moves without rotating
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
circle.applyAngularImpulse(-0.02);
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
circle.applyAngularImpulse(0.02);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
circle.applyForceToCenter(new Phaser.Vec2(-8, 0));
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
circle.applyForceToCenter(new Phaser.Vec2(8, 0));
|
||||
}
|
||||
*/
|
||||
|
||||
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
circle.applyForceToCenter(new Phaser.Vec2(0, -10));
|
||||
}
|
||||
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
{
|
||||
circle.applyForceToCenter(new Phaser.Vec2(0, 5));
|
||||
}
|
||||
|
||||
//console.log(circle.velocity.x, circle.velocity.y);
|
||||
//console.log('p', circle.position.x, circle.position.y);
|
||||
}
|
||||
|
||||
function renderBounds(body: Phaser.Physics.Advanced.Body) {
|
||||
|
||||
game.stage.context.fillStyle = 'rgba(0,255,200,0.2)';
|
||||
|
||||
game.stage.context.fillRect(body.bounds.x, body.bounds.y, body.bounds.width, body.bounds.height);
|
||||
|
||||
}
|
||||
|
||||
function renderCircle(shape) {
|
||||
|
||||
game.stage.context.beginPath();
|
||||
game.stage.context.arc(shape.tc.x * 50, shape.tc.y * 50, shape.radius * 50, 0, Math.PI * 2, false);
|
||||
|
||||
if (shape.body.isAwake)
|
||||
{
|
||||
game.stage.context.fillStyle = 'rgba(0,255,0, 0.3)';
|
||||
}
|
||||
else
|
||||
{
|
||||
game.stage.context.fillStyle = 'rgba(100,100,100, 0.1)';
|
||||
}
|
||||
|
||||
game.stage.context.fill();
|
||||
game.stage.context.closePath();
|
||||
|
||||
}
|
||||
|
||||
function drawPolygon(ctx, shape, lineWidth, fillStyle) {
|
||||
|
||||
var verts = shape.tverts;
|
||||
var body = shape.body;
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(body.position.x + verts[0].x * 50, body.position.y + verts[0].y * 50);
|
||||
|
||||
for (var i = 0; i < verts.length; i++) {
|
||||
ctx.lineTo(body.position.x + verts[i].x * 50, body.position.y + verts[i].y * 50);
|
||||
}
|
||||
|
||||
ctx.lineTo(body.position.x + verts[verts.length - 1].x * 50, body.position.y + verts[verts.length - 1].y * 50);
|
||||
|
||||
ctx.closePath();
|
||||
|
||||
ctx.fillStyle = fillStyle;
|
||||
ctx.fill();
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
//game.stage.context.fillStyle = 'rgb(255,255,0)';
|
||||
//game.stage.context.fillText('x: ' + t.position.x + ' y: ' + t.position.y, 32, 32);
|
||||
//game.stage.context.fillText('vx: ' + t.velocity.x + ' vy: ' + t.velocity.y, 32, 64);
|
||||
//game.stage.context.fillText('x: ' + t.bounds.x + ' y: ' + t.bounds.y, 32, 32);
|
||||
//game.stage.context.fillText('vx: ' + t.velocity.x + ' vy: ' + t.velocity.y, 32, 64);
|
||||
|
||||
//renderCircle(circle.shapes[0]);
|
||||
//renderBounds(circle);
|
||||
|
||||
drawPolygon(game.stage.context, walls.shapes[0], 1, 'rgb(0,255,255)');
|
||||
//drawPolygon(game.stage.context, walls.shapes[1], 1, 'rgb(0,255,255)');
|
||||
|
||||
//renderCircle(t.shapes[0]);
|
||||
drawPolygon(game.stage.context, t.shapes[0], 1, 'rgb(255,255,255)');
|
||||
//renderBounds(t);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,33 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
function init() {
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('atari', 'assets/sprites/atari800xl.png');
|
||||
game.load.image('card', 'assets/sprites/mana_card.png');
|
||||
game.load.start();
|
||||
}
|
||||
var atari;
|
||||
var card;
|
||||
function create() {
|
||||
atari = game.add.sprite(200, 310, 'atari');
|
||||
card = game.add.sprite(500, 300, 'card');
|
||||
atari.input.start(0);
|
||||
atari.input.enableDrag();
|
||||
card.input.start(0);
|
||||
card.events.onInputDown.add(rotateIt, this);
|
||||
}
|
||||
function rotateIt() {
|
||||
card.rotation += 10;
|
||||
}
|
||||
function update() {
|
||||
}
|
||||
function render() {
|
||||
game.stage.context.save();
|
||||
game.stage.context.strokeStyle = 'rgb(255,255,0)';
|
||||
game.stage.context.strokeRect(atari.cameraView.x, atari.cameraView.y, atari.cameraView.width, atari.cameraView.height);
|
||||
game.stage.context.strokeStyle = 'rgb(255,0,255)';
|
||||
game.stage.context.strokeRect(card.cameraView.x, card.cameraView.y, card.cameraView.width, card.cameraView.height);
|
||||
game.stage.context.restore();
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,54 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var game = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
|
||||
function init() {
|
||||
|
||||
// Using Phasers asset loader we load up a PNG from the assets folder
|
||||
game.load.image('atari', 'assets/sprites/atari800xl.png');
|
||||
game.load.image('card', 'assets/sprites/mana_card.png');
|
||||
game.load.start();
|
||||
|
||||
}
|
||||
|
||||
var atari: Phaser.Sprite;
|
||||
var card: Phaser.Sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
atari = game.add.sprite(200, 310, 'atari');
|
||||
|
||||
card = game.add.sprite(500, 300, 'card');
|
||||
|
||||
atari.input.start(0);
|
||||
atari.input.enableDrag();
|
||||
|
||||
card.input.start(0);
|
||||
card.events.onInputDown.add(rotateIt, this);
|
||||
|
||||
}
|
||||
|
||||
function rotateIt() {
|
||||
card.rotation += 10;
|
||||
}
|
||||
|
||||
function update() {
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
game.stage.context.save();
|
||||
|
||||
game.stage.context.strokeStyle = 'rgb(255,255,0)';
|
||||
game.stage.context.strokeRect(atari.cameraView.x, atari.cameraView.y, atari.cameraView.width, atari.cameraView.height);
|
||||
|
||||
game.stage.context.strokeStyle = 'rgb(255,0,255)';
|
||||
game.stage.context.strokeRect(card.cameraView.x, card.cameraView.y, card.cameraView.width, card.cameraView.height);
|
||||
|
||||
game.stage.context.restore();
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,113 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
var Physics = (function () {
|
||||
function Physics() {
|
||||
this.max_bodies = 512;
|
||||
this.max_vertices = 1024;
|
||||
this.max_edges = 1024;
|
||||
this.max_body_vertices = 64;
|
||||
this.max_body_edges = 64;
|
||||
this.vertices = [];
|
||||
this.edges = [];
|
||||
this.bodies = [];
|
||||
}
|
||||
Physics.prototype.updateForces = // Sets the force on each vertex to the gravity force. You could of course apply other forces like magnetism etc.
|
||||
function () {
|
||||
for(var i = 0; i < this.vertexCount; i++) {
|
||||
this.vertices[i].acceleration = this.gravity;
|
||||
}
|
||||
};
|
||||
Physics.prototype.updateVerlet = // Updates the vertex position
|
||||
function () {
|
||||
for(var i = 0; i < this.vertexCount; i++) {
|
||||
var v = this.vertices[i];
|
||||
var temp = v.position;
|
||||
//v.position.mutableAdd(
|
||||
//v.position += v.position - v.oldPosition + v.acceleration * this.timestep * this.timestep;
|
||||
}
|
||||
};
|
||||
Physics.prototype.updateEdges = function () {
|
||||
};
|
||||
Physics.prototype.iterateCollisions = function () {
|
||||
};
|
||||
Physics.prototype.detectCollision = function (body1, body2) {
|
||||
};
|
||||
Physics.prototype.processCollision = function () {
|
||||
};
|
||||
Physics.prototype.intervalDistance = function (minA, maxA, minB, maxB) {
|
||||
};
|
||||
Physics.prototype.bodiesOverlap = function (body1, body2) {
|
||||
};
|
||||
Physics.prototype.update = // CollisionInfo
|
||||
// depth, normal, edge, vertex
|
||||
function () {
|
||||
};
|
||||
Physics.prototype.render = function () {
|
||||
};
|
||||
Physics.prototype.addBody = function (body) {
|
||||
this.bodies.push(body);
|
||||
this.bodyCount = this.bodies.length;
|
||||
};
|
||||
Physics.prototype.addEdge = function (edge) {
|
||||
this.edges.push(edge);
|
||||
this.edgeCount = this.edges.length;
|
||||
};
|
||||
Physics.prototype.addVertex = function (vertex) {
|
||||
this.vertices.push(vertex);
|
||||
this.vertexCount = this.vertices.length;
|
||||
};
|
||||
Physics.prototype.findVertex = function (x, y) {
|
||||
};
|
||||
return Physics;
|
||||
})();
|
||||
var PhysicsBody = (function () {
|
||||
function PhysicsBody() {
|
||||
this.vertices = [];
|
||||
this.edges = [];
|
||||
}
|
||||
PhysicsBody.prototype.addEdge = function (edge) {
|
||||
};
|
||||
PhysicsBody.prototype.addVertex = function (vertex) {
|
||||
};
|
||||
PhysicsBody.prototype.projectToAxis = function (axis, min, max) {
|
||||
};
|
||||
PhysicsBody.prototype.calculateCenter = function () {
|
||||
};
|
||||
PhysicsBody.prototype.createBox = function (x, y, width, height) {
|
||||
};
|
||||
return PhysicsBody;
|
||||
})();
|
||||
var Vertex = (function () {
|
||||
function Vertex(body, posX, posY) {
|
||||
}
|
||||
return Vertex;
|
||||
})();
|
||||
var Edge = (function () {
|
||||
function Edge(body, pV1, pV2, pBoundary) {
|
||||
}
|
||||
return Edge;
|
||||
})();
|
||||
(function () {
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
function init() {
|
||||
myGame.loader.addImageFile('atari1', 'assets/sprites/atari130xe.png');
|
||||
myGame.loader.load();
|
||||
}
|
||||
function create() {
|
||||
var p = new Physics();
|
||||
//p.max_bodies
|
||||
}
|
||||
function update() {
|
||||
}
|
||||
function render() {
|
||||
//myGame.stage.context.strokeStyle = 'rgb(0,255,0)';
|
||||
//myGame.stage.context.beginPath();
|
||||
//myGame.stage.context.moveTo(poly1.points[0].x + poly1.pos.x, poly1.points[0].y + poly1.pos.y);
|
||||
//for (var i = 1; i < poly1.points.length; i++)
|
||||
//{
|
||||
// myGame.stage.context.lineTo(poly1.points[i].x + poly1.pos.x, poly1.points[i].y + poly1.pos.y);
|
||||
//}
|
||||
//myGame.stage.context.lineTo(poly1.points[0].x + poly1.pos.x, poly1.points[0].y + poly1.pos.y);
|
||||
//myGame.stage.context.stroke();
|
||||
//myGame.stage.context.closePath();
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,200 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
|
||||
class Physics {
|
||||
|
||||
constructor() {
|
||||
|
||||
this.vertices = [];
|
||||
this.edges = [];
|
||||
this.bodies = [];
|
||||
|
||||
}
|
||||
|
||||
public gravity: Phaser.Vector2;
|
||||
|
||||
public max_bodies: number = 512;
|
||||
public max_vertices: number = 1024;
|
||||
public max_edges: number = 1024;
|
||||
public max_body_vertices: number = 64;
|
||||
public max_body_edges: number = 64;
|
||||
|
||||
public bodyCount: number;
|
||||
public vertexCount: number;
|
||||
public edgeCount: number;
|
||||
public timestep: number;
|
||||
public iterations;
|
||||
|
||||
public vertices: Vertex[];
|
||||
public edges: Edge[];
|
||||
public bodies: PhysicsBody[];
|
||||
|
||||
// Sets the force on each vertex to the gravity force. You could of course apply other forces like magnetism etc.
|
||||
public updateForces() {
|
||||
|
||||
for (var i:number = 0; i < this.vertexCount; i++)
|
||||
{
|
||||
this.vertices[i].acceleration = this.gravity;
|
||||
}
|
||||
}
|
||||
|
||||
// Updates the vertex position
|
||||
public updateVerlet() {
|
||||
|
||||
for (var i:number = 0; i < this.vertexCount; i++)
|
||||
{
|
||||
var v:Vertex = this.vertices[i];
|
||||
var temp: Phaser.Vector2 = v.position;
|
||||
//v.position.mutableAdd(
|
||||
//v.position += v.position - v.oldPosition + v.acceleration * this.timestep * this.timestep;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public updateEdges() {
|
||||
}
|
||||
|
||||
public iterateCollisions() {
|
||||
}
|
||||
|
||||
public detectCollision(body1, body2) {
|
||||
}
|
||||
|
||||
public processCollision() {
|
||||
}
|
||||
|
||||
public intervalDistance(minA, maxA, minB, maxB) {
|
||||
}
|
||||
|
||||
public bodiesOverlap(body1, body2) {
|
||||
}
|
||||
|
||||
// CollisionInfo
|
||||
// depth, normal, edge, vertex
|
||||
|
||||
public update() {
|
||||
}
|
||||
|
||||
public render() {
|
||||
}
|
||||
|
||||
public addBody(body:PhysicsBody) {
|
||||
this.bodies.push(body);
|
||||
this.bodyCount = this.bodies.length;
|
||||
}
|
||||
|
||||
public addEdge(edge:Edge) {
|
||||
this.edges.push(edge);
|
||||
this.edgeCount = this.edges.length;
|
||||
}
|
||||
|
||||
public addVertex(vertex:Vertex) {
|
||||
this.vertices.push(vertex);
|
||||
this.vertexCount = this.vertices.length;
|
||||
}
|
||||
|
||||
public findVertex(x, y) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class PhysicsBody {
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
center: Phaser.Vector2;
|
||||
minX;
|
||||
minY;
|
||||
maxX;
|
||||
maxY;
|
||||
vertextCount;
|
||||
edgeCount;
|
||||
|
||||
vertices = [];
|
||||
edges = [];
|
||||
|
||||
public addEdge(edge) {
|
||||
}
|
||||
|
||||
public addVertex(vertex) {
|
||||
|
||||
}
|
||||
|
||||
public projectToAxis(axis, min, max) {
|
||||
}
|
||||
|
||||
public calculateCenter() {
|
||||
}
|
||||
|
||||
public createBox(x, y, width, height) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Vertex {
|
||||
|
||||
constructor(body, posX, posY) {
|
||||
}
|
||||
|
||||
position: Phaser.Vector2;
|
||||
oldPosition: Phaser.Vector2;
|
||||
acceleration: Phaser.Vector2;
|
||||
parent: PhysicsBody;
|
||||
}
|
||||
|
||||
class Edge {
|
||||
|
||||
constructor(body, pV1, pV2, pBoundary) {
|
||||
}
|
||||
|
||||
v1: Vertex;
|
||||
v2: Vertex;
|
||||
length;
|
||||
boundary;
|
||||
parent: PhysicsBody;
|
||||
|
||||
}
|
||||
|
||||
(function () {
|
||||
|
||||
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
|
||||
function init() {
|
||||
|
||||
myGame.loader.addImageFile('atari1', 'assets/sprites/atari130xe.png');
|
||||
myGame.loader.load();
|
||||
|
||||
}
|
||||
|
||||
function create() {
|
||||
|
||||
var p = new Physics();
|
||||
//p.max_bodies
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
//myGame.stage.context.strokeStyle = 'rgb(0,255,0)';
|
||||
//myGame.stage.context.beginPath();
|
||||
//myGame.stage.context.moveTo(poly1.points[0].x + poly1.pos.x, poly1.points[0].y + poly1.pos.y);
|
||||
|
||||
//for (var i = 1; i < poly1.points.length; i++)
|
||||
//{
|
||||
// myGame.stage.context.lineTo(poly1.points[i].x + poly1.pos.x, poly1.points[i].y + poly1.pos.y);
|
||||
//}
|
||||
|
||||
//myGame.stage.context.lineTo(poly1.points[0].x + poly1.pos.x, poly1.points[0].y + poly1.pos.y);
|
||||
|
||||
//myGame.stage.context.stroke();
|
||||
//myGame.stage.context.closePath();
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
Before Width: | Height: | Size: 344 KiB |
Reference in New Issue
Block a user