diff --git a/maze-game/Beam.java b/maze-game/Beam.java new file mode 100644 index 0000000..eada6dc --- /dev/null +++ b/maze-game/Beam.java @@ -0,0 +1,38 @@ +import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) + +/** + * Write a description of class Beam here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class Beam extends Actor +{ + private int direction, speed; + + public Beam(int dir) + { + GreenfootImage beam = getImage(); + beam.scale(15, 15); + + direction = dir; + speed = 15; + } + /** + * Act - do whatever the Beam wants to do. This method is called whenever + * the 'Act' or 'Run' button gets pressed in the environment. + */ + public void act() + { + setRotation(direction); + move(speed); + if (isTouching(Wall1.class)) + { + getWorld().removeObject(this); + } + else if (isAtEdge()) + { + getWorld().removeObject(this); + } + } +} diff --git a/maze-game/End.java b/maze-game/End.java index bdba7d5..85b388e 100644 --- a/maze-game/End.java +++ b/maze-game/End.java @@ -28,7 +28,7 @@ private void score_treasure() { Actor Treasure; Treasure = getOneIntersectingObject(Treasure.class); - MyWorld.score += 300; + MyWorld.score += 500; World world; world = getWorld(); world.removeObject(Treasure); diff --git a/maze-game/Ghost1.java b/maze-game/Ghost1.java index 995e5c0..715901b 100644 --- a/maze-game/Ghost1.java +++ b/maze-game/Ghost1.java @@ -38,6 +38,13 @@ public void act() { move(); } + if (isTouching(Beam.class)) + { + getWorld().addObject(new Treasure(), getX(), getY()); + getWorld().removeObject(this); + Greenfoot.playSound("ghost_gone.mp3"); + MyWorld.score += 200; + } } /** diff --git a/maze-game/Ghost2.java b/maze-game/Ghost2.java index cb5097f..27e292d 100644 --- a/maze-game/Ghost2.java +++ b/maze-game/Ghost2.java @@ -38,6 +38,13 @@ public void act() { move(); } + if (isTouching(Beam.class)) + { + getWorld().addObject(new Treasure(), getX(), getY()); + getWorld().removeObject(this); + Greenfoot.playSound("ghost_gone.mp3"); + MyWorld.score += 200; + } } /** diff --git a/maze-game/Ghost3.java b/maze-game/Ghost3.java index fcf4624..69e926d 100644 --- a/maze-game/Ghost3.java +++ b/maze-game/Ghost3.java @@ -38,6 +38,13 @@ public void act() { move(); } + if (isTouching(Beam.class)) + { + getWorld().addObject(new Treasure(), getX(), getY()); + getWorld().removeObject(this); + Greenfoot.playSound("ghost_gone.mp3"); + MyWorld.score += 200; + } } /** diff --git a/maze-game/Ghost4.java b/maze-game/Ghost4.java index 4bde7b0..2537c7a 100644 --- a/maze-game/Ghost4.java +++ b/maze-game/Ghost4.java @@ -38,6 +38,13 @@ public void act() { move(); } + if (isTouching(Beam.class)) + { + getWorld().addObject(new Treasure(), getX(), getY()); + getWorld().removeObject(this); + Greenfoot.playSound("ghost_gone.mp3"); + MyWorld.score += 200; + } } /** diff --git a/maze-game/Ghost_buster_icon.java b/maze-game/Ghost_buster_icon.java new file mode 100644 index 0000000..37f7990 --- /dev/null +++ b/maze-game/Ghost_buster_icon.java @@ -0,0 +1,24 @@ +import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) + +/** + * Write a description of class ghost_buster_icon here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class Ghost_buster_icon extends Actor +{ + public Ghost_buster_icon() //constructor to resize ghost_buster_icon to be a better fit for the inventory + { + GreenfootImage zap = getImage(); + zap.scale(100, 100); + } + /** + * Act - do whatever the ghost_buster_icon wants to do. This method is called whenever + * the 'Act' or 'Run' button gets pressed in the environment. + */ + public void act() + { + // Add your action code here. + } +} diff --git a/maze-game/MyWorld.java b/maze-game/MyWorld.java index c37e938..e99f465 100644 --- a/maze-game/MyWorld.java +++ b/maze-game/MyWorld.java @@ -50,6 +50,7 @@ public void act() Player.hasWallBreaker = false; Player.freeze = false; Player.hasTeleport = false; + Player.hasZapper = false; stop = false; Player.hasWallBreaker = false; Player.hasSpeedPotion = false; @@ -66,8 +67,6 @@ public void act() // add in items addItems(); - // add in treasure - addTreasure(); // start the timer, setting it to 0 timer = 0; @@ -338,43 +337,29 @@ private void addItems() Collections.sort(ex_list); ex = ex_list.toArray(new Integer[ex_list.size()]); int spawn_tele = getRandomWithExclusion(rnd, 1, 12, ex); + ex = null; + ex_list.add(spawn_tele); + + Collections.sort(ex_list); + ex = ex_list.toArray(new Integer[ex_list.size()]); + int spawn_gun = getRandomWithExclusion(rnd, 1, 12, ex); + ex = null; + ex_list.add(spawn_gun); int[] result1 = decodeNumber(spawn_breaker); int[] result2 = decodeNumber(spawn_time); int[] result3 = decodeNumber(spawn_speed); int[] result4 = decodeNumber(spawn_tele); + int[] result5 = decodeNumber(spawn_gun); addObject(new WallBreaker(), result1[0], result1[1]); addObject(new TimePotion(), result2[0], result2[1]); addObject(new SpeedPotion(), result3[0], result3[1]); addObject(new Teleport(), result4[0], result4[1]); + addObject(new Zapper(), result5[0], result5[1]); } - /** - * adds in treasure - * it spawns randomly in one of three locations - * then can be moved around by the player - * with the goal of moving it to the end for 300 points - */ - private void addTreasure() - { - Treasure treasure = new Treasure(); - - // the wall breaker will spawn at one of the selected spawn points, at random - int treasure_spawn = (Greenfoot.getRandomNumber(2)); - - if (treasure_spawn == 0) - { - addObject(treasure, 475, 175); - } - - if (treasure_spawn == 1) - { - addObject(treasure, 340, 575); - } - } - /** * Prepare the world for the start of the program. * That is: create the initial objects and add them to the world. diff --git a/maze-game/Player.java b/maze-game/Player.java index 15cdd77..96eee24 100644 --- a/maze-game/Player.java +++ b/maze-game/Player.java @@ -9,6 +9,7 @@ public class Player extends Actor public static boolean hasWallBreaker = false; public static boolean freeze = false; public static boolean hasTeleport = false; + public static boolean hasZapper = false; private MyWorld myworld; // to clear confusion: // - hasSpeedPotion is true when the player picks up the speed potion @@ -92,6 +93,14 @@ public void act() teleport(); } } + + if(Greenfoot.isKeyDown("4") == true) + { + if(hasZapper == true) + { + zap(); + } + } if (useSpeedPotion == true) { @@ -209,6 +218,14 @@ public void act() { collectSpeedPotion(); } + + /** + * if touching a ghost zapper, call the collectZapper function + */ + if (isTouching(Zapper.class)) + { + collectZapper(); + } /** * if is touching a breakable wall, call touchingBreakable function @@ -254,6 +271,25 @@ private void collectWallBreaker() Breaker_icon breaker = new Breaker_icon(); world.addObject(breaker,1100,900); } + + /** + * if player is touching Zapper, collect it, then delete the Zapper object + */ + private void collectZapper() + { + MyWorld.score += 10; + hasZapper = true; + Actor Zapper; + Zapper = getOneIntersectingObject(Zapper.class); + World world; + world = getWorld(); + world.removeObject(Zapper); + + Ghost_buster_icon busters = new Ghost_buster_icon(); + world.addObject(busters,350,900); + + Greenfoot.playSound("ghost_busters.mp3"); + } /** * teleport functionality @@ -315,6 +351,45 @@ private void collectSpeedPotion() world.addObject(speed,150,900); } + /** + * when 4 is pressed and they have the ghost zapper, it fires a beam to destroy the ghosts + */ + private void zap() + { + if(Greenfoot.isKeyDown("up") == true) + { + hasZapper = false; + getWorld().removeObjects(getWorld().getObjects(Ghost_buster_icon.class)); + Greenfoot.playSound("zap.mp3"); + + getWorld().addObject(new Beam(-90), getX(), getY()); + } + if(Greenfoot.isKeyDown("down") == true) + { + hasZapper = false; + getWorld().removeObjects(getWorld().getObjects(Ghost_buster_icon.class)); + Greenfoot.playSound("zap.mp3"); + + getWorld().addObject(new Beam(90), getX(), getY()); + } + if(Greenfoot.isKeyDown("left") == true) + { + hasZapper = false; + getWorld().removeObjects(getWorld().getObjects(Ghost_buster_icon.class)); + Greenfoot.playSound("zap.mp3"); + + getWorld().addObject(new Beam(180), getX(), getY()); + } + if(Greenfoot.isKeyDown("right") == true) + { + hasZapper = false; + getWorld().removeObjects(getWorld().getObjects(Ghost_buster_icon.class)); + Greenfoot.playSound("zap.mp3"); + + getWorld().addObject(new Beam(0), getX(), getY()); + } + } + /** * what happens when speedPotion is used */ @@ -367,7 +442,7 @@ private void endGame() Greenfoot.playSound("victory.mp3"); MyWorld.startTimer = false; - MyWorld.score += 100; + MyWorld.score += 400; if (MyWorld.secondsTimer < 30) //these are meant to stack { diff --git a/maze-game/Treasure.java b/maze-game/Treasure.java index 1f452c3..8f8f8f6 100644 --- a/maze-game/Treasure.java +++ b/maze-game/Treasure.java @@ -12,7 +12,7 @@ public class Treasure extends Actor { /** - * constructor to resize treasure to be slightly bigger than the maze wall to make moveing it not impossible + * constructor to resize treasure to be small so manovering around the maze isn't impossible */ public Treasure() { diff --git a/maze-game/Wall1.java b/maze-game/Wall1.java index 58b94df..5b67748 100644 --- a/maze-game/Wall1.java +++ b/maze-game/Wall1.java @@ -13,5 +13,6 @@ public class Wall1 extends Actor public void act() { + } } diff --git a/maze-game/Zapper.java b/maze-game/Zapper.java new file mode 100644 index 0000000..6ab9ada --- /dev/null +++ b/maze-game/Zapper.java @@ -0,0 +1,24 @@ +import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) + +/** + * Write a description of class Zapper here. + * + * @author (your name) + * @version (a version number or a date) + */ +public class Zapper extends Actor +{ + public Zapper() //constructor to resize Teleport icon to be a better fit for the maze + { + GreenfootImage zap = getImage(); + zap.scale(50, 50); + } + /** + * Act - do whatever the Zapper wants to do. This method is called whenever + * the 'Act' or 'Run' button gets pressed in the environment. + */ + public void act() + { + // Add your action code here. + } +} diff --git a/maze-game/images/beam.jpeg b/maze-game/images/beam.jpeg new file mode 100644 index 0000000..048f96f Binary files /dev/null and b/maze-game/images/beam.jpeg differ diff --git a/maze-game/images/ghostBusters.png b/maze-game/images/ghostBusters.png new file mode 100644 index 0000000..023bf0e Binary files /dev/null and b/maze-game/images/ghostBusters.png differ diff --git a/maze-game/images/ghostZapper2000.jpeg b/maze-game/images/ghostZapper2000.jpeg new file mode 100644 index 0000000..7f45c88 Binary files /dev/null and b/maze-game/images/ghostZapper2000.jpeg differ diff --git a/maze-game/project.greenfoot b/maze-game/project.greenfoot index 19e3bdb..f6dfa1f 100644 --- a/maze-game/project.greenfoot +++ b/maze-game/project.greenfoot @@ -1,5 +1,6 @@ #Greenfoot project file class.Again.image=button-green.png +class.Beam.image=beam.jpeg class.Breakable.image=crackedWall.png class.Breaker_icon.image=wall_breaker.png class.End.image=wet-blue.jpg @@ -7,6 +8,7 @@ class.Ghost1.image=ghost1.png class.Ghost2.image=ghost1.png class.Ghost3.image=ghost1.png class.Ghost4.image=ghost1.png +class.Ghost_buster_icon.image=ghostBusters.png class.Intro.image=Intro.png class.Moveable.image=bomb.png class.MyWorld.image=greyBackground.png @@ -24,6 +26,7 @@ class.Treasure.image=treasure_image.jpeg class.Trophy.image=trophy_image.jpeg class.Wall1.image=newWall.png class.WallBreaker.image=wall_breaker.png +class.Zapper.image=ghostZapper2000.jpeg dependency1.from=MyWorld dependency1.to=Intro dependency1.type=UsesDependency @@ -31,7 +34,7 @@ dependency10.from=MyWorld dependency10.to=Teleport dependency10.type=UsesDependency dependency11.from=MyWorld -dependency11.to=Treasure +dependency11.to=Zapper dependency11.type=UsesDependency dependency12.from=MyWorld dependency12.to=Breakable @@ -54,102 +57,129 @@ dependency17.type=UsesDependency dependency18.from=TimeFilter dependency18.to=MyWorld dependency18.type=UsesDependency -dependency19.from=Player -dependency19.to=MyWorld +dependency19.from=Beam +dependency19.to=Wall1 dependency19.type=UsesDependency dependency2.from=MyWorld dependency2.to=Player dependency2.type=UsesDependency dependency20.from=Player -dependency20.to=TimeFilter +dependency20.to=MyWorld dependency20.type=UsesDependency dependency21.from=Player -dependency21.to=Breaker_icon +dependency21.to=TimeFilter dependency21.type=UsesDependency dependency22.from=Player -dependency22.to=Tele_option_3 +dependency22.to=Breaker_icon dependency22.type=UsesDependency dependency23.from=Player -dependency23.to=Time_option_1 +dependency23.to=Ghost_buster_icon dependency23.type=UsesDependency dependency24.from=Player -dependency24.to=SpeedPotion_option_1 +dependency24.to=Tele_option_3 dependency24.type=UsesDependency dependency25.from=Player -dependency25.to=Again +dependency25.to=Time_option_1 dependency25.type=UsesDependency dependency26.from=Player -dependency26.to=Quit +dependency26.to=SpeedPotion_option_1 dependency26.type=UsesDependency dependency27.from=Player -dependency27.to=Trophy +dependency27.to=Beam dependency27.type=UsesDependency dependency28.from=Player -dependency28.to=Wall1 +dependency28.to=Again dependency28.type=UsesDependency dependency29.from=Player -dependency29.to=Treasure +dependency29.to=Quit dependency29.type=UsesDependency dependency3.from=MyWorld dependency3.to=Ghost1 dependency3.type=UsesDependency dependency30.from=Player -dependency30.to=End +dependency30.to=Trophy dependency30.type=UsesDependency dependency31.from=Player -dependency31.to=Ghost1 +dependency31.to=Wall1 dependency31.type=UsesDependency dependency32.from=Player -dependency32.to=Ghost2 +dependency32.to=Treasure dependency32.type=UsesDependency dependency33.from=Player -dependency33.to=Ghost3 +dependency33.to=End dependency33.type=UsesDependency dependency34.from=Player -dependency34.to=Ghost4 +dependency34.to=Ghost1 dependency34.type=UsesDependency dependency35.from=Player -dependency35.to=WallBreaker +dependency35.to=Ghost2 dependency35.type=UsesDependency dependency36.from=Player -dependency36.to=TimePotion +dependency36.to=Ghost3 dependency36.type=UsesDependency dependency37.from=Player -dependency37.to=Teleport +dependency37.to=Ghost4 dependency37.type=UsesDependency dependency38.from=Player -dependency38.to=SpeedPotion +dependency38.to=WallBreaker dependency38.type=UsesDependency dependency39.from=Player -dependency39.to=Breakable +dependency39.to=TimePotion dependency39.type=UsesDependency dependency4.from=MyWorld dependency4.to=Ghost2 dependency4.type=UsesDependency dependency40.from=Player -dependency40.to=Puzzel_world_1_tp +dependency40.to=Teleport dependency40.type=UsesDependency -dependency41.from=Ghost4 -dependency41.to=MyWorld +dependency41.from=Player +dependency41.to=SpeedPotion dependency41.type=UsesDependency -dependency42.from=Ghost3 -dependency42.to=MyWorld +dependency42.from=Player +dependency42.to=Zapper dependency42.type=UsesDependency -dependency43.from=Ghost2 -dependency43.to=MyWorld +dependency43.from=Player +dependency43.to=Breakable dependency43.type=UsesDependency -dependency44.from=Ghost1 -dependency44.to=MyWorld +dependency44.from=Player +dependency44.to=Puzzel_world_1_tp dependency44.type=UsesDependency -dependency45.from=End -dependency45.to=Treasure +dependency45.from=Ghost4 +dependency45.to=MyWorld dependency45.type=UsesDependency -dependency46.from=End -dependency46.to=MyWorld +dependency46.from=Ghost4 +dependency46.to=Beam dependency46.type=UsesDependency +dependency47.from=Ghost3 +dependency47.to=MyWorld +dependency47.type=UsesDependency +dependency48.from=Ghost3 +dependency48.to=Beam +dependency48.type=UsesDependency +dependency49.from=Ghost2 +dependency49.to=MyWorld +dependency49.type=UsesDependency dependency5.from=MyWorld dependency5.to=Ghost3 dependency5.type=UsesDependency +dependency50.from=Ghost2 +dependency50.to=Beam +dependency50.type=UsesDependency +dependency51.from=Ghost1 +dependency51.to=Treasure +dependency51.type=UsesDependency +dependency52.from=Ghost1 +dependency52.to=MyWorld +dependency52.type=UsesDependency +dependency53.from=Ghost1 +dependency53.to=Beam +dependency53.type=UsesDependency +dependency54.from=End +dependency54.to=Treasure +dependency54.type=UsesDependency +dependency55.from=End +dependency55.to=MyWorld +dependency55.type=UsesDependency dependency6.from=MyWorld dependency6.to=Ghost4 dependency6.type=UsesDependency @@ -162,13 +192,13 @@ dependency8.type=UsesDependency dependency9.from=MyWorld dependency9.to=SpeedPotion dependency9.type=UsesDependency -editor.fx.0.height=838 -editor.fx.0.width=1550 -editor.fx.0.x=-7 -editor.fx.0.y=-7 -height=838 -package.numDependencies=46 -package.numTargets=26 +editor.fx.0.height=1055 +editor.fx.0.width=990 +editor.fx.0.x=2442 +editor.fx.0.y=25 +height=864 +package.numDependencies=55 +package.numTargets=31 project.charset=UTF-8 publish.hasSource=false publish.locked=true @@ -179,7 +209,7 @@ publish.title= publish.url= readme.height=60 readme.name=@README -readme.width=49 +readme.width=48 readme.x=10 readme.y=10 simulation.speed=50 @@ -191,70 +221,70 @@ target1.width=120 target1.x=0 target1.y=0 target10.height=70 -target10.name=TimePotion +target10.name=Beam target10.showInterface=false target10.type=ClassTarget target10.width=120 target10.x=0 target10.y=0 target11.height=70 -target11.name=Puzzel_world_1_tp +target11.name=TimePotion target11.showInterface=false target11.type=ClassTarget target11.width=120 target11.x=0 target11.y=0 target12.height=70 -target12.name=Time_option_1 +target12.name=Puzzel_world_1_tp target12.showInterface=false target12.type=ClassTarget target12.width=120 target12.x=0 target12.y=0 target13.height=70 -target13.name=MyWorld +target13.name=Ghost_buster_icon target13.showInterface=false target13.type=ClassTarget -target13.width=120 +target13.width=160 target13.x=0 target13.y=0 target14.height=70 -target14.name=Player +target14.name=Time_option_1 target14.showInterface=false target14.type=ClassTarget target14.width=120 target14.x=0 target14.y=0 target15.height=70 -target15.name=WallBreaker +target15.name=MyWorld target15.showInterface=false target15.type=ClassTarget target15.width=120 target15.x=0 target15.y=0 target16.height=70 -target16.name=Moveable +target16.name=Break_option_1 target16.showInterface=false target16.type=ClassTarget target16.width=120 target16.x=0 target16.y=0 target17.height=70 -target17.name=Breakable +target17.name=Player target17.showInterface=false target17.type=ClassTarget target17.width=120 target17.x=0 target17.y=0 target18.height=70 -target18.name=Ghost4 +target18.name=WallBreaker target18.showInterface=false target18.type=ClassTarget target18.width=120 target18.x=0 target18.y=0 target19.height=70 -target19.name=Wall1 +target19.name=Zapper target19.showInterface=false target19.type=ClassTarget target19.width=120 @@ -268,54 +298,75 @@ target2.width=120 target2.x=0 target2.y=0 target20.height=70 -target20.name=Ghost3 +target20.name=Breakable target20.showInterface=false target20.type=ClassTarget target20.width=120 target20.x=0 target20.y=0 target21.height=70 -target21.name=Intro +target21.name=Wall1 target21.showInterface=false target21.type=ClassTarget target21.width=120 target21.x=0 target21.y=0 target22.height=70 -target22.name=Ghost2 +target22.name=Ghost4 target22.showInterface=false target22.type=ClassTarget target22.width=120 target22.x=0 target22.y=0 target23.height=70 -target23.name=Ghost1 +target23.name=Ghost3 target23.showInterface=false target23.type=ClassTarget target23.width=120 target23.x=0 target23.y=0 target24.height=70 -target24.name=SpeedPotion +target24.name=Intro target24.showInterface=false target24.type=ClassTarget target24.width=120 target24.x=0 target24.y=0 target25.height=70 -target25.name=End +target25.name=Ghost2 target25.showInterface=false target25.type=ClassTarget target25.width=120 target25.x=0 target25.y=0 target26.height=70 -target26.name=Breaker_icon +target26.name=Ghost1 target26.showInterface=false target26.type=ClassTarget target26.width=120 target26.x=0 target26.y=0 +target27.height=70 +target27.name=SpeedPotion +target27.showInterface=false +target27.type=ClassTarget +target27.width=120 +target27.x=0 +target27.y=0 +target28.height=70 +target28.name=End +target28.showInterface=false +target28.type=ClassTarget +target28.width=120 +target28.x=0 +target28.y=0 +target29.height=70 +target29.name=Wall3 +target29.showInterface=false +target29.type=ClassTarget +target29.width=120 +target29.x=0 +target29.y=0 target3.height=70 target3.name=SpeedPotion_option_1 target3.showInterface=false @@ -323,6 +374,20 @@ target3.type=ClassTarget target3.width=140 target3.x=0 target3.y=0 +target30.height=70 +target30.name=Breaker_icon +target30.showInterface=false +target30.type=ClassTarget +target30.width=120 +target30.x=0 +target30.y=0 +target31.height=70 +target31.name=Wall2 +target31.showInterface=false +target31.type=ClassTarget +target31.width=120 +target31.x=0 +target31.y=0 target4.height=70 target4.name=Again target4.showInterface=false @@ -366,7 +431,7 @@ target9.width=120 target9.x=0 target9.y=0 version=3.0.0 -width=1550 +width=1456 world.lastInstantiated=MyWorld -xPosition=0 -yPosition=0 +xPosition=184 +yPosition=38 diff --git a/maze-game/sounds/ghost_busters.mp3 b/maze-game/sounds/ghost_busters.mp3 new file mode 100644 index 0000000..f662851 Binary files /dev/null and b/maze-game/sounds/ghost_busters.mp3 differ diff --git a/maze-game/sounds/ghost_gone.mp3 b/maze-game/sounds/ghost_gone.mp3 new file mode 100644 index 0000000..48fad2c Binary files /dev/null and b/maze-game/sounds/ghost_gone.mp3 differ diff --git a/maze-game/sounds/zap.mp3 b/maze-game/sounds/zap.mp3 new file mode 100644 index 0000000..d860246 Binary files /dev/null and b/maze-game/sounds/zap.mp3 differ