diff --git a/ArcadeDemo.java b/ArcadeDemo.java new file mode 100644 index 0000000..b2fe632 --- /dev/null +++ b/ArcadeDemo.java @@ -0,0 +1,247 @@ +package animation; + +import java.applet.AudioClip; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Image; +import java.awt.Point; +import java.awt.Toolkit; +import java.awt.event.KeyEvent; +import java.awt.event.MouseEvent; +import java.util.ArrayList; + +/** + * Class ArcadeDemo + * This class contains demos of many of the things you might + * want to use to make an animated arcade game. + * + * Adapted from the AppletAE demo from years past. + */ + +import gameObjects.Item; +import gameObjects.Player; +import gameObjects.Room; +import gameObjects.TextBox; +import rooms.ColorRoom; +import rooms.ColorRoom1; +import rooms.CustomRoom; +import rooms.KamiRoomOne; +import rooms.MultiButtonRoom; +import rooms.MysteryDoorRoom; +import rooms.RainbowRoom; +import rooms.RoomOne; +import rooms.RoomSearch; +import rooms.RoomThree; +//import rooms.RoomThree; +import rooms.RoomTwo; +import rooms.RoomWithRandomHiddenButton; +import rooms.RoomWithStuff; +import rooms.RoomZero; +import rooms.SafeRoom; +import rooms.TimedButtonRoom; +import rooms.initialRoom; +import rooms.lightsOut; +import rooms.lightswitchRoom; + +public class ArcadeDemo extends AnimationPanel { + + // Constants + // ------------------------------------------------------- + + // Instance Variables + // ------------------------------------------------------- + private Player player; + private ArrayList rooms; + private int currentRoom; + public static TextBox textBox; + + private boolean waitMode; + private int waitBeforeNextRoomTimer; + private boolean started = false; + private int totalTime; + private int roomTime; + + // Constructor + // ------------------------------------------------------- + public ArcadeDemo() { // Enter the name and width and height. + super("Escape Room 2020", 640, 480); + player = new Player("Demo"); + rooms = new ArrayList<>(); + addRoomsToList(); + currentRoom = 0; + + waitMode = false; + waitBeforeNextRoomTimer = 0; + totalTime = 0; + roomTime = 0; + textBox = new TextBox(); + } + + public void addRoomsToList() { + rooms.add(new initialRoom()); + rooms.add(new lightsOut()); + rooms.add(new lightswitchRoom()); + rooms.add(new RainbowRoom()); + rooms.add(new TimedButtonRoom()); + rooms.add(new RoomSearch()); + rooms.add(new RoomThree()); + rooms.add(new RoomTwo()); + rooms.add(new RoomZero()); + rooms.add(new MultiButtonRoom()); + rooms.add(new RoomWithStuff()); + rooms.add(new KamiRoomOne()); + rooms.add(new CustomRoom()); // good, not easy + rooms.add(new RoomWithRandomHiddenButton()); // DIFFICULT! +// rooms.add(new ColorRoom1()); //doesn't work +// rooms.add(new ColorRoom()); //can't get to work +// rooms.add(new SafeRoom()); //Crashes +// rooms.add(new MysteryDoorRoom()); //crashes + rooms.add(new RoomOne()); + } + + // The renderFrame method is the one which is called each time a frame is drawn. + // ------------------------------------------------------- + protected Graphics renderFrame(Graphics g) { + if (started == false) { + g.drawImage(startingScreen, 0, -10, null); + if (rooms.get(currentRoom).isDone()) { + started = true; + currentRoom++; + } + } else { + + // Draw a circle that follows the mouse. + g.setColor(Color.BLACK); + g.fillOval(mouseX - 10, mouseY - 10, 20, 20); + + rooms.get(currentRoom).draw(g, this); + rooms.get(currentRoom).updateMouseCoords(mouseX, mouseY); + + if (rooms.get(currentRoom).isDone() && !waitMode) { + waitMode = true; + waitBeforeNextRoomTimer = 200; + } + if (waitMode) { + if (waitBeforeNextRoomTimer > 0) { + waitBeforeNextRoomTimer--; + g.drawImage(congrats, 0, -10, null); + } else { + textBox.closeBox(); + waitMode = false; + if (currentRoom < rooms.size() - 1) { + currentRoom++; + roomTime = 0; + } else { + textBox.openBox("You Have Escaped ALL the rooms!", false); + System.out.println("You Have Escaped ALL the rooms!"); + } + } + + } + if (!waitMode) { + textBox.draw(g, this); + player.drawInventory(g, this); + + // General Text (Draw this last to make sure it's on top.) + g.setColor(Color.BLACK); + g.drawString("CurrentRoom = " + currentRoom, 10, 12); + g.drawString("f#" + frameNumber, 150, 12); + g.drawString("Total Time: " + totalTime / 60, 500, 80); + g.drawString("Room Time: " + roomTime / 60, 500, 100); + roomTime++; + totalTime++; + } + } + return g; + + }// --end of renderFrame method-- + + // ------------------------------------------------------- + // Respond to Mouse Events + // ------------------------------------------------------- + public void mouseClicked(MouseEvent e) { + Point clickPoint = e.getPoint(); + if (textBox.shouldClose() && textBox.isOpen()) { + textBox.closeBox(); + } else { + rooms.get(currentRoom).onClick(clickPoint, player); + rooms.get(currentRoom).onClickGeneric(clickPoint, player); + } + } + + public void mouseDragged(MouseEvent e) { + Point clickPoint = e.getPoint(); + rooms.get(currentRoom).onDrag(clickPoint, player); + + } + + public void mouseReleased(MouseEvent e) { + Point clickPoint = e.getPoint(); + rooms.get(currentRoom).onMouseRelease(clickPoint, player); + + } + + // ------------------------------------------------------- + // Respond to Keyboard Events + // ------------------------------------------------------- + public void keyTyped(KeyEvent e) { + char c = e.getKeyChar(); + rooms.get(currentRoom).onKey(c, player); + } + + public void keyPressed(KeyEvent e) { + int v = e.getKeyCode(); + + } + + public void keyReleased(KeyEvent e) { + int v = e.getKeyCode(); + + } + + // ------------------------------------------------------- + // Initialize Graphics + // ------------------------------------------------------- +//----------------------------------------------------------------------- + /* + * Image section... To add a new image to the program, do three things. 1. Make + * a declaration of the Image by name ... Image imagename; 2. Actually make the + * image and store it in the same directory as the code. 3. Add a line into the + * initGraphics() function to load the file. + * //----------------------------------------------------------------------- + */ + Image ballImage; + Image starImage; + Image startingScreen; + Image congrats; + + public void initGraphics() { + Toolkit toolkit = Toolkit.getDefaultToolkit(); + + Item.loadImages(toolkit); + startingScreen = toolkit.getImage("src/items/images/escape.png"); + congrats = toolkit.getImage("src/items/images/congrats.jpg"); +// ballImage = toolkit.getImage("ball.gif"); +// starImage = toolkit.getImage("star.gif"); + } // --end of initGraphics()-- + + // ------------------------------------------------------- + // Initialize Sounds + // ------------------------------------------------------- +//----------------------------------------------------------------------- + /* + * Music section... To add music clips to the program, do four things. 1. Make a + * declaration of the AudioClip by name ... AudioClip clipname; 2. Actually + * make/get the .wav file and store it in the same directory as the code. 3. Add + * a line into the initMusic() function to load the clip. 4. Use the play(), + * stop() and loop() functions as needed in your code. + * //----------------------------------------------------------------------- + */ + AudioClip themeMusic; + AudioClip bellSound; + + public void initMusic() { + } + +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +}// --end of ArcadeDemo class-- diff --git a/anotherButton.java b/anotherButton.java new file mode 100644 index 0000000..83fe263 --- /dev/null +++ b/anotherButton.java @@ -0,0 +1,35 @@ +package items; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.image.ImageObserver; + +import gameObjects.Item; +import gameObjects.Player; + +public class anotherButton extends Item { + boolean isOn = false; + //Select Location its located at and width and height + public anotherButton(int x, int y, int width, int height) { + super("anotherButton", new Rectangle(x, y, width, height)); + } + + public boolean isOn() { + return isOn; + } + + public void reactToClick(Point p, Player player) { + isOn = !isOn; + System.out.println("anotherButton Clicked!"); + } + + public void draw(Graphics g, ImageObserver io) { + if (isOn) + g.setColor(Color.black); + else + g.setColor(new Color(238,238,238)); + g.fillRect(getRect().x, getRect().y, getRect().width, getRect().height); + } +} diff --git a/initialRoom.java b/initialRoom.java new file mode 100644 index 0000000..e1c608a --- /dev/null +++ b/initialRoom.java @@ -0,0 +1,36 @@ +package rooms; + +import java.awt.Point; + +import gameObjects.Item; +import gameObjects.Player; +import gameObjects.Room; +import items.BasicDoor; +import items.SimpleButton; +import items.anotherButton; + +public class initialRoom extends Room { + + public initialRoom() { + super(); + this.addItem(new anotherButton(380, 250, 80, 150)); + } + + public void onClick(Point p, Player player) { + for (int index = 0; index < getItems().size(); index++) { + Item i = getItems().get(index); + + if (i.getHitBox().contains(p)) { + if (((anotherButton) getItemByName("anotherButton")).isOn()) + i.reactToClick(p, player); + } else // all other objects, in this case only the button + i.reactToClick(p, player); + + } + } + + public boolean isDone() { + return ((anotherButton) getItemByName("anotherButton")).isOn(); + } + +} diff --git a/lightTile.java b/lightTile.java new file mode 100644 index 0000000..cb472ea --- /dev/null +++ b/lightTile.java @@ -0,0 +1,35 @@ +package items; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.image.ImageObserver; + +import gameObjects.Item; +import gameObjects.Player; + +public class lightTile extends Item { + boolean isOn = false; + + // Select Location its located at and width and height + public lightTile(int x, int y) { + super("lightTile", new Rectangle(x, y, 50, 50)); + } + + public boolean isOn() { + return isOn; + } + + public void reactToClick(Point p, Player player) { + isOn = !isOn; + } + + public void draw(Graphics g, ImageObserver io) { + if (isOn) + g.setColor(Color.black); + else + g.setColor(Color.yellow); + g.fillRect(getRect().x, getRect().y, getRect().width, getRect().height); + } +} \ No newline at end of file diff --git a/lightsOut.java b/lightsOut.java new file mode 100644 index 0000000..06c917c --- /dev/null +++ b/lightsOut.java @@ -0,0 +1,70 @@ +package rooms; + +import java.awt.Point; + +import gameObjects.Item; +import gameObjects.Player; +import gameObjects.Room; +import items.BasicDoor; +import items.SimpleButton; +import items.anotherButton; +import items.lightTile; + +public class lightsOut extends Room { + private boolean isDone = false; + + public lightsOut() { + super(); + for (int i = 200; i < 354; i += 51) { + this.addItem(new lightTile(i, 200 - 50)); + this.addItem(new lightTile(i, 251 - 50)); + this.addItem(new lightTile(i, 302 - 50)); + this.addItem(new lightTile(i, 353 - 50)); + } + } + + public void onClick(Point p, Player player) { + for (int index = 0; index < getItems().size(); index++) { + Item i = getItems().get(index); + + if (i.getHitBox().contains(p) && i instanceof lightTile) { + for (int k = 0; k < getItems().size(); k++) { + Item temp = getItems().get(k); + if (temp instanceof lightTile) { + if ((((Math.abs(temp.getRect().x - i.getRect().x)) == 51 + && (Math.abs(temp.getRect().y - i.getRect().y) == 0)) + || ((Math.abs(temp.getRect().y - i.getRect().y) == 51) + && (Math.abs(temp.getRect().x - i.getRect().x) == 0))) + && (((Math.abs(temp.getRect().x - i.getRect().x)) + + (Math.abs(temp.getRect().y - i.getRect().y))) != 0)) { + temp.reactToClick(p, player); + } + + } + } + } + + if (i.getHitBox().contains(p)) { + i.reactToClick(p, player); + } // all other objects, in this case only the button + } + int count = 0; + for (int index = 0; index < getItems().size(); index++) { + Item i = getItems().get(index); + if (i instanceof lightTile) { + if (((lightTile) i).isOn()) { + count++; + } + } + } + if (count == 16) { + isDone = true; + } + + } + + public boolean isDone() { + return isDone; + } + +} diff --git a/lightswitchRoom.java b/lightswitchRoom.java new file mode 100644 index 0000000..8487c53 --- /dev/null +++ b/lightswitchRoom.java @@ -0,0 +1,41 @@ +package rooms; + +import java.awt.Color; +import java.awt.Point; + +import gameObjects.Item; +import gameObjects.Player; +import gameObjects.Room; +import items.BasicDoor; +import items.SimpleButton; +import items.anotherButton; +import items.lightSwitch; + +public class lightswitchRoom extends Room { + public lightswitchRoom() { + super(); + this.addItem(new BasicDoor()); + this.addItem(new lightSwitch(50, 300, 20, 20)); + this.addItem(new anotherButton(100, 100, 10, 10)); + } + + public void onClick(Point p, Player player) { + for (int index = 0; index < getItems().size(); index++) { + Item i = getItems().get(index); + + if (i.getHitBox().contains(p)) { + if (i instanceof BasicDoor) { + if (((anotherButton) getItemByName("anotherButton")).isOn()) + i.reactToClick(p, player); + } else // all other objects, in this case only the button + i.reactToClick(p, player); + + } + } + } + + public boolean isDone() { + return ((BasicDoor) getItemByName("BasicDoor")).isOpen() + && ((anotherButton) getItemByName("anotherButton")).isOn(); + } +} \ No newline at end of file