Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a gun and made the treasure dropped by the ghost #66

Merged
merged 2 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions maze-game/Beam.java
Original file line number Diff line number Diff line change
@@ -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())
Will-Cross1 marked this conversation as resolved.
Show resolved Hide resolved
{
getWorld().removeObject(this);
}
}
}
2 changes: 1 addition & 1 deletion maze-game/End.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions maze-game/Ghost1.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Will-Cross1 marked this conversation as resolved.
Show resolved Hide resolved
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions maze-game/Ghost2.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions maze-game/Ghost3.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions maze-game/Ghost4.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/**
Expand Down
24 changes: 24 additions & 0 deletions maze-game/Ghost_buster_icon.java
Original file line number Diff line number Diff line change
@@ -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.
}
}
37 changes: 11 additions & 26 deletions maze-game/MyWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -66,8 +67,6 @@ public void act()
// add in items
addItems();

// add in treasure
addTreasure();

// start the timer, setting it to 0
timer = 0;
Expand Down Expand Up @@ -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.
Expand Down
77 changes: 76 additions & 1 deletion maze-game/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -92,6 +93,14 @@ public void act()
teleport();
}
}

if(Greenfoot.isKeyDown("4") == true)
{
if(hasZapper == true)
{
zap();
}
}

if (useSpeedPotion == true)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion maze-game/Treasure.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
1 change: 1 addition & 0 deletions maze-game/Wall1.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public class Wall1 extends Actor

public void act()
{

}
}
24 changes: 24 additions & 0 deletions maze-game/Zapper.java
Original file line number Diff line number Diff line change
@@ -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.
}
}
Binary file added maze-game/images/beam.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added maze-game/images/ghostBusters.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added maze-game/images/ghostZapper2000.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading