Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added component management system and part of the rendering system

  • Loading branch information...
commit 539265d2151d17add698dc2b7d7e798416da6132 1 parent 2732c4c
@TyOverby authored
View
2  compile.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+coffee --join bin/compiled.js -cw src/
View
1  src/engine/MathUtils.coffee
@@ -1 +0,0 @@
-
View
38 src/engine/client/Camera.coffee
@@ -0,0 +1,38 @@
+class Camera
+ constructor: (canvasId,centerPos)->
+ @pane = new Pane canvasId
+ @pos = centerPos
+
+ # Returns the width of the view-port
+ getWidth: ->
+ do @canvas.getWidth
+
+ # Returns the height of the view-port
+ getHeight: ->
+ do @canvas.getHeight
+
+ inBounds: (position, radius) ->
+ left = position.x - @pos.x + radius > 0
+ right = position.x + @pos.x - radius < @getWidth()
+
+ top = position.y - @pos.x + radius > 0
+ bot = position.y + @pos.y - radius < @getHeight()
+
+ left && right && top && bot
+
+ getModPos: (enityPos) ->
+ entityPos.minus(@pos)
+
+ move: (amount) ->
+ @pos.plusEquals amount
+
+ _half: ->
+ {
+ x: @getWidth() / 2
+ y: @getHeight() / 2
+ }
+
+ setCenter: (value) ->
+ @pos = value.minusEquals(_half())
+
+
View
4 src/client/ClientGame.coffee → src/engine/client/ClientGame.coffee
@@ -1,8 +1,10 @@
class global.Client extends Game
+
+ # Prepare the camera, init game state
load: ->
- # Do things like load the canvas here
super()
+ # Make updates to the state of the game
update: ->
super()
this.render()
View
4 src/engine/client/Pane.coffee
@@ -0,0 +1,4 @@
+Pane (id) ->
+ return document.getElementById(id).getContext("2d")
+
+
View
2  src/game/Game.coffee → src/engine/game/Game.coffee
@@ -3,4 +3,4 @@ class global.Game extends Engine
super()
console.log("loading from Game")
update: ->
- # All of the updates for the game go here
+ throw "update() from Game not yet implemented"
View
10 src/engine/preload.coffee
@@ -0,0 +1,10 @@
+root = exports ? this
+
+root.requestAnimationFrame ||=
+ root.webkitRequestAnimationFrame ||
+ root.mozRequestAnimationFrame ||
+ root.oRequestAnimationFrame ||
+ root.msRequestAnimationFrame ||
+ (callback, element) ->
+ setTimeout( ->
+ callback(+new Date()) 1000 / 60)
View
2  src/engine/Engine.coffee → src/engine/shared/Engine.coffee
@@ -1,4 +1,4 @@
-class global.Engine
+class root.Engine
constructor: ->
@gamestate = {}
@loaded = false
View
16 src/engine/shared/MathUtils.coffee
@@ -0,0 +1,16 @@
+Math::randDouble = (limit1, limit2)->
+ switch arguments.length
+ when 1
+ randDouble(0,limit1)
+ when 2
+ Math.random(limit2-limit1)+limit1
+
+Math::randInt = (limit1,limit2)->
+ switch arguments.length
+ when 1
+ randInt(0,limit1)
+ when 2
+ Math.floor Math.randDouble(limit1,limit2)
+
+Math::decision = (factor)->
+ math.random()<=factor
View
2  src/engine/Vector2f.coffee → src/engine/shared/Vector2f.coffee
@@ -1,5 +1,5 @@
# Add more to this as you need more
-class global.Vector2f
+class root.Vector2f
constructor:(x,y)->
@x = x
@y = y
View
6 src/engine/shared/entity/Component.coffee
@@ -0,0 +1,6 @@
+class root.Component
+ update: (deltat) ->
+ throw "update() not implemented yet"
+
+ setParent: (parent) ->
+ @parent = parent
View
6 src/engine/shared/entity/DynamicComponent.coffee
@@ -0,0 +1,6 @@
+class root.DynamicComponent extends Component
+ constructor: (position, rotation, velocity, acceleration) ->
+ @position = position
+ @rotation = rotation
+ @velocity = velocity
+ @acceleration = acceleration
View
24 src/engine/shared/entity/GameObject.coffee
@@ -0,0 +1,24 @@
+class root.GameObject
+ components = []
+
+ addComponent: (component)->
+ components.push component
+ component.setParent this
+
+ getComponent: (componentType)->
+ for component in components
+ if component instanceof componentType
+ return component
+
+ update: (deltat)->
+ for component in components
+ component.update deltat
+ true
+
+ render: ->
+ for component in components
+ if render in component
+ do component.render
+ true
+
+
View
6 src/engine/shared/entity/RenderComponent.coffee
@@ -0,0 +1,6 @@
+class RenderComponent extends Component
+ update: ->
+ throw "update() not yet implemented"
+
+ render: ->
+ throw "render() not yet implemented"
View
4 src/engine/shared/entity/StaticComponent.coffee
@@ -0,0 +1,4 @@
+class root.StaticComponent extends Component
+ constructor: (position, rotation) ->
+ @position = position
+ @rotation = rotation
View
20 src/preload.js
@@ -1,20 +0,0 @@
-// Generated by CoffeeScript 1.3.3
-(function() {
-
- if (typeof window !== "undefined" && window !== null) {
- global = window;
-
- }
-
- if (typeof exports !== "undefined" && exports !== null) {
- global = exports;
-
- }
-
- global.requestAnimationFrame || (global.requestAnimationFrame = global.webkitRequestAnimationFrame || global.mozRequestAnimationFrame || global.oRequestAnimationFrame || global.msRequestAnimationFrame || function(callback, element) {
- return setTimeout(function() {
- return callback(+new Date())(1000 / 60);
- });
- });
-
-}).call(this);
Please sign in to comment.
Something went wrong with that request. Please try again.