Show CamerasInRoomSimpleGame.java syntax highlighted
/*
* Copyright (C) 2001-2005 Pleasant nightmare studio
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package skunkworks;
import com.jme.input.InputHandler;
import com.jme.input.KeyInput;
import com.jme.input.action.KeyNodeBackwardAction;
import com.jme.input.action.KeyNodeForwardAction;
import com.jme.input.action.KeyNodeStrafeLeftAction;
import com.jme.input.action.KeyNodeStrafeRightAction;
import com.jme.math.Vector3f;
import com.jme.scene.Geometry;
import com.jme.scene.shape.Sphere;
import org.pleasantnightmare.riotinecity.CameraChangeInputAction;
import org.pleasantnightmare.riotinecity.CameraPositionController;
import org.pleasantnightmare.riotinecity.ConsoleGame;
import org.pleasantnightmare.riotinecity.spatials.PlayerSpatial;
import org.pleasantnightmare.riotinecity.spatials.SquareRoom;
/**
* @author deus
* @version 1.0
* @since Feb 12, 2007 8:42:30 PM
*/
public class CamerasInRoomSimpleGame extends ConsoleGame {
private static final int MOVE_SPEED = 2;
private static final int ROOM_WIDTH = 130;
private static final int ROOM_DEPTH = 50;
private static final int ROOM_HEIGHT = 30;
private SquareRoom squareRoomWithCameras;
private Geometry person;
protected void simpleInitGame() {
addRoom();
addPerson();
initInputHandler();
}
private void initInputHandler() {
InputHandler input = new InputHandler();
addHandler(input);
forward(input);
back(input);
left(input);
right(input);
switchCamera(input);
}
private void left(InputHandler input) {
input.addAction(new KeyNodeStrafeLeftAction(person, MOVE_SPEED), "left", KeyInput.KEY_A, true);
}
private void right(InputHandler input) {
input.addAction(new KeyNodeStrafeRightAction(person, MOVE_SPEED), "right", KeyInput.KEY_D, true);
}
private void back(InputHandler input) {
input.addAction(new KeyNodeBackwardAction(person, MOVE_SPEED), "back", KeyInput.KEY_S, true);
}
private void forward(InputHandler input) {
input.addAction(new KeyNodeForwardAction(person, MOVE_SPEED), "forward", KeyInput.KEY_W, true);
}
private void switchCamera(InputHandler input) {
// TODO FIXME
CameraPositionController cameraPositionController = new CameraPositionController(camera, new PlayerSpatial());
input.addAction(new CameraChangeInputAction(cameraPositionController), "camera", KeyInput.KEY_C, false);
}
private void addRoom() {
squareRoomWithCameras = new SquareRoom(ROOM_WIDTH, ROOM_DEPTH, ROOM_HEIGHT);
sceneRoot.attachChild(squareRoomWithCameras);
}
private void addPerson() {
person = new Sphere("person", new Vector3f(0, 0, 0), 10, 10, 3);
sceneRoot.attachChild(person);
}
public static void main(String[] args) {
CamerasInRoomSimpleGame c = new CamerasInRoomSimpleGame();
c.setDialogBehaviour(FIRSTRUN_OR_NOCONFIGFILE_SHOW_PROPS_DIALOG);
c.start();
}
}
See more files for this project here