mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
added skateboard :D
This commit is contained in:
parent
fa9a0d5d22
commit
81611050d2
6 changed files with 144 additions and 321 deletions
89
app/Game/Core/GameObjects/Items/Skateboard.js
Normal file
89
app/Game/Core/GameObjects/Items/Skateboard.js
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
define([
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Item",
|
||||
"Lib/Vendor/Box2D",
|
||||
"Game/Config/Settings"
|
||||
],
|
||||
|
||||
function (Parent, Box2D, Settings) {
|
||||
|
||||
function Skateboard(physicsEngine, uid, options) {
|
||||
this.physicsEngine = physicsEngine;
|
||||
|
||||
Parent.call(this, physicsEngine, uid, options);
|
||||
|
||||
this.addWheel(
|
||||
options.x + 8,
|
||||
options.y + 1.5
|
||||
);
|
||||
|
||||
this.addWheel(
|
||||
options.x - 8,
|
||||
options.y + 1.5
|
||||
);
|
||||
}
|
||||
|
||||
Skateboard.prototype = Object.create(Parent.prototype);
|
||||
|
||||
Skateboard.prototype.createFixture = function () {
|
||||
|
||||
var itemShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
||||
var w = this.options.width / Settings.RATIO;
|
||||
var h = 1.5 / Settings.RATIO;
|
||||
itemShape.SetAsOrientedBox(w / 2, h / 2, new Box2D.Common.Math.b2Vec2(0, -(1.5 / Settings.RATIO)));
|
||||
|
||||
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
|
||||
fixtureDef.shape = itemShape;
|
||||
|
||||
var offset = 4,
|
||||
factor = 80;
|
||||
var density = ((this.options.weight + offset) / this.options.width / this.options.height) * factor;
|
||||
fixtureDef.density = density;
|
||||
fixtureDef.friction = Settings.ITEM_FRICTION;
|
||||
fixtureDef.restitution = Settings.ITEM_RESTITUTION;
|
||||
fixtureDef.isSensor = false;
|
||||
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
}
|
||||
|
||||
Skateboard.prototype.addWheel = function(x, y) {
|
||||
|
||||
var bodyDef = new Box2D.Dynamics.b2BodyDef();
|
||||
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
|
||||
bodyDef.position.x = x / Settings.RATIO;
|
||||
bodyDef.position.y = y / Settings.RATIO;
|
||||
bodyDef.angle = 0;
|
||||
|
||||
var wheelShape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||
wheelShape.SetRadius(1.5 / Settings.RATIO);
|
||||
wheelShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, 0));
|
||||
|
||||
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
|
||||
var offset = 4,
|
||||
factor = 80;
|
||||
var density = ((this.options.weight + offset) / this.options.width / this.options.height) * factor;
|
||||
fixtureDef.density = density;
|
||||
fixtureDef.shape = wheelShape;
|
||||
fixtureDef.isSensor = false;
|
||||
|
||||
var wheelBody = this.physicsEngine.getWorld().CreateBody(bodyDef);
|
||||
wheelBody.CreateFixture(fixtureDef);
|
||||
|
||||
var revoluteJointDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
|
||||
revoluteJointDef.enableMotor = false;
|
||||
|
||||
revoluteJointDef.Initialize(this.body, wheelBody, wheelBody.GetWorldCenter());
|
||||
this.physicsEngine.getWorld().CreateJoint(revoluteJointDef);
|
||||
|
||||
// FIXME this means, that we will have bodies in the world, which must not be
|
||||
// updated (wheels) because they are always connected to a body which will be updated.
|
||||
};
|
||||
|
||||
Skateboard.prototype.flip = function(direction) {
|
||||
this.flipDirection = direction;
|
||||
|
||||
// FIXME: implement body flip if necessary
|
||||
};
|
||||
|
||||
return Skateboard;
|
||||
|
||||
});
|
||||
|
|
@ -3,9 +3,10 @@ define([
|
|||
"Lib/Vendor/Box2D",
|
||||
"Game/" + GLOBALS.context + "/Collision/Detector",
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Tile",
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Item"
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Item",
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Items/Skateboard",
|
||||
|
||||
], function (Settings, Box2D, CollisionDetector, Tile, Item) {
|
||||
], function (Settings, Box2D, CollisionDetector, Tile, Item, Skateboard) {
|
||||
|
||||
// Public
|
||||
function Level (path, engine, gameObjects) {
|
||||
|
|
@ -48,8 +49,18 @@ define([
|
|||
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var options = items[i];
|
||||
var item;
|
||||
var uid = "item-" + i;
|
||||
|
||||
this.gameObjects.animated.push(new Item(this.engine, "item-" + i, options));
|
||||
switch(options.type) {
|
||||
case 'skateboard':
|
||||
item = new Skateboard(this.engine, uid, options);
|
||||
break;
|
||||
default:
|
||||
item = new Item(this.engine, uid, options);
|
||||
break
|
||||
}
|
||||
this.gameObjects.animated.push(item);
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -117,7 +128,7 @@ microwave: 3.744
|
|||
{
|
||||
name:'Banana',
|
||||
image:'banana.gif',
|
||||
shape:'rectangle',
|
||||
type:'rectangle',
|
||||
category:'kitchen',
|
||||
weight: 1,
|
||||
width:5,
|
||||
|
|
@ -131,7 +142,7 @@ microwave: 3.744
|
|||
{
|
||||
name:'Refridgerator',
|
||||
image:'fridge.gif',
|
||||
shape:'rectangle',
|
||||
type:'rectangle',
|
||||
category:'kitchen',
|
||||
weight: 10,
|
||||
width:31,
|
||||
|
|
@ -144,7 +155,7 @@ microwave: 3.744
|
|||
{
|
||||
name:'Microwave',
|
||||
image:'microwave.gif',
|
||||
shape:'rectangle',
|
||||
type:'rectangle',
|
||||
category:'kitchen',
|
||||
weight: 4,
|
||||
width:19,
|
||||
|
|
@ -158,7 +169,7 @@ microwave: 3.744
|
|||
{
|
||||
name:'Large Cleaver',
|
||||
image:'cleaver_large.gif',
|
||||
shape:'rectangle',
|
||||
type:'rectangle',
|
||||
category:'kitchen',
|
||||
weight: 3,
|
||||
width:8,
|
||||
|
|
@ -171,7 +182,7 @@ microwave: 3.744
|
|||
{
|
||||
name:'Small Cleaver',
|
||||
image:'cleaver_small.gif',
|
||||
shape:'rectangle',
|
||||
type:'rectangle',
|
||||
category:'kitchen',
|
||||
weight:2,
|
||||
width:6,
|
||||
|
|
@ -184,7 +195,7 @@ microwave: 3.744
|
|||
{
|
||||
name:'Coffeemachine',
|
||||
image:'coffeemachine.gif',
|
||||
shape:'rectangle',
|
||||
type:'rectangle',
|
||||
category:'kitchen',
|
||||
weight:2.4,
|
||||
width:11,
|
||||
|
|
@ -196,7 +207,7 @@ microwave: 3.744
|
|||
{
|
||||
name:'Knife',
|
||||
image:'knife.gif',
|
||||
shape:'rectangle',
|
||||
type:'rectangle',
|
||||
category:'kitchen',
|
||||
weight:1.5,
|
||||
width:4,
|
||||
|
|
@ -209,7 +220,7 @@ microwave: 3.744
|
|||
{
|
||||
name:'Laundry Machine',
|
||||
image:'laundry_machine.gif',
|
||||
shape:'rectangle',
|
||||
type:'rectangle',
|
||||
category:'laundry',
|
||||
weight: 15,
|
||||
width:24,
|
||||
|
|
@ -218,6 +229,19 @@ microwave: 3.744
|
|||
y:0,
|
||||
rotation: 0,
|
||||
grabAngle: -0.5
|
||||
},
|
||||
{
|
||||
name:'Skateboard',
|
||||
image:'skateboard.gif',
|
||||
type:'skateboard',
|
||||
category:'outdoor',
|
||||
weight: 5,
|
||||
width:26,
|
||||
height:6,
|
||||
x:200,
|
||||
y:0,
|
||||
rotation: 0,
|
||||
grabAngle: -1.5
|
||||
}
|
||||
],
|
||||
tiles: /*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue