Permalink
Browse files

playing around with masses

  • Loading branch information...
1 parent d546085 commit 580d2eb6932c06fa2b4991fa5c2c982af7fb0a87 @hoodie hoodie committed May 10, 2012
Showing with 57 additions and 18 deletions.
  1. +1 −1 Makefile
  2. +22 −6 coffee/Game.coffee
  3. +10 −0 coffee/Graph.coffee
  4. +2 −1 coffee/Layer.coffee
  5. +1 −6 coffee/Naub.coffee
  6. +2 −2 coffee/Naubino.coffee
  7. +4 −1 coffee/Settings.coffee
  8. +1 −0 coffee/Shapes.coffee
  9. +14 −1 coffee/TestCase.coffee
View
@@ -8,7 +8,7 @@ LIB_DIR = lib/
TMP_DIR = js/
SRC := $(shell find $(SRC_DIR) -type f -iname \*.coffee)
-TMP := $(SRC:$(SRC_DIR)%.coffee=js/%.js)
+TMP := $(SRC:$(SRC_DIR)%.coffee=$(TMP_DIR)%.js)
all: $(min_TARGET)
View
@@ -66,12 +66,13 @@ define ["Layer", "Naub", "Graph", "Shapes", "CollisionHandler"], (Layer, Naub, G
stfs = Naubino.settings.physics.center_join.stiffness
dmpg = Naubino.settings.physics.center_join.damping
- joint =
- new cp.DampedSpring( obj.physical_body, @space.staticBody, cp.vzero, obj.center, rstl, stfs, dmpg)
+ joint = new cp.DampedSpring( obj.physical_body, @space.staticBody, cp.vzero, obj.center, rstl, stfs, dmpg)
@centerjoins.push joint
@space.addConstraint( joint)
obj.constraints.push joint
+ obj.physical_body.naub_number = @objects_count if obj.physical_body?
+ obj.physical_shape.naub_number = @objects_count if obj.physical_shape?
# the game gives it the game takes it
# FACTORIES
@@ -222,24 +223,39 @@ define ["Layer", "Naub", "Graph", "Shapes", "CollisionHandler"], (Layer, Naub, G
@focused_naub = naub
@mouseBody.p = @pointer
- @mouseJoint = new cp.PivotJoint(@mouseBody, naub.physical_body, cp.v(0,0), cp.v(0,0))
- @mouseJoint.maxForce = 50000
- @mouseJoint.errorBias = Math.pow(1 - 0.15, 60)
+ @mouseJoint = new cp.PivotJoint(@mouseBody, naub.physical_body, cp.vzero, cp.vzero)
+ @mouseJoint.errorBias = Math.pow(1 - 0.5, 60)
@space.addConstraint(@mouseJoint)
+
+ # make naubs lighter
+ attached_naubs = @graph.tree(naub.number)
+ for n in attached_naubs
+ naub = @get_object n
+ naub.physical_body.setMass Naubino.settings.naub.light_mass
+ naub.physical_shape.setElasticity Naubino.settings.naub.soft
+
+
# callback for mouseup signal
unfocus: =>
if @mousedown
@mousedown = false
+
if @focused_naub
+ # undo make naubs lighter
+ attached_naubs = @graph.tree(@focused_naub.number)
+ for n in attached_naubs
+ naub = @get_object n
+ naub.physical_body.setMass Naubino.settings.naub.mass
+ naub.physical_shape.setElasticity Naubino.settings.naub.hard
+
@focused_naub.unfocus()
@focused_naub = null
if @space? && @mouseJoint?
@space.removeConstraint @mouseJoint
@mouseJoint = null
-
# produces a random set of coordinates outside the field
random_outside: ->
offset = Naubino.settings.game.creation_offset
View
@@ -84,6 +84,16 @@ define -> class Graph
return
+
+ tree: (naub, visited = null) ->
+ visited = [] unless visited?
+ for p in @partners naub
+ unless p in visited
+ visited.push p
+ @tree(p, visited)
+
+ return visited
+
# recursive part of cycle_test
#
# @param [id] naub naub in question
View
@@ -80,7 +80,8 @@ define -> class Layer
@space.addBody obj.physical_body if obj.physical_body?
obj.center = @center
- obj.set_number ++@objects_count
+ ++@objects_count
+ obj.number = @objects_count
@objects[@objects_count] = obj
@objects_count
View
@@ -44,11 +44,6 @@ define -> class Naub
@physical_shape.setFriction @friction
- set_number: (@number) ->
- @physical_shape.naub_number = @number
- @physical_body.naub_number = @number
-
-
# Returns the area value of the first shape that implements it,
area: ->
r = @size/2
@@ -188,7 +183,7 @@ define -> class Naub
#restLength, stiffness, damping
minlen = Naubino.settings.naub.min_join_len * @size
maxlen = Naubino.settings.naub.max_join_len * @size
- joint = new cp.DampedSpring( @physical_body, other.physical_body, cp.vzero, cp.vzero, minlen, 10, 4)
+ joint = new cp.DampedSpring( @physical_body, other.physical_body, cp.vzero, cp.vzero, minlen, 4, 30)
joint2 = new cp.SlideJoint( @physical_body, other.physical_body, cp.vzero, cp.vzero, minlen, maxlen)
@layer.space.addConstraint( joint )
View
@@ -56,8 +56,8 @@ define ["Background", "Game", "Keybindings", "Menu", "Overlay", "StandardGame",
@game_standard = new StandardGame(@game_canvas)
@game_testcase = new TestCase(@game_canvas)
@game_tutorial = new Tutorial(@game_canvas)
- @game = @game_standard
- #@game = @game_testcase
+ #@game = @game_standard
+ @game = @game_testcase
#@game = @game_tutorial
#@menu = new Menu(@menu_canvas)
@overlay = new Overlay(@overlay_canvas)
View
@@ -13,9 +13,12 @@ define -> Settings = {
naub:
size: 28
- mass: 5
+ mass: 15
+ light_mass: 5
friction: 0.5
elasticity: 1
+ hard: 1
+ soft: 0.01
min_join_len: 1.2 # times size
max_join_len: 2 # times size
View
@@ -298,6 +298,7 @@ StringShape: class StringShape extends Shape
super(@naub)
render: (ctx, x,y) ->
+ @string = @naub.physical_body.m
size = @naub.size * .7
ctx.save()
View
@@ -3,9 +3,9 @@ define ["Naub","Game","Shapes","StandardGame"], (Naub,Game,{NumberShape, Ball, F
# super()
oninit: ->
super()
- @create_matching_naubs()
Naubino.settings.graphics.updating = on
Naubino.settings.game.creation_offset = -50
+ @create_matching_naubs()
@gravity = on
@naub_replaced.add (number)=> @graph.cycle_test(number)
@@ -23,3 +23,16 @@ define ["Naub","Game","Shapes","StandardGame"], (Naub,Game,{NumberShape, Ball, F
event:->
#check: =>
+ add_ball: (pos = @random_outside(), color = null) =>
+ naub = new Naub this, color
+ ball = new Ball
+
+ naub.add_shape ball
+ naub.setup_physics()
+ naub.physical_body.setPos( pos.Copy() ) # remember to set position
+ naub.kind = 'ball'
+
+ @add_object naub
+ naub.add_shape new NumberShape
+ #naub.update() # again just to get the numbers
+ naub

0 comments on commit 580d2eb

Please sign in to comment.