mirror of
https://github.com/wassname/phaser.git
synced 2026-08-14 12:40:17 +08:00
Merge branch 'photonstorm/097'
This commit is contained in:
@@ -186,6 +186,14 @@
|
||||
<Content Include="physics\aabb vs aabb 1.js">
|
||||
<DependentUpon>aabb vs aabb 1.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\obb vs obb.ts" />
|
||||
<TypeScriptCompile Include="physics\body1.ts" />
|
||||
<Content Include="physics\body1.js">
|
||||
<DependentUpon>body1.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="physics\obb vs obb.js">
|
||||
<DependentUpon>obb vs obb.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="scrollzones\ballscroller.js">
|
||||
<DependentUpon>ballscroller.ts</DependentUpon>
|
||||
</Content>
|
||||
|
||||
+3676
-15
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,104 @@
|
||||
/// <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 atari;
|
||||
var card;
|
||||
var physics;
|
||||
var circle;
|
||||
var walls;
|
||||
var ground;
|
||||
function create() {
|
||||
atari = game.add.sprite(200, 100, 'atari');
|
||||
atari.transform.origin.setTo(0.5, 0.5);
|
||||
//card = game.add.sprite(500, 300, 'card');
|
||||
physics = new Phaser.Physics.Advanced.Manager(game);
|
||||
walls = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_STATIC);
|
||||
walls.game = game;
|
||||
// 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, physics.pixelsToMeters(300), physics.pixelsToMeters(200));
|
||||
circle.game = game;
|
||||
var shape = new Phaser.Physics.Advanced.Shapes.Circle(0.4, 0, 0);
|
||||
shape.elasticity = 0.8;
|
||||
shape.friction = 1;
|
||||
shape.density = 1;
|
||||
circle.addShape(shape);
|
||||
circle.resetMassData();
|
||||
physics.space.addBody(circle);
|
||||
}
|
||||
function update() {
|
||||
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 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.verts;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(verts[0].x * 50, verts[0].y * 50);
|
||||
for(var i = 0; i < verts.length; i++) {
|
||||
ctx.lineTo(verts[i].x * 50, verts[i].y * 50);
|
||||
}
|
||||
ctx.lineTo(verts[verts.length - 1].x * 50, 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: ' + circle.position.x + ' y: ' + circle.position.y, 32, 32);
|
||||
game.stage.context.fillText('vx: ' + circle.velocity.x + ' vy: ' + circle.velocity.y, 32, 64);
|
||||
renderCircle(circle.shapes[0]);
|
||||
drawPolygon(game.stage.context, walls.shapes[0], 1, 'rgb(0,255,255)');
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,160 @@
|
||||
/// <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 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 ground: Phaser.Physics.Advanced.Shapes.Box;
|
||||
|
||||
function create() {
|
||||
|
||||
atari = game.add.sprite(200, 100, 'atari');
|
||||
atari.transform.origin.setTo(0.5, 0.5);
|
||||
//card = game.add.sprite(500, 300, 'card');
|
||||
|
||||
physics = new Phaser.Physics.Advanced.Manager(game);
|
||||
|
||||
walls = new Phaser.Physics.Advanced.Body(null, Phaser.Types.BODY_STATIC);
|
||||
walls.game = game;
|
||||
|
||||
// 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, physics.pixelsToMeters(300), physics.pixelsToMeters(200));
|
||||
circle.game = game;
|
||||
|
||||
var shape = new Phaser.Physics.Advanced.Shapes.Circle(0.4, 0, 0);
|
||||
shape.elasticity = 0.8;
|
||||
shape.friction = 1;
|
||||
shape.density = 1;
|
||||
circle.addShape(shape);
|
||||
circle.resetMassData();
|
||||
|
||||
physics.space.addBody(circle);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
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 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.verts;
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(verts[0].x * 50, verts[0].y * 50);
|
||||
|
||||
for (var i = 0; i < verts.length; i++) {
|
||||
ctx.lineTo(verts[i].x * 50, verts[i].y * 50);
|
||||
}
|
||||
|
||||
ctx.lineTo(verts[verts.length - 1].x * 50, 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: ' + circle.position.x + ' y: ' + circle.position.y, 32, 32);
|
||||
game.stage.context.fillText('vx: ' + circle.velocity.x + ' vy: ' + circle.velocity.y, 32, 64);
|
||||
|
||||
renderCircle(circle.shapes[0]);
|
||||
|
||||
drawPolygon(game.stage.context, walls.shapes[0], 1, 'rgb(0,255,255)');
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user