Permalink
Browse files

added component management system and part of the rendering system

  • Loading branch information...
1 parent 2732c4c commit 539265d2151d17add698dc2b7d7e798416da6132 @TyOverby committed Jun 7, 2012
View
@@ -0,0 +1,2 @@
+#!/bin/sh
+coffee --join bin/compiled.js -cw src/
@@ -1 +0,0 @@
-
@@ -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())
+
+
@@ -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()
@@ -0,0 +1,4 @@
+Pane (id) ->
+ return document.getElementById(id).getContext("2d")
+
+
@@ -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
@@ -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)
@@ -1,4 +1,4 @@
-class global.Engine
+class root.Engine
constructor: ->
@gamestate = {}
@loaded = false
@@ -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
@@ -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
@@ -0,0 +1,6 @@
+class root.Component
+ update: (deltat) ->
+ throw "update() not implemented yet"
+
+ setParent: (parent) ->
+ @parent = parent
@@ -0,0 +1,6 @@
+class root.DynamicComponent extends Component
+ constructor: (position, rotation, velocity, acceleration) ->
+ @position = position
+ @rotation = rotation
+ @velocity = velocity
+ @acceleration = acceleration
@@ -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
+
+
@@ -0,0 +1,6 @@
+class RenderComponent extends Component
+ update: ->
+ throw "update() not yet implemented"
+
+ render: ->
+ throw "render() not yet implemented"
@@ -0,0 +1,4 @@
+class root.StaticComponent extends Component
+ constructor: (position, rotation) ->
+ @position = position
+ @rotation = rotation
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit 539265d

Please sign in to comment.