Changeset 925
- Timestamp:
- 02/06/2011 05:21:35 PM (10 years ago)
- Location:
- scenarios/GerminationX
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
scenarios/GerminationX/fungi/src/Fungi.hx
r924 r925 26 26 import truffle.SpriteEntity; 27 27 import truffle.SkeletonEntity; 28 import truffle.Bone; 28 29 29 30 // todo: remove this … … 157 158 var Debug:flash.text.TextField; 158 159 var BG:Graphics; 160 var Emotions:Dynamic; 159 161 160 162 public function new(world:World, name:String, pos) … … 162 164 super(world,pos); 163 165 Name = name; 166 Speed=0.1; 167 UpdateFreq=5; 168 Hide(true); 169 Emotions={Love:0}; 164 170 } 165 171 … … 207 213 Std.parseInt(e.tile.y))); 208 214 209 LogicalPos = new Vec3(Std.parseInt(e.pos.x), 210 Std.parseInt(e.pos.y), 215 216 LogicalPos = new Vec3(Std.parseInt(e.emotionalloc.x), 217 Std.parseInt(e.emotionalloc.y), 211 218 4); 212 219 213 var ee = e.emotions.content; 220 Emotions = e.emotions; 221 222 var ee = e.fatemotions.content; 214 223 var mood=Std.parseFloat(ee[0].content[0]); 215 224 … … 223 232 224 233 text+="Actions:\n"; 225 var acs = cast(e. actions,Array<Dynamic>);234 var acs = cast(e.fatactions,Array<Dynamic>); 226 235 for (i in 0...acs.length) 227 236 { 228 text+=acs[i] +"\n";237 text+=acs[i].msg+"\n"; 229 238 } 230 239 … … 245 254 246 255 //trace(text); 256 } 257 258 override function Update(frame:Int, world:World) 259 { 260 if (Emotions!=null) 261 { 262 //Draw(cast(world,truffle.World)); 263 var c=this; 264 Root.Recurse(function(b:Bone,depth:Int) 265 { 266 b.SetRotate(15*Math.sin( 267 (((10-depth)+frame*0.04)*c.Emotions.Love) + 268 (world.MyRndGen.RndFlt()*45*c.Emotions.Hate) 269 )); 270 }); 271 } 272 super.Update(frame,world); 247 273 } 248 274 } … … 526 552 for (p in data) 527 553 { 528 var e = c.Get(new Vec2(p.pos.x,p.pos.y)); 529 if (!Std.is(e,Plant)) 554 var worldpos = new Vec2(p.pos.x,p.pos.y); 555 var e = c.Get("Plant",worldpos); 556 if (e==null) 530 557 { 531 var pos = new Vec3(p.pos.x,p.pos.y,e.LogicalPos.z+1); 532 var plant = new Plant(c,p.owner,pos,p.type,p.state); 533 c.Plants.push(plant); 558 //trace("making new plant"); 559 var cube = c.Get("Cube",worldpos); 560 if (cube!=null) 561 { 562 var pos = new Vec3(p.pos.x,p.pos.y,cube.LogicalPos.z+1); 563 var plant = new Plant(c,p.owner,pos,p.type,p.state); 564 c.Plants.push(plant); 565 } 534 566 } 535 567 else 536 568 { 537 569 //trace("updating plant"); 570 //trace(e); 571 //trace(p.state); 538 572 cast(e,Plant).StateUpdate(p.state,c); 539 573 } -
scenarios/GerminationX/fungi/src/truffle/Entity.hx
r924 r925 25 25 public var NeedsUpdate:Bool; 26 26 public var Hidden:Bool; 27 27 public var Speed:Float; 28 public var UpdateFreq:Int; 29 28 30 public function new(w:World,pos:Vec3) 29 31 { … … 32 34 TilePos = null; 33 35 Depth = Pos.z; 36 Speed = 0; 37 UpdateFreq=0; 34 38 NeedsUpdate=false; 35 39 w.Add(this); … … 57 61 public function Update(frame:Int, world:World) 58 62 { 59 Pos = Pos2PixelPos(LogicalPos); 63 if (Speed==0) 64 { 65 Pos = Pos2PixelPos(LogicalPos); 66 } 67 else 68 { 69 var Dst = Pos2PixelPos(LogicalPos); 70 if (!Dst.Eq(Pos)) 71 { 72 Pos = Pos.Lerp(Dst,Speed); 73 } 74 } 75 60 76 Depth = Pos.z; 61 77 } -
scenarios/GerminationX/fungi/src/truffle/SkeletonEntity.hx
r905 r925 133 133 { 134 134 super.Update(frame,world); 135 136 //Root.SetRotate(25*Math.sin(frame*0.04));137 //Draw(cast(world,truffle.World));138 139 //UpdateDepth();140 var c=this;141 142 Root.Recurse(function(b:Bone,depth:Int)143 {144 b.SetRotate(15*Math.sin((10-depth)*0.58+frame*(0.04+0.01*c.Id)));145 }146 );147 148 135 Root.SetPos(new Vec2(Pos.x,Pos.y)); 149 136 Root.Update(frame,null); -
scenarios/GerminationX/fungi/src/truffle/Vec2.hx
r814 r925 21 21 public var y:Float; 22 22 23 public function new(px:Float, py:Float)23 public inline function new(px:Float, py:Float) 24 24 { 25 25 x=px; y=py; 26 26 } 27 27 28 public function Add(other:Vec2) : Vec228 public inline function Add(other:Vec2) : Vec2 29 29 { 30 30 return new Vec2(x+other.x,y+other.y); 31 31 } 32 32 33 public function Sub(other:Vec2) : Vec233 public inline function Sub(other:Vec2) : Vec2 34 34 { 35 35 return new Vec2(x-other.x,y-other.y); 36 36 } 37 37 38 public function Div(v:Float) : Vec238 public inline function Div(v:Float) : Vec2 39 39 { 40 40 return new Vec2(x/v,y/v); 41 41 } 42 42 43 public function Mul(v:Float) : Vec243 public inline function Mul(v:Float) : Vec2 44 44 { 45 45 return new Vec2(x*v,y*v); 46 46 } 47 47 48 public function Mag() : Float48 public inline function Mag() : Float 49 49 { 50 50 return Math.sqrt(x*x+y*y); 51 51 } 52 52 53 public function Lerp(other:Vec2,t:Float) : Vec253 public inline function Lerp(other:Vec2,t:Float) : Vec2 54 54 { 55 55 return new Vec2(x*(1-t) + other.x*t, … … 57 57 } 58 58 59 public function Eq(other:Vec2) : Bool59 public inline function Eq(other:Vec2) : Bool 60 60 { 61 61 return x==other.x && y==other.y; 62 62 } 63 63 64 public function AsStr()64 public inline function AsStr() 65 65 { 66 66 return Std.string(x)+", "+Std.string(y); -
scenarios/GerminationX/fungi/src/truffle/Vec3.hx
r814 r925 22 22 public var z:Float; 23 23 24 public function new(px:Float, py:Float, pz:Float)24 public inline function new(px:Float, py:Float, pz:Float) 25 25 { 26 26 x=px; y=py; z=pz; 27 27 } 28 28 29 publicfunction Add(other:Vec3) : Vec329 public inline function Add(other:Vec3) : Vec3 30 30 { 31 31 return new Vec3(x+other.x,y+other.y,z+other.z); 32 32 } 33 33 34 public function Sub(other:Vec3) : Vec334 public inline function Sub(other:Vec3) : Vec3 35 35 { 36 36 return new Vec3(x-other.x,y-other.y,z-other.z); 37 37 } 38 39 public inline function Mul(v:Float) : Vec3 40 { 41 return new Vec3(x*v,y*v,z*v); 42 } 43 44 public inline function Div(v:Float) : Vec3 45 { 46 return new Vec3(x/v,y/v,z/v); 47 } 38 48 39 public function Mag() : Float49 public inline function Mag() : Float 40 50 { 41 51 return Math.sqrt(x*x+y*y+z*z); 42 52 } 53 54 public inline function Normalise() : Vec3 55 { 56 return Div(Mag()); 57 } 43 58 44 public function Lerp(other:Vec3,t:Float) : Vec359 public inline function Lerp(other:Vec3,t:Float) : Vec3 45 60 { 46 61 return new Vec3(x*(1-t) + other.x*t, … … 49 64 } 50 65 51 public function Eq(other:Vec3) : Bool66 public inline function Eq(other:Vec3) : Bool 52 67 { 53 68 return x==other.x && y==other.y && z==other.z; 54 69 } 55 70 56 public function AsStr()71 public inline function AsStr() 57 72 { 58 73 return Std.string(x)+", "+Std.string(y)+", "+Std.string(z); -
scenarios/GerminationX/fungi/src/truffle/flash/FlashSprite.hx
r924 r925 216 216 public function Update(frame:Int, tx:Dynamic) 217 217 { 218 // we don't want to pass on the centering offset to the hierachy 218 219 Transform.identity(); 219 // we don't want to pass on the centering offset to the hierachy220 220 var tmp = new Matrix(Transform.a,Transform.b,Transform.c,Transform.d, 221 221 Transform.tx-Centre.x,Transform.ty-Centre.y); … … 237 237 } 238 238 transform.matrix = tmp; 239 240 //transform.matrix = Transform; 241 //x=x-Centre.x; 242 //y=y-Centre.y; 239 243 } 240 244 } -
scenarios/GerminationX/fungi/src/truffle/flash/FlashWorld.hx
r924 r925 50 50 } 51 51 52 public function Get( p:Vec2) : Dynamic52 public function Get(type:String, p:Vec2) : Dynamic 53 53 { 54 var top:Entity = null;55 var upper:Float=-9999;56 57 54 for (e in Scene) 58 55 { 59 56 if (p.x==e.LogicalPos.x && 60 p.y==e.LogicalPos.y) 57 p.y==e.LogicalPos.y && 58 Type.getClassName(Type.getClass(e))==type) 61 59 { 62 if (e.LogicalPos.z>upper) 63 { 64 top=e; 65 upper=e.LogicalPos.z; 66 } 60 return e; 67 61 } 68 62 } 69 return top;63 return null; 70 64 } 71 65 … … 123 117 } 124 118 125 if (e.NeedsUpdate && !e.Hidden) 119 if (e.NeedsUpdate && !e.Hidden && 120 (e.UpdateFreq==0 || 121 (time % e.UpdateFreq)==0)) 126 122 { 127 123 e.Update(time,cast(this,truffle.World)); -
scenarios/GerminationX/fungi/src/truffle/interfaces/World.hx
r924 r925 23 23 public function Add(e:Entity) : Void; 24 24 public function Remove(e:Entity) : Void; 25 public function Get( p:Vec2) : Dynamic;25 public function Get(type:String, p:Vec2) : Dynamic; 26 26 public function AddSprite(s:Sprite) : Void; 27 27 public function RemoveSprite(s:Sprite) : Void; -
scenarios/GerminationX/oak/run.sh
r923 r925 1 1 java -classpath $( echo lib/*.jar . | sed 's/ /:/g'):src clojure.main src/oak/core.clj & 2 sleep 302 sleep 40 3 3 echo starting agents... 4 4 java -cp lib/FAtiMA.jar FAtiMA.Agent localhost 46874 false CanopySpirit F CanopySpirit CanopySpirit strength:4 hurt:false pose:standing & -
scenarios/GerminationX/oak/src/oak/game_world.clj
r923 r925 176 176 "owner" (:layer entity) 177 177 "position" (str (:x (:pos entity)) "," (:y (:pos entity))) 178 "tile" "0,0"178 "tile" (:pos tile) 179 179 "type" "object" 180 180 "time" time})) … … 182 182 fw 183 183 (:entities tile))) 184 fatima-world 184 ; update the agent's tile position 185 (merge fatima-world 186 {:agents 187 (map 188 (fn [agent] 189 (merge agent 190 {:tile 191 (:tile 192 (find-spirit game-world (remote-agent-name agent)))})) 193 (world-agents fatima-world))}) 185 194 (:tiles game-world))) 186 195 -
scenarios/GerminationX/oak/src/oak/io.clj
r923 r925 35 35 (defn parse-number [s] 36 36 (try (Integer/parseInt (.trim s)) 37 (catch NumberFormatException e nil))) 38 39 (defn parse-float [s] 40 (try (Float/parseFloat (.trim s)) 37 41 (catch NumberFormatException e nil))) 38 42 -
scenarios/GerminationX/oak/src/oak/remote_agent.clj
r917 r925 14 14 15 15 (ns oak.remote-agent 16 (:use oak.io) 16 (:use 17 oak.vec2 18 oak.io) 17 19 (:import 18 20 java.net.Socket … … 36 38 :done 37 39 :random 38 :reader) 40 :reader 41 :tile) 39 42 40 43 (def remote-agent-properties (accessor remote-agent :properties)) … … 49 52 (def remote-agent-random (accessor remote-agent :random)) 50 53 (def remote-agent-reader (accessor remote-agent :reader)) 54 (def remote-agent-tile (accessor remote-agent :tile)) 51 55 52 56 (defn remote-agent-add-property [agent property] … … 79 83 (new java.util.Random) 80 84 reader 85 (make-vec2 0 0) 81 86 ))) 82 87 -
scenarios/GerminationX/oak/src/oak/spirit.clj
r923 r925 29 29 name 30 30 emotions 31 actions]) 31 emotionalloc 32 fatactions 33 fatemotions]) 34 35 (defn emotion-map [] 36 { "Love" 0 37 "Hate" 0 38 "Hope" 0 39 "Fear" 0 40 "Satisfaction" 0 41 "Relief" 0 42 "Fears-Confirmed" 0 43 "Disappointment" 0 44 "Joy" 0 45 "Distress" 0 46 "Happy-For" 0 47 "Pitty" 0 48 "Resentment" 0 49 "Gloating" 0 50 "Pride" 0 51 "Shame" 0 52 "Gratification" 0 53 "Remorse" 0 54 "Admiration" 0 55 "Reproach" 0 56 "Gratitude" 0 57 "Anger" 0 }) 32 58 33 59 (defn make-spirit [remote-agent] … … 37 63 (make-vec2 0 0) 38 64 (remote-agent-name remote-agent) 65 (emotion-map) 66 (make-vec2 0 0) 39 67 '() '())) 40 68 … … 49 77 (defn spirit-update [spirit remote-agent tile] 50 78 ; for the moment take a straight copy of actions and emotions 51 (let [spirit (modify :emotions 52 (fn [emotions] 53 (remote-agent-emotions remote-agent)) 54 (modify :actions 55 (fn [actions] 56 (remote-agent-done remote-agent)) 57 spirit))] 79 (let [spirit 80 (modify 81 :emotionalloc ; get the object causing the highest emotion 82 (fn [emotionalloc] 83 (first 84 (reduce 85 (fn [r emotion] 86 (let [e (:attrs emotion)] 87 (if e 88 (let [intensity (parse-float (:intensity e))] 89 (if (> intensity (second r)) 90 (let [id (fatima-name->id (:direction e))] 91 (if id 92 (let [obj (tile-find-entity tile id)] 93 (if obj 94 (list (:pos obj) intensity) 95 r)) 96 r)) 97 r)) 98 r))) 99 (list emotionalloc 0) 100 (:content (remote-agent-emotions remote-agent))))) 101 (modify 102 :emotions ; process emotions into a useable form 103 (fn [emotions] 104 (reduce 105 (fn [r emotion] 106 (let [e (:attrs emotion)] 107 (if e 108 (merge r {(:type e) 109 (+ (parse-float (:intensity e)) 110 (get r (:type e)))}) 111 r))) 112 (emotion-map) 113 (:content (remote-agent-emotions remote-agent)))) 114 (modify 115 :fatemotions ; copy the fatima stuff for debug output 116 (fn [emotions] 117 ;(println emotions) 118 (remote-agent-emotions remote-agent)) 119 (modify 120 :fatactions 121 (fn [actions] 122 (remote-agent-done remote-agent)) 123 spirit))))] 124 125 ; (println (:emotionalloc spirit)) 58 126 59 127 ; if we have some actions 60 (if (not (empty? (: actions spirit)))61 (let [latest-action (first (: actions spirit))128 (if (not (empty? (:fatactions spirit))) 129 (let [latest-action (first (:fatactions spirit)) 62 130 latest-subject (nth (.split (:msg latest-action) " ") 1) 63 131 id (fatima-name->id latest-subject)] -
scenarios/GerminationX/oak/src/oak/world.clj
r923 r925 17 17 oak.forms 18 18 oak.remote-agent 19 oak.io) 19 oak.io 20 oak.vec2) 20 21 (:import 21 22 java.util.ArrayList … … 141 142 (do 142 143 (world-broadcast-all world (str "ENTITY-ADDED " (get object "name"))) 143 ( println (str "added " (get object "name") " " (get object "position") " "144 (comment println (str "added " (get object "name") " " (get object "position") " " 144 145 (count (world-objects world)) " objects stored")) 145 146 (merge world {:objects (cons object (world-objects world))})) … … 194 195 (= type "look-at") 195 196 (do 196 ;(println (str (remote-agent-name agent) " -----------> LOOKING AT: " (nth toks 1))) 197 (send-msg (remote-agent-socket agent) 198 (str "LOOK-AT " (nth toks 1) " " 199 (hash-map-to-string 200 (world-get-properties world (nth toks 1))))) 201 (merge agent {:done (max-cons {:time (world-time world) 202 :msg msg} 203 (remote-agent-done agent) 4)})) 197 (let [object-name (nth toks 1)] 198 ;(println (remote-agent-tile agent)) 199 ; is the agent on the same tile as the object? 200 (if (vec2-eq? (remote-agent-tile agent) 201 (get (world-get-object world object-name) "tile")) 202 (do 203 (send-msg (remote-agent-socket agent) 204 (str "LOOK-AT " object-name " " 205 (hash-map-to-string 206 (world-get-properties world (nth toks 1))))) 207 (merge agent {:done (max-cons {:time (world-time world) 208 :msg msg} 209 (remote-agent-done agent) 4)})) 210 agent))) 204 211 (= type "say") 205 212 (do (println "say")
Note: See TracChangeset
for help on using the changeset viewer.