Skip to content

Instantly share code, notes, and snippets.

@macroxela
Created April 24, 2014 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macroxela/11273357 to your computer and use it in GitHub Desktop.
Save macroxela/11273357 to your computer and use it in GitHub Desktop.
Final project for Object Oriented course, basically a mini version of a Zelda dungeon. Includes various enemies, mid level boss and final boss. Rooms have to be accessed sequentially to unlock them.
/*
Code From DaniWeb
http://www.daniweb.com/software-development/java/threads/162294/clock.java
*/
import java.util.*;
import java.text.*;
public class Clock
{
private int hours;
private int minutes;
private int seconds;
int minutesleft, secondsleft;
//Constructor
Clock()
{
hours=0;
minutes=0;
seconds=0;
}
Clock(int h, int m, int s)
{
hours=h;
minutes=m;
seconds=s;
}
//Accessors
public void setTime(int h, int m, int s)
{
hours=h;
minutes=m;
seconds=s;
}
public int getHours()
{
return hours;
}
public int getMinutes()
{
return minutes;
}
public int getSeconds()
{
return seconds;
}
public void setHours(int h)
{
hours=h;
}
//Modifiers
public void setMinutes(int m)
{
minutes=m;
}
public void setSeconds(int s)
{
seconds=s;
}
public void printTime()
{
System.out.println(hours+ "H:" + minutes + "M:" + seconds + "S");
}
public void inputTime()
{
Scanner input=new Scanner(System.in);
System.out.println("Enter hours: ");
hours=input.nextInt();
System.out.println("Enter minutes: ");
minutes=input.nextInt();
System.out.println("Enter seconds: ");
seconds=input.nextInt();
}
public String toString()
{
String s= hours+ "H:" + minutes + "M:" + seconds + "S";
return s;
}
public void incrementSeconds(int seconds)
{
this.seconds = this.seconds+seconds;
}
public void incrementMinutes(int minutes)
{
this.minutes = this.minutes+ minutes;
}
public void incrementHours(int hours)
{
this.hours = this.hours+hours;
}
}
// this is the end of class Clock, put all new methods before this
import javax.swing.*;
import java.awt.*;
public class Driver {
public static void main(String[] args) {
DungeonPanel panel = new DungeonPanel();
JFrame frame = new JFrame("Dungeon");
frame.getContentPane().add(panel);
frame.setSize(600,600);
frame.setVisible(true);
//B: Shoot arrows
//C: Drop Bombs
//Space or Ctrl: Sword attack, stopped working after adding bombs
}
}
public class Dungeon {
Room rooms[];
Room current;
int roomscleared;
Dungeon()
{
//Room baseroom = new Room();
//Room nextRoom = new Room();
rooms = new Room[10];
rooms[0] = new Room(1);
rooms[1] = new Room(2);
rooms[2] = new Room(3);
rooms[3] = new Room(4);
rooms[4] = new Room(5);
rooms[5] = new Room(6);
rooms[6] = new Room(7);
rooms[7] = new Room(8);
rooms[8] = new Room(9);
rooms[9] = new Room(10);
current = rooms[0];
roomscleared = 0;
}
public void roomCheck()
{
//System.out.println(current.name);
//System.out.println(current.next);
if(current.cleared && current.name.equalsIgnoreCase("Entry"))
{
//System.out.println("Cleared");
current = rooms[1];
}
if(current.next.equalsIgnoreCase("up") && current.name.equalsIgnoreCase("MovingTilesRoom"))
{
current.next = "none";
current = rooms[7];
current.next = "none";
}
if(current.next.equalsIgnoreCase("up") && current.name.equalsIgnoreCase("StairRoom"))
{
current.next = "none";
current = rooms[8];
current.next = "none";
}
if(current.next.equalsIgnoreCase("left") && current.name.equalsIgnoreCase("Arena Entry 3"))
{
current.next = "none";
current = rooms[9];
current.next = "none";
}
if(/*current.cleared && */current.next.equalsIgnoreCase("left") && current.name.equalsIgnoreCase("base"))
{
//System.out.println("Cleared");
current = rooms[2];
}
if(current.next.equalsIgnoreCase("right") && current.name.equalsIgnoreCase("base"))
{
current.next = "none";
current = rooms[4];
current.next = "none";
}
if(current.next.equalsIgnoreCase("up") && current.name.equalsIgnoreCase("base"))
{
current.next = "none";
current = rooms[6];
}
if(current.next.equalsIgnoreCase("right") && current.name.equalsIgnoreCase("Arena Entry 1"))
{
current.next = "none";
current = rooms[1];
current.next = "none";
}
if(current.next.equalsIgnoreCase("up") && current.name.equalsIgnoreCase("Arena Entry 1") && rooms[3].passable)
{
current.next = "none";
current = rooms[3];
current.next = "none";
}
if(current.next.equalsIgnoreCase("down") && current.name.equalsIgnoreCase("Arena 1"))
{
current.next = "none";
current = rooms[2];
current.next = "none";
current.ent1 = false;
}
if(current.next.equalsIgnoreCase("down") && current.name.equalsIgnoreCase("Arena 2"))
{
current.next = "none";
current = rooms[4];
current.next = "none";
current.ent2 = false;
}
if(current.next.equalsIgnoreCase("left") && current.name.equalsIgnoreCase("Arena Entry 2"))
{
current.next = "none";
current = rooms[1];
current.next = "none";
}
if(current.next.equalsIgnoreCase("up") && current.name.equalsIgnoreCase("Arena Entry 2") && rooms[5].passable)
{
current.next = "none";
current = rooms[5];
current.next = "none";
}
}
}
import javax.swing.*;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import java.applet.*;
public class DungeonPanel extends JPanel implements KeyListener
{
Hero user;
Enemy en;
ImageIcon background, tri, GM, start_sq, end_sq;
LinkedList<Projectile> item = new LinkedList<Projectile>();
LinkedList<Enemy> enemies = new LinkedList<Enemy>();
LinkedList<MovableObjects> tiles = new LinkedList<MovableObjects>();
ShadowLink link;
Random ran;
Dungeon dungeon;
int cnt = 0;
int vx = 0;
int vy = 0;
boolean start, won, end;
long t1, t2, t3, t4;
DungeonPanel()
{
//background = new ImageIcon("data/deathmountaind1.png");
dungeon = new Dungeon();
background = dungeon.current.back;//new ImageIcon("data/BaseRoom.png");
tri = new ImageIcon("data/TriforceAnimated.gif");
GM = new ImageIcon("data/GameOver.gif");
start_sq = new ImageIcon("data/ZeldaLogo.gif");
end_sq = new ImageIcon("data/Explosion2.png");
user = new Hero();
ran = new Random();
//Projectile s = new Projectile(100,100,"none","IronBall");
t1 = 0;
t2 = 0;
t3 = 0;
t4 = 0;
start = true;
won = false;
end = true;
UpdateThread ut = new UpdateThread(this);
ut.start();
addKeyListener(this);
setFocusable(true);
}
public void startanimation(Graphics g)
{
if(start && t1 == 0)
t1 = System.currentTimeMillis();
if(start)
t2 = System.currentTimeMillis();
if(t2 - t1 < 1500 && start)
g.drawImage(start_sq.getImage(),0,0,getWidth(),getHeight(),this);
else
{
start = false;
t1 = 0; t2 = 0;
}
}
public void endanimation(Graphics g)
{
if(t3 == 0)
{
t3 = System.currentTimeMillis();
System.out.println("It ended");
}
System.out.println(t4 - t3);
t4 = System.currentTimeMillis();
//System.out.println(" End Vx: " + vx + " Vy: " + vy);
if(t4 - t3 > 1000)
{
end_sq = new ImageIcon("data/Explosion2.png");
//g.drawImage(end_sq.getImage(),vx,vy,70,70,this);
}
if(t4 - t3 > 1500)
{
end_sq = new ImageIcon("data/Explosion3.png");
//g.drawImage(end_sq.getImage(),vx,vy,70,70,this);
}
if(t4 - t3 > 2000)
{
end_sq = new ImageIcon("data/Explosion2.png");
//g.drawImage(end_sq.getImage(),vx,vy,70,70,this);
}
if(t4 - t3 > 2500)
{
end_sq = new ImageIcon("data/Explosion3.png");
//g.drawImage(end_sq.getImage(),vx,vy,70,70,this);
}
if(t4 - t3 > 3000)
{
end_sq = new ImageIcon("data/Explosion2.png");
//g.drawImage(end_sq.getImage(),vx,vy,70,70,this);
}
if(t4 - t3 > 3500)
{
end_sq = new ImageIcon("data/Explosion3.png");
//g.drawImage(end_sq.getImage(),vx,vy,70,70,this);
}
if(t4 - t3 > 4000)
{
end_sq = new ImageIcon("data/Explosion2.png");
//g.drawImage(end_sq.getImage(),vx,vy,70,70,this);
}
if(t4 - t3 > 4500)
{
end_sq = new ImageIcon("data/Explosion3.png");
//g.drawImage(end_sq.getImage(),vx,vy,70,70,this);
}
if(t4 - t3 > 5000)
{
end_sq = new ImageIcon("data/transparent.png");
end = false;
}
}
public void paintComponent(Graphics g)
{
g.drawImage(background.getImage(),0,0,getWidth(),getHeight(),this);
for(MovableObjects o : tiles)
{
o.draw(g, this);
}
//g.drawImage(tri.getImage(),252,209,50,50,this);
user.draw(g, this);
for(Enemy o : enemies)
{
o.draw(g, this);
}
for(Projectile o : item)
{
o.draw(g, this);
}
if(won)
{
endanimation(g);
g.drawImage(end_sq.getImage(),vx,vy,70,70,this);
g.setColor(Color.white);
g.setFont( new Font( "stupid font", Font.BOLD, 50 ) );
g.drawString("THE END", 200, 300);
g.drawImage(tri.getImage(),250,150,100,100,this);
}
if(user.over)
g.drawImage(GM.getImage(), 0, 0, getWidth(), getHeight(), this);
startanimation(g);
}
public void update()
{
if(!won)
{
if(dungeon.current.name.equalsIgnoreCase("StairRoom") && user.num == 4)
{
System.out.println(user.num);
en = new Enemy(3);
user.num = 5;
enemies.add(en);
System.out.println("Shadow Link");
System.out.println(user.num);
}
if(dungeon.current.name.equalsIgnoreCase("MovingTilesRoom") && user.num == 3)
{
MovableObjects tile = new MovableObjects("tile");
tile.x = 425;
tile.y = 356;
tile.setDirection("Horizontal");
tile.number = "first";
tiles.add(tile);
tile = new MovableObjects("tile");
tile.x = 85;
tile.y = 100;
tile.setDirection("Vertical");
tiles.add(tile);
tile = new MovableObjects("tile");
tile.x = 385;
tile.y = 250;
tile.setDirection("Horizontal");
tile.dx = 6;
tiles.add(tile);
tile = new MovableObjects("tile");
tile.x = 430;
tile.y = 100;
tile.setDirection("Vertical");
tiles.add(tile);
user.num = 4;
}
if(dungeon.rooms[6].cleared)
{
LinkedList<MovableObjects> del = new LinkedList<MovableObjects>();
for(MovableObjects o : tiles)
{
del.add(o);
}
for(MovableObjects o : del)
{
tiles.remove(o);
}
}
if(dungeon.current.name.equalsIgnoreCase("Final Arena") && dungeon.current.stage1 && dungeon.current.stage2 && !dungeon.current.stage3)
{
en = new Enemy(4);
en.x = 100;
en.y = 200;
enemies.add(en);
dungeon.current.stage3 = true;
}
if(dungeon.current.name.equalsIgnoreCase("MovingTilesRoom"))
{
for(MovableObjects o : tiles)
{
if(o.contains(user) && user.y >= 80)
{
user.passable = true;
user.dx = o.dx;
user.dy = o.dy;
o.moveAround();
user.dx = o.dx;
user.dy = o.dy;
if(user.y == 80)
{
user.dy = 0;
dungeon.current.cleared = true;
}
}
else
o.moveAround();
}
}
if(dungeon.current.name.equalsIgnoreCase("Arena 1") && (user.num == 1 || user.num == 0))
{
en = new Enemy(1);
en.x = 200;
en.y = 200;
enemies.add(en);
en = new Enemy(1);
en.x = 300;
en.y = 200;
enemies.add(en);
user.num = 2;
}
if(dungeon.current.name.equalsIgnoreCase("Arena 2") && (user.num == 0 || user.num == 1))
{
en = new Enemy(0);
en.x = 200;
en.y = 200;
enemies.add(en);
en = new Enemy(0);
en.x = 300;
en.y = 200;
enemies.add(en);
en = new Enemy(0);
en.x = 400;
en.y = 200;
enemies.add(en);
user.num = 2;
}
if(dungeon.roomscleared >= 10)
{
won = true;
t1 = 0;
t2 = 0;
}
if(dungeon.current.name.equalsIgnoreCase("base") && dungeon.roomscleared == 2 && (user.num == 2 || user.num == 1))
{
en = new Enemy(2);
en.x = 200;
en.y = 200;
enemies.add(en);
Projectile IronBall = new Projectile(en.x,en.y,"none","IronBall");
IronBall.usID = en.ID;
item.add(IronBall);
user.num = 3;
}
user.setEnemies(enemies);
boolean collided = false;
for(Enemy o : enemies)
{
for(Enemy u : enemies)
{
if(o.ID != u.ID)
{
if(o.intersects(u))
{
if(u.x - o.x < o.width && u.x - o.x > 0)
{
o.x = u.x - o.width - 10;
}
if(u.y - o.y < o.height && u.y - o.y > 0)
{
o.y = u.y - o.height - 10;
}
if(o.y - u.y < u.height && o.y - u.y > 0)
{
o.y += 10;
}
if(o.x - u.x < u.width && o.x - u.x > 0)
{
o.x += 10;
}
}
}
for(Projectile r : item)
{
if(o.name.equalsIgnoreCase("IronBallSoldier") && r.attribute.equalsIgnoreCase("IronBall") && o.ID == r.usID)
{
r.setUserPos(o.x, o.y);
}
if(o.intersects(r) && !r.attribute.equalsIgnoreCase("bomb") && !r.attribute.equalsIgnoreCase("IronBall"))
{
o.hp--;
if(r.direction.equalsIgnoreCase("right") || r.direction.equalsIgnoreCase("left"))
{
o.y -= 10;
}
if(r.direction.equalsIgnoreCase("up") || r.direction.equalsIgnoreCase("down"))
{
o.x -= 10;
}
}
}
}
if(o.intersects(user))
{
if(o.action.equalsIgnoreCase("attack") && !user.action.equalsIgnoreCase("sword") && !user.action.equalsIgnoreCase("sword slash") && !user.action.equalsIgnoreCase("sword dash"))
{
user.hp--;
if(user.hp <= 0)
{
user.alive = false;
}
}
if(user.action.equalsIgnoreCase("sword") || user.action.equalsIgnoreCase("sword slash") || user.action.equalsIgnoreCase("sword dash"))
{
if(!o.action.equalsIgnoreCase("attack"))
o.hp--;
//System.out.println("Enemy Hp: " + o.hp);
if(user.x - o.x < o.width && user.x - o.x > 0)
{
o.x = user.x - o.width - 10;
}
if(user.y - o.y < o.height && user.y - o.y > 0)
{
o.y = user.y - o.height - 10;
}
if(o.y - user.y < user.height && o.y - user.y > 0)
{
o.y += 10;
}
if(o.x - user.x < user.width && o.x - user.x > 0)
{
o.x += 10;
}
}
else
{
if(user.x - o.x < o.width && user.x - o.x > 0)
{
user.x = o.x + o.width + 10;
}
if(user.y - o.y < o.height && user.y - o.y > 0)
{
user.y = o.y + o.height + 10;
}
if(o.y - user.y < user.height && o.y - user.y > 0)
{
user.y -= 10;
}
if(o.x - user.x < user.width && o.x - user.x > 0)
{
user.x -= 10;
}
collided = true;
}
}
if(o.hp <= 0)
{
o.dead = true;
}
}
if(!collided)
{
dungeon.current.checkCollision(user);
dungeon.roomCheck();
background = dungeon.current.back;
user.update();
}
if(user.alive)
{
Enemy v;
for(Enemy o : enemies)
{
if(o.name.equalsIgnoreCase("Vaati"))
{
vx = o.x;
vy = o.y;
//System.out.println("Vx: " + vx + " Vy: " + vy);
}
}
LinkedList<Enemy> dummy = new LinkedList<Enemy>();
for(Enemy o : enemies)
{
if(!o.dead)
{
o.update(user.x, user.y);
dungeon.current.checkCollision(o);
if(o.name.equalsIgnoreCase("Vaati") && o.minions)
{
int randnum = ran.nextInt(2) + 5;
int num = ran.nextInt(10);
en = new Enemy(randnum);
en.x = vx + num + 50;
en.y = vy + num + 50;
dummy.add(en);
o.minioncnt++;
if(o.minioncnt > 4)
{
o.minions = false;
o.minioncnt = 0;
}
}
}
else
{
o.x = -50;
o.y = -50;
o.dx = 0;
o.dy = 0;
}
}
for(Enemy o : dummy)
{
enemies.add(o);
}
}
if(t1 == 0)
t1 = System.currentTimeMillis();
t2 = System.currentTimeMillis();
for(Projectile o : item)
{
o.update();
if(user.intersects(o) && (o.attribute.equalsIgnoreCase("explosion") || o.attribute.equalsIgnoreCase("IronBall")))
{
user.hp--;
if(o.attribute.equalsIgnoreCase("IronBall"))
{
if(user.y < o.y)
user.y += 150;
else
user.y -= 150;
}
if(user.hp < 0)
{
user.alive = false;
}
}
}
if(t2 - t1 > 500 && user.action.equalsIgnoreCase("sword slash"))
{
int num = 0;
if(t2 - t1 > 750)
num = 1;
if(t2 - t1 > 900)
num = 2;
if(t2 - t1 > 1050)
num = 3;
if(user.direction.equalsIgnoreCase("up"))
{
if(num == 0)
user.pic = new ImageIcon("data/LinkSwordSlashUp2.png");
if(num == 1)
{
user.pic = new ImageIcon("data/LinkSwordSlashUp3.png");
}
if(num == 2)
user.pic = new ImageIcon("data/LinkSwordSlashUp4.png");
}
if(user.direction.equalsIgnoreCase("down"))
{
if(num == 0)
user.pic = new ImageIcon("data/LinkSwordSlashDown2.png");
if(num == 1)
{
user.pic = new ImageIcon("data/LinkSwordSlashDown3.png");
}
if(num == 2)
user.pic = new ImageIcon("data/LinkSwordSlashDown4.png");
}
if(user.direction.equalsIgnoreCase("left"))
{
if(num == 0)
user.pic = new ImageIcon("data/LinkSwordSlashLeft2.png");
if(num == 1)
{
user.pic = new ImageIcon("data/LinkSwordSlashLeft3.png");
}
if(num == 2)
user.pic = new ImageIcon("data/LinkSwordSlashLeft4.png");
}
if(user.direction.equalsIgnoreCase("right"))
{
if(num == 0)
user.pic = new ImageIcon("data/LinkSwordSlashRight2.png");
if(num == 1)
{
user.pic = new ImageIcon("data/LinkSwordSlashRight3.png");
}
if(num == 2)
user.pic = new ImageIcon("data/LinkSwordSlashRight4.png");
}
/**/
if(num >= 3)
{
user.action = "none";
if(user.direction.equalsIgnoreCase("up"))
{
user.pic = new ImageIcon("data/LinkStandingUp.png");
}
if(user.direction.equalsIgnoreCase("down"))
{
user.pic = new ImageIcon("data/LinkStandingDown.png");
}
if(user.direction.equalsIgnoreCase("left"))
{
user.pic = new ImageIcon("data/LinkStandingLeft.png");
}
if(user.direction.equalsIgnoreCase("right"))
{
user.pic = new ImageIcon("data/LinkStandingRight.png");
}
user.height = 20;
user.width = 20;
t1 = 0; t2 = 0;
}
}
//////////////////////////////////////////////////////////
if(t2 - t1 > 500 && user.action.equalsIgnoreCase("sword dash"))
{
int num = 0;
if(t2 - t1 > 750)
num = 1;
if(t2 - t1 > 900)
num = 2;
if(t2 - t1 > 1050)
num = 3;
if(t2 - t1 > 1200)
num = 4;
if(user.direction.equalsIgnoreCase("up"))
{
if(num == 0)
user.pic = new ImageIcon("data/LinkDashSlashUp2.png");
if(num == 1)
{
user.pic = new ImageIcon("data/LinkDashSlashUp3.png");
user.dy = -5;
}
if(num == 2)
user.pic = new ImageIcon("data/LinkDashSlashUp4.png");
if(num == 3)
user.pic = new ImageIcon("data/LinkDashSlashUp5.png");
}
if(user.direction.equalsIgnoreCase("down"))
{
if(num == 0)
user.pic = new ImageIcon("data/LinkDashSlashDown2.png");
if(num == 1)
{
user.pic = new ImageIcon("data/LinkDashSlashDown3.png");
user.dy = 5;
}
if(num == 2)
user.pic = new ImageIcon("data/LinkDashSlashDown4.png");
if(num == 3)
user.pic = new ImageIcon("data/LinkDashSlashDown5.png");
}
if(user.direction.equalsIgnoreCase("left"))
{
if(num == 0)
user.pic = new ImageIcon("data/LinkDashSlashLeft2.png");
if(num == 1)
{
user.pic = new ImageIcon("data/LinkDashSlashLeft3.png");
user.dx = -5;
}
if(num == 2)
user.pic = new ImageIcon("data/LinkDashSlashLeft4.png");
if(num == 3)
user.pic = new ImageIcon("data/LinkDashSlashLeft5.png");
}
if(user.direction.equalsIgnoreCase("right"))
{
if(num == 0)
user.pic = new ImageIcon("data/LinkDashSlashRight2.png");
if(num == 1)
{
user.pic = new ImageIcon("data/LinkDashSlashRight3.png");
user.dx = 5;
}
if(num == 2)
user.pic = new ImageIcon("data/LinkDashSlashRight4.png");
if(num == 3)
user.pic = new ImageIcon("data/LinkDashSlashRight5.png");
}
if(num >= 4)
{
user.action = "none";
if(user.direction.equalsIgnoreCase("up"))
{
user.pic = new ImageIcon("data/LinkStandingUp.png");
}
if(user.direction.equalsIgnoreCase("down"))
{
user.pic = new ImageIcon("data/LinkStandingDown.png");
}
if(user.direction.equalsIgnoreCase("left"))
{
user.pic = new ImageIcon("data/LinkStandingLeft.png");
}
if(user.direction.equalsIgnoreCase("right"))
{
user.pic = new ImageIcon("data/LinkStandingRight.png");
}
user.height = 20;
user.width = 20;
user.dx = 0;
user.dy = 0;
t1 = 0; t2 = 0;
}
}
if((t2 - t1 > 500 && user.action.equalsIgnoreCase("sword")) || (t2 - t1 > 800 && user.action.equalsIgnoreCase("thrown")))
{
user.height = 20;
user.width = 20;
user.action = "none";
if(user.direction.equalsIgnoreCase("up"))
{
user.pic = new ImageIcon("data/LinkStandingUp.png");
}
if(user.direction.equalsIgnoreCase("down"))
{
user.pic = new ImageIcon("data/LinkStandingDown.png");
}
if(user.direction.equalsIgnoreCase("left"))
{
user.pic = new ImageIcon("data/LinkStandingLeft.png");
}
if(user.direction.equalsIgnoreCase("right"))
{
user.pic = new ImageIcon("data/LinkStandingRight.png");
}
t1 = 0; t2 = 0;
}
//System.out.println(dungeon.roomscleared);
if(dungeon.current.numdead == 2 && dungeon.current.name.equalsIgnoreCase("Arena 1"))
{
dungeon.current.numdead = 0;
dungeon.current.cleared = true;
dungeon.roomscleared++;
}
if(dungeon.current.numdead == 3 && dungeon.current.name.equalsIgnoreCase("Arena 2"))
{
dungeon.current.numdead = 0;
dungeon.current.cleared = true;
dungeon.roomscleared++;
}
LinkedList<Enemy> en = new LinkedList<Enemy>();
LinkedList<Projectile> p = new LinkedList<Projectile>();
for(Enemy o : enemies)
{
if(o.dead)
{
if(o.name.equalsIgnoreCase("Vaati"))
dungeon.roomscleared = 10;
en.add(o);
}
}
for(Projectile o : item)
{
for(Enemy u : en)
{
if(u.ID == o.usID)
p.add(o);
}
if(!o.active)
{
System.out.println("Not Active");
p.add(o);
}
}
for(Enemy o : en)
{
/*if(o.name.equalsIgnoreCase("Vaati"))
{
vx = o.x;
vy = o.y;
System.out.println("Vx: " + vx + " Vy: " + vy);
}*/
enemies.remove(o);
System.out.println("Removed");
dungeon.current.numdead++;
System.out.println("Dead: " + dungeon.current.numdead);
if(enemies.isEmpty())
System.out.println("Empty");
}
for(Projectile o : p)
{
item.remove(o);
System.out.println("Item removed");
}
repaint();
}
}
public void keyPressed(KeyEvent k)
{
int c = k.getKeyCode();
if(user.alive)
{
if(c == KeyEvent.VK_B)
{
user.action = "arrow";
if(user.direction.equalsIgnoreCase("up"))
{
user.pic = new ImageIcon("data/LinkArrowUp.png");
}
else if(user.direction.equalsIgnoreCase("left"))
{
user.pic = new ImageIcon("data/LinkArrowLeft.png");
}
else if(user.direction.equalsIgnoreCase("right"))
{
user.pic = new ImageIcon("data/LinkArrowRight.png");
}
else if(user.direction.equalsIgnoreCase("down"))
{
user.pic = new ImageIcon("data/LinkArrowDown.png");
}
}
if(c == KeyEvent.VK_CONTROL)
{
user.action = "sword dash";
if(user.direction.equalsIgnoreCase("up"))
{
user.pic = new ImageIcon("data/LinkDashSlashUp1.png");
user.height = 30;
}
if(user.direction.equalsIgnoreCase("down"))
{
user.pic = new ImageIcon("data/LinkDashSlashDown1.png");
user.height = 30;
}
if(user.direction.equalsIgnoreCase("left"))
{
user.pic = new ImageIcon("data/LinkDashSlashLeft1.png");
user.width = 30;
}
if(user.direction.equalsIgnoreCase("right"))
{
user.pic = new ImageIcon("data/LinkDashSlashRight1.png");
user.width = 30;
}
}
if(c == KeyEvent.VK_C)
{
user.action = "bomb";
if(user.direction.equalsIgnoreCase("up"))
{
user.pic = new ImageIcon("data/LinkBombUp.png");
user.height = 30;
}
if(user.direction.equalsIgnoreCase("down"))
{
user.pic = new ImageIcon("data/LinkBombDown.png");
user.height = 30;
}
if(user.direction.equalsIgnoreCase("left"))
{
user.pic = new ImageIcon("data/LinkBombLeft.png");
user.height = 30;
}
if(user.direction.equalsIgnoreCase("right"))
{
user.pic = new ImageIcon("data/LinkBombRight.png");
user.height = 30;
}
}
if(c == KeyEvent.VK_SPACE)
{
int rand = ran.nextInt(2);
if(rand == 0)
{
user.action = "sword slash";
if(user.direction.equalsIgnoreCase("up"))
{
user.pic = new ImageIcon("data/LinkSwordSlashUp1.png");
user.height = 30;
}
if(user.direction.equalsIgnoreCase("down"))
{
user.pic = new ImageIcon("data/LinkSwordSlashDown1.png");
user.height = 30;
}
if(user.direction.equalsIgnoreCase("left"))
{
user.pic = new ImageIcon("data/LinkSwordSlashLeft1.png");
user.width = 30;
}
if(user.direction.equalsIgnoreCase("right"))
{
user.pic = new ImageIcon("data/LinkSwordSlashRight1.png");
user.width = 30;
}
}
else
{
user.action = "sword";
if(user.direction.equalsIgnoreCase("up"))
{
user.pic = new ImageIcon("data/LinkSwordFowardUp2.png");
user.height = 30;
}
if(user.direction.equalsIgnoreCase("down"))
{
user.pic = new ImageIcon("data/LinkSwordFowardDown2.png");
user.height = 30;
}
if(user.direction.equalsIgnoreCase("left"))
{
user.pic = new ImageIcon("data/LinkSwordFowardLeft2.png");
user.width = 30;
}
if(user.direction.equalsIgnoreCase("right"))
{
user.pic = new ImageIcon("data/LinkSwordFowardRight2.png");
user.width = 30;
}
}
}
if(c == KeyEvent.VK_LEFT)
{
user.dx = -5;
if(!user.action.equalsIgnoreCase("arrow") && !user.action.equalsIgnoreCase("bomb"))
{
user.action = "none";
if(user.x %2 == 0)
user.pic = new ImageIcon("data/LinkLeft1.png");
else
user.pic = new ImageIcon("data/LinkLeft2.png");
user.direction = "left";
user.height = 20;
user.width = 20;
}
else if(user.action.equalsIgnoreCase("bomb"))
{
if(user.x %2 == 0)
user.pic = new ImageIcon("data/LinkBombMoveLeft1.png");
else
user.pic = new ImageIcon("data/LinkBombMoveLeft2.png");
user.direction = "left";
user.height = 30;
}
}
if(c == KeyEvent.VK_RIGHT)
{
user.dx = 5;
if(!user.action.equalsIgnoreCase("arrow") && !user.action.equalsIgnoreCase("bomb"))
{
user.action = "none";
if(user.x %2 == 0)
user.pic = new ImageIcon("data/LinkRight1.png");
else
user.pic = new ImageIcon("data/LinkRight2.png");
user.direction = "right";
user.height = 20;
user.width = 20;
}
else if(user.action.equalsIgnoreCase("bomb"))
{
if(user.x %2 == 0)
user.pic = new ImageIcon("data/LinkBombMoveRight1.png");
else
user.pic = new ImageIcon("data/LinkBombMoveRight2.png");
user.direction = "right";
user.height = 30;
}
}
if(c == KeyEvent.VK_UP)
{
user.dy = -5;
if(!user.action.equalsIgnoreCase("arrow") && !user.action.equalsIgnoreCase("bomb"))
{
user.action = "none";
if(user.y %2 == 0)
user.pic = new ImageIcon("data/LinkUp3.png");
if(user.y %2 == 1)
user.pic = new ImageIcon("data/LinkUp2.png");
user.direction = "up";
user.height = 20;
user.width = 20;
}
else if(user.action.equalsIgnoreCase("bomb"))
{
if(user.y %2 == 0)
user.pic = new ImageIcon("data/LinkBombMoveUp1.png");
else
user.pic = new ImageIcon("data/LinkBombMoveUp2.png");
user.direction = "up";
user.height = 30;
}
}
if(c == KeyEvent.VK_DOWN)
{
user.dy = 5;
if(!user.action.equalsIgnoreCase("arrow") && !user.action.equalsIgnoreCase("bomb"))
{
user.action = "none";
if(user.y %2 == 0)
user.pic = new ImageIcon("data/LinkDown1.png");
else
user.pic = new ImageIcon("data/LinkDown2.png");
user.direction = "down";
user.height = 20;
user.width = 20;
}
else if(user.action.equalsIgnoreCase("bomb"))
{
if(user.y %2 == 0)
user.pic = new ImageIcon("data/LinkBombMoveDown1.png");
else
user.pic = new ImageIcon("data/LinkBombMoveDown2.png");
user.direction = "down";
user.height = 30;
}
}
}
repaint();
}
public void keyReleased(KeyEvent k)
{
int c = k.getKeyCode();
if(user.alive)
{
if(c == KeyEvent.VK_B)
{
user.action = "thrown";
if(user.direction.equalsIgnoreCase("up"))
{
user.pic = new ImageIcon("data/LinkArrowUp2.png");
}
if(user.direction.equalsIgnoreCase("down"))
{
user.pic = new ImageIcon("data/LinkArrowDown2.png");
}
if(user.direction.equalsIgnoreCase("left"))
{
user.pic = new ImageIcon("data/LinkArrowLeft2.png");
}
if(user.direction.equalsIgnoreCase("right"))
{
user.pic = new ImageIcon("data/LinkArrowRight2.png");
}
item.add(new Projectile(user.x, user.y, user.direction, "arrow"));
}
if(c == KeyEvent.VK_C)
{
user.action = "none";
if(user.direction.equalsIgnoreCase("up"))
{
item.add(new Projectile(user.x, user.y - 10, "none", "bomb"));
}
if(user.direction.equalsIgnoreCase("down"))
{
item.add(new Projectile(user.x, user.y + user.height + 10, "none", "bomb"));
}
if(user.direction.equalsIgnoreCase("left"))
{
item.add(new Projectile(user.x - 10, user.y, "none", "bomb"));
}
if(user.direction.equalsIgnoreCase("right"))
{
item.add(new Projectile(user.x + user.width + 10, user.y, "none", "bomb"));
}
}
if( c == KeyEvent.VK_RIGHT || c == KeyEvent.VK_LEFT || c == KeyEvent.VK_UP || c == KeyEvent.VK_DOWN || c == KeyEvent.VK_C )
{
user.dx = 0;
user.dy = 0;
if(!user.action.equalsIgnoreCase("arrow"))
{
user.action = "none";
user.width = 20;
user.height = 20;
if(user.direction.equalsIgnoreCase("up"))
{
user.pic = new ImageIcon("data/LinkStandingUp.png");
}
if(user.direction.equalsIgnoreCase("down"))
{
user.pic = new ImageIcon("data/LinkStandingDown.png");
}
if(user.direction.equalsIgnoreCase("left"))
{
user.pic = new ImageIcon("data/LinkStandingLeft.png");
}
if(user.direction.equalsIgnoreCase("right"))
{
user.pic = new ImageIcon("data/LinkStandingRight.png");
}
}
}
}
}
public void keyTyped(KeyEvent k)
{
}
}
import java.awt.*;
import java.util.*;
import javax.swing.*;
public class Enemy extends Rectangle{
ImageIcon pic, pic2;
Random ran;
int hp;
int dx, dy, movecnt, ID, random, attackcnt, minioncnt;
String direction;
String action, name, secact;
boolean dead, minions;
long t1, t2;
double t;
//Projectile proc;
Enemy()
{
}
Enemy(int num)
{
ran = new Random();
//int num = ran.nextInt(2);
ID = ran.nextInt();
dead = false;
if(num == 0)
{
pic = new ImageIcon("data/DarknutDown.png");
name = "Darknut";
x = 250;
y = x;
dy = 3;
hp = 15;
width = 30;
height = 30;
}
if(num == 1)
{
pic = new ImageIcon("data/SpearMoblinDown.png");
name = "SpearMoblin";
x = 350;
y = x;
dy = 3;
hp = 25;
width = 30;
height = 30;
}
if(num == 2)
{
pic = new ImageIcon("data/IronBallSoldierDown.png");
name = "IronBallSoldier";
x = 350;
y = x;
dy = 3;
hp = 25;
width = 30;
height = 30;
}
if(num == 3)
{
pic = new ImageIcon("data/ShadowLinkDown.png");
name = "ShadowLink";
x = 280;
y = 235;
hp = 30;
dy = 3;
width = 20;
height = 20;
}
if(num == 4)
{
pic = new ImageIcon("data/Vaati.png");
name = "Vaati";
hp = 100;
width = 50;
height = 50;
}
if(num == 5)
{
pic = new ImageIcon("data/Eye_w_2.png");
name = "whiteminion";
hp = 1;
width = 15;
height = 15;
}
if(num == 6)
{
pic = new ImageIcon("data/Eye_y_2.png");
name = "yellowminion";
hp = 1;
width = 15;
height = 15;
}
movecnt = 1;
direction = "down";
action = "none";
secact = "none";
random = 0;
attackcnt = 0;
minioncnt = 0;
minions = false;
t1 = 0;
}
public void attackHero()
{
if(t1 == 0)
{
t1 = System.currentTimeMillis();
random = ran.nextInt(4) + 1;
}
t2 = System.currentTimeMillis();
int num = 0;
if(name.equalsIgnoreCase("yellowminion") || name.equalsIgnoreCase("whiteminion"))
{
//action = "none";
//dx = 5;
//dy = 5;
x += dx;
y += dy;
t1 = 0; t2 = 0;
}
if(name.equalsIgnoreCase("ShadowLink"))
{
//random = 4;
//System.out.println("Nothing . . . . .");
if(random == 1)
{
// t1 = 0; t2 = 0;
action = "none";
if(t2 - t1 > 750)
{
num = 1;
}
}
if(random == 2)
{
if(t2 - t1 > 500)
num = 1;
if(t2 - t1 > 750)
num = 2;
if(t2 - t1 > 900)
num = 3;
if(t2 - t1 > 1050)
num = 4;
}
if(random == 3)
{
if(t2 - t1 > 750)
num = 1;
if(t2 - t1 > 900)
num = 2;
if(t2 - t1 > 1050)
num = 3;
if(t2 - t1 > 1200)
num = 4;
}
if(random == 4)
{
if(t2 - t1 > 100)
num = 1;
if(t2 - t1 > 200)
num = 2;
if(t2 - t1 > 300)
num = 2;
if(t2 - t1 > 400)
num = 3;
if(t2 - t1 > 500)
num = 4;
if(t1 - t2 > 600)
num = 0;
if(t1 - t2 > 700)
num = 1;
if(t2 - t1 > 800)
num = 2;
if(t2 - t1 > 900)
num = 3;
if(t2 - t1 > 1000)
num = 4;
if(t2 - t1 > 1100)
num = 5;
}
}
if(name.equalsIgnoreCase("Darknut"))
{
if(t2 - t1 > 750)
num = 1;
if(t2 - t1 > 900)
num = 2;
if(t2 - t1 > 1050)
num = 3;
if(t2 - t1 > 1170)
num = 4;
if(t2 - t1 > 2350)
num = 5;
if(t2 - t1 > 3450)
num = 6;
}
if(name.equalsIgnoreCase("SpearMoblin"))
{
if(t2 - t1 > 750)
num = 1;
if(t2 - t1 > 1350)
num = 2;
if(t2 - t1 > 1950)
num = 3;
}
if(name.equalsIgnoreCase("IronBallSoldier"))
{
if(t2 - t1 > 750)
num = 1;
if(t2 - t1 > 1350)
num = 2;
if(t2 - t1 > 1950)
num = 3;
}
/*if(t2 - t1 > 1000)
num = 1;
if(t2 - t1 > 2000)
num = 2;
if(t2 - t1 > 3000)
num = 3;
if(t2 - t1 > 3000)
num = 4;
if(t2 - t1 > 4000)
num = 5;
if(t2 - t1 > 5000)
num = 6;*/
//System.out.println(num);
//System.out.println(t2);
if(name.equalsIgnoreCase("ShadowLink"))
{
if(random == 4)
{
if(direction.equalsIgnoreCase("up"))
dy = -4;
if(direction.equalsIgnoreCase("down"))
dy = 4;
if(direction.equalsIgnoreCase("left"))
dx = -4;
if(direction.equalsIgnoreCase("right"))
dx = 4;
}
if(num == 0 && random == 4)
{
pic = new ImageIcon("data/ShadowLinkSpin1.png");
height = 30;
width = 25;
}
if(num == 2 && random == 4)
{
pic = new ImageIcon("data/ShadowLinkSpin2.png");
height = 25;
width = 30;
}
if(num == 3 && random == 4)
{
pic = new ImageIcon("data/ShadowLinkSpin3.png");
height = 30;
width = 25;
}
if(num == 4 && random == 4)
{
pic = new ImageIcon("data/ShadowLinkSpin4.png");
height = 25;
width = 30;
}
if(num == 5 && random == 4)
{
height = 20; width = 20;
t1 = 0; t2 = 0;
dx = 0; dy = 0;
action = "none";
}
if(direction.equalsIgnoreCase("up"))
{
if(num == 0 && random == 1)
{
pic = new ImageIcon("data/ShadowLinkAttackUp.png");
height = 25;
dy = -5;
}
if(num == 1 && random == 1)
{
action = "none";
dy = 0;
width = 20; height = 20;
t1 = 0; t2 = 0;
//pic = new ImageIcon("data/ShadowLinkUp.png");
}
//////////////////////////////////////////////////////////////////
if(num == 0 && random == 3)
{
pic = new ImageIcon("data/ShadowLinkDashSlashUp1.png");
height = 30;
}
if(num == 1 && random == 3)
{
pic = new ImageIcon("data/ShadowLinkDashSlashUp2.png");
dy = -5;
}
if(num == 2 && random == 3)
{
pic = new ImageIcon("data/ShadowLinkDashSlashUp3.png");
}
if(num == 3 && random == 3)
{
pic = new ImageIcon("data/ShadowLinkDashSlashUp4.png");
}
if(num == 4 && random == 3)
{
pic = new ImageIcon("data/ShadowLinkDashSlashUp5.png");
action = "none";
dy = 0;
width = 20; height = 20;
t1 = 0; t2 = 0;
}
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
if(num == 0 && random == 2)
{
pic = new ImageIcon("data/ShadowLinkSwordSlashUp1.png");
height = 30;
}
if(num == 1 && random == 2)
{
pic = new ImageIcon("data/ShadowLinkSwordSlashUp2.png");
dy = -5;
}
if(num == 2 && random == 2)
{
pic = new ImageIcon("data/ShadowLinkSwordSlashUp3.png");
}
if(num == 3 && random == 2)
pic = new ImageIcon("data/ShadowLinkSwordSlashUp4.png");
}
if(direction.equalsIgnoreCase("down"))
{
if(num == 0 && random == 1)
{
pic = new ImageIcon("data/ShadowLinkAttackDown.png");
height = 25;
dy = 5;
}
if(num == 1 && random == 1)
{
action = "none";
dy = 0;
width = 20; height = 20;
t1 = 0; t2 = 0;
//pic = new ImageIcon("data/ShadowLinkDown.png");
}
//////////////////////////////////////////////////////////////////
if(num == 0 && random == 3)
{
pic = new ImageIcon("data/ShadowLinkDashSlashDown1.png");
height = 30;
}
if(num == 1 && random == 3)
{
pic = new ImageIcon("data/ShadowLinkDashSlashDown2.png");
dy = -5;
}
if(num == 2 && random == 3)
{
pic = new ImageIcon("data/ShadowLinkDashSlashDown3.png");
}
if(num == 3 && random == 3)
{
pic = new ImageIcon("data/ShadowLinkDashSlashDown4.png");
}
if(num == 4 && random == 3)
{
pic = new ImageIcon("data/ShadowLinkDashSlashDown5.png");
action = "none";
dy = 0;
width = 20; height = 20;
t1 = 0; t2 = 0;
}
////////////////////////////////////////////////////////////////////
if(num == 0 && random == 2)
{
pic = new ImageIcon("data/ShadowLinkSwordSlashDown1.png");
height = 30;
}
if(num == 1 && random == 2)
{
pic = new ImageIcon("data/ShadowLinkSwordSlashDown2.png");
dy = 5;
}
if(num == 2 && random == 2)
{
pic = new ImageIcon("data/ShadowLinkSwordSlashDown3.png");
}
if(num == 3 && random == 2)
pic = new ImageIcon("data/ShadowLinkSwordSlashDown4.png");
}
if(direction.equalsIgnoreCase("left"))
{
if(num == 0 && random == 1)
{
pic = new ImageIcon("data/ShadowLinkAttackLeft.png");
width = 25;
dx = -5;
}
if(num == 1 && random == 1)
{
action = "none";
dy = 0;
width = 20; height = 20;
t1 = 0; t2 = 0;
//pic = new ImageIcon("data/ShadowLinkLeft.png");
}
////////////////////////////////////////////////////////////////////////
if(num == 0 && random == 3)
{
pic = new ImageIcon("data/ShadowLinkDashSlashLeft1.png");
height = 30;
}
if(num == 1 && random == 3)
{
pic = new ImageIcon("data/ShadowLinkDashSlashLeft2.png");
dy = -5;
}
if(num == 2 && random == 3)
{
pic = new ImageIcon("data/ShadowLinkDashSlashLeft3.png");
}
if(num == 3 && random == 3)
{
pic = new ImageIcon("data/ShadowLinkDashSlashLeft4.png");
}
if(num == 4 && random == 3)
{
pic = new ImageIcon("data/ShadowLinkDashSlashLeft5.png");
action = "none";
dy = 0;
width = 20; height = 20;
t1 = 0; t2 = 0;
}
///////////////////////////////////////////////////////////////////////
if(num == 0 && random == 2)
{
pic = new ImageIcon("data/ShadowLinkSwordSlashLeft1.png");
width = 30;
}
if(num == 1 && random == 2)
{
pic = new ImageIcon("data/ShadowLinkSwordSlashLeft2.png");
dx = -5;
}
if(num == 2 && random == 2)
{
pic = new ImageIcon("data/ShadowLinkSwordSlashLeft3.png");
}
if(num == 3 && random == 2)
pic = new ImageIcon("data/ShadowLinkSwordSlashLeft4.png");
}
if(direction.equalsIgnoreCase("right"))
{
if(num == 0 && random == 1)
{
pic = new ImageIcon("data/ShadowLinkAttackRight.png");
width = 25;
dx = 5;
}
if(num == 1 && random == 1)
{
action = "none";
dy = 0;
width = 20; height = 20;
t1 = 0; t2 = 0;
//pic = new ImageIcon("data/ShadowLinkRight.png");
}
/////////////////////////////////////////////////////////////////////////////
if(num == 0 && random == 3)
{
pic = new ImageIcon("data/ShadowLinkDashSlashRight1.png");
height = 30;
}
if(num == 1 && random == 3)
{
pic = new ImageIcon("data/ShadowLinkDashSlashRight2.png");
dy = -5;
}
if(num == 2 && random == 3)
{
pic = new ImageIcon("data/ShadowLinkDashSlashRight3.png");
}
if(num == 3 && random == 3)
{
pic = new ImageIcon("data/ShadowLinkDashSlashRight4.png");
}
if(num == 4 && random == 3)
{
pic = new ImageIcon("data/ShadowLinkDashSlashRight5.png");
action = "none";
dy = 0;
width = 20; height = 20;
t1 = 0; t2 = 0;
}
////////////////////////////////////////////////////////////////////////////
if(num == 0 && random == 2)
{
pic = new ImageIcon("data/ShadowLinkSwordSlashRight1.png");
width = 30;
}
if(num == 1 && random == 2)
{
pic = new ImageIcon("data/ShadowLinkSwordSlashRight2.png");
dx = 5;
}
if(num == 2 && random == 2)
{
pic = new ImageIcon("data/ShadowLinkSwordSlashRight3.png");
}
if(num == 3 && random == 2)
pic = new ImageIcon("data/ShadowLinkSwordSlashRight4.png");
}
/**/
if(num == 4 && random == 2)
{
action = "none";
if(direction.equalsIgnoreCase("up"))
{
pic = new ImageIcon("data/ShadowLinkUp.png");
}
if(direction.equalsIgnoreCase("down"))
{
pic = new ImageIcon("data/ShadowLinkDown.png");
}
if(direction.equalsIgnoreCase("left"))
{
pic = new ImageIcon("data/ShadowLinkLeft.png");
}
if(direction.equalsIgnoreCase("right"))
{
pic = new ImageIcon("data/ShadowLinkRight.png");
}
height = 20;
width = 20;
dx = 0; dy = 0;
t1 = 0; t2 = 0;
random = 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
if(direction.equalsIgnoreCase("up"))
{
if(num == 0)
{
if(name.equalsIgnoreCase("Darknut"))
pic = new ImageIcon("data/DarknutAttackUp1.png");
if(name.equalsIgnoreCase("SpearMoblin"))
{
pic = new ImageIcon("data/SpearMoblinAttackUp1.png");
height = 40;
dy = -1;
}
if(name.equalsIgnoreCase("IronBallSoldier"))
{
//action = "open";
pic = new ImageIcon("data/IronBallSoldierAttackUp1.png");
}
//System.out.println("Hello");
}
if(num == 1)
{
if(name.equalsIgnoreCase("Darknut"))
pic = new ImageIcon("data/DarknutAttackUp2.png");
if(name.equalsIgnoreCase("SpearMoblin"))
{
pic = new ImageIcon("data/SpearMoblinAttackUp2.png");
action = "open";
dy = 0;
width = 30;
height = 30;
}
if(name.equalsIgnoreCase("IronBallSoldier"))
{
pic = new ImageIcon("data/IronBallSoldierAttackUp2.png");
}
//System.out.println("About to ");
}
if(num == 2)///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
{
if(name.equalsIgnoreCase("Darknut"))
{
dy = -10;
pic = new ImageIcon("data/DarknutAttackUp3.png");
//System.out.println("Attacking");
height = 35;
action = "attack";
}
if(name.equalsIgnoreCase("SpearMoblin"))
{
action = "none";
t1 = 0; t2 = 0;
//width = 30;
//height = 30;
}
if(name.equalsIgnoreCase("IronBallSoldier"))
{
pic = new ImageIcon("data/IronBallSoldierUp.png");
action = "none";
t1 = 0; t2 = 0;
}
}//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(num == 3)
{
if(name.equalsIgnoreCase("Darknut"))
{
pic = new ImageIcon("data/DarknutAttackUp4.png");
height = 30;
width = 35;
//System.out.println("Attacking 2");
}
}
if(num == 4)
{
if(name.equalsIgnoreCase("Darknut"))
{
action = "open";
pic = new ImageIcon("data/DarknutAttackUp5.png");
width = 45;
height = 30;
//System.out.println("Attacked");
}
}
if(num == 5)
{
if(name.equalsIgnoreCase("Darknut"))
{
pic = new ImageIcon("data/DarknutOpenUp.png");
width = 30;
height = 30;
//System.out.println("Open");
}
}
if(num == 6)
{
if(name.equalsIgnoreCase("Darknut"))
{
//pic = new ImageIcon("data/DarknutUp.png");
action = "defend";
t1 = 0; t2 = 0;
}
}
}
if(direction.equalsIgnoreCase("down"))
{
if(num == 0)
{
if(name.equalsIgnoreCase("Darknut"))
pic = new ImageIcon("data/DarknutAttackDown1.png");
if(name.equalsIgnoreCase("SpearMoblin"))
{
pic = new ImageIcon("data/SpearMoblinAttackDown1.png");
height = 40;
dy = 1;
}
if(name.equalsIgnoreCase("IronBallSoldier"))
{
//action = "open";
pic = new ImageIcon("data/IronBallSoldierAttackDown1.png");
}
}
if(num == 1)
{
if(name.equalsIgnoreCase("Darknut"))
pic = new ImageIcon("data/DarknutAttackDown2.png");
if(name.equalsIgnoreCase("SpearMoblin"))
{
pic = new ImageIcon("data/SpearMoblinAttackDown2.png");
action = "open";
dy = 0;
width = 30;
height = 30;
}
if(name.equalsIgnoreCase("IronBallSoldier"))
{
pic = new ImageIcon("data/IronBallSoldierAttackDown2.png");
}
}
if(num == 2)
{
if(name.equalsIgnoreCase("Darknut"))
{
dy = 10;
pic = new ImageIcon("data/DarknutAttackDown3.png");
height = 35;
action = "attack";
}
if(name.equalsIgnoreCase("IronBallSoldier"))
{
pic = new ImageIcon("data/IronBallSoldierDown.png");
action = "none";
t1 = 0; t2 = 0;
}
}
if(num == 3)
{
if(name.equalsIgnoreCase("Darknut"))
{
pic = new ImageIcon("data/DarknutAttackDown4.png");
height = 30;
width = 35;
}
if(name.equalsIgnoreCase("SpearMoblin"))
{
action = "none";
t1 = 0; t2 = 0;
width = 30;
height = 30;
}
}
if(num == 4)
{
if(name.equalsIgnoreCase("Darknut"))
{
action = "open";
dy = 0;
pic = new ImageIcon("data/DarknutAttackDown5.png");
width = 45;
height = 30;
}
}
if(num == 5)
{
if(name.equalsIgnoreCase("Darknut"))
{
pic = new ImageIcon("data/DarknutOpenDown.png");
width = 30;
height = 30;
}
}
if(num == 6)
{
if(name.equalsIgnoreCase("Darknut"))
{
//pic = new ImageIcon("data/DarknutDown.png");
action = "defend";
t1 = 0; t2 = 0;
}
}
}
if(direction.equalsIgnoreCase("left"))
{
if(num == 0)
{
if(name.equalsIgnoreCase("Darknut"))
pic = new ImageIcon("data/DarknutAttackLeft1.png");
if(name.equalsIgnoreCase("SpearMoblin"))
{
pic = new ImageIcon("data/SpearMoblinAttackLeft1.png");
width = 40;
dx = -1;
}
if(name.equalsIgnoreCase("IronBallSoldier"))
{
//action = "open";
pic = new ImageIcon("data/IronBallSoldierAttackLeft1.png");
}
}
if(num == 1)
{
if(name.equalsIgnoreCase("Darknut"))
{
pic = new ImageIcon("data/DarknutAttackLeft2.png");
width = 30;
}
if(name.equalsIgnoreCase("SpearMoblin"))
{
pic = new ImageIcon("data/SpearMoblinAttackLeft2.png");
action = "open";
dx = 0;
width = 30;
height = 30;
}
if(name.equalsIgnoreCase("IronBallSoldier"))
{
pic = new ImageIcon("data/IronBallSoldierAttackLeft2.png");
}
}
if(num == 2)
{
if(name.equalsIgnoreCase("Darknut"))
{
dx = -10;
height = 30;
pic = new ImageIcon("data/DarknutAttackLeft3.png");
action = "attack";
}
if(name.equalsIgnoreCase("SpearMoblin"))
{
action = "none";
t1 = 0; t2 = 0;
width = 30;
height = 30;
}
if(name.equalsIgnoreCase("IronBallSoldier"))
{
pic = new ImageIcon("data/IronBallSoldierLeft.png");
action = "none";
t1 = 0; t2 = 0;
}
}
if(num == 3)
{
if(name.equalsIgnoreCase("Darknut"))
{
pic = new ImageIcon("data/DarknutAttackLeft4.png");
width = 35;
}
}
if(num == 4)
{
if(name.equalsIgnoreCase("Darknut"))
{
action = "open";
dx = 0;
pic = new ImageIcon("data/DarknutAttackLeft5.png");
width = 40;
}
}
if(num == 5)
{
if(name.equalsIgnoreCase("Darknut"))
{
pic = new ImageIcon("data/DarknutOpenLeft.png");
width = 30;
}
}
if(num == 6)
{
if(name.equalsIgnoreCase("Darknut"))
{
//pic = new ImageIcon("data/DarknutLeft.png");
action = "defend";
t1 = 0; t2 = 0;
}
}
}
if(direction.equalsIgnoreCase("right"))
{
if(num == 0)
{
if(name.equalsIgnoreCase("Darknut"))
pic = new ImageIcon("data/DarknutAttackRight1.png");
if(name.equalsIgnoreCase("SpearMoblin"))
{
pic = new ImageIcon("data/SpearMoblinAttackRight1.png");
width = 40;
dx = 1;
}
if(name.equalsIgnoreCase("IronBallSoldier"))
{
//action = "open";
pic = new ImageIcon("data/IronBallSoldierAttackRight1.png");
}
}
if(num == 1)
{
if(name.equalsIgnoreCase("Darknut"))
{
pic = new ImageIcon("data/DarknutAttackRight2.png");
width = 30;
}
if(name.equalsIgnoreCase("SpearMoblin"))
{
pic = new ImageIcon("data/SpearMoblinAttackRight2.png");
action = "open";
dx = 0;
width = 30;
height = 30;
}
if(name.equalsIgnoreCase("IronBallSoldier"))
{
pic = new ImageIcon("data/IronBallSoldierAttackRight2.png");
}
}
if(num == 2)
{
if(name.equalsIgnoreCase("Darknut"))
{
dx = 10;
height = 35;
pic = new ImageIcon("data/DarknutAttackRight3.png");
action = "attack";
}
if(name.equalsIgnoreCase("SpearMoblin"))
{
action = "none";
t1 = 0; t2 = 0;
width = 30;
height = 30;
//System.out.println("Error here");
}
if(name.equalsIgnoreCase("IronBallSoldier"))
{
pic = new ImageIcon("data/IronBallSoldierRight.png");
action = "none";
t1 = 0; t2 = 0;
}
}
if(num == 3)
{
if(name.equalsIgnoreCase("Darknut"))
{
pic = new ImageIcon("data/DarknutAttackRight4.png");
width = 40;
}
}
if(num == 4)
{
if(name.equalsIgnoreCase("Darknut"))
{
action = "open";
dx = 0;
pic = new ImageIcon("data/DarknutAttackRight5.png");
width = 35;
}
}
if(num == 5)
{
if(name.equalsIgnoreCase("Darknut"))
{
pic = new ImageIcon("data/DarknutOpenRight.png");
width = 30;
}
}
if(num == 6)
{
if(name.equalsIgnoreCase("Darknut"))
{
//pic = new ImageIcon("data/DarknutRight.png");
action = "defend";
t1 = 0; t2 = 0;
}
}
}
//dx = 0; dy = 0;
x += dx;
y += dy;
}
public void vaatiAttack()
{
if(t1 == 0)
{
t1 = System.currentTimeMillis();
random = ran.nextInt(2);
}
t2 = System.currentTimeMillis();
//random = 1;
int num = 0;
if(random == 0)
{
if(t2 - t1 > 500)
num = 1;
if(t2 - t1 > 750)
num = 2;
if(t2 - t1 > 1000)
num = 3;
if(t2 - t1 > 1500)
num = 4;
if(t2 - t1 > 2000)
num = 5;
if(t2 - t1 > 2500)
num = 6;
if(t2 - t1 > 3000)
num = 7;
if(t2 - t1 > 3500)
num = 8;
}
if(random == 1)
{
if(t2 - t1 > 500)
num = 1;
if(t2 - t1 > 1000)
num = 2;
if(t2 - t1 > 1500)
num = 3;
if(t2 - t1 > 2000)
{
num = 4;
//System.out.println("Process 4 . . . .");
}
if(t2 - t1 > 2500)
num = 5;
if(t2 - t1 > 3000)
num = 6;
if(t2 - t1 > 3500)
num = 7;
if(t2 - t1 > 4000)
num = 8;
if(t2 - t1 > 4300)
num = 9;
}
if(num == 0 && random == 0)
{
pic = new ImageIcon("data/Vaati_t1.png");
}
if(num == 1 && random == 0)
{
pic = new ImageIcon("data/Vaati_t2.png");
}
if(num == 2 && random == 0)
{
pic = new ImageIcon("data/Vaati_t3.png");
width = 52;
}
if(num == 3 && random == 0)
{
pic = new ImageIcon("data/Vaati_t4.png");
width = 55;
height = 55;
}
if(num == 4 && random == 0)
{
pic = new ImageIcon("data/Vaati_t5.png");
width = 57;
height = 57;
}
if(num == 5 && random == 0)
{
pic = new ImageIcon("data/Vaati_t6.png");
width = 60;
height = 60;
}
if(num == 6 && random == 0)
{
pic = new ImageIcon("data/Vaati_t7.png");
width = 70;
height = 70;
}
if(num == 7 && random == 0)
{
pic = new ImageIcon("data/Vaati_t8.png");
action = "Attack";
t2 = 0; t1 = 0;
}
if(num == 0 && random == 1)
{
pic = new ImageIcon("data/VaatiAttack1.png");
}
if(num == 1 && random == 1)
{
pic = new ImageIcon("data/VaatiAttack2.png");
}
if(num == 2 && random == 1)
{
pic = new ImageIcon("data/VaatiAttack3.png");
width = 52;
}
if(num == 3 && random == 1)
{
pic = new ImageIcon("data/VaatiAttack4.png");
width = 55;
height = 55;
}
if(num == 4 && random == 1)
{
pic = new ImageIcon("data/VaatiAttack5.png");
width = 57;
height = 57;
}
if(num == 5 && random == 1)
{
pic = new ImageIcon("data/VaatiAttack6.png");
width = 60;
height = 60;
}
if(num == 6 && random == 1)
{
pic = new ImageIcon("data/VaatiAttack7.png");
width = 70;
height = 70;
}
if(num == 7 && random == 1)
{
pic = new ImageIcon("data/Vaati.png");
pic2 = new ImageIcon("data/VaatiAttack8.png");
width = 50;
height = 50;
}
if(num == 8 && random == 1)
{
pic2 = new ImageIcon("data/VaatiAttack9.png");
//System.out.println("Attack 9");
}
if(num == 9 && random == 1)
{
pic2 = null;
minions = true;
action = "none";
t2 = 0; t1 = 0;
}
//System.out.println(t2 - t1);
}
public void moveAround(int _x, int _y)
{
//System.out.println(action);
if((action.equalsIgnoreCase("attack") || action.equalsIgnoreCase("open")) && !name.equalsIgnoreCase("Vaati") && !name.equalsIgnoreCase("whiteminion") && !name.equalsIgnoreCase("yellowminion"))
{
dx = 0;
dy = 0;
attackHero();
//System.out.println("Still attacking . . . .");
}
else if(!name.equalsIgnoreCase("Vaati"))
{
if(x > _x)
{
dx = -3;
if( Math.abs(x - _x) > 5)
direction = "left";
}
if(x <= _x)
{
dx = 3;
if(Math.abs(x - _x) > 5)
direction = "right";
}
if(y > _y)
{
dy = -3;
if(Math.abs(y - _y) >= 5)
direction = "up";
}
if(y <= _y)
{
dy = 3;
if(Math.abs(y - _y) >= 5)
direction = "down";
}
if(x == _x)
{
dx = 0;
if(y > _y)
direction = "down";
else
direction = "up";
}
if(y == _y)
{
dy = 0;
if(x > _x)
direction = "left";
else
direction = "right";
}
//}
if((Math.abs(x - _x) < 35 && Math.abs(y - _y) < 10) || (Math.abs(x - _x) < 10 && Math.abs(y - _y) < 35))
{
dx = 0;
dy = 0;
if(!action.equalsIgnoreCase("attack") && !action.equalsIgnoreCase("Open"))
{
if(direction.equalsIgnoreCase("up"))
{
if(name.equalsIgnoreCase("Darknut"))
pic = new ImageIcon("data/DarknutUp.png");
if(name.equalsIgnoreCase("SpearMoblin"))
pic = new ImageIcon("data/SpearMoblinUp.png");
if(name.equalsIgnoreCase("IronBallSoldier"))
pic = new ImageIcon("data/IronBallSoldierUp.png");
if(name.equalsIgnoreCase("ShadowLink"))
pic = new ImageIcon("data/ShadowLinkUp.png");
}
if(direction.equalsIgnoreCase("down"))
{
if(name.equalsIgnoreCase("Darknut"))
pic = new ImageIcon("data/DarknutDown.png");
if(name.equalsIgnoreCase("SpearMoblin"))
pic = new ImageIcon("data/SpearMoblinDown.png");
if(name.equalsIgnoreCase("IronBallSoldier"))
pic = new ImageIcon("data/IronBallSoldierDown.png");
if(name.equalsIgnoreCase("ShadowLink"))
pic = new ImageIcon("data/ShadowLinkDown.png");
}
if(direction.equalsIgnoreCase("right"))
{
if(name.equalsIgnoreCase("Darknut"))
pic = new ImageIcon("data/DarknutRight.png");
if(name.equalsIgnoreCase("SpearMoblin"))
pic = new ImageIcon("data/SpearMoblinRight.png");
if(name.equalsIgnoreCase("IronBallSoldier"))
pic = new ImageIcon("data/IronBallSoldierRight.png");
if(name.equalsIgnoreCase("ShadowLink"))
pic = new ImageIcon("data/ShadowLinkRight.png");
}
if(direction.equalsIgnoreCase("left"))
{
if(name.equalsIgnoreCase("Darknut"))
pic = new ImageIcon("data/DarknutLeft.png");
if(name.equalsIgnoreCase("SpearMoblin"))
pic = new ImageIcon("data/SpearMoblinLeft.png");
if(name.equalsIgnoreCase("IronBallSoldier"))
pic = new ImageIcon("data/IronBallSoldierLeft.png");
if(name.equalsIgnoreCase("ShadowLink"))
pic = new ImageIcon("data/ShadowLinkLeft.png");
}
int num = ran.nextInt(3);
if(num == 1)
{
action = "attack";
attackHero();
}
}
}
else
{
if(direction.equalsIgnoreCase("up"))
{
if(movecnt%2 == 0)
{
if(name.equalsIgnoreCase("Darknut"))
pic = new ImageIcon("data/DarknutMoveUp1.png");
if(name.equalsIgnoreCase("SpearMoblin"))
pic = new ImageIcon("data/SpearMoblinMoveUp1.png");
if(name.equalsIgnoreCase("ShadowLink"))
pic = new ImageIcon("data/ShadowLinkMoveUp1.png");
}
else
{
if(name.equalsIgnoreCase("Darknut"))
pic = new ImageIcon("data/DarknutMoveUp2.png");
if(name.equalsIgnoreCase("SpearMoblin"))
pic = new ImageIcon("data/SpearMoblinMoveUp2.png");
if(name.equalsIgnoreCase("ShadowLink"))
pic = new ImageIcon("data/ShadowLinkMoveUp2.png");
}
}
if(direction.equalsIgnoreCase("down"))
{
if(movecnt%2 == 0)
{
if(name.equalsIgnoreCase("Darknut"))
pic = new ImageIcon("data/DarknutMoveDown1.png");
if(name.equalsIgnoreCase("SpearMoblin"))
pic = new ImageIcon("data/SpearMoblinMoveDown1.png");
if(name.equalsIgnoreCase("ShadowLink"))
pic = new ImageIcon("data/ShadowLinkMoveDown1.png");
}
else
{
if(name.equalsIgnoreCase("Darknut"))
pic = new ImageIcon("data/DarknutMoveDown2.png");
if(name.equalsIgnoreCase("SpearMoblin"))
pic = new ImageIcon("data/SpearMoblinMoveDown2.png");
if(name.equalsIgnoreCase("ShadowLink"))
pic = new ImageIcon("data/ShadowLinkMoveDown2.png");
}
}
if(direction.equalsIgnoreCase("right"))
{
if(movecnt%2 == 0)
{
if(name.equalsIgnoreCase("Darknut"))
pic = new ImageIcon("data/DarknutMoveRight1.png");
if(name.equalsIgnoreCase("SpearMoblin"))
pic = new ImageIcon("data/SpearMoblinMoveRight.png");
if(name.equalsIgnoreCase("ShadowLink"))
pic = new ImageIcon("data/ShadowLinkMoveRight1.png");
}
else
{
if(name.equalsIgnoreCase("Darknut"))
pic = new ImageIcon("data/DarknutMoveRight2.png");
if(name.equalsIgnoreCase("SpearMoblin"))
pic = new ImageIcon("data/SpearMoblinMoveRight.png");
if(name.equalsIgnoreCase("ShadowLink"))
pic = new ImageIcon("data/ShadowLinkMoveRight2.png");
}
}
if(direction.equalsIgnoreCase("left"))
{
if(movecnt%2 == 0)
{
if(name.equalsIgnoreCase("Darknut"))
pic = new ImageIcon("data/DarknutMoveLeft1.png");
if(name.equalsIgnoreCase("SpearMoblin"))
pic = new ImageIcon("data/SpearMoblinMoveLeft.png");
if(name.equalsIgnoreCase("ShadowLink"))
pic = new ImageIcon("data/ShadowLinkMoveLeft1.png");
}
else
{
if(name.equalsIgnoreCase("Darknut"))
pic = new ImageIcon("data/DarknutMoveLeft2.png");
if(name.equalsIgnoreCase("SpearMoblin"))
pic = new ImageIcon("data/SpearMoblinMoveLeft.png");
if(name.equalsIgnoreCase("ShadowLink"))
pic = new ImageIcon("data/ShadowLinkMoveLeft2.png");
}
}
movecnt++;
}
}
if(name.equalsIgnoreCase("Vaati"))
{
if(!action.equalsIgnoreCase("change"))
{
if(x > _x)
{
dx = -3;
if(Math.abs(x - _x) > 15)
direction = "left";
}
if(x <= _x)
{
dx = 3;
if(Math.abs(x - _x) > 15)
direction = "right";
}
if(y > _y)
{
dy = -3;
if(Math.abs(y - _y) >= 15)
direction = "up";
}
if(y <= _y)
{
dy = 3;
if(Math.abs(y - _y) >= 15)
direction = "down";
}
if(x == _x)
{
dx = 0;
if(y > _y)
direction = "down";
else
direction = "up";
}
if(y == _y)
{
dy = 0;
if(x > _x)
direction = "left";
else
direction = "right";
}
}
// x < _x && y < _y
// x > _x && y < _y
// x > _x && y > _y
// x < _x && y > _y
if(!action.equalsIgnoreCase("Attack") && !action.equalsIgnoreCase("change"))// && !secact.equalsIgnoreCase("minion"))
{
if(t1 == 0)
t1 = System.currentTimeMillis();
t2 = System.currentTimeMillis();
int num = ran.nextInt(500);
//System.out.println("Going to change . . .");
//System.out.println(t2 - t1);gsf
if(t2 - t1 > 8000)
{
action = "change";
t2 = 0;
t1 = 0;
vaatiAttack();
dx = 0;
dy = 0;
}
}
if(action.equalsIgnoreCase("change"))
{
vaatiAttack();
//System.out.println("Changing . . . .");
}
if(action.equalsIgnoreCase("Attack"))
{
if(t1 == 0)
t1 = System.currentTimeMillis();
t2 = System.currentTimeMillis();
if(t2 - t1 > 15000)
{
action = "none";
pic = new ImageIcon("data/Vaati.png");
width = 50;
height = 50;
t2 = 0; t1 = 0;
System.out.println("Problem Here 1 . . . .");
}
}
//System.out.println(action);
}
//System.out.println("Position y:" + y);
}
public void update(int _x, int _y)
{
moveAround(_x, _y);
x += dx;
y += dy;
}
public void draw(Graphics g, Component c)
{
if( pic != null )
{
g.drawImage(pic.getImage(),x,y,width,height,c);
}
if( pic2 != null )
{
g.drawImage(pic2.getImage(),x - 10,y - 10,70,70,c);
}
}
}
import java.awt.*;
import java.util.*;
import javax.swing.*;
public class Hero extends Rectangle{
String name;
int hp;
ImageIcon pic;
ImageIcon life_full, life_3_4, life_1_2, life_1_4;
int dx, dy, num;
String direction;
String action;
boolean alive, over, bomb, passable;
long t1, t2;
LinkedList<Enemy> enemies = new LinkedList<Enemy>();
LinkedList<ImageIcon> hearts = new LinkedList<ImageIcon>();
Hero()
{
name = "Default";
hp = 6;
num = 4;
alive = true;
bomb = false;
pic = new ImageIcon("data/LinkStandingUp.png");
//x = 418;
//y = 80;
x = 280;
y = 485;
width = 20;
height = 20;
direction = "up";
action = "none";
hp = 20;
life_full = new ImageIcon("data/HeartContainer.png");
life_3_4 = new ImageIcon("data/HeartContainer_3_4.png");
life_1_2 = new ImageIcon("data/HeartContainer_1_2.png");
life_1_4 = new ImageIcon("data/HeartContainer_1_4.png");
for(int i = 0; i < 5; i++)
{
hearts.add(life_full);
}
over = false;
passable = false;
}
Hero(String _n)
{
name = _n;
hp = 6;
pic = new ImageIcon("data/LinkStandingUp.png");
x = 150;
y = x;
width = 20;
height = 20;
direction = "up";
action = "none";
over = false;
}
public void setEnemies(LinkedList<Enemy> en)
{
//for(Enemy o : en)
//{
enemies = en;
//}
}
public void faintSequence()
{
if(!alive)
{
if(t1 == 0)
t1 = System.currentTimeMillis();
t2 = System.currentTimeMillis();
int num = 0;
if(t2 - t1 > 650)
num = 1;
if(t2 - t1 > 1300)
num = 2;
if(t2 - t1 > 1950)
num = 3;
if(t2 - t1 > 2600)
num = 4;
if(t2 - t1 > 3250)
num = 5;
if(t2 - t1 > 3900)
num = 6;
if(t2 - t1 > 6000)
num = 7;
if(num == 1)
{
pic = new ImageIcon("data/LinkDead1.png");
}
if(num == 2)
{
pic = new ImageIcon("data/LinkDead2.png");
}
if(num == 3)
{
pic = new ImageIcon("data/LinkDead3.png");
}
if(num == 4)
{
pic = new ImageIcon("data/LinkDead4.png");
}
if(num == 5)
{
pic = new ImageIcon("data/LinkDead5.png");
}
if(num == 6)
{
pic = new ImageIcon("data/LinkDead6.png");
}
if(num == 7)
{
over = true;
}
}
}
public void update()
{
if(alive)
{
x += dx;
y += dy;
//System.out.println("X: " + x + "\nY: " + y);
}
else
{
dx = 0;
dy = 0;
faintSequence();
}
//System.out.println("HP: " + hp);
LinkedList<ImageIcon> dummy = new LinkedList<ImageIcon>();
if(hp < 20)
{
while(!hearts.isEmpty())
{
hearts.remove();
}
}
if(hp == 19)
{
/*if(!hearts.isEmpty())
hearts.removeLast();
hearts.add(life_3_4);*/
for(int i = 0; i < 4; i++)
{
dummy.add(life_full);
}
dummy.add(life_3_4);
for(ImageIcon o : dummy)
{
hearts.add(o);
}
}
if(hp == 18)
{
/*if(!hearts.isEmpty())
hearts.removeLast();
hearts.add(life_1_2);*/
for(int i = 0; i < 4; i++)
{
dummy.add(life_full);
}
dummy.add(life_1_2);
for(ImageIcon o : dummy)
{
hearts.add(o);
}
}
if(hp == 17)
{
/*if(!hearts.isEmpty())
hearts.removeLast();
hearts.add(life_1_4);*/
for(int i = 0; i < 4; i++)
{
dummy.add(life_full);
}
dummy.add(life_1_4);
for(ImageIcon o : dummy)
{
hearts.add(o);
}
}
if(hp == 16)
{
/*if(!hearts.isEmpty())
hearts.removeLast();
System.out.println("Problem Here");*/
for(int i = 0; i < 4; i++)
{
dummy.add(life_full);
}
for(ImageIcon o : dummy)
{
hearts.add(o);
}
}
if(hp == 15)
{
/*if(!hearts.isEmpty())
hearts.removeLast();
hearts.add(life_3_4);*/
for(int i = 0; i < 3; i++)
{
dummy.add(life_full);
}
dummy.add(life_3_4);
for(ImageIcon o : dummy)
{
hearts.add(o);
}
}
if(hp == 14)
{
/*if(!hearts.isEmpty())
hearts.removeLast();
hearts.add(life_1_2);*/
for(int i = 0; i < 3; i++)
{
dummy.add(life_full);
}
dummy.add(life_1_2);
for(ImageIcon o : dummy)
{
hearts.add(o);
}
}
if(hp == 13)
{
/*if(!hearts.isEmpty())
hearts.removeLast();
hearts.add(life_1_4);*/
for(int i = 0; i < 3; i++)
{
dummy.add(life_full);
}
dummy.add(life_1_4);
for(ImageIcon o : dummy)
{
hearts.add(o);
}
}
if(hp == 12)
{
/*if(!hearts.isEmpty())
hearts.removeLast();
System.out.println("Problem Here");*/
for(int i = 0; i < 3; i++)
{
dummy.add(life_full);
}
for(ImageIcon o : dummy)
{
hearts.add(o);
}
}
if(hp == 11)
{
/*if(!hearts.isEmpty())
hearts.removeLast();
hearts.add(life_3_4);*/
for(int i = 0; i < 2; i++)
{
dummy.add(life_full);
}
dummy.add(life_3_4);
for(ImageIcon o : dummy)
{
hearts.add(o);
}
}
if(hp == 10)
{
/*if(!hearts.isEmpty())
hearts.removeLast();
hearts.add(life_1_2);*/
for(int i = 0; i < 2; i++)
{
dummy.add(life_full);
}
dummy.add(life_1_2);
for(ImageIcon o : dummy)
{
hearts.add(o);
}
}
if(hp == 9)
{
/*if(!hearts.isEmpty())
hearts.removeLast();
hearts.add(life_1_4);*/
for(int i = 0; i < 2; i++)
{
dummy.add(life_full);
}
dummy.add(life_1_4);
for(ImageIcon o : dummy)
{
hearts.add(o);
}
}
if(hp == 8)
{
/*if(!hearts.isEmpty())
hearts.removeLast();*/
for(int i = 0; i < 2; i++)
{
dummy.add(life_full);
}
for(ImageIcon o : dummy)
{
hearts.add(o);
}
}
if(hp == 7)
{
/*if(!hearts.isEmpty())
hearts.removeLast();
hearts.add(life_3_4);*/
dummy.add(life_full);
dummy.add(life_3_4);
for(ImageIcon o : dummy)
{
hearts.add(o);
}
}
if(hp == 6)
{
/*if(!hearts.isEmpty())
hearts.removeLast();
hearts.add(life_1_2);*/
dummy.add(life_full);
dummy.add(life_1_2);
for(ImageIcon o : dummy)
{
hearts.add(o);
}
}
if(hp == 5)
{
/*if(!hearts.isEmpty())
hearts.removeLast();
hearts.add(life_1_4);*/
dummy.add(life_full);
dummy.add(life_1_4);
for(ImageIcon o : dummy)
{
hearts.add(o);
}
}
if(hp == 4)
{
/*if(!hearts.isEmpty())
hearts.removeLast();*/
dummy.add(life_full);
for(ImageIcon o : dummy)
{
hearts.add(o);
}
}
if(hp == 3)
{
/*if(!hearts.isEmpty())
hearts.removeLast();
hearts.add(life_3_4);*/
dummy.add(life_3_4);
for(ImageIcon o : dummy)
{
hearts.add(o);
}
}
if(hp == 2)
{
/*if(!hearts.isEmpty())
hearts.removeLast();
hearts.add(life_1_2);*/
dummy.add(life_1_2);
for(ImageIcon o : dummy)
{
hearts.add(o);
}
}
if(hp == 1)
{
/*if(!hearts.isEmpty())
hearts.removeLast();
hearts.add(life_1_4);*/
dummy.add(life_1_4);
for(ImageIcon o : dummy)
{
hearts.add(o);
}
}
if(hp == 0)
{
/*if(!hearts.isEmpty())
hearts.removeLast();*/
for(ImageIcon o : dummy)
{
hearts.add(o);
}
}
while(!dummy.isEmpty())
{
dummy.remove();
}
}
public void draw(Graphics g, Component c)
{
if( pic != null )
{
g.drawImage(pic.getImage(),x,y,width,height,c);
}
int cnt = 10;
if(life_full != null)
{
for(ImageIcon o : hearts)
{
g.drawImage(o.getImage(), cnt, 20, 20, 20, c);
cnt += 20;
}
}
}
}
import java.awt.*;
import javax.swing.*;
public class MovableObjects extends Rectangle{
ImageIcon pic;
String property, direction, number;
int dx, dy;
MovableObjects(String property)
{
if(property.equalsIgnoreCase("tile"))
{
pic = new ImageIcon("data/Tile.png");
width = 30;
height = 30;
}
dx = 0;
dy = 0;
number = "none";
}
public void setDirection(String dir)
{
if(dir.equalsIgnoreCase("Vertical"))
dy = 5;
if(dir.equalsIgnoreCase("Horizontal"))
dx = 5;
if(dir.equalsIgnoreCase("Diagonal"))
{
dx = 3;
dy = 3;
}
direction = dir;
}
public void moveAround()
{
if(x > 505 || x < 75)
dx *= -1;
//if(y < 100 || y > 375)
//dy *= -1;
if(x > 410 && (y > 260 || y < 50))
dy *= -1;
else if(x < 400 && (y < 100 || y > 375))
dy *= -1;
x += dx;
y += dy;
}
public void draw(Graphics g, Component c)
{
g.drawImage(pic.getImage(),x,y,width,height,c);
}
}
import java.awt.*;
import java.util.*;
import javax.swing.*;
public class Projectile extends Rectangle{
int dx, dy, usx, usy, usID, ID;
String direction;
String attribute;
boolean active;
long t1, t2;
double t;
Random ran = new Random();
ImageIcon pic;
Projectile()
{
}
Projectile(int _x, int _y, String dir, String att)
{
x = _x;
y = _y;
active = true;
dx = 0;
dy = 0;
direction = dir;
attribute = att;
usx = 0;
usy = 0;
usID = 0;
ID = ran.nextInt();
if(attribute.equalsIgnoreCase("IronBall"))
{
pic = new ImageIcon("data/IronBall.png");
//System.out.println("Iron Ball made");
width = 20;
height = 20;
}
if(attribute == "arrow")
{
if(direction.equalsIgnoreCase("up"))
dy = -7;
if(direction.equalsIgnoreCase("down"))
dy = 7;
if(direction.equalsIgnoreCase("right"))
dx = 7;
if(direction.equalsIgnoreCase("left"))
dx = -7;
if(attribute.equalsIgnoreCase("arrow"))
{
if(direction.equalsIgnoreCase("up"))
{
pic = new ImageIcon("data/ArrowUp1.png");
width = 5;
height = 10;
}
if(direction.equalsIgnoreCase("down"))
{
pic = new ImageIcon("data/ArrowDown1.png");
width = 5;
height = 10;
}
if(direction.equalsIgnoreCase("right"))
{
pic = new ImageIcon("data/ArrowRight1.png");
width = 10;
height = 5;
}
if(direction.equalsIgnoreCase("left"))
{
pic = new ImageIcon("data/ArrowLeft1.png");
width = 10;
height = 5;
}
}
}
if(attribute == "bomb")
{
pic = new ImageIcon("data/bomb.png");
width = 15;
height = 15;
}
}
public void setUserPos(int _x, int _y)
{
usx = _x;
usy = _y;
}
public void update()
{
if(t1 == 0)
t1 = System.currentTimeMillis();
t2 = System.currentTimeMillis();
if(attribute == "IronBall")
{
x = (int) (50 * Math.sin(t)) + usx;
y = (int) (50 *Math.cos(t)) + usy;
t += 0.2;
//System.out.println("Iron Ball Updated");
//System.out.println("Iron Ball" + usID + " X: " + x + " Iron Ball" + usID + " Y: " + y);
}
if(attribute == "arrow" )
{
//System.out.println(active);
if(x <= 0 || y <= 0 || x > 700 || y > 700)
{
dx = 0;
dy = 0;
active = false;
//System.out.println("Hit Wall");
}
else
{
x += dx;
y += dy;
}
}
if(attribute == "bomb" || attribute == "explosion")
{
int num = 0;
if(t2 - t1 > 1750)
{
num = 1;
}
if(t2 - t1 > 2750)
{
num = 2;
}
if(t2 - t1 > 3400)
num = 3;
/*if(t2 - t1 > 1170)
num = 4;
if(t2 - t1 > 2350)
num = 5;
if(t2 - t1 > 3450)
num = 6;*/
if(num == 1)
{
pic = new ImageIcon("data/BombRed.png");
width = 20;
height = 20;
}
if(num == 2)
{
pic = new ImageIcon("data/Explosion1.png");
attribute = "explosion";
width = 50;
height = 50;
}
if(num == 3)
{
x = -10;
y = -10;
width = 1;
height = 1;
}
}
}
public void draw(Graphics g, Component c)
{
//if( pic != null )
//{
g.drawImage(pic.getImage(),x,y,width,height,c);
//System.out.println("Position: " + x + "," + y);
//}
/*else
{
g.setColor(Color.RED);
g.drawRect(x, y, width, height);
}*/
}
}
import javax.swing.*;
public class Room {
ImageIcon back;
boolean cleared, passable, ent1, ent2, stage1, stage2, stage3;
String name;
String next;
int numdead;
long t1, t2;
Room(int num)
{
cleared = false;
passable = true;
ent1 = true;
ent2 = true;
stage1 = false;
stage2 = false;
stage3 = false;
numdead = 0;
t1 = 0;
t2 = 0;
next = "none";
if(num == 1)
{
back = new ImageIcon("data/EntryRoom.png");
name = "entry";
}
if(num == 2)
{
back = new ImageIcon("data/BaseRoom.png");
name = "base";
}
if(num == 3)
{
back = new ImageIcon("data/ArenaEntrance1.png");
name = "Arena Entry 1";
}
if(num == 4)
{
back = new ImageIcon("data/Arena1.png");
name = "Arena 1";
}
if(num == 5)
{
back = new ImageIcon("data/RoomRight1.png");
name = "Arena Entry 2";
}
if(num == 6)
{
back = new ImageIcon("data/RoomRight2.png");
name = "Arena 2";
}
if(num == 7)
{
back = new ImageIcon("data/TileMoveMap.png");
name = "MovingTilesRoom";
}
if(num == 8)
{
back = new ImageIcon("data/StairRoom.png");
name = "StairRoom";
}
if(num == 9)
{
back = new ImageIcon("data/ArenaEntrance3.png");
name = "Arena Entry 3";
}
if(num == 10)
{
back = new ImageIcon("data/FinalBoss1.png");
name = "Final Arena";
}
}
public void checkCollision(Enemy us)
{
//Base
//////////////////////////
if(name.equalsIgnoreCase("base"))
{
if(us.y > 485)
{
us.y = 485;
if(us.dy > 0)
{
us.dy = 0;
}
}
if(us.y < 50)
{
us.y = 50;
if(us.dy < 0)
{
us.dy = 0;
}
}
if(us.y > 40 && us.y < 170)
{
if(us.x < 55)
{
us.x = 55;
if(us.dx < 0)
{
us.dx = 0;
}
}
if(us.x > 505)
{
us.x = 505;
if(us.dx > 0)
{
us.dx = 0;
}
}
}
if(us.y > 165 && us.y < 215)
{
if(us.x > 475)
{
us.x = 475;
if(us.dx > 0)
{
us.dx = 0;
}
}
if(us.x < 90)
{
us.x = 90;
if(us.dx < 0)
{
us.dx = 0;
}
}
}
if(us.y > 90 && us.y < 360)
{
if(us.x > 475)
{
us.x = 475;
if(us.dx > 0)
{
us.dx = 0;
}
}
if(us.x < 90)
{
us.x = 90;
if(us.dx < 0)
{
us.dx = 0;
}
}
}
if(us.y < 275)
{
if(us.x < 215)
{
if(us.x > 200)
{
us.x = 200;
if(us.dx > 0)
{
us.dx = 0;
}
}
}
if(us.x > 350)
{
if(us.x < 365)
{
us.x = 365;
if(us.dx < 0)
{
us.dx = 0;
}
}
}
}
if(us.x > 215 && us.x < 275 || us.x > 290 && us.x < 350)//us.x < 350)
{
if(us.y < 270 && us.y > 230)
{
us.y = 270;
if(us.dy < 0)
{
us.dy = 0;
}
}
}
if(us.y > 365)
{
//else
//{
if(us.x < 55)
{
us.x = 55;
if(us.dx < 0)
{
us.dx = 0;
}
}
if(us.x > 505)
{
us.x = 505;
if(us.dx > 0)
{
us.dx = 0;
}
}
//}
}
/*if(us.y >= 410 && us.y <= 415)
{
if(us.x < 55)
{
cleared = true;
next = "left";
}
if(us.x > 505)
{
cleared = true;
next = "right";
}
}*/
}
///////////////////////////
//Arena Entry 1
if(name.equalsIgnoreCase("Arena Entry 1"))
{
//next = "none";
if(us.y > 480)
{
if(us.x > 95 && us.x < 275 || us.x > 325 && us.x < 415)
{
if(us.y < 490)
{
us.y = 490;
if(us.dy < 0)
{
us.dy = 0;
}
}
}
}
if(us.x > 235 && us.x < 335)
{
if(us.y < 120 && us.y > 65)
{
us.y = 120;
if(us.dy < 0)
{
us.dy = 0;
}
}
}
if(us.y < 120 && us.y > 65 & us.x < 165)
{
us.x = 165;
if(us.dx < 0)
{
us.dx = 0;
}
}
if(us.y < 480 && us.x < 335)
{
if(us.x > 325)
{
us.x = 325;
if(us.dx > 0)
{
us.dx = 0;
}
}
}
if(us.x > 220 && us.y < 495)
{
if(us.y > 435 && us.x < 275)
{
us.y = 435;
if(us.dy > 0)
{
us.dy = 0;
}
}
if(us.y > 120)
{
if(us.x < 235)
{
us.x = 235;
if(us.dx < 0)
{
us.dx = 0;
}
}
}
}
if(us.y < 50)
{
//else
//{
us.y = 50;
if(us.dy < 0)
{
us.dy = 0;
}
//}
}
if(us.x < 95)
{
us.x = 95;
if(us.dx < 0)
{
us.dx = 0;
}
}
if(us.y > 495)
{
us.y = 495;
if(us.dy > 0)
{
us.dy = 0;
}
}
if(us.y > 385 && us.x > 400)
{
if(us.y < 400)
{
us.y = 400;
if(us.dy < 0)
{
us.dy = 0;
}
}
if(us.y >= 410 && us.y <= 420)
{
//else if(us.x < 415)
//{
us.x = 415;
if(us.dx < 0)
{
us.dx = 0;
}
//}
}
else if(us.x > 465)
{
us.x = 465;
if(us.dx > 0)
{
us.dx = 0;
}
}
else
{
if(us.x < 415 && us.y < 490)
{
us.x = 415;
if(us.dx < 0)
{
us.dx = 0;
}
}
}
}
}
///////////////////////////////
if(name.equalsIgnoreCase("Arena 1"))
{
if(us.y <= 445 && us.y >= 160)
{
if(us.x < 55)
{
us.x = 55;
if(us.dx < 0)
{
us.dx = 0;
}
}
if(us.x > 515)
{
us.x = 515;
if(us.dx > 0)
{
us.dx = 0;
}
}
}
if(us.y < 75)
{
us.y = 75;
if(us.dy < 0)
{
us.dy = 0;
}
}
if(us.x > 450 && us.x <= 515 || us.x > 55 && us.x < 120)
{
if(us.y < 160)
{
us.y = 160;
if(us.dy < 0)
{
us.dy = 0;
}
}
if(us.y > 450)
{
us.y = 450;
if(us.dy > 0)
{
us.dy = 0;
}
}
}
//else
//{
if(us.y > 525)
{
us.y = 525;
if(us.dy > 0)
{
us.dy = 0;
}
}
//}
}
if(name.equalsIgnoreCase("StairRoom"))
{
if(us.y > 500)
{
us.y = 500;
}
if(us.x > 475)
{
us.x = 475;
}
if(us.x < 85)
{
us.x = 85;
}
if(us.y < 35)
{
us.y = 35;
}
if((us.x <= 125 && us.x >= 85) || (us.x <= 475 && us.x >= 435))
{
if(us.y < 375 && us.y > 330)
{
us.y = 375;
}
if(us.y > 90 && us.y < 115)
{
us.y = 90;
}
}
if((us.y < 450 && us.y >= 375) || (us.y <= 95 && us.y > 55))
{
if(us.x > 120 && us.x < 130)
{
us.x = 120;
}
if(us.x < 440 && us.x > 430)
{
us.x = 440;
}
}
if((us.x < 440 && us.x > 305) || (us.x < 255 && us.x > 120))
{
if(us.y < 450 && us.y > 420)
{
us.y = 450;
}
if(us.y > 55 && us.y < 65)
{
us.y = 55;
}
}
if((us.y <= 390 && us.y >= 325) || (us.y >= 100 && us.y < 165))
{
if(us.x < 215 && us.x > 205)
{
us.x = 215;
}
if(us.x > 345 && us.x < 355)
{
us.x = 345;
}
}
if(((us.x > 125 && us.x < 215) || (us.x > 345 && us.x < 440)) && us.y < 330 && us.y > 150)
{
if(us.y > 315)
{
us.y = 315;
}
if(us.y < 170)
{
us.y = 170;
}
}
if((us.y <= 315 && us.y >= 170))
{
if(us.x < 145)
{
us.x = 145;
}
if(us.x > 415)
{
us.x = 415;
}
}
}
}
//Hero Collision
public void checkCollision(Hero us)
{
if(name.equalsIgnoreCase("entry"))
{
if(us.x < 95)
{
us.x = 95;
if(us.dx < 0)
{
us.dx = 0;
}
}
if(us.x > 465)
{
us.x = 465;
if(us.dx > 0)
{
us.dx = 0;
}
}
if(us.y > 485)
{
us.y = 485;
if(us.dy > 0)
{
us.dy = 0;
}
}
if(us.y < 45)
{
if(us.x > 270 && us.x < 290)
{
cleared = true;
us.x = 280;
us.y = 480;
}
else
{
us.y = 45;
if(us.dy < 0)
{
us.dy = 0;
}
}
}
if(us.y >= 460)
{
//System.out.println("Below 465");
if(us.x > 200 && us.x < 360)
{
//System.out.println("Between 209 & 351");
if(us.x > 200 && us.x < 275 && us.y < 465)
{
us.y = 465;
if(us.dy < 0)
{
us.dy = 0;
}
}
if(us.x > 285 && us.x < 355 && us.y < 465)
{
us.y = 465;
if(us.dy < 0)
{
us.dy = 0;
}
}
if(us.x < 210)
{
//System.out.println("Past left bound");
us.x = 210;
if(us.dx < 0)
{
us.dx = 0;
}
}
if(us.x > 350)
{
//System.out.println("Past right bound");
us.x = 350;
if(us.dx > 0)
{
us.dx = 0;
}
}
}
}
if(us.y > 415 && us.y < 460)
{
//System.out.println("Between 415 & 455");
if(us.x > 260 && us.x < 295)
{
if(us.x < 270)
{
//System.out.println("Past left bound");
us.x = 275;
if(us.dx < 0)
{
us.dx = 0;
}
}
if(us.x > 285)
{
//System.out.println("Past right bound");us.x = 285;
if(us.dx > 0)
{
us.dx = 0;
}
}
}
}
if(us.y < 420)
{
if(us.x > 120 && us.x < 270)
{
if(us.y > 410)
{
us.y = 410;
if(us.dy > 0)
{
us.dy = 0;
}
}
}
if(us.x > 280 && us.x < 445)
{
if(us.y > 410)
{
us.y = 410;
if(us.dy > 0)
{
us.dy = 0;
}
}
}
}
if(us.y > 415)
{
if(us.x > 420 && us.x < 465)
{
if(us.x < 440)
{
us.x = 440;
if(us.dx < 0)
{
us.dx = 0;
}
}
}
if(us.x > 95 && us.x < 135)
{
if(us.x > 125)
{
us.x = 125;
if(us.dx > 0)
{
us.dx = 0;
}
}
}
}
}
//Entry
//////////////////////////
//Base
//////////////////////////
if(name.equalsIgnoreCase("base"))
{
if(us.y > 485)
{
us.y = 485;
if(us.dy > 0)
{
us.dy = 0;
}
}
if(us.y < 50)
{
if(us.x >= 275 && us.x <= 290 && us.num == 3)
{
next = "up";
us.x = 285;
us.y = 475;
}
else
{
us.y = 50;
if(us.dy < 0)
{
us.dy = 0;
}
}
}
if(us.y > 40 && us.y < 170)
{
if(us.x < 55)
{
us.x = 55;
if(us.dx < 0)
{
us.dx = 0;
}
}
if(us.x > 505)
{
us.x = 505;
if(us.dx > 0)
{
us.dx = 0;
}
}
}
if(us.y > 165 && us.y < 215)
{
if(us.x > 475)
{
us.x = 475;
if(us.dx > 0)
{
us.dx = 0;
}
}
if(us.x < 90)
{
us.x = 90;
if(us.dx < 0)
{
us.dx = 0;
}
}
}
if(us.y > 90 && us.y < 360)
{
if(us.x > 475)
{
us.x = 475;
if(us.dx > 0)
{
us.dx = 0;
}
}
if(us.x < 90)
{
us.x = 90;
if(us.dx < 0)
{
us.dx = 0;
}
}
}
if(us.y < 275)
{
if(us.x < 215)
{
if(us.x > 200)
{
us.x = 200;
if(us.dx > 0)
{
us.dx = 0;
}
}
}
if(us.x > 350)
{
if(us.x < 365)
{
us.x = 365;
if(us.dx < 0)
{
us.dx = 0;
}
}
}
}
if(us.x > 215 && us.x < 275 || us.x > 290 && us.x < 350)//us.x < 350)
{
if(us.y < 270 && us.y > 230)
{
us.y = 270;
if(us.dy < 0)
{
us.dy = 0;
}
}
}
if(us.y > 365)
{
if(us.y >= 410 && us.y <= 420)
{
if(us.x < 55)
{
cleared = true;
next = "left";
us.x = 465;
us.y = 415;
}
if(us.x > 505)
{
cleared = true;
next = "right";
us.x = 85;
us.y = 265;
}
}
else
{
if(us.x < 55)
{
us.x = 55;
if(us.dx < 0)
{
us.dx = 0;
}
}
if(us.x > 505)
{
us.x = 505;
if(us.dx > 0)
{
us.dx = 0;
}
}
}
}
/*if(us.y >= 410 && us.y <= 415)
{
if(us.x < 55)
{
cleared = true;
next = "left";
}
if(us.x > 505)
{
cleared = true;
next = "right";
}
}*/
}
///////////////////////////
//Arena Entry 1
if(name.equalsIgnoreCase("Arena Entry 1"))
{
//next = "none";
if(us.y > 480)
{
if(us.x > 95 && us.x < 275 || us.x > 325 && us.x < 415)
{
if(us.y < 490)
{
us.y = 490;
if(us.dy < 0)
{
us.dy = 0;
}
}
}
}
if(us.x > 235 && us.x < 335)
{
if(us.y < 120 && us.y > 65)
{
us.y = 120;
if(us.dy < 0)
{
us.dy = 0;
}
}
}
if(us.y < 120 && us.y > 65 & us.x < 165)
{
us.x = 165;
if(us.dx < 0)
{
us.dx = 0;
}
}
if(us.y < 480 && us.x < 335)
{
if(us.x > 325)
{
us.x = 325;
if(us.dx > 0)
{
us.dx = 0;
}
}
}
if(us.x > 220 && us.y < 495)
{
if(us.y > 435 && us.x < 275)
{
us.y = 435;
if(us.dy > 0)
{
us.dy = 0;
}
}
if(us.y > 120)
{
if(us.x < 235)
{
us.x = 235;
if(us.dx < 0)
{
us.dx = 0;
}
}
}
}
if(us.y < 50)
{
if(us.x > 265 && us.x < 295 && ent1)
{
next = "up";
us.x = 275;
us.y = 545;
us.num = 1;
}
else
{
us.y = 50;
if(us.dy < 0)
{
us.dy = 0;
}
}
}
if(us.x < 95)
{
us.x = 95;
if(us.dx < 0)
{
us.dx = 0;
}
}
if(us.y > 495)
{
us.y = 495;
if(us.dy > 0)
{
us.dy = 0;
}
}
if(us.y > 385 && us.x > 400)
{
if(us.y < 400)
{
us.y = 400;
if(us.dy < 0)
{
us.dy = 0;
}
}
if(us.y >= 410 && us.y <= 420)
{
if(us.x > 470)
{
next = "right";
us.x = 55;
us.y = 410;
}
else if(us.x < 415)
{
us.x = 415;
if(us.dx < 0)
{
us.dx = 0;
}
}
}
else if(us.x > 465)
{
us.x = 465;
if(us.dx > 0)
{
us.dx = 0;
}
}
else
{
if(us.x < 415 && us.y < 490)
{
us.x = 415;
if(us.dx < 0)
{
us.dx = 0;
}
}
}
}
}
///////////////////////////////
if(name.equalsIgnoreCase("Arena 1"))
{
if(us.y <= 445 && us.y >= 160)
{
if(us.x < 55)
{
us.x = 55;
if(us.dx < 0)
{
us.dx = 0;
}
}
if(us.x > 515)
{
us.x = 515;
if(us.dx > 0)
{
us.dx = 0;
}
}
}
if(us.y < 75)
{
us.y = 75;
if(us.dy < 0)
{
us.dy = 0;
}
}
if(us.x > 450 && us.x <= 515 || us.x > 55 && us.x < 120)
{
if(us.y < 160)
{
us.y = 160;
if(us.dy < 0)
{
us.dy = 0;
}
}
if(us.y > 450)
{
us.y = 450;
if(us.dy > 0)
{
us.dy = 0;
}
}
}
if(cleared)
{
passable = false;
if(us.y > 525)
{
next = "down";
us.x = 285;
us.y = 50;
}
}
else
{
if(us.y > 525)
{
us.y = 525;
if(us.dy > 0)
{
us.dy = 0;
}
}
}
}
if(name.equalsIgnoreCase("Arena Entry 2"))
{
if(us.y < 80)
{
if(us.x >= 270 && us.x <= 295 && ent2)
{
next = "up";
us.y = 450;
us.x = 285;
us.num = 0;
}
else
{
us.y = 80;
if(us.dy < 0)
{
us.dy = 0;
}
}
}
if(us.y > 445)
{
us.y = 445;
if(us.dy > 0)
{
us.dy = 0;
}
}
if(us.x > 485)
{
us.x = 485;
if(us.dx > 0)
{
us.dx = 0;
}
}
if(us.x < 80)
{
if(us.y <= 280 && us.y >= 255)
{
next = "left";
us.x = 500;
us.y = 410;
}
else
{
us.x = 80;
if(us.dx < 0)
{
us.dx = 0;
}
}
}
}
if(name.equalsIgnoreCase("Arena 2"))
{
if(us.x > 485)
{
us.x = 485;
if(us.dx > 0)
{
us.dx = 0;
}
}
if(us.x < 85)
{
us.x = 85;
if(us.dx < 0)
{
us.dx = 0;
}
}
if(us.y < 80)
{
us.y = 80;
if(us.dy < 0)
{
us.dy = 0;
}
}
if(us.y > 410)
{
if(us.x < 175)
{
us.x = 175;
if(us.dx < 0)
{
us.dx = 0;
}
}
if(us.x > 390)
{
us.x = 390;
if(us.dx > 0)
{
us.dx = 0;
}
}
}
if(us.y > 365 && us.y < 410)
{
if(us.x < 135)
{
us.x = 135;
if(us.dx < 0)
{
us.dx = 0;
}
}
if(us.x > 430)
{
us.x = 430;
if(us.dx > 0)
{
us.dx = 0;
}
}
}
if(us.y < 135)
{
if(us.x < 255)
{
us.x = 255;
if(us.dx < 0)
{
us.dx = 0;
}
}
if(us.x > 310)
{
us.x = 310;
if(us.dx > 0)
{
us.dx = 0;
}
}
}
if(us.y > 135 && us.y < 180)
{
if(us.x < 135)
{
us.x = 135;
if(us.dx < 0)
{
us.dx = 0;
}
}
if(us.x > 430)
{
us.x = 430;
if(us.dx > 0)
{
us.dx = 0;
}
}
}
if(cleared)
{
passable = false;
if(us.y > 465)
{
next = "down";
us.x = 285;
us.y = 50;
}
}
if(us.y > 465)
{
us.y = 465;
if(us.dy > 0)
{
us.dy = 0;
}
}
}
if(name.equalsIgnoreCase("MovingTilesRoom"))
{
if(us.y > 420)
{
if(us.x <= 280)
{
us.x = 280;
if(us.dx < 0)
us.dx = 0;
}
if(us.x > 300 && us.x < 445 && us.y > 445)
{
us.y = 445;
}
if(us.x >= 280 && us.x < 420 && us.y < 435)
{
us.y = 435;
}
}
if(us.y >= 450 && us.x > 295)
{
us.x = 295;
}
if(us.y >= 365 && us.x > 440 && us.passable == false)
{
us.x = 440;
//System.out.println("Error Here");
}
if(us.y < 425 && us.y >= 365 && us.x > 415)
{
if(us.x < 425 && us.passable == false)
us.x = 425;
}
////////////////////////////////////////////////////////////////////////// Need to figure out how not to walk on black background
if(us.x <= 445 && us.x >= 425)
{
if(us.y <= 405 && us.y > 355)
{
if(us.y < 365)// && !us.passable)
{
us.y = 365;
System.out.println("Cannot Pass");
}
}
}
//////////////////////////////////////////////////////////////////////////
if(us.y > 500)
{
us.y = 500;
}
if(cleared)
{
if(us.y > 80)
{
us.y = 80;
}
if(us.x < 418)
{
us.x = 418;
}
if(us.x > 438)
{
us.x = 438;
}
}
if(us.y < 50)
{
if(us.x >= 424 && us.x <= 438)
{
next = "up";
us.direction = "right";
us.pic = new ImageIcon("data/LinkStandingRight.png");
System.out.println("Next Room");
us.x = 85;
us.y = 420;
//us.x = 160;
//us.y = 475;
}
else
{
us.y = 50;
}
}
}
if(name.equalsIgnoreCase("StairRoom"))
{
if(us.y > 500)
{
us.y = 500;
}
if(us.x > 475)
{
us.x = 475;
}
if(us.x < 85)
{
us.x = 85;
}
if(us.y < 35)
{
if(us.x >= 265 && us.x <= 290)
{
next = "up";
us.x = 130;
us.y = 475;
}
else
{
us.y = 35;
}
}
if((us.x <= 125 && us.x >= 85) || (us.x <= 475 && us.x >= 435))
{
if(us.y < 375 && us.y > 330)
{
us.y = 375;
}
if(us.y > 90 && us.y < 115)
{
us.y = 90;
}
}
if((us.y < 450 && us.y >= 375) || (us.y <= 95 && us.y > 55))
{
if(us.x > 120 && us.x < 130)
{
us.x = 120;
}
if(us.x < 440 && us.x > 430)
{
us.x = 440;
}
}
if((us.x < 440 && us.x > 305) || (us.x < 255 && us.x > 120))
{
if(us.y < 450 && us.y > 420)
{
us.y = 450;
}
if(us.y > 55 && us.y < 65)
{
us.y = 55;
}
}
if((us.y <= 390 && us.y >= 325) || (us.y >= 100 && us.y < 165))
{
if(us.x < 215 && us.x > 205)
{
us.x = 215;
}
if(us.x > 345 && us.x < 355)
{
us.x = 345;
}
}
if(((us.x > 125 && us.x < 215) || (us.x > 345 && us.x < 440)) && us.y < 330 && us.y > 150)
{
if(us.y > 315)
{
us.y = 315;
}
if(us.y < 170)
{
us.y = 170;
}
}
if((us.y <= 315 && us.y >= 170))
{
if(us.x < 145)
{
us.x = 145;
}
if(us.x > 415)
{
us.x = 415;
}
}
/*if((us.x >= 215 && us.x < 255) || (us.x > 305 && us.x <= 345 ))
{
if(us.y < 110 && us.y > 90)
{
us.y = 110;
}
if(us.y > 390 && us.x < 410)
{
us.y = 390;
}
}*/
}
if(name.equalsIgnoreCase("Arena Entry 3"))
{
if(us.y > 475)
{
us.y = 475;
}
if(us.x < 45)
{
us.x = 45;
}
if(us.y < 90)
{
us.y = 90;
}
if((us.y <= 480 && us.y > 330) || (us.y >= 85 && us.y < 230))
{
if(us.x > 235 && us.x < 245)
{
us.x = 235;
}
if(us.x < 340 && us.x > 330)
{
us.x = 340;
}
}
if(us.x >= 245 && us.x <= 330)
{
if(us.y < 240)
{
us.y = 240;
}
if(us.y > 330)
{
us.y = 330;
}
}
if(us.y > 160 && us.y < 400)
{
if(us.x > 195 && us.x < 375)
{
if(us.x < 210)
{
us.x = 210;
}
if(us.x > 365)
{
us.x = 365;
}
}
if(us.x < 90 && us.x > 70)
{
us.x = 70;
}
if(us.x < 510 && us.x > 500)
{
us.x = 510;
}
}
if((us.x <= 195 && us.x >= 90) || (us.x >= 375 && us.x <= 500))
{
if(us.y < 400 && us.y > 390)
{
us.y = 400;
}
if(us.y > 160 && us.y < 170)
{
us.y = 160;
}
//System.out.println("Here");
}
if(us.x > 525)
{
if(us.y >= 275 && us.y <= 295)
{
next = "left";
us.direction = "up";
us.pic = new ImageIcon("data/LinkStandingUp.png");
//System.out.println("Next Room");
us.x = 280;
us.y = 525;
}
else
{
us.x = 525;
}
}
}
if(name.equalsIgnoreCase("Final Arena"))
{
if(!stage1)
{
if((us.x > 30 && us.x < 220) || (us.x > 345 && us.x < 535))
{
//System.out.println("Within Bounds . . . .");
if(us.y < 495)
{
us.y = 495;
}
}
if(us.y > 535)
{
us.y = 535;
}
if(us.y > 490 && us.y < 540)
{
if(us.x < 40)
{
us.x = 40;
}
if(us.x > 525)
{
us.x = 525;
}
}
if(us.y < 395)
{
back = new ImageIcon("data/FinalBoss2.png");
stage1 = true;
}
}
if(stage1 && !stage2)
{
if(t1 == 0)
t1 = System.currentTimeMillis();
t2 = System.currentTimeMillis();
if(us.y > 390)
{
us.y = 390;
}
if(t2 - t1 > 3000)
{
stage2 = true;
back = new ImageIcon("data/FinalBoss3.png");
t1 = 0; t2 = 0;
}
}
if(stage1 && stage2)
{
if(us.x < 40)
{
us.x = 40;
}
if(us.x > 525)
{
us.x = 525;
}
if(us.y < 50)
{
us.y = 50;
}
if(us.y > 490)
{
us.y = 490;
}
}
}
}
}
import javax.swing.*;
public class UpdateThread extends Thread
{
DungeonPanel panel;
UpdateThread(DungeonPanel p)
{
panel = p;
}
public void run()
{
while(true)
{
panel.update();
try
{
Thread.sleep(50);
}
catch(Exception e){}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment