2 import org
.alterverse
.world
.*;
3 import org
.alterverse
.shapes
.*;
4 import org
.alterverse
.sound
.*;
5 import org
.alterverse
.game
.*;
6 import org
.alterverse
.control
.*;
7 import org
.alterverse
.speech
.*;
9 public class WorldExample
extends GameContext
{
10 boolean editing
= false;
13 class Floor
extends GameObject
{
14 public Floor(Shape shape
) {
19 class Stair
extends Floor
{
20 public Stair(Shape shape
) {
25 class Wall
extends GameObject
{
26 public Wall(Shape shape
) {
31 class Machine
extends GameObject
{
33 public Machine(Shape shape
) {
35 sound
= new Sound("sounds/machine1.ogg");
42 class Human
extends DirectionalObject
{
47 public Human(Shape shape
) {
49 land
= new Sound("sounds/step.ogg");
50 wall
= new Sound("sounds/wall.ogg");
53 watch
= new Sound("sounds/watch.ogg");
55 stair
= new Sound("sounds/stair.ogg");
60 public void onFall(double distance
) {
63 public void updateListener() {
65 SoundManager
.setListenerPosition(getX(),getY(),getZ());
68 public void onBump(GameObject othr
) {
69 if (othr
instanceof Wall
)
71 else if (othr
instanceof Stair
)
73 else if (othr
instanceof Floor
)
75 if (othr
instanceof Human
)
82 double lx
,ly
,lz
,ux
,uy
,uz
;
83 public WorldExample() {
84 engine
= new GameEngine(this);
92 area
.add(new Floor(new Box(-30,-2,-20,60,2,22)));
93 area
.add(new Floor(new Box(-30,-7,-19,60,2,40)));
94 area
.add(new Stair(new Box(-2,-1.5,2,4,1,1)));
95 area
.add(new Stair(new Box(-2,-2,3,4,1,1)));
96 area
.add(new Stair(new Box(-2,-2.5,4,4,1,1)));
97 area
.add(new Stair(new Box(-2,-3,5,4,1,1)));
98 area
.add(new Stair(new Box(-2,-3.5,6,4,1,1)));
99 area
.add(new Stair(new Box(-2,-4,7,4,1,1)));
100 area
.add(new Stair(new Box(-2,-4.5,8,4,1,1)));
101 area
.add(new Stair(new Box(-2,-5,9,4,1,1)));
102 area
.add(new Stair(new Box(-2,-5.5,10,4,1,1)));
103 area
.add(new Wall(new Box(-30,0,-3,30,10,1)));
104 area
.add(new Wall(new Box(-1,0,-6,1,10,4)));
105 area
.add(new Wall(new Box(-1,0,-12,1,10,5)));
106 area
.add(new Wall(new Box(-10,0,-12,1,10,10)));
107 area
.add(new Wall(new Box(-9,0,-12,8,10,1)));
108 area
.add(new Wall(new Box(1,0,-3,10,10,1)));
109 area
.add(new Machine(new Box(-9,0,-11,2,2,1)));
110 Wall w
= new Wall(new Box(1.0,0.0,-6.0,2.0,4.0,2.0));
111 w
.addChild(new Wall(new Box(5.0,0.0,-6.0,2.0,4.0,2.0)));
112 w
.addShape(new Box(9.0,0.0,-6.0,2.0,4.0,2.0));
114 player
=new Player(new Box(-0.2,2,0.2,0.4,1.9,0.4));
116 area
.add(new Nonplayer(new Box(-5,1,1,0.4,1.9,0.4)));
117 area
.add(new Nonplayer(new Box(5,1,1,0.4,1.9,0.4)));
118 area
.setGravity(true);
119 tts
.speak("Starting up", 2);
124 public void process() {
128 public class Nonplayer
extends Human
{
130 public Nonplayer(Shape shape
) {
134 public void process() {
137 double dx
= (Math
.random()*2)-1;
138 double dz
= (Math
.random()*2)-1;
145 public class Player
extends Human
{
146 public Player(Shape shape
) {
151 public void updateData() {
153 SoundManager
.setListenerPosition(getX(), getY(), getZ());
154 Point p
= new Point(getDirection(),1);
155 SoundManager
.setListenerOrientation(p
.x
,p
.y
,p
.z
,0,1,0);
159 public void keyDown(int key
) {
163 if (player
.getSolid())
164 player
.setSolid(false);
166 player
.setSolid(true);
167 tts
.speak(player
.getSolid()?
"Solid":"Non-solid", 2);
171 if (bcl
.isKeyDown(Keys
.LSHIFT
))
172 player
.setY(player
.getY()+0.5);
173 player
.updateListener();
177 if (bcl
.isKeyDown(Keys
.LSHIFT
))
178 player
.setY(player
.getY()-0.5);
179 player
.updateListener();
185 if (bcl
.isKeyDown(Keys
.LSHIFT
) && bcl
.isKeyDown(Keys
.LALT
)) {
190 tts
.speak(editing?
"Edit mode": "normal mode", 2);
191 area
.setGravity(! editing
);
196 if (bcl
.isKeyDown(Keys
.LSHIFT
))
198 else if (bcl
.isKeyDown(Keys
.LALT
))
205 if (bcl
.isKeyDown(Keys
.LSHIFT
))
207 else if (bcl
.isKeyDown(Keys
.LALT
))
208 player
.turnRight90();
214 if (! bcl
.isKeyDown(Keys
.LSHIFT
))
215 player
.moveForward();
219 if (! bcl
.isKeyDown(Keys
.LSHIFT
))
220 player
.moveBackward();
223 tts
.speak(""+player
.getDirection(),2);
226 tts
.speak("position: " + player
.getX()+", "+player
.getY()+", " + player
.getZ(),2);
230 ly
= player
.getY()-3.0;
239 GameObject gobj
= new GameObject(area
,new BoundBox(lx
,ly
,lz
,ux
,uy
,uz
));
240 GameObject candidate
= area
.getTouchingObjects(gobj
).get(0);
241 ly
= candidate
.minY();
242 uy
= candidate
.maxY();
243 candidate
.split(lx
,ly
,lz
,ux
,uy
,uz
);
251 public static void main (String
[] args
) {