summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cube.ts15
-rw-r--r--src/element.ts65
-rw-r--r--src/omni.ts136
-rw-r--r--src/pointerlock.ts5
-rw-r--r--src/puzzle.ts22
5 files changed, 243 insertions, 0 deletions
diff --git a/src/cube.ts b/src/cube.ts
new file mode 100644
index 0000000..7c7013d
--- /dev/null
+++ b/src/cube.ts
@@ -0,0 +1,15 @@
+module Omni {
+ export class Cube extends Physijs.Scene {
+ private elements:Element[];
+ private puzzles:Puzzle[];
+
+ constructor() {
+ super();
+ }
+
+ tick(delta:number):void {
+
+ this.simulate(delta);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/element.ts b/src/element.ts
new file mode 100644
index 0000000..490475a
--- /dev/null
+++ b/src/element.ts
@@ -0,0 +1,65 @@
+module Omni {
+ export class Element {
+ private state:number;
+
+ private mesh:Physijs.BoxMesh;
+
+ //will take the correct state as params?
+ constructor(mesh_file:string) {
+ this.mesh = this.loadMesh(mesh_file);
+ }
+
+ loadMesh(mesh_file:string):Physijs.BoxMesh {
+ //todo rewrite this into some loader, no need to have a new loader for each mesh
+ //load mesh from the json file supplied from the static part of the subclass
+ //load "json/" + mesh_file
+ let mesh = null;
+ let loader = new THREE.JSONLoader();
+ loader.load(("json/" + mesh_file), function (geometry) {
+ mesh = new THREE.Mesh(geometry);
+ }
+ );
+ return new Physijs.BoxMesh(mesh, new THREE.MeshDepthMaterial(), 0);
+ }
+
+ getState():number {
+ return this.state;
+ }
+
+ setState(state:number):void {
+ this.state = state;
+ }
+ }
+
+ /**
+ * Button element with 2 states
+ */
+ export class ButtonElement extends Element {
+ //need to make good design choices here, with the handling of states..
+ static mesh_file = "buttonElement.json";
+
+ constructor() {
+ super(ButtonElement.mesh_file);
+ }
+ }
+
+ /**
+ * Lever element with 4 positions/states
+ */
+ export class LeverElement extends Element {
+ static mesh_file = "leverElement.json";
+
+ constructor() {
+ super(LeverElement.mesh_file);
+ }
+ }
+
+ /**
+ * Plain element without any puzzles.
+ */
+ export class PlainElement extends Element {
+
+ }
+
+
+} \ No newline at end of file
diff --git a/src/omni.ts b/src/omni.ts
new file mode 100644
index 0000000..e6ae782
--- /dev/null
+++ b/src/omni.ts
@@ -0,0 +1,136 @@
+/// <reference path="../ts/three.d.ts" />
+/// <reference path="../ts/physijs.d.ts" />
+/// <reference path="cube.ts" />
+/// <reference path="element.ts" />
+/// <reference path="puzzle.ts" />
+/// <reference path="pointerlock.ts" />
+
+
+module Omni {
+ /**
+ * Base game class, will handle the game loop, rendering,
+ */
+ class Game {
+ private renderer:THREE.WebGLRenderer;
+ private camera:THREE.PerspectiveCamera;
+
+ private current_cube:Omni.Cube;
+
+ private ticks:number = 0;
+ private delta:number = 0;
+ private lastFrame:number = 0;
+ private timestep:number = 1000 / 60;
+ private maxFPS:number = 60;
+
+ private keepRunning:boolean;
+
+ static CAMERA_FOV:number = 55;
+ static CAMERA_NEAR:number = 1;
+ static CAMERA_FAR:number = 1000;
+
+ /**
+ *
+ */
+ constructor() {
+ this.camera = new THREE.PerspectiveCamera(Game.CAMERA_FOV, window.innerWidth / window.innerHeight, Game.CAMERA_NEAR, Game.CAMERA_FAR);
+ }
+
+ /**
+ *
+ */
+ init():void {
+
+ window.addEventListener("resize", this.onWindowResize, false);
+ }
+
+ /**
+ *
+ */
+ start():void {
+
+ }
+
+ /**
+ *
+ */
+ unpause():void {
+
+ }
+
+ /**
+ *
+ * @param delta
+ */
+ tick(delta:number):void {
+ this.ticks++;
+ this.current_cube.tick(delta);
+ }
+
+ /**
+ *
+ */
+ render():void {
+ this.renderer.render(this.current_cube, this.camera);
+ }
+
+ /**
+ *
+ * @param timestamp
+ */
+ run(timestamp?:number):void {
+ if (!timestamp) {
+ timestamp = performance.now();
+ }
+
+ if (timestamp < this.lastFrame + (1000 / this.maxFPS)) {
+ if (this.keepRunning) {
+ requestAnimationFrame(() => this.run());
+ }
+ return;
+ }
+ this.delta += timestamp - this.lastFrame;
+ this.lastFrame = timestamp;
+
+ var numUpdateSteps = 0;
+ while (this.delta >= this.timestep) {
+ this.tick(this.timestep);
+ this.delta -= this.timestep;
+ if (++numUpdateSteps >= 240) {
+ // panic here, reset delta
+ this.delta = 0;
+ break;
+ }
+ }
+ this.render();
+ if (this.keepRunning) {
+ requestAnimationFrame((time) => this.run(time));
+ }
+ }
+
+ /**
+ * When releasing pointer lock/on menu. Menu is HTML based.
+ */
+ pause():void {
+
+ }
+
+ /**
+ * When leaving the page.
+ */
+ stop():void {
+
+ }
+
+ onWindowResize = () => {
+ this.camera.aspect = window.innerWidth / window.innerHeight;
+ this.camera.updateProjectionMatrix();
+
+ this.renderer.setSize(window.innerWidth, window.innerHeight);
+ };
+
+ }
+}
+
+window.onload = () => {
+
+};
diff --git a/src/pointerlock.ts b/src/pointerlock.ts
new file mode 100644
index 0000000..d75ccda
--- /dev/null
+++ b/src/pointerlock.ts
@@ -0,0 +1,5 @@
+module Omni {
+ export class PointerLocker {
+
+ }
+} \ No newline at end of file
diff --git a/src/puzzle.ts b/src/puzzle.ts
new file mode 100644
index 0000000..e478a14
--- /dev/null
+++ b/src/puzzle.ts
@@ -0,0 +1,22 @@
+module Omni {
+ export class Puzzle {
+
+ private elements:Element[] = [];
+
+ //contains elements,
+ /**
+ * takes elements, and their correct state.
+ */
+ constructor() {
+
+ }
+
+ /**
+ * Whether this puzzle is currently in the correct state
+ */
+ isCorrect():boolean {
+ //true if states of all elements match the correct state-> correct state can be more.
+ return false;
+ }
+ }
+} \ No newline at end of file