# Features of the environment for the simulation # Environment.tz (c) 2010 Jacob Schrum. # See Simulation.tz for more copyright information @use Mobile. @use Stationary. # Environment @define RICOCHET_SPACING 1.2. @define HALF_WALL_LENGTH 30. @define HALF_WALL_HEIGHT 1. @define WALL_BUFFER 5. @define POWERUP_DRIFT 2.0. @define TIME_BETWEEN_POWERUP_RESPAWN 20. @define HEALTH_BOOST 20. @define SPEED_BOOST_DURATION 20. @define BULLET_SPEED 8. @define BULLET_LOSS 10. @define BULLET_TIME 0.5. @define GUN_TIME 20. @define WRAP_BUFFER 2. Stationary : Goal { + variables: sunk (int). + to archive: return 1. + to dearchive: return 1. + to init: sunk = 0. + to create at location (vector): self handle-collisions with-type "Player" with-method "sink-goal". self register with-shape ((controller get-graphics) get-goal-shape) at-location location. self set-color to ((controller get-graphics) get-goal-color). + to sink-goal with ball (object): sunk = 1. + to goal-sunk: return sunk. } Stationary : Wall { # location: position in world to place center of wall # sizeVector: vector defining dimensions of wall # theColor: color of wall as a vector with components between 0 and 1 inclusive + to create at location (vector) size sizeVector (vector) color theColor (vector): wallShape (object). wallShape = (new Cube init-with size sizeVector). self register with-shape wallShape at-location location. self set-color to theColor. } Mobile : Bullet { + variables: shooter (object). # returns 1 if a bullet was shot by the player, 0 otherwise + to from-player: if (shooter is a "Player") : return 1. else return 0. # location: position to create the bullet # facing: direction in which the bullet will shoot # agent: Agent that shot the bullet + to create at location (vector) direction facing (vector) from agent (object): bulletShape (object). shooter = agent. bulletShape = (new Sphere init-with radius 0.25). self set-shape to bulletShape. self move to location. self set-color to (0,0,0). self set-velocity to (facing * BULLET_SPEED). self handle-collisions with-type "Wall" with-method "disappear". self handle-collisions with-type "Sword" with-method "disappear". self handle-collisions with-type "Player" with-method "damage". self handle-collisions with-type "Monster" with-method "damage". # thing: any physical object that a bullet can hit + to disappear after-hitting thing (object): free self. # agent: Agent that got hit by the bullet + to damage this agent (object): if shooter : { if ((shooter is a "Monster") && (agent is a "Player")) : { shooter shoot the agent with self. self disappear after-hitting agent. } else if ((shooter is a "Player") && (agent is a "Monster")) : { agent receive-damage-from-player of BULLET_LOSS. agent repell from self. self disappear after-hitting agent. } } } Mobile : PowerUp { + variables: radius (double). + to create radius theRadius (double) color theColor (vector): powerupShape (object). radius = theRadius. powerupShape = (new Sphere init-with radius theRadius). self set-shape to powerupShape. self move to (((controller get-math) get-random-spot-in-bin) + (0,(theRadius - 1),0)). self set-color to theColor. self handle-collisions with-type "Wall" with-method "bounce". self handle-collisions with-type "HealthBoost" with-method "bounce". self handle-collisions with-type "SpeedBoost" with-method "bounce". self handle-collisions with-type "GunBoost" with-method "bounce". self handle-collisions with-type "Player" with-method "confer-benefit". self handle-collisions with-type "Monster" with-method "confer-benefit". + to respawn: self move to (((controller get-math) get-random-spot-in-bin) + (0,(radius - 1),0)). + to bounce off thing (object): self set-velocity to (-1 * (self get-velocity)). + to iterate: self drift. + to drift: self set-acceleration to (random[((POWERUP_DRIFT * 2),0,(POWERUP_DRIFT * 2))] - (POWERUP_DRIFT,0,POWERUP_DRIFT)). + to confer-benefit on agent (object): self schedule method-call "respawn" at-time ((controller get-time) + TIME_BETWEEN_POWERUP_RESPAWN). # Move out of sight self move to (0,-1000,0). self set-acceleration to (0,0,0). self set-velocity to (0,0,0). if (agent is a "Monster") : agent give-powerup. else if (agent is a "Player") : controller player-gets-powerup. } PowerUp : HealthBoost { + to confer-benefit on agent (object): super confer-benefit on agent. if (agent is a "Monster") : agent restore damage HEALTH_BOOST. agent set-energy to ((agent get-energy) + HEALTH_BOOST). } PowerUp : SpeedBoost { + to confer-benefit on agent (object): super confer-benefit on agent. agent boost-speed. } PowerUp : GunBoost { + to confer-benefit on agent (object): super confer-benefit on agent. agent arm. }