|
/* * Elude * By Tylor * * * */ import java.awt.image.BufferedImage; import javax.swing.JFrame; import java.awt.Dimension; import java.awt.Graphics; import javax.swing.JPanel; import java.io.PrintStream; import java.awt.Graphics; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import java.awt.Toolkit; import java.applet.*; import java.awt.*; import java.awt.image.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.text.*; import java.util.*; import java.util.zip.*;
public final class JGame extends JFrame { Grid grid; GameLoop gLoop; public static boolean p_up = false; public static boolean p_down = false; public static boolean p_left = false; public static boolean p_right = false; static Player player; static BufferedImage img;
public JGame() { super("Eludë 0.1"); this.grid = new Grid(); add(this.grid);
setDefaultCloseOperation(3); this.gLoop = new GameLoop(this); this.gLoop.start();
}
public void Menu() {
}
public static void main(String[] args) {
int a = 2; int b = "DSU".hashCode() % 3000; int c = "WXC".hashCode() % 3000; for (int i = 0; i <= c; i++) { a = (a ^ i) % b; } System.out.println(a); JGame fm = new JGame(); fm.setVisible(true); fm.setResizable(false); fm.setExtendedState(fm.MAXIMIZED_BOTH); fm.pack(); fm.show(); } } class Player implements KeyListener { int x; int buildings; Grid grid;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int y; int clevel = 1; String level = "Level: " + this.clevel; String version = "Eludë 0.1"; String user = "Player.gif";
boolean p_up = false; boolean p_down = false; boolean p_left = false; boolean p_right = false; int loop = 400; int startloop = 0; int backgroundx = 50; int backgroundy = 50; int backgroundx2 = 50; int backgroundy2 = 50; int backgroundx3 = 50; int backgroundy3 = 50; int backgroundx4 = 50; int backgroundy4 = 50;
BufferedImage image;
static int followx = 400; static int followy = 400; static boolean morex = false; static boolean morey = false;
public Player(int i, int a) { this.x = i; this.y = a; try { image = ImageIO.read(Player.class.getResource(this.user)); } catch (IOException e) { System.out.println("Image Not In Root"); } }
public void draw(Graphics g) { int gamespeed = 5; boolean boxagro = false;
g.fillRect(followx, followy, 20, 20);
g.drawString("Player", this.x - 2, this.y - 5); g.drawString(this.level, 0, screenSize.height - 25); g.drawString(this.version, screenSize.width - 90, screenSize.height - 25); //while ( startloop < loop) //{ Random generator = new Random(); backgroundx = generator.nextInt(screenSize.width); // System.out.println("backgroundX: " + backgroundx); backgroundy = generator.nextInt(screenSize.height); backgroundx2 = generator.nextInt(screenSize.width); //System.out.println("backgroundX2: " + backgroundx2); backgroundy2 = generator.nextInt(screenSize.height); backgroundx3 = generator.nextInt(screenSize.width); //System.out.println("backgroundX3: " + backgroundx3); backgroundy3 = generator.nextInt(screenSize.height); backgroundx4 = generator.nextInt(screenSize.width); backgroundy4 = generator.nextInt(screenSize.height); //} g.fillRect(backgroundx,backgroundy,5,5); g.fillRect(backgroundx2,backgroundy2,5,5); g.fillRect(backgroundx3,backgroundy3,5,5); g.fillRect(backgroundx4,backgroundy4,5,5);
g.drawImage(image, this.x, this.y, null); int ydiff = this.y - followy; int xdiff = this.x - followx; //System.out.println("Xdiff" + xdiff); //System.out.println("Ydiff" + ydiff); if (ydiff < 300 || (xdiff < 300)) { boxagro = true; } if (ydiff > 300 || (xdiff > 300) || (xdiff < -300) || (ydiff < -300)) { boxagro = false; //System.out.println(boxagro); } if (boxagro == true) { if ( this.y < followy) { if (followy > 0 ) { followy--;followy--; } } if ( this.y > followy ) { if (followy < screenSize.height - 30) { followy++; followy++; } } if ( this.x > followx) { if (followx > 0 ) { followx++;followx++; } } if ( this.x < followx) { if (followy < screenSize.width ) { followx--;followx--; } } }
if ((this.p_up == true) && (this.y > 25)) { this.y -= gamespeed;
} if ((this.p_down == true) && (this.y < screenSize.height - 55)) { this.y += gamespeed;
} if ((this.p_left == true) && (this.x > 10)) { this.x -= gamespeed;
} if ((this.p_right == true) && (this.x < screenSize.width - 35)) { this.x += gamespeed;
} }
public void keyPressed(KeyEvent ke) { if ((ke.getKeyCode() == 38) && (this.y > 15)) { //System.out.println("Y: " + this.y); this.p_up = true; //System.out.println("FollowY" + followy);
} if ((ke.getKeyCode() == 40) && (this.y < screenSize.height - 45)) { //System.out.println("Y: " + this.y); this.p_down = true; //System.out.println("FollowY" + followy);
} if ((ke.getKeyCode() == 37) && (this.x > 5)) {
//System.out.println("X: " + this.x); this.p_left = true; //System.out.println("FollowX" + followx); } if ((ke.getKeyCode() == 39) && (this.x < screenSize.width - 35)) { //System.out.println("X: " + this.x); this.p_right = true; //System.out.println("FollowX" + followx);
} if (ke.getKeyCode() == 16) { this.clevel += 1; this.level = ("Level: " + this.clevel); } }
public void keyReleased(KeyEvent ke) { if (ke.getKeyCode() == 38) { this.p_up = false; } if (ke.getKeyCode() == 40) { this.p_down = false; } if (ke.getKeyCode() == 37) { this.p_left = false; } if (ke.getKeyCode() == 39) { this.p_right = false; } }
public void keyTyped(KeyEvent ke) { } } class Grid extends JPanel { Player player;
public Grid() { setFocusable(true); requestFocus(); setBackground(Color.pink); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setBounds(0,0,screenSize.width, screenSize.height); setPreferredSize(new Dimension(screenSize.width, screenSize.height));
this.player = new Player(16, 16); addKeyListener(this.player); }
@Override public void paintComponent(Graphics g) { super.paintComponent(g); this.player.draw(g); } }
class GameLoop extends Thread {
//int gamespeed = 1; JGame game; public GameLoop(JGame g) { this.game = g; }
@Override public void run() { Player player; Grid grid; while (true) { this.game.repaint(); try { Thread.sleep(15L);
} catch (Exception e) { System.out.println("Error @ Thread.Sleep"); } } } }
|