Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New tank game! #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified examples/tank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion gladius/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ Start by cloning the repository or downloading a zipped version from github.
Inside the project directory you'll find pre-built versions of the following modules:

* gladius-core: the engine core; you'll definitely need to load this
* gladius-cubicvr: CubicVR rendering backend
* gladius-cubicvr: CubicVR renderer
* gladius-box2d: Box2D physics
* gladius-input: user input

We tested the examples with these module versions.
If you build your own modules, the examples might still work, but they also might not.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions gladius/examples/assets/procedural-sphere.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function proc( options ) {

options = options || {};
options.type = options.type || "sphere";
options.radius = options.radius || 0.5;
options.latDetail = options.latDetail || 24;
options.lonDetail = options.lonDetail || 24;

var mesh =
{
primitive: {
type: options.type,
radius: options.radius,
lat: options.latDetail,
lon: options.lonDetail,
uvmapper: {
projectionMode: "cubic",
scale: [1, 1, 1]
}
},
compile: true
};

return mesh;

}
8 changes: 2 additions & 6 deletions gladius/examples/camera-rotate/camera-rotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,9 @@ document.addEventListener( "DOMContentLoaded", function( e ) {
space.add( parentCube );

var task = new engine.FunctionTask( function() {
var cubeRotation = new engine.math.Vector3( space.findNamed( "cube" ).findComponent( "Transform" ).rotation );
cubeRotation = engine.math.vector3.add( cubeRotation, [0, space.clock.delta * 0.0003, 0] );
space.findNamed( "cube" ).findComponent( "Transform" ).setRotation( cubeRotation );
space.findNamed( "cube" ).findComponent( "Transform" ).rotation.y += space.clock.delta * 0.0003;

var cameraRotation = new engine.math.Vector3( space.findNamed( "camera" ).findComponent( "Transform" ).rotation );
cameraRotation = engine.math.vector3.add( cameraRotation, [0, space.clock.delta * 0.0003, 0] );
space.findNamed( "camera" ).findComponent( "Transform" ).setRotation( cameraRotation );
space.findNamed( "camera" ).findComponent( "Transform" ).rotation.y += space.clock.delta * 0.0003;
}, {
tags: ["@update"]
});
Expand Down
17 changes: 9 additions & 8 deletions gladius/examples/cube-collision/cube-collision.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ document.addEventListener( "DOMContentLoaded", function( e ) {

var box2dOptions = {
resolver: {
gravity: [0,-0.5]
dimensionMap: box2dExtension.services.resolver.service.prototype.DimensionMaps.XY
}
};

engine.registerExtension( cubicvrExtension, cubicvrOptions );
engine.registerExtension( box2dExtension);//, box2dOptions);
engine.registerExtension( box2dExtension, box2dOptions);

var resources = {};

Expand Down Expand Up @@ -102,13 +102,14 @@ document.addEventListener( "DOMContentLoaded", function( e ) {

var lightDefinition = new cubicvr.LightDefinition({
intensity: 1,
distance: 20,
light_type: cubicvr.LightDefinition.LightTypes.POINT,
method: cubicvr.LightDefinition.LightingMethods.DYNAMIC
});

space.add( new engine.Entity( "camera",
[
new engine.core.Transform( [0, 0, 5] ),
new engine.core.Transform( [0, 0, 10] ),
new cubicvr.Light( lightDefinition ),
new cubicvr.Camera( {
targeted:false
Expand All @@ -117,7 +118,7 @@ document.addEventListener( "DOMContentLoaded", function( e ) {
));

var bodyDefinition = new box2d.BodyDefinition();
var fixtureDefinition = new box2d.FixtureDefinition({shape:new box2d.BoxShape(0.25,0.25)});
var fixtureDefinition = new box2d.FixtureDefinition({shape:new box2d.BoxShape(1,1)});

for (var cubeIndex = 0; cubeIndex < 5; cubeIndex++){

Expand All @@ -132,7 +133,7 @@ document.addEventListener( "DOMContentLoaded", function( e ) {
};
var firstCube = new engine.Entity( "cube1",
[
new engine.core.Transform( [3 + cubeIndex * 1.5, 0.125, 0], [0, 0, 0], [0.5, 0.5, 0.5] ),
new engine.core.Transform( [3 + cubeIndex * 3, 0.25, 0], [0, 0, 0]),
firstBody,
new cubicvr.Model( resources.mesh, resources.material )
]
Expand All @@ -151,14 +152,14 @@ document.addEventListener( "DOMContentLoaded", function( e ) {

var secondCube = new engine.Entity( "cube2",
[
new engine.core.Transform( [-3 - cubeIndex * 1.5, -0.125, 0], [0, 0, 0], [0.5, 0.5, 0.5] ),
new engine.core.Transform( [-3 - cubeIndex * 3, -0.25, 0], [0, 0, 0]),
secondBody,
new cubicvr.Model( resources.mesh, resources.material )
]
);
space.add( secondCube );
new engine.Event("LinearImpulse", {impulse: [-0.25,0]}).dispatch(firstCube);
new engine.Event("LinearImpulse", {impulse: [0.25,0]}).dispatch(secondCube);
new engine.Event("LinearImpulse", {impulse: [-1,0]}).dispatch(firstCube);
new engine.Event("LinearImpulse", {impulse: [1,0]}).dispatch(secondCube);
}

var task = new engine.FunctionTask( function() {
Expand Down
11 changes: 7 additions & 4 deletions gladius/examples/cube-impulse/cube-impulse.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,25 @@ document.addEventListener( "DOMContentLoaded", function( e ) {
var cubePosition = new engine.math.Vector3( space.findNamed( "cube").findComponent( "Transform").position);
// var camera = space.findNamed("camera").findComponent("Camera");
// camera.setTarget(cubePosition);
if (cubePosition[1] < -1.5){

var cubeY = cubePosition.y;
var cubeX = cubePosition.x;
if (cubeY < -1.5){
var impEvent = new engine.Event('LinearImpulse',{impulse: [getRandom(0,0.1), getRandom(0,1)]});
impEvent.dispatch(parentCube);
}
if (cubePosition[1] > 1.5){
if (cubeY > 1.5){
var impEvent = new engine.Event('LinearImpulse',{impulse: [getRandom(0,0.1) * -1, getRandom(0, 1) * -1]});
impEvent.dispatch(parentCube);
}
if (cubePosition[0] < -1.5){
if (cubeX < -1.5){
var impEvent = new engine.Event('LinearImpulse',{impulse: [getRandom(0,1), 0]});
impEvent.dispatch(parentCube);

var angEvent = new engine.Event('AngularImpulse',{impulse: getRandom(0, 0.1)});
angEvent.dispatch(parentCube);
}
if (cubePosition[0] > 1.5){
if (cubeX > 1.5){
var impEvent = new engine.Event('LinearImpulse',{impulse: [getRandom(0, 1) * -1, 0]});
impEvent.dispatch(parentCube);

Expand Down
8 changes: 2 additions & 6 deletions gladius/examples/cube/cube.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,9 @@ document.addEventListener( "DOMContentLoaded", function( e ) {
space.findNamed( "light-marker" ).setParent( space.findNamed( "light-center" ) );

var task = new engine.FunctionTask( function() {
var cubeRotation = new engine.math.Vector3( space.findNamed( "cube" ).findComponent( "Transform" ).rotation );
cubeRotation = engine.math.vector3.add( cubeRotation, [space.clock.delta * 0.003, space.clock.delta * 0.001, space.clock.delta * 0.0007] );
space.findNamed( "cube" ).findComponent( "Transform" ).setRotation( cubeRotation );
space.findNamed( "cube" ).findComponent( "Transform" ).rotation.add([space.clock.delta * 0.003, space.clock.delta * 0.001, space.clock.delta * 0.0007]);

var lightRotation = new engine.math.Vector3( space.findNamed( "light-center" ).findComponent( "Transform" ).rotation );
lightRotation = engine.math.vector3.add( lightRotation, [0, space.clock.delta * 0.001, 0] );
space.findNamed( "light-center" ).findComponent( "Transform" ).setRotation( lightRotation );
space.findNamed( "light-center" ).findComponent( "Transform" ).rotation.y += space.clock.delta * 0.001;
}, {
tags: ["@update"]
});
Expand Down
4 changes: 3 additions & 1 deletion gladius/examples/tank/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ <h2>Tank controls</h2>
Press S to move the tank backwards<br />
Press A to turn the tank left<br />
Press D to turn the tank right<br />
Press Space to trigger a fire event (viewable in the console)
Press the left arrow key to turn the turret to the left<br />
Press the right arrow key to turn the turret to the right<br />
Press Space to fire
</p>
</body>
</html>
4 changes: 3 additions & 1 deletion gladius/examples/tank/tank-controls.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"MoveBackward": [ "S" ],
"TurnLeft": [ "A" ],
"TurnRight": [ "D" ],
"StrafeModifier": [ "SHIFT" ]
"StrafeModifier": [ "SHIFT" ],
"TurnTurretLeft": [ "LEFT" ],
"TurnTurretRight": [ "RIGHT" ]
},
"Actions": {
"Fire": [ "SPACE" ]
Expand Down
Loading