# Graphical maintenence of the simulation # GraphicsHandler.tz (c) 2010 Jacob Schrum. # See Simulation.tz for more copyright information @use Abstract. @use Stationary. Stationary : Ground { + to init: self move to (0,-0.5,0). self set-shape to (new Cube init-with size (500,1,500)). } Abstract : GraphicsHandler { + variables: player-shape (object). monster-color (vector). sword-shape (object). sword-color (vector). sensor-shape (object). sensor-color (vector). monster-shape (object). bot-colors (list). disk (object). ball-shape (object). goal-shape (object). goal-color (vector). + to init: floor (object). if ((controller get-commandline) bit-param named "show-floor") : floor = new Ground. controller set-background-color to (.4, .6, .9). ball-shape = (new Sphere init-with radius 1). player-shape = (new PolygonCone init-with radius 1 sides 5 height 2). bot-colors = {0,0,0,0}. bot-colors{MODE_PREY} = (0,0,0). bot-colors{MODE_PRED} = (1,0,0). bot-colors{MODE_FIGHT} = (0,1,0). bot-colors{MODE_BALL} = (0,1,1). bot-colors{MODE_RAM} = (1,1,0). bot-colors{MODE_BACKRAM} = (1,0,1). sword-shape = (new Cube init-with size (.2, 5, .2)). sword-color = (0,0,1). sensor-shape = (new Cube init-with size (.2, ((controller get-commandline) num-param named "sensor-length"), .2)). sensor-color = (1,1,1). monster-shape = (new PolygonCone init-with radius 1 sides 5 height 2). monster-color = (1,1,0). disk = new Shape init-with-polygon-disk sides 20 height 0.5 radius ((controller get-commandline) num-param named "very-close-monster"). goal-shape = new Shape init-with-polygon-disk sides 20 height 0.5 radius ((controller get-commandline) num-param named "goal-size"). goal-color = (0,0,0). + to get-goal-shape: return goal-shape. + to get-goal-color: return goal-color. + to get-ball-shape: return ball-shape. + to get-player-shape: return player-shape. + to get-monster-color: return monster-color. + to get-sword-shape: return sword-shape. + to get-sword-color: return sword-color. + to get-sensor-shape: return sensor-shape. + to get-sensor-color: return sensor-color. + to get-monster-shape: return monster-shape. + to get-bot-color for-mode mode (int): return bot-colors{mode}. + to get-num-bot-colors: return |bot-colors|. + to get-disk: return disk. + to bit-map digit x (int): if (x == 0) : return (0,0,1). else if (x == 1) : return (0,1,0). else if (x == 2) : return (0,1,1). else if (x == 3) : return (1,0,0). else if (x == 4) : return (1,0,1). else if (x == 5) : return (1,1,0). else if (x == 6) : return (1,1,1). else { print "Digit not in [0,6]". controller end-simulation. } # Maps integers to unique colors for each mode. # Level distinction decreases as number of modes grows. + to map-mode-to-color mode m (int): base-color (vector). base-color = (self bit-map digit (m % 7)). return (base-color * (0.75 ^ (m / 7))). }