Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Binary file added Bullet.class
Binary file not shown.
12 changes: 12 additions & 0 deletions Bullet.ctxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#BlueJ class context
comment0.target=Bullet
comment0.text=\r\n\ Write\ a\ description\ of\ class\ Bullet\ here.\r\n\ \r\n\ @author\ (your\ name)\ \r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n
comment1.params=direction\ character\ damage
comment1.target=Bullet(boolean,\ boolean,\ int)
comment2.params=
comment2.target=void\ act()
comment3.params=
comment3.target=void\ animateBook()
comment4.params=
comment4.target=void\ initAnimationSprites()
numComments=5
91 changes: 91 additions & 0 deletions Bullet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
* Write a description of class Bullet here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Bullet extends Actor
{
/**
* Act - do whatever the Bullet wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public boolean left;
public boolean fighter;
public int velocity = 20;
public int damage;
public boolean dodged;
private int animCounter = 0;
private int ground = 520;
private double gravity = 2.0;
private double gravity_velocity = 0;
GreenfootImage[] book = new GreenfootImage[15];
GreenfootImage fire = new GreenfootImage("fire.png");

public Bullet(boolean direction, boolean character, int damage) {
left = direction;
fighter = character;
this.damage = damage;
initAnimationSprites();

/*
GreenfootImage image = new GreenfootImage(50, 20);
image.setColor(Color.RED);
image.fillRect(0, 0, 50, 20);
setImage(image)*/
}

