Skip to content

Commit

Permalink
sky, level, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
jlongster committed Nov 30, 2012
1 parent a46ac38 commit ec2f245
Show file tree
Hide file tree
Showing 26 changed files with 509 additions and 126 deletions.
102 changes: 52 additions & 50 deletions ai.js
Expand Up @@ -37,39 +37,39 @@ function handlePacket(packet) {
// AI

function initAI() {
var obj = {
type: p.inputPacket.typeId,
from: 0,
dt: .25,
sequenceId: id++,
mouseX: 0,
mouseY: 0,
mouseDown: 0,
left: 1,
right: 0,
up: 0,
down: 0
};

var packet = p.makePacket(obj, p.inputPacket);
stream.write(packet);

obj = {
type: p.inputPacket.typeId,
from: 0,
dt: 2.5,
sequenceId: id++,
mouseX: 0,
mouseY: 0,
mouseDown: 0,
left: 0,
right: 0,
up: 1,
down: 0
};

packet = p.makePacket(obj, p.inputPacket);
stream.write(packet);
// var obj = {
// type: p.inputPacket.typeId,
// from: 0,
// dt: .25,
// sequenceId: id++,
// mouseX: 0,
// mouseY: 0,
// mouseDown: 0,
// left: 1,
// right: 0,
// up: 0,
// down: 0
// };

// var packet = p.makePacket(obj, p.inputPacket);
// stream.write(packet);

// obj = {
// type: p.inputPacket.typeId,
// from: 0,
// dt: 2.5,
// sequenceId: id++,
// mouseX: 0,
// mouseY: 0,
// mouseDown: 0,
// left: 0,
// right: 0,
// up: 1,
// down: 0
// };

// packet = p.makePacket(obj, p.inputPacket);
// stream.write(packet);
}

var last = Date.now();
Expand All @@ -78,27 +78,29 @@ function runAI() {
var now = Date.now();
var dt = (now - last) / 1000;

var obj = {
type: p.inputPacket.typeId,
from: 0,
dt: Math.random() / 20,
sequenceId: id++,
mouseX: -1,
mouseY: 0,
mouseDown: 0,
left: 0,
right: 0,
up: 0,
down: 0
};

var packet = p.makePacket(obj, p.inputPacket);
stream.write(packet);
// var obj = {
// type: p.inputPacket.typeId,
// from: 0,
// //dt: Math.random() / 20,
// dt: .001,
// sequenceId: id++,
// mouseX: -1,
// mouseY: 0,
// mouseDown: 0,
// left: 0,
// right: 0,
// up: 0,
// down: 0
// };

// var packet = p.makePacket(obj, p.inputPacket);
// stream.write(packet);

obj = {
type: p.inputPacket.typeId,
from: 0,
dt: Math.random() / 40,
//dt: Math.random() / 40,
dt: .001,
sequenceId: id++,
mouseX: 0,
mouseY: 0,
Expand Down
52 changes: 27 additions & 25 deletions scene.js
Expand Up @@ -52,33 +52,35 @@ module.exports = Scene.extend({
var user = lookupUser(ent);
var buffer = ent.flushPackets();

if(buffer.length) {
var state = {
type: p.statePacket.typeId,
from: 0,
sequenceId: buffer[buffer.length - 1].sequenceId,
x: 0,
y: 0,
z: 0,
rotX: 0,
rotY: 0,
rotZ: 0
};
if(user) {
if(buffer.length) {
var state = {
type: p.statePacket.typeId,
from: 0,
sequenceId: buffer[buffer.length - 1].sequenceId,
x: 0,
y: 0,
z: 0,
rotX: 0,
rotY: 0,
rotZ: 0
};

for(var j=0, bl=buffer.length; j<bl; j++) {
var obj = buffer[j];
state.x += obj.x;
state.y += obj.y;
state.z += obj.z;
state.rotX += obj.rotX;
state.rotY += obj.rotY;
state.rotZ += obj.rotZ;
}
for(var j=0, bl=buffer.length; j<bl; j++) {
var obj = buffer[j];
state.x += obj.x;
state.y += obj.y;
state.z += obj.z;
state.rotX += obj.rotX;
state.rotY += obj.rotY;
state.rotZ += obj.rotZ;
}

user.stream.write(p.makePacket(state, p.statePacket));
state.from = user.id;
broadcast(user, p.makePacket(state, p.statePacket));
ent.saveHistory(state);
user.stream.write(p.makePacket(state, p.statePacket));
state.from = user.id;
broadcast(user, p.makePacket(state, p.statePacket));
ent.saveHistory(state);
}
}
});
}, 100);
Expand Down
Binary file added static/img/cube.psd
Binary file not shown.
Binary file added static/img/octo.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/octo.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/octo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/sky.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/sky.psd
Binary file not shown.
58 changes: 42 additions & 16 deletions static/js/entity.js
@@ -1,10 +1,10 @@

(function(SceneNode, Cube, CubeMesh, Terrain, Collision, packets, vec3, mat4) {

var Entity = SceneNode.extend({
var Entity = Cube.extend({
init: function(opts) {
opts = opts || {};
this.parent(opts.pos, opts.rot, opts.scale);
this.parent(opts.pos, opts.rot, opts.scale, { centered: true });
this.speed = opts.speed || 100;

// The server does the collision for us (whee)
Expand All @@ -20,16 +20,44 @@
if(!opts.rot) {
this.rotateY(Math.PI);
}

// Center whatever mesh is used
this.preMatrix = mat4.create();
mat4.identity(this.preMatrix);
mat4.translate(this.preMatrix, [-.5, -.5, -.5]);


if(!opts.scale) {
this.setScale(25, 25, 25);
}

this.color = opts.color || vec3.createFrom(0, 0, 1);

// Add some tentacles
var R = this.addObject(new SceneNode({
update: function(dt) {
this.rotateY(-Math.PI * dt);
}
}));
R.AABB = null;

for(var i=0; i<=Math.PI * 2; i+=Math.PI / 4) {
var tent = R.addObject(new Cube(
[Math.sin(i) / 2.0, -1.1, Math.cos(i) / 2.0],
[-Math.cos(i) / 6.0, 0, Math.sin(i) / 6.0],
[.15, 1, .15],
{ centered: true }
));

var c = vec3.create();
vec3.scale(this.color, .5, c);
tent.color = c;
tent.AABB = null;
}

if(typeof module === 'undefined') {
this.setImage('img/octo.png');
this.setMaterial(['textured.vsh', 'textured.fsh']);
this.textureScale = vec2.createFrom(25.0 / 32.0,
150.0 / 256.0);
this.blend = true;
this.backface = true;
}

var halfScale = vec3.create();
vec3.scale(this.scale, .5, halfScale);
this.setAABB([0, 0, 0], halfScale);
Expand All @@ -49,7 +77,7 @@
this.historyPos = vec3.create();
this.historyRot = vec3.create();

if(Cube && !Cube.mesh) {
if(CubeMesh && !Cube.mesh) {
Cube.mesh = new CubeMesh();
Cube.mesh.create();
}
Expand Down Expand Up @@ -169,8 +197,10 @@
},

restart: function(spawnPoint) {
var sceneX = 256 * 4;
var sceneY = 256 * 4;
// var sceneX = scene.sceneWidth;
// var sceneY = scene.sceneDepth;
var sceneX = 255 * 4;
var sceneY = 255 * 4;

switch(spawnPoint) {
case 0:
Expand Down Expand Up @@ -243,10 +273,6 @@
this.targetRot);
this.interp = 0.0;
}
},

render: function() {
Cube.mesh.render(this._program.program);
}
});

Expand All @@ -259,7 +285,7 @@

}).apply(this, (typeof module !== 'undefined' ?
[require('./node-shade').SceneNode,
null,
require('./node-shade').Cube,
null,
require('./terrain'),
require('./node-shade').Collision,
Expand Down
23 changes: 20 additions & 3 deletions static/js/main.js
Expand Up @@ -52,7 +52,7 @@ function notify(msg) {

function init() {
renderer = new sh.Renderer(w, h);
scene = new sh.Scene(255, 255);
scene = new sh.Scene(255 * 4, 255 * 4);
server = new ServerConnection();

createLevel(scene);
Expand All @@ -63,6 +63,18 @@ function init() {
scene.setCamera(new sh.Camera(player));
renderer.perspective(45, w / h, 1.0, 5000.0);

var sky = new sh.Cube(null,
null,
[50, 50, 50],
{ centered: true });
sky.update = function(dt) {
this.setPos(player.pos[0], player.pos[1], player.pos[2]);
};
sky.id = 'sky';
sky.backface = true;
sky.noZbuffer = true;
scene.addObject(sky);

var terrain = new Terrain(null, null, null,
scene.sceneWidth,
scene.sceneDepth);
Expand Down Expand Up @@ -194,7 +206,7 @@ function initPage() {
document.addEventListener('mozpointerlockerror', onPointerLockError, false);
document.addEventListener('webkitpointerlockerror', onPointerLockError, false);

showIntro();
showInGame();
}

function showIntro() {
Expand Down Expand Up @@ -228,11 +240,16 @@ function showInGame() {
'shaders/debug.vsh',
'shaders/ui.fsh',
'shaders/ui.vsh',
'shaders/sky.fsh',
'shaders/sky.vsh',
'shaders/terrain.fsh',
'shaders/terrain.vsh',
'img/test.png',
'shaders/textured.fsh',
'shaders/textured.vsh',
'img/octo.png',
'img/crosshair.png',
'img/grass.jpg',
'img/sky.png',
'sounds/laser.wav'
]);

Expand Down

0 comments on commit ec2f245

Please sign in to comment.