mirror of
https://github.com/wassname/phaser.git
synced 2026-09-11 12:31:29 +08:00
Added the GameObjectManager
This commit is contained in:
@@ -118,6 +118,10 @@
|
||||
<TypeScriptCompile Include="input\multitouch.ts" />
|
||||
<TypeScriptCompile Include="groups\display order.ts" />
|
||||
<TypeScriptCompile Include="collision\mask test 1.ts" />
|
||||
<TypeScriptCompile Include="collision\mask animation 1.ts" />
|
||||
<Content Include="collision\mask animation 1.js">
|
||||
<DependentUpon>mask animation 1.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="collision\mask test 1.js">
|
||||
<DependentUpon>mask test 1.ts</DependentUpon>
|
||||
</Content>
|
||||
@@ -131,6 +135,10 @@
|
||||
</Content>
|
||||
<TypeScriptCompile Include="geometry\rotate point 2.ts" />
|
||||
<TypeScriptCompile Include="geometry\rotate point 1.ts" />
|
||||
<TypeScriptCompile Include="geometry\rope bridge.ts" />
|
||||
<Content Include="geometry\rope bridge.js">
|
||||
<DependentUpon>rope bridge.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="geometry\rotate point 1.js">
|
||||
<DependentUpon>rotate point 1.ts</DependentUpon>
|
||||
</Content>
|
||||
@@ -190,6 +198,14 @@
|
||||
<Content Include="particles\mousetrail.js">
|
||||
<DependentUpon>mousetrail.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\temp1.ts" />
|
||||
<Content Include="physics\temp1.js">
|
||||
<DependentUpon>temp1.ts</DependentUpon>
|
||||
</Content>
|
||||
<TypeScriptCompile Include="physics\temp2.ts" />
|
||||
<Content Include="physics\temp2.js">
|
||||
<DependentUpon>temp2.ts</DependentUpon>
|
||||
</Content>
|
||||
<Content Include="scrollzones\ballscroller.js">
|
||||
<DependentUpon>ballscroller.ts</DependentUpon>
|
||||
</Content>
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
function init() {
|
||||
myGame.loader.addImageFile('card', 'assets/sprites/mana_card.png');
|
||||
myGame.loader.addTextureAtlas('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json');
|
||||
myGame.loader.load();
|
||||
}
|
||||
var card;
|
||||
var bot;
|
||||
function create() {
|
||||
card = myGame.createSprite(200, 220, 'card');
|
||||
bot = myGame.createSprite(myGame.stage.width - 100, 300, 'bot');
|
||||
// The collision mask is much thinner than the animated sprite
|
||||
bot.collisionMask.offset.x = 16;
|
||||
bot.collisionMask.width = 32;
|
||||
bot.renderDebug = true;
|
||||
bot.animations.add('run');
|
||||
bot.animations.play('run', 10, true);
|
||||
bot.velocity.x = -150;
|
||||
}
|
||||
function update() {
|
||||
if(bot.x < -bot.width) {
|
||||
bot.x = myGame.stage.width;
|
||||
bot.velocity.x = -150;
|
||||
card.x = 200;
|
||||
card.velocity.x = 0;
|
||||
}
|
||||
myGame.collide(card, bot);
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,50 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
|
||||
|
||||
function init() {
|
||||
|
||||
myGame.loader.addImageFile('card', 'assets/sprites/mana_card.png');
|
||||
myGame.loader.addTextureAtlas('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json');
|
||||
myGame.loader.load();
|
||||
|
||||
}
|
||||
|
||||
var card: Phaser.Sprite;
|
||||
var bot: Phaser.Sprite;
|
||||
|
||||
function create() {
|
||||
|
||||
card = myGame.createSprite(200, 220, 'card');
|
||||
|
||||
bot = myGame.createSprite(myGame.stage.width - 100, 300, 'bot');
|
||||
|
||||
// The collision mask is much thinner than the animated sprite
|
||||
bot.collisionMask.offset.x = 16;
|
||||
bot.collisionMask.width = 32;
|
||||
bot.renderDebug = true;
|
||||
|
||||
bot.animations.add('run');
|
||||
bot.animations.play('run', 10, true);
|
||||
|
||||
bot.velocity.x = -150;
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
if (bot.x < -bot.width)
|
||||
{
|
||||
bot.x = myGame.stage.width;
|
||||
bot.velocity.x = -150;
|
||||
card.x = 200;
|
||||
card.velocity.x = 0;
|
||||
}
|
||||
|
||||
myGame.collide(card, bot);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -34,6 +34,5 @@
|
||||
console.log('Collision!!!!!');
|
||||
}
|
||||
function render() {
|
||||
//atari1.ren
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -59,9 +59,6 @@
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
//atari1.ren
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
function init() {
|
||||
myGame.loader.addImageFile('ball5', 'assets/sprites/purple_ball.png');
|
||||
myGame.loader.load();
|
||||
}
|
||||
var segment;
|
||||
function create() {
|
||||
myGame.verlet.friction = 1;
|
||||
myGame.verlet.hideNearestEntityCircle = true;
|
||||
var points = [];
|
||||
var startX = 100;
|
||||
var startY = 200;
|
||||
var spacing = 20;
|
||||
for(var i = 0; i < 30; i++) {
|
||||
points.push(new Phaser.Vector2(startX + (i * spacing), startY));
|
||||
}
|
||||
segment = myGame.verlet.createLineSegments(points, 0.5);
|
||||
segment.loadGraphic('ball5');
|
||||
segment.hideConstraints = false;
|
||||
segment.pin(0);
|
||||
segment.pin(points.length - 1);
|
||||
}
|
||||
function update() {
|
||||
}
|
||||
function render() {
|
||||
myGame.verlet.render();
|
||||
//myGame.stage.context.fillStyle = 'rgb(255,255,0)';
|
||||
//myGame.stage.context.fillRect(p1.x, p1.y, 4, 4);
|
||||
//myGame.stage.context.fillStyle = 'rgb(255,0,0)';
|
||||
//myGame.stage.context.fillRect(p2.x, p2.y, 4, 4);
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,55 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
|
||||
(function () {
|
||||
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
|
||||
function init() {
|
||||
|
||||
myGame.loader.addImageFile('ball5', 'assets/sprites/purple_ball.png');
|
||||
myGame.loader.load();
|
||||
|
||||
}
|
||||
|
||||
var segment: Phaser.Verlet.Composite;
|
||||
|
||||
function create() {
|
||||
|
||||
myGame.verlet.friction = 1;
|
||||
myGame.verlet.hideNearestEntityCircle = true;
|
||||
|
||||
var points: Phaser.Vector2[] = [];
|
||||
var startX: number = 100;
|
||||
var startY: number = 200;
|
||||
var spacing: number = 20;
|
||||
|
||||
for (var i = 0; i < 30; i++)
|
||||
{
|
||||
points.push(new Phaser.Vector2(startX + (i * spacing), startY));
|
||||
}
|
||||
|
||||
segment = myGame.verlet.createLineSegments(points, 0.5);
|
||||
segment.loadGraphic('ball5');
|
||||
segment.hideConstraints = false;
|
||||
|
||||
segment.pin(0);
|
||||
segment.pin(points.length - 1);
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
myGame.verlet.render();
|
||||
|
||||
//myGame.stage.context.fillStyle = 'rgb(255,255,0)';
|
||||
//myGame.stage.context.fillRect(p1.x, p1.y, 4, 4);
|
||||
|
||||
//myGame.stage.context.fillStyle = 'rgb(255,0,0)';
|
||||
//myGame.stage.context.fillRect(p2.x, p2.y, 4, 4);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -22,9 +22,5 @@
|
||||
}
|
||||
function render() {
|
||||
myGame.verlet.render();
|
||||
//myGame.stage.context.fillStyle = 'rgb(255,255,0)';
|
||||
//myGame.stage.context.fillRect(p1.x, p1.y, 4, 4);
|
||||
//myGame.stage.context.fillStyle = 'rgb(255,0,0)';
|
||||
//myGame.stage.context.fillRect(p2.x, p2.y, 4, 4);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -28,12 +28,6 @@
|
||||
|
||||
myGame.verlet.render();
|
||||
|
||||
//myGame.stage.context.fillStyle = 'rgb(255,255,0)';
|
||||
//myGame.stage.context.fillRect(p1.x, p1.y, 4, 4);
|
||||
|
||||
//myGame.stage.context.fillStyle = 'rgb(255,0,0)';
|
||||
//myGame.stage.context.fillRect(p2.x, p2.y, 4, 4);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
/// <reference path="../../Phaser/Game.ts" />
|
||||
(function () {
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
var cube;
|
||||
var b1;
|
||||
var b2;
|
||||
var b3;
|
||||
var b4;
|
||||
function init() {
|
||||
myGame.loader.addImageFile('ball0', 'assets/sprites/yellow_ball.png');
|
||||
myGame.loader.addImageFile('ball1', 'assets/sprites/aqua_ball.png');
|
||||
@@ -15,33 +10,23 @@
|
||||
myGame.loader.addImageFile('ball5', 'assets/sprites/purple_ball.png');
|
||||
myGame.loader.load();
|
||||
}
|
||||
var wheel;
|
||||
var diamond;
|
||||
var triangle;
|
||||
var cube;
|
||||
function create() {
|
||||
myGame.verlet.friction = 1;
|
||||
myGame.verlet.step = 32;
|
||||
//var wheel = myGame.verlet.createTire(new Phaser.Vector2(200,50), 100, 30, 0.3, 0.9);
|
||||
//var tire2 = myGame.verlet.createTire(new Phaser.Vector2(400,50), 70, 7, 0.1, 0.2);
|
||||
cube = myGame.verlet.createTire(new Phaser.Vector2(300, 50), 100, 4, 1, 1);
|
||||
//var tri = myGame.verlet.createTire(new Phaser.Vector2(700,50), 100, 3, 1, 1);
|
||||
var dc = new Phaser.Verlet.DistanceConstraint(cube.particles[0], cube.particles[1], 1);
|
||||
cube.constraints.push(dc);
|
||||
var dc2 = new Phaser.Verlet.DistanceConstraint(cube.particles[1], cube.particles[2], 1);
|
||||
cube.constraints.push(dc2);
|
||||
var dc3 = new Phaser.Verlet.DistanceConstraint(cube.particles[2], cube.particles[3], 1);
|
||||
cube.constraints.push(dc3);
|
||||
b1 = myGame.createSprite(cube.particles[0].pos.x, cube.particles[0].pos.y, 'ball0');
|
||||
b2 = myGame.createSprite(cube.particles[1].pos.x, cube.particles[1].pos.y, 'ball1');
|
||||
b3 = myGame.createSprite(cube.particles[2].pos.x, cube.particles[2].pos.y, 'ball2');
|
||||
b4 = myGame.createSprite(cube.particles[3].pos.x, cube.particles[3].pos.y, 'ball3');
|
||||
wheel = myGame.verlet.createTire(new Phaser.Vector2(200, 50), 100, 30, 0.3, 0.9);
|
||||
wheel.loadGraphic('ball0');
|
||||
diamond = myGame.verlet.createTire(new Phaser.Vector2(400, 50), 70, 7, 0.1, 0.2);
|
||||
diamond.loadGraphic('ball1');
|
||||
triangle = myGame.verlet.createTire(new Phaser.Vector2(600, 50), 100, 3, 1, 1);
|
||||
triangle.loadGraphic('ball2');
|
||||
cube = myGame.verlet.createTire(new Phaser.Vector2(300, 50), 100, 4, 0.3, 0.9);
|
||||
cube.loadGraphic('ball3');
|
||||
}
|
||||
function update() {
|
||||
b1.x = cube.particles[0].pos.x - 8;
|
||||
b1.y = cube.particles[0].pos.y - 8;
|
||||
b2.x = cube.particles[1].pos.x - 8;
|
||||
b2.y = cube.particles[1].pos.y - 8;
|
||||
b3.x = cube.particles[2].pos.x - 8;
|
||||
b3.y = cube.particles[2].pos.y - 8;
|
||||
b4.x = cube.particles[3].pos.x - 8;
|
||||
b4.y = cube.particles[3].pos.y - 8;
|
||||
}
|
||||
function render() {
|
||||
myGame.verlet.render();
|
||||
|
||||
@@ -4,13 +4,6 @@
|
||||
|
||||
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update, render);
|
||||
|
||||
var cube: Phaser.Verlet.Composite;
|
||||
|
||||
var b1: Phaser.Sprite;
|
||||
var b2: Phaser.Sprite;
|
||||
var b3: Phaser.Sprite;
|
||||
var b4: Phaser.Sprite;
|
||||
|
||||
function init() {
|
||||
|
||||
myGame.loader.addImageFile('ball0', 'assets/sprites/yellow_ball.png');
|
||||
@@ -24,46 +17,31 @@
|
||||
|
||||
}
|
||||
|
||||
var wheel: Phaser.Verlet.Composite;
|
||||
var diamond: Phaser.Verlet.Composite;
|
||||
var triangle: Phaser.Verlet.Composite;
|
||||
var cube: Phaser.Verlet.Composite;
|
||||
|
||||
function create() {
|
||||
|
||||
myGame.verlet.friction = 1;
|
||||
myGame.verlet.step = 32;
|
||||
|
||||
//var wheel = myGame.verlet.createTire(new Phaser.Vector2(200,50), 100, 30, 0.3, 0.9);
|
||||
//var tire2 = myGame.verlet.createTire(new Phaser.Vector2(400,50), 70, 7, 0.1, 0.2);
|
||||
cube = myGame.verlet.createTire(new Phaser.Vector2(300, 50), 100, 4, 1, 1);
|
||||
//var tri = myGame.verlet.createTire(new Phaser.Vector2(700,50), 100, 3, 1, 1);
|
||||
|
||||
var dc: Phaser.Verlet.DistanceConstraint = new Phaser.Verlet.DistanceConstraint(cube.particles[0], cube.particles[1], 1);
|
||||
cube.constraints.push(dc);
|
||||
|
||||
var dc2: Phaser.Verlet.DistanceConstraint = new Phaser.Verlet.DistanceConstraint(cube.particles[1], cube.particles[2], 1);
|
||||
cube.constraints.push(dc2);
|
||||
|
||||
var dc3: Phaser.Verlet.DistanceConstraint = new Phaser.Verlet.DistanceConstraint(cube.particles[2], cube.particles[3], 1);
|
||||
cube.constraints.push(dc3);
|
||||
|
||||
b1 = myGame.createSprite(cube.particles[0].pos.x, cube.particles[0].pos.y, 'ball0');
|
||||
b2 = myGame.createSprite(cube.particles[1].pos.x, cube.particles[1].pos.y, 'ball1');
|
||||
b3 = myGame.createSprite(cube.particles[2].pos.x, cube.particles[2].pos.y, 'ball2');
|
||||
b4 = myGame.createSprite(cube.particles[3].pos.x, cube.particles[3].pos.y, 'ball3');
|
||||
wheel = myGame.verlet.createTire(new Phaser.Vector2(200,50), 100, 30, 0.3, 0.9);
|
||||
wheel.loadGraphic('ball0');
|
||||
|
||||
diamond = myGame.verlet.createTire(new Phaser.Vector2(400,50), 70, 7, 0.1, 0.2);
|
||||
diamond.loadGraphic('ball1');
|
||||
|
||||
triangle = myGame.verlet.createTire(new Phaser.Vector2(600,50), 100, 3, 1, 1);
|
||||
triangle.loadGraphic('ball2');
|
||||
|
||||
cube = myGame.verlet.createTire(new Phaser.Vector2(300, 50), 100, 4, 0.3, 0.9);
|
||||
cube.loadGraphic('ball3');
|
||||
|
||||
}
|
||||
|
||||
function update() {
|
||||
|
||||
b1.x = cube.particles[0].pos.x - 8;
|
||||
b1.y = cube.particles[0].pos.y - 8;
|
||||
|
||||
b2.x = cube.particles[1].pos.x - 8;
|
||||
b2.y = cube.particles[1].pos.y - 8;
|
||||
|
||||
b3.x = cube.particles[2].pos.x - 8;
|
||||
b3.y = cube.particles[2].pos.y - 8;
|
||||
|
||||
b4.x = cube.particles[3].pos.x - 8;
|
||||
b4.y = cube.particles[3].pos.y - 8;
|
||||
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
+1622
-716
File diff suppressed because it is too large
Load Diff
@@ -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
@@ -23,6 +23,7 @@
|
||||
emitter.setRotation(0, 0);
|
||||
// Looks like a smoke trail!
|
||||
//emitter.globalCompositeOperation = 'xor';
|
||||
// Looks way cool :)
|
||||
emitter.globalCompositeOperation = 'lighter';
|
||||
bullets = myGame.createGroup(50);
|
||||
// Create our bullet pool
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
myGame.loader.load();
|
||||
|
||||
}
|
||||
|
||||
var CACTUS = 31;
|
||||
var SIGN_POST = 46;
|
||||
var map: Phaser.Tilemap;
|
||||
var car: Phaser.Sprite;
|
||||
var tile: Phaser.Tile;
|
||||
@@ -28,10 +29,10 @@
|
||||
|
||||
// When the car collides with the cactus tile we'll flash the screen red briefly,
|
||||
// but it won't stop the car (the separateX/Y values are set to false)
|
||||
map.setCollisionByIndex([31], Phaser.Collision.ANY, true, false, false);
|
||||
map.setCollisionByIndex([CACTUS], Phaser.Collision.ANY, true, false, false);
|
||||
|
||||
// When the car collides with the sign post tile we'll stop the car moving (separation is set to true)
|
||||
map.setCollisionByIndex([46], Phaser.Collision.ANY, true, true, true);
|
||||
map.setCollisionByIndex([SIGN_POST], Phaser.Collision.ANY, true, true, true);
|
||||
|
||||
// This is the callback that will be called every time map.collide() returns true
|
||||
map.collisionCallback = collide;
|
||||
@@ -79,12 +80,12 @@
|
||||
// collisionData is an array containing all of the tiles the object overlapped with (can be more than 1)
|
||||
for (var i = 0; i < collisionData.length; i++)
|
||||
{
|
||||
if (collisionData[i].tile.index == 31)
|
||||
if (collisionData[i].tile.index == CACTUS)
|
||||
{
|
||||
console.log('you hit a cactus!');
|
||||
flash.start(0xff0000, 1);
|
||||
}
|
||||
else if (collisionData[i].tile.index == 31)
|
||||
else if (collisionData[i].tile.index == SIGN_POST)
|
||||
{
|
||||
console.log('you hit a sign post!');
|
||||
}
|
||||
|
||||
+18
-16
@@ -11,7 +11,7 @@
|
||||
myGame.loader.load();
|
||||
}
|
||||
var map;
|
||||
var car;
|
||||
var ufo;
|
||||
var tile;
|
||||
var emitter;
|
||||
var test;
|
||||
@@ -19,6 +19,7 @@
|
||||
map = myGame.createTilemap('tiles', 'platform', Phaser.Tilemap.FORMAT_TILED_JSON);
|
||||
map.setCollisionRange(21, 53);
|
||||
map.setCollisionRange(105, 109);
|
||||
myGame.camera.opaque = true;
|
||||
myGame.camera.backgroundColor = 'rgb(47,154,204)';
|
||||
myGame.input.keyboard.addKeyCapture([
|
||||
Phaser.Keyboard.LEFT,
|
||||
@@ -26,36 +27,37 @@
|
||||
Phaser.Keyboard.UP,
|
||||
Phaser.Keyboard.DOWN
|
||||
]);
|
||||
emitter = myGame.createEmitter(32, 80);
|
||||
emitter.width = 700;
|
||||
emitter.makeParticles('chunk', 100, false, 1);
|
||||
emitter.gravity = 200;
|
||||
emitter.bounce = 0.8;
|
||||
emitter.start(false, 10, 0.05);
|
||||
car = myGame.createSprite(250, 64, 'ufo');
|
||||
car.renderRotation = false;
|
||||
//emitter = myGame.createEmitter(32, 80);
|
||||
//emitter.width = 700;
|
||||
//emitter.makeParticles('chunk', 100, false, 1);
|
||||
//emitter.gravity = 200;
|
||||
//emitter.bounce = 0.8;
|
||||
//emitter.start(false, 10, 0.05);
|
||||
ufo = myGame.createSprite(250, 64, 'ufo');
|
||||
ufo.renderDebug = true;
|
||||
ufo.renderRotation = false;
|
||||
test = myGame.createSprite(200, 64, 'ufo');
|
||||
test.elasticity = 1;
|
||||
test.velocity.x = 50;
|
||||
test.velocity.y = 100;
|
||||
car.setBounds(0, 0, map.widthInPixels - 32, map.heightInPixels - 32);
|
||||
ufo.setBounds(0, 0, map.widthInPixels - 32, map.heightInPixels - 32);
|
||||
}
|
||||
function update() {
|
||||
// Collide everything with the map
|
||||
map.collide();
|
||||
// And collide everything in the game :)
|
||||
myGame.collide();
|
||||
car.velocity.x = 0;
|
||||
car.velocity.y = 0;
|
||||
ufo.velocity.x = 0;
|
||||
ufo.velocity.y = 0;
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
car.velocity.x = -200;
|
||||
ufo.velocity.x = -200;
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
car.velocity.x = 200;
|
||||
ufo.velocity.x = 200;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
car.velocity.y = -200;
|
||||
ufo.velocity.y = -200;
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
||||
car.velocity.y = 200;
|
||||
ufo.velocity.y = 200;
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
+18
-16
@@ -18,7 +18,7 @@
|
||||
}
|
||||
|
||||
var map: Phaser.Tilemap;
|
||||
var car: Phaser.Sprite;
|
||||
var ufo: Phaser.Sprite;
|
||||
var tile: Phaser.Tile;
|
||||
var emitter: Phaser.Emitter;
|
||||
var test: Phaser.Sprite;
|
||||
@@ -29,26 +29,28 @@
|
||||
map.setCollisionRange(21,53);
|
||||
map.setCollisionRange(105,109);
|
||||
|
||||
myGame.camera.opaque = true;
|
||||
myGame.camera.backgroundColor = 'rgb(47,154,204)';
|
||||
|
||||
myGame.input.keyboard.addKeyCapture([Phaser.Keyboard.LEFT, Phaser.Keyboard.RIGHT, Phaser.Keyboard.UP, Phaser.Keyboard.DOWN]);
|
||||
|
||||
emitter = myGame.createEmitter(32, 80);
|
||||
emitter.width = 700;
|
||||
emitter.makeParticles('chunk', 100, false, 1);
|
||||
emitter.gravity = 200;
|
||||
emitter.bounce = 0.8;
|
||||
emitter.start(false, 10, 0.05);
|
||||
//emitter = myGame.createEmitter(32, 80);
|
||||
//emitter.width = 700;
|
||||
//emitter.makeParticles('chunk', 100, false, 1);
|
||||
//emitter.gravity = 200;
|
||||
//emitter.bounce = 0.8;
|
||||
//emitter.start(false, 10, 0.05);
|
||||
|
||||
car = myGame.createSprite(250, 64, 'ufo');
|
||||
car.renderRotation = false;
|
||||
ufo = myGame.createSprite(250, 64, 'ufo');
|
||||
ufo.renderDebug = true;
|
||||
ufo.renderRotation = false;
|
||||
|
||||
test = myGame.createSprite(200, 64, 'ufo');
|
||||
test.elasticity = 1;
|
||||
test.velocity.x = 50;
|
||||
test.velocity.y = 100;
|
||||
|
||||
car.setBounds(0, 0, map.widthInPixels - 32, map.heightInPixels - 32);
|
||||
ufo.setBounds(0, 0, map.widthInPixels - 32, map.heightInPixels - 32);
|
||||
|
||||
}
|
||||
|
||||
@@ -60,25 +62,25 @@
|
||||
// And collide everything in the game :)
|
||||
myGame.collide();
|
||||
|
||||
car.velocity.x = 0;
|
||||
car.velocity.y = 0;
|
||||
ufo.velocity.x = 0;
|
||||
ufo.velocity.y = 0;
|
||||
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
car.velocity.x = -200;
|
||||
ufo.velocity.x = -200;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
car.velocity.x = 200;
|
||||
ufo.velocity.x = 200;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
car.velocity.y = -200;
|
||||
ufo.velocity.y = -200;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
{
|
||||
car.velocity.y = 200;
|
||||
ufo.velocity.y = 200;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user