diff --git a/a3/AvatarNear.class b/a3/AvatarNear.class new file mode 100644 index 0000000..24ad064 Binary files /dev/null and b/a3/AvatarNear.class differ diff --git a/a3/GetBig.class b/a3/GetBig.class new file mode 100644 index 0000000..cbc2cec Binary files /dev/null and b/a3/GetBig.class differ diff --git a/a3/GetSmall.class b/a3/GetSmall.class new file mode 100644 index 0000000..988f974 Binary files /dev/null and b/a3/GetSmall.class differ diff --git a/a3/GoWalk.class b/a3/GoWalk.class new file mode 100644 index 0000000..a08ede0 Binary files /dev/null and b/a3/GoWalk.class differ diff --git a/a3/MyGame.java b/a3/MyGame.java index 26400b3..aa2a85e 100644 --- a/a3/MyGame.java +++ b/a3/MyGame.java @@ -24,12 +24,15 @@ import java.awt.geom.*; import javax.script.*; +import java.util.Scanner; // get user input from command line + import myGameEngine.*; import java.net.InetAddress; import ray.networking.IGameConnection.ProtocolType; // import networking import java.util.Iterator; + import java.util.UUID; // import networking import java.io.IOException; // import networking import java.net.InetAddress; // import networking @@ -45,13 +48,22 @@ import ray.audio.*; // import audio import com.jogamp.openal.ALFactory; // import audio +import javax.script.ScriptEngine; // import script +import javax.script.ScriptEngineFactory; // import script +import javax.script.ScriptEngineManager; // import script +import javax.script.ScriptException; // import script + + class MyGame extends VariableFrameRateGame { private static MyGame game; - public static String MAP_TEXTURE_SCRIPT = "scripts\\map_texture.js"; - public static String MAP_FILE_SCRIPT = "scripts\\map_file.js"; + public static String MAP_TEXTURE_SCRIPT = "scripts\\map_texture.js"; // script for map texture + public static String MAP_FILE_SCRIPT = "scripts\\map_file.js"; // script for map file + public static String CONFIG_SCRIPT = "scripts\\config.js"; // script for configuration + String configScript; // script after reading + private Player player; private OrbitCameraController orbitCamera; private Camera cam; @@ -67,13 +79,9 @@ class MyGame extends VariableFrameRateGame { private MoveRightAction dMoveR; private YawLeftAction dYawL; private YawRightAction dYawR; + + //May not need this because we have OrbitCameraController. //private Camera3PController orbitController, orbitController2; - private MoveForwardAction eMoveF; - private MoveBackwardAction eMoveB; - private MoveLeftAction eMoveL; - private MoveRightAction eMoveR; - private YawLeftAction eYawL; - private YawRightAction eYawR; private String serverAddress; // network private int serverPort; // network @@ -81,6 +89,8 @@ class MyGame extends VariableFrameRateGame { private ProtocolClient protClient; // network private boolean isClientConnected; // network private Vector gameObjectsToRemove; // network + private Vector ghostAvatarList; //network + private Vector ghostNPCList; //AI private SceneNode earthNode, coneNode, groundNode; // physics private SceneNode cameraPositionNode; // physics @@ -95,8 +105,16 @@ class MyGame extends VariableFrameRateGame { private SceneNode robotNode; // set to gloabl for sound - IAudioManager audioMgr; // sound - Sound oceanSound, hereSound; // sound + private IAudioManager audioMgr; // sound + private Sound oceanSound, hereSound; // sound + private boolean soundToggle = true; // sound PRESS 'O' to enable and disable sound + + private int maxscore; // maxscore read from JavaScript file + private int p1Score = 0; // score for Player 1 + private int p2Score = 0; // score for Player 2 + + private GL4RenderSystem rs; // HUD + private String elapsTimeStr, dispStr; // HUD //I'll leave this static because I wouldn't want two MyGames public static MyGame getGame() { @@ -113,7 +131,13 @@ protected MyGame(String serverAddr, int sPort) { public static void main(String[] args) { //game = new MyGame(args[0], Integer.parseInt(args[1])); //Needs to have assets and a3 in the same directory. - game = new MyGame("130.86.65.78", 8000); + + System.out.print("Enter Networking Server IP Address: "); +/* Scanner in = new Scanner (System.in); // input IP address + game = new MyGame(in.next(), 8000); +*/ game = new MyGame("130.86.65.78", 8000); // hardcored IP + + //Client client; try { game.startup(); @@ -141,6 +165,8 @@ public static void setPlayerNode(SceneNode node) { @Override protected void setupWindow(RenderSystem rs, GraphicsEnvironment ge) { rs.createRenderWindow(new DisplayMode(1000, 700, 24, 60), false); + //rs.createRenderWindow(new DisplayMode(1000, 700, 24, 60), true); + //rs.createRenderWindow(true); } @Override @@ -160,32 +186,61 @@ protected void setupScene(Engine eng, SceneManager sm) throws IOException { setupNetworking(); im = new GenericInputManager(); //Initializing input manager for controllers - this.sm = sm; + //Activate physics + running = false; + + // Java Script ScriptEngineManager factory = new ScriptEngineManager(); - ScriptEngine jsEngine = factory.getEngineByName("js"); - sm.getAmbientLight().setIntensity(new Color(0.5f, 0.5f, 0.5f)); + ScriptEngine jsEngine = factory.getEngineByName("js"); + + this.sm = sm; + + // ambient light + //sm.getAmbientLight().setIntensity(new Color(0.5f, 0.5f, 0.5f)); + sm.getAmbientLight().setIntensity(new Color(.1f, .1f, .1f)); + + // Positional Light + Light plight = sm.createLight("testLamp1", Light.Type.POINT); + plight.setAmbient(new Color(.3f, .3f, .3f)); + plight.setDiffuse(new Color(.7f, .7f, .7f)); + plight.setSpecular(new Color(1.0f, 1.0f, 1.0f)); + plight.setRange(5f); + SceneNode plightNode = sm.getRootSceneNode().createChildSceneNode("plightNode"); + plightNode.attachObject(plight); + + // Spot Light + Light spotLight = sm.createLight("spotLight", Light.Type.SPOT); + spotLight.setAmbient(new Color(.4f, .3f, .5f)); + spotLight.setDiffuse(new Color(.7f, .3f, .5f)); + spotLight.setSpecular(new Color(1.0f, 1.0f, 1.0f)); + spotLight.setRange(3f); + SceneNode spotLightNode = sm.getRootSceneNode().createChildSceneNode("spotLightNode"); + spotLightNode.attachObject(spotLight); + SceneNode cameraNode = sm.getRootSceneNode().createChildSceneNode("CameraNode"); cameraNode.attachObject(cam); +// LightManager lightMggr = new LightManager(this); +// lightMgr.putLightSpotFocusOnNode(sm.getSceneNode("hatoflifeNode"), "L1", new Color(75,72,25)); +// LightMgr.putLightSpotFocusOnNode(sm.getSceneNode("hatofLifeNode"), "L2", new Color(255, 55, 35)); + //Initialize Player player = new Player(sm); + + // Load map map = new Map(eng, sm, readScript(jsEngine, MAP_FILE_SCRIPT), readScript(jsEngine, MAP_TEXTURE_SCRIPT)); + // Load configuration file + configScript = readScript(jsEngine, CONFIG_SCRIPT); + maxscore = (int) jsEngine.get("maxscore"); + System.out.println("MAXSCORE: " + maxscore); // print to command line the maxscore + + //Initialize Orbit Camera orbitCamera = new OrbitCameraController(cameraNode, player.getNode(), cam); setupSkybox(eng, sm); - //Initializing actions and connecting to nodes. - SceneNode playerN = sm.getSceneNode("playerNode"); - dMoveF = new MoveForwardAction(playerN); - dMoveB = new MoveBackwardAction(playerN); - dMoveL = new MoveLeftAction(playerN); - dMoveR = new MoveRightAction(playerN); - dYawL = new YawLeftAction(playerN); - dYawR = new YawRightAction(playerN); - setupInputs(sm); - //Creating the sea /*ManualObject sea = ManualGraphics.makePlane("default.mtl", "default.png", Color.BLUE); SceneNode seaNode = sm.getRootSceneNode().createChildSceneNode("SeaNode"); @@ -264,7 +319,27 @@ protected void setupScene(Engine eng, SceneManager sm) throws IOException { groundNode.setLocalPosition(0, 0, 0); // set ground to xyz to 0 initPhysicsSystem(); createRagePhysicsWorld(); - + + //Initializing actions and connecting to nodes. + if(running == true) { + dMoveF = new MoveForwardAction(playerNode, playerPhysObj, protClient, running); + dMoveB = new MoveBackwardAction(playerNode, playerPhysObj, protClient, running); + dMoveL = new MoveLeftAction(playerNode, playerPhysObj, protClient, running); + dMoveR = new MoveRightAction(playerNode, playerPhysObj, protClient, running); + dYawL = new YawLeftAction(playerNode, playerPhysObj, protClient, running); + dYawR = new YawRightAction(playerNode, playerPhysObj, protClient, running); + setupInputs(sm); + } + + if(running == false) { + dMoveF = new MoveForwardAction(playerNode, playerPhysObj, protClient, running); + dMoveB = new MoveBackwardAction(playerNode, playerPhysObj, protClient, running); + dMoveL = new MoveLeftAction(playerNode, playerPhysObj, protClient, running); + dMoveR = new MoveRightAction(playerNode, playerPhysObj, protClient, running); + dYawL = new YawLeftAction(playerNode, playerPhysObj, protClient, running); + dYawR = new YawRightAction(playerNode, playerPhysObj, protClient, running); + setupInputs(sm); + } System.out.println("Press P to start the physics engine!"); initAudio(sm); // SOUND @@ -395,9 +470,18 @@ protected void update(Engine engine) { } // sound - hereSound.setLocation(robotNode.getWorldPosition()); - oceanSound.setLocation(earthNode.getWorldPosition()); - setEarParameters(sm); + if (soundToggle) { + hereSound.setLocation(robotNode.getWorldPosition()); + oceanSound.setLocation(earthNode.getWorldPosition()); + setEarParameters(sm); + } + + // build and set HUD + rs = (GL4RenderSystem) engine.getRenderSystem(); + elapsTimeStr = Integer.toString(Math.round(seconds)); + dispStr = "Time = " + elapsTimeStr + " P1 Score: " + Integer.toString(p1Score) + + " P2 Score: " + Integer.toString(p2Score); + rs.setHUD(dispStr, 15, 15); } @@ -408,6 +492,8 @@ public void setIsConnected(boolean b) { private void setupNetworking() { gameObjectsToRemove = new Vector(); + ghostAvatarList = new Vector(); + ghostNPCList = new Vector(); isClientConnected = false; System.out.println("Setting up networking...\n"); try { @@ -446,7 +532,8 @@ public int getNumGhosts() { } public void addGhostAvatarToGameWorld(GhostAvatar avatar) throws IOException { - if (avatar != null) { + if (avatar != null) { + System.out.println("Don't forget to increment the ghost entity name"); Entity ghostE = sm.createEntity("ghost", "dolphinHighPoly.obj"); ghostE.setPrimitive(Primitive.TRIANGLES); SceneNode ghostN = sm.getRootSceneNode(). @@ -455,14 +542,16 @@ public void addGhostAvatarToGameWorld(GhostAvatar avatar) throws IOException { ghostN.setLocalPosition(avatar.getPosition()); avatar.setNode(ghostN); avatar.setEntity(ghostE); + ghostAvatarList.add(avatar); //avatar.setPosition(node’s position... maybe redundant); } } public void addGhostNPCtoGameWorld(GhostNPC npc) throws IOException { - //Has a problem with id. Should it be an int or an UUID? Prof code has as an int. - if (npc != null) { - Entity ghostE = sm.createEntity("ghost", "dolphinHighPoly.obj"); + System.out.println("Adding GhostNPC to Game World."); + if (npc != null) { + + Entity ghostE = sm.createEntity("ghostNPC" + npc.getID(), "dolphinHighPoly.obj"); ghostE.setPrimitive(Primitive.TRIANGLES); SceneNode ghostN = sm.getRootSceneNode(). createChildSceneNode(Integer.toString(npc.getID())); @@ -478,6 +567,15 @@ public void removeGhostAvatarFromGameWorld(GhostAvatar avatar) { if(avatar != null) gameObjectsToRemove.add(avatar.getID()); } + public GhostAvatar getGhostAvatarByID(UUID ghostID) throws Exception { + for(GhostAvatar ghost: this.ghostAvatarList) { + if(ghost.getID().compareTo(ghostID) == 0) { + return ghost; + } + } + throw new Exception("Could not find the Ghost by ID"); //Should create own classes for exception later. + } + private void initPhysicsSystem() { String engine = "ray.physics.JBullet.JBulletPhysicsEngine"; float[] gravity = {0, -3f, 0}; @@ -491,12 +589,12 @@ private void createRagePhysicsWorld() { float up[] = {0,1,0}; double[] temptf; - /*System.out.println("Adding player Physics"); + System.out.println("Adding player Physics"); temptf = toDoubleArray(playerNode.getLocalTransform().toFloatArray()); playerPhysObj = physicsEngine.addBoxObject(physicsEngine.nextUID(), mass, temptf, up); //playerPhysObj.setBounciness(1.0f); playerPhysObj.setFriction(1.0f); - playerNode.setPhysicsObject(playerPhysObj);*/ + playerNode.setPhysicsObject(playerPhysObj); temptf = toDoubleArray(earthNode.getLocalTransform().toFloatArray()); earthPhysObj = physicsEngine.addSphereObject(physicsEngine.nextUID(),mass, temptf, 2.0f); @@ -558,7 +656,7 @@ public void initAudio(SceneManager sm) { System.out.println("Audio Manager failed to initialize!"); return; } - resource1 = audioMgr.createAudioResource("Cartoon Hop-SoundBible.com-553158131.wav",AudioResourceType.AUDIO_SAMPLE); + resource1 = audioMgr.createAudioResource("Civil War Drummer -SoundBible.com-700036269.wav",AudioResourceType.AUDIO_SAMPLE); resource2 = audioMgr.createAudioResource("Water Splash-SoundBible.com-800223477.wav",AudioResourceType.AUDIO_SAMPLE); hereSound = new Sound(resource1,SoundType.SOUND_EFFECT, 100, true); oceanSound = new Sound(resource2,SoundType.SOUND_EFFECT, 100, true); @@ -577,7 +675,51 @@ public void initAudio(SceneManager sm) { setEarParameters(sm); hereSound.play(); oceanSound.play(); - } + } + + public void keyPressed(KeyEvent evt) { + int keyCode = evt.getKeyCode(); + switch(keyCode) { + case KeyEvent.VK_E: + orbitCamera.setRotateLeft(true); + break; + case KeyEvent.VK_Q: + orbitCamera.setRotateRight(true); + break; + case KeyEvent.VK_SPACE: + this.doAttack(); + break; + case KeyEvent.VK_W: + this.doNWalk(); + break; + case KeyEvent.VK_O: + soundToggle = ! soundToggle; + if (soundToggle == true) + audioMgr.resumeAllSounds(); + else + audioMgr.pauseAllSounds();; + break; + } + } + + public void keyReleased(KeyEvent evt) { + int keyCode = evt.getKeyCode(); + switch(keyCode) { + case KeyEvent.VK_E: + orbitCamera.setRotateLeft(false); + break; + case KeyEvent.VK_Q: + orbitCamera.setRotateRight(false); + break; + case KeyEvent.VK_SPACE: + this.doAttack(); + break; + } + } + + public SceneNode getPlayerNode() { + return playerNode; + } } diff --git a/a3/OneSecPassed.class b/a3/OneSecPassed.class new file mode 100644 index 0000000..bec18e4 Binary files /dev/null and b/a3/OneSecPassed.class differ diff --git a/myGameEngine/MoveBackwardAction.class b/myGameEngine/MoveBackwardAction.class new file mode 100644 index 0000000..5554592 Binary files /dev/null and b/myGameEngine/MoveBackwardAction.class differ diff --git a/myGameEngine/MoveForwardAction.class b/myGameEngine/MoveForwardAction.class new file mode 100644 index 0000000..f4cecd8 Binary files /dev/null and b/myGameEngine/MoveForwardAction.class differ diff --git a/myGameEngine/MoveLeftAction.class b/myGameEngine/MoveLeftAction.class new file mode 100644 index 0000000..6ee8da0 Binary files /dev/null and b/myGameEngine/MoveLeftAction.class differ diff --git a/myGameEngine/MoveRightAction.class b/myGameEngine/MoveRightAction.class new file mode 100644 index 0000000..440b698 Binary files /dev/null and b/myGameEngine/MoveRightAction.class differ diff --git a/myGameEngine/PitchForwardAction.class b/myGameEngine/PitchForwardAction.class new file mode 100644 index 0000000..041cb1d Binary files /dev/null and b/myGameEngine/PitchForwardAction.class differ diff --git a/myGameEngine/YawLeftAction.class b/myGameEngine/YawLeftAction.class new file mode 100644 index 0000000..60e011a Binary files /dev/null and b/myGameEngine/YawLeftAction.class differ diff --git a/myGameEngine/YawRightAction.class b/myGameEngine/YawRightAction.class new file mode 100644 index 0000000..657688e Binary files /dev/null and b/myGameEngine/YawRightAction.class differ