public void act()
{
if (left) {
setLocation(getX() - 14, getY()-25);
if (getY() < ground) {
gravity_velocity += gravity;
setLocation(getX(), (int)(getY() + gravity_velocity));
}
if (getY() > ground) {
setLocation(getX(), ground);
}
}
else {
setLocation(getX() + 14, getY()-25);
if (getY() < ground) {
gravity_velocity += gravity;
setLocation(getX(), (int)(getY() + gravity_velocity));
}
if (getY() > ground) {
setLocation(getX(), ground);
}
}
if (fighter && !getObjectsInRange(50, Enemy.class).isEmpty() && !dodged) {
Enemy enemy = getObjectsInRange(50, Enemy.class).get(0);
enemy.hp -= damage / 2; // bullet should do half damage of punching
setImage(fire);
getWorld().removeObject(this);
}
else if (!fighter && !getObjectsInRange(50, Fighter.class).isEmpty() && !dodged) {
Fighter fighter = getObjectsInRange(50, Fighter.class).get(0);
fighter.hp -= damage / 2;
setImage(fire);
getWorld().removeObject(this);
}
else if (getX() == 0 || getX() == 1279) { // for some reason doesn't work when it's 1280
getWorld().removeObject(this);
}
else if(getY() > ground){
getWorld().removeObject(this);
}
animateBook();
}
public void animateBook(){
setImage(book[animCounter++%15]);
}
public void initAnimationSprites(){
for(int i = 1; i < 16; i++){
String filename = "b" + i + ".png";
book[i-1] = new GreenfootImage(filename);
}
}
}
Binary file added Button.class
Binary file not shown.
8 changes: 8 additions & 0 deletions Button.ctxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#BlueJ class context
comment0.target=Button
comment0.text=\r\n\ Write\ a\ description\ of\ class\ Button\ here.\r\n\ \r\n\ @author\ (your\ name)\ \r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n
comment1.params=x1\ x2\ y1\ y2
comment1.target=Button(int,\ int,\ int,\ int)
comment2.params=
comment2.target=boolean\ hovered()
numComments=3
34 changes: 34 additions & 0 deletions Button.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
* Write a description of class Button here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Button extends Actor
{
/**
* Act - do whatever the Button wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private int x1;
private int x2;
private int y1;
private int y2;
public Button(int x1, int x2, int y1, int y2) {
this.x1 = x1;
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
}
public boolean hovered() {
MouseInfo mouse = Greenfoot.getMouseInfo();
if (mouse.getX() >= x1 && mouse.getX() <= x2) {
if (mouse.getY() >= y1 && mouse.getY() <= y2) {
return true;
}
}
return false;
}
}
Binary file added Character.class
Binary file not shown.
12 changes: 12 additions & 0 deletions Character.ctxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#BlueJ class context
comment0.target=Character
comment0.text=\r\n\ Write\ a\ description\ of\ class\ Character\ here.\r\n\ \r\n\ @author\ (your\ name)\ \r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n
comment1.params=
comment1.target=void\ act()
comment2.params=isFighter
comment2.target=void\ fall(boolean)
comment3.params=
comment3.target=void\ jump()
comment4.params=
comment4.target=void\ debugHP()
numComments=5
51 changes: 45 additions & 6 deletions Character.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,58 @@ public class Character extends Actor
* Act - do whatever the Character wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public String left_file = "";
public String right_file = "";
public String jump_file = "";
public int velocity;
public double gravity = 2.0;
public double gravity_velocity = 0;
public double initial_jump_velocity = -30.0;
public int ground = 520;
public int jump_random = 1000;
public int[] enemy_stats_location = {100, 100};
public int maxhp;
public int hp;
public double recoil_acceleration = 3.0;
public double initial_recoil_velocity = 30.0;
public double recoil_velocity = 0.0;
public boolean recoil = false;
public int delaycounter;
public int damage;
public String name;
public boolean attacked = false;
public void act()
{
// Add your action code here.

}
public void fall(boolean isFighter) {
// vertical acceleration
if (getY() < ground) {
gravity_velocity += gravity;
setLocation(getX(), (int)(getY() + gravity_velocity));
}
if (getY() > ground) {
setLocation(getX(), ground);
}
// recoil acceleration
if (recoil_velocity < 0) {
recoil_velocity = 0;
recoil = false;
attacked = false;
}
if (recoil && isFighter) {
Enemy enemy = getWorld().getObjects(Enemy.class).get(0);
recoil_velocity -= recoil_acceleration;
if (enemy.getX() > getX()) {
setLocation((int)(getX() - recoil_velocity), getY());
}
else {
setLocation((int)(getX() + recoil_velocity), getY());
}
}
}
public void jump() {
if (getY() == ground) {
gravity_velocity = initial_jump_velocity;
setLocation(getX(), (int)(getY() + gravity_velocity));
}
}
public void debugHP() {
System.out.println(hp);
}
}
Binary file added Countdown.class
Binary file not shown.
9 changes: 9 additions & 0 deletions Countdown.ctxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#BlueJ class context
comment0.target=Countdown
comment0.text=\r\n\ Write\ a\ description\ of\ class\ Countdown\ here.\r\n\ \r\n\ @author\ (your\ name)\ \r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n
comment1.params=time\ type
comment1.target=Countdown(int,\ java.lang.String)
comment1.text=\r\n\ Constructor\ for\ objects\ of\ class\ Countdown\r\n
comment2.params=
comment2.target=void\ act()
numComments=3
29 changes: 29 additions & 0 deletions Countdown.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import greenfoot.Actor;

/**
* Write a description of class Countdown here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Countdown extends Actor
{
// instance variables - replace the example below with your own
public int time;
public String type;
/**
* Constructor for objects of class Countdown
*/
public Countdown(int time, String type)
{
this.time = time;
this.type = type;
}
public void act() {
if (time <= 0) {
getWorld().removeObject(this);
}
time--;
System.out.println("cooldown");
}
}
Binary file added DelayCounter.class
Binary file not shown.
9 changes: 9 additions & 0 deletions DelayCounter.ctxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#BlueJ class context
comment0.target=DelayCounter
comment0.text=\r\n\ Write\ a\ description\ of\ class\ DelayCounter\ here.\r\n\ \r\n\ @author\ (your\ name)\ \r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n
comment1.params=target
comment1.target=DelayCounter(int)
comment1.text=\r\n\ Constructor\ for\ objects\ of\ class\ DelayCounter\r\n
comment2.params=
comment2.target=boolean\ counter()
numComments=3
31 changes: 31 additions & 0 deletions DelayCounter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Write a description of class DelayCounter here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class DelayCounter
{
// instance variables - replace the example below with your own
private int target;
private int count;
/**
* Constructor for objects of class DelayCounter
*/
public DelayCounter(int target)
{
this.target = target;
}

public boolean counter()
{
if (count == target) {
count = 0;
return true;
}
else {
count++;
return false;
}
}
}
Binary file added Enemy.class
Binary file not shown.
14 changes: 14 additions & 0 deletions Enemy.ctxt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#BlueJ class context
comment0.target=Enemy
comment0.text=\r\n\ Write\ a\ description\ of\ class\ Enemy\ here.\r\n\ \r\n\ @author\ (your\ name)\ \r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n
comment1.params=
comment1.target=void\ act()
comment2.params=
comment2.target=void\ moveTowardsPlayer()
comment3.params=
comment3.target=void\ attack()
comment4.params=
comment4.target=void\ dodgeBullet()
comment5.params=
comment5.target=void\ shoot()
numComments=6
Loading