rendered paste bodyimport java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.applet.*;
import java.net.*;
public class gauntletMain extends Applet implements Runnable, KeyListener
{
Thread thread;
Player player1;
Monster monster1;
//Wall wall1;
Wall[] wallArray = new Wall [1];
mapTile[] [] map001 = new mapTile [102] [77];
//position[] [] position = new position [102] [77];
private Image dbImage;
private Graphics dbg;
private int tileSize = 10;
String debug = "";
public class Wall
{
private int x_pos;
private int y_pos;
private int wallLength;
private int wallWidth;
public Wall (int x_, int y_, int length, int width)
{
x_pos = x_;
y_pos = y_;
wallLength = length;
wallWidth = width;
}
public int getX ()
{
return x_pos;
}
public void paint (Graphics g)
{
g.setColor (Color.black);
//g.fillRect (x_pos, y_pos, wallLength, wallWidth);
}
}
public class mapTile
{
private boolean passability = true;
private String tileName;
public void changePassability (boolean getNewPassability)
{
passability = getNewPassability;
}
}
public void position ()
{
debug = "No Boxes in the way";
if (map001 [player1.x_tile] [player1.y_tile + 1].passability == false)
{
player1.downTest = false;
debug = "DownTest is false";
}
else
{
player1.downTest = true;
}
if (player1.y_tile != 0)
{
if (map001 [player1.x_tile] [player1.y_tile - 1].passability == false)
{
player1.upTest = false;
debug = "UpTest is false";
}
else
{
player1.upTest = true;
}
}
//if (player1.x_tile != 10){
if (map001 [player1.x_tile + 1] [player1.y_tile].passability == false)
{
player1.rightTest = false;
debug = "RightTest is false";
}
else
{
player1.rightTest = true;
}
//}
if (player1.x_tile != 0)
{
if (map001 [player1.x_tile - 1] [player1.y_tile].passability == false)
{
player1.leftTest = false;
debug = "LeftTest is false";
}
else
{
player1.leftTest = true;
}
}
}
public void init ()
{
for (int i = 0 ; i < map001.length ; i++)
{
for (int j = 0 ; j < map001 [0].length ; j++)
{
map001 [i] [j] = new mapTile ();
}
}
setSize (1020, 770);
player1 = new Player (15, 15, 1, 1);
monster1 = new Monster (500, 300);
wallArray [0] = new Wall (0, 200, 620, 20);
//Top Wall==========================
for (int i = 0 ; i < 102 ; i++)
{
map001 [i] [0].changePassability (false);
}
//Left Wall =======================
for (int i = 0 ; i < 77 ; i++)
{
map001 [0] [i].changePassability (false);
}
//Bot Wall==========================
for (int i = 0 ; i < 102 ; i++)
{
map001 [i] [76].changePassability (false);
}
//Right Wall =======================
for (int i = 0 ; i < 77 ; i++)
{
map001 [101] [i].changePassability (false);
}
for (int i = 0 ; i < 20 ; i++)
{
map001 [i] [15].changePassability (false);
}
//System.out.println (x_tile);
addKeyListener (this);
}
//Method to start Thread==================
public void start ()
{
thread = new Thread (this);
thread.start ();
}
//Method to stop Thread===================
public void stop ()
{
thread.stop ();
}
public void run ()
{
Thread.currentThread ().setPriority (Thread.MIN_PRIORITY);
while (true)
{
repaint ();
for (int i = 0 ; i < wallArray.length ; i++)
{
player1.collision (wallArray [i].x_pos, wallArray [i].y_pos);
}
position ();
player1.move ();
monster1.move ();
try
{
Thread.sleep (40);
}
catch (InterruptedException ex)
{
break;
}
Thread.currentThread ().setPriority (Thread.MAX_PRIORITY);
}
}
public void paint (Graphics g)
{
player1.paint (g);
monster1.paint(g);
for (int j = 0 ; j < wallArray.length ; j++)
{
//g.fillRect (wallArray[j].x_pos, wallArray[j].y_pos, wallArray[j].wallLength, wallArray[j].wallWidth);
wallArray [j].paint (g);
}
for (int i = 0 ; i < map001.length ; i++)
{
for (int j = 0 ; j < map001 [0].length ; j++)
{
g.drawRect (i * tileSize, j * tileSize, tileSize, tileSize);
if (map001 [i] [j].passability == false)
{
g.fillRect (i * tileSize, j * tileSize, tileSize, tileSize);
}
}
}
g.drawString (debug, 100, 40);
}
public void update (Graphics g)
{
if (dbImage == null)
{
dbImage = createImage (this.getSize ().width, this.getSize ().height);
dbg = dbImage.getGraphics ();
}
dbg.setColor (getBackground ());
dbg.fillRect (0, 0, this.getSize ().width, this.getSize ().height);
dbg.setColor (getForeground ());
paint (dbg);
g.drawImage (dbImage, 0, 0, this);
}
public void keyPressed (KeyEvent e)
{
int key = e.getKeyCode ();
if (key == KeyEvent.VK_UP)
{
player1.moveUpward = true;
}
if (key == KeyEvent.VK_DOWN)
{
player1.moveDownward = true;
}
if (key == KeyEvent.VK_RIGHT)
{
player1.moveRight = true;
}
if (key == KeyEvent.VK_LEFT)
{
player1.moveLeft = true;
}
}
public void keyTyped (KeyEvent e)
{
}
//Makes the paddle stop when key is released
public void keyReleased (KeyEvent e)
{
int key = e.getKeyCode ();
if (key == KeyEvent.VK_UP)
{
player1.moveUpward = false;
}
if (key == KeyEvent.VK_DOWN)
{
player1.moveDownward = false;
}
if (key == KeyEvent.VK_RIGHT)
{
player1.moveRight = false;
}
if (key == KeyEvent.VK_LEFT)
{
player1.moveLeft = false;
}
}
public boolean keyDown (Event e, int key)
{
return true;
}
}