This repository was archived by the owner on Nov 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoard.java
71 lines (64 loc) · 1.53 KB
/
Board.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import javax.swing.JPanel;
import javax.imageio.ImageIO;
import java.awt.Image;
import java.awt.Graphics;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.*;
public class Board extends JPanel implements Runnable
{
private Player player;
private Image bg;
//private java.awt.Rectangle bound;
public Board()
{
//java.awt.GraphicsEnvironment ge = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment();
//System.out.println(ge.getMaximumWindowBounds().height);
//java.awt.GraphicsDevice gd = ge.getDefaultScreenDevice();
// bound = gd.getDefaultConfiguration().getBounds();
this.setBackground(java.awt.Color.BLACK);
//System.out.println(ev.getKeyChar());
this.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent ev)
{
player.keyPressed(ev);
}
public void keyReleased(KeyEvent ev)
{
player.keyReleased(ev);
}
});
try
{
bg = ImageIO.read(this.getClass().getResource("lom-tree.jpg"));
}
catch(Exception e){}
this.setDoubleBuffered(true);
this.setFocusable(true);
player = new Player();
//this.setIgnoreRepaint(true);
new Thread(this).start();
}
public void run ()
{
while (true)
{
player.move();
repaint();
try
{
Thread.sleep(20);
}
catch (InterruptedException e)
{}
}
}
public void paint(Graphics g)
{
super.paint(g);
Location p = player.getPos();
g.drawImage(bg,0,0,800,600, this);// bound.width, bound.height, this);
g.drawImage(player.getImage(), p.x, p.y, this);
g.dispose();
}
}