-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoardFace.java
More file actions
143 lines (126 loc) · 4.79 KB
/
BoardFace.java
File metadata and controls
143 lines (126 loc) · 4.79 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.Timer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.imageio.*;
import java.awt.image.*;
import java.io.*;
import java.util.Scanner;
public class BoardFace extends JPanel implements Runnable, MouseListener
{
private Dimension d;
int BOARD_WIDTH=500;
int BOARD_HEIGHT=500;
int x = 0;
int y = 0;
boolean mousePressed = false;//is true when mouse is pressed
BufferedImage img;
private Thread animator;
public BoardFace()
{
addMouseListener(this);
setFocusable(true);
d = new Dimension(BOARD_WIDTH, BOARD_HEIGHT);
if (animator == null ) {
animator = new Thread(this);
animator.start();
}
setDoubleBuffered(true);
}
public void paint(Graphics g){
super.paint(g);
Color consoleGrey = new Color (207, 202, 198);//main console color
Color screenGreen = new Color (168, 164, 5);//aka puke green
Color screenGrey = new Color(103, 104, 122);//for cover around screen
Color buttonRed = new Color (138, 1, 71);//for action buttons and dim led
Color buttonBlack = new Color (10, 11, 16);//for d pad
Color ledRed = new Color(222, 51, 31);//for bright led
Color textBlue = new Color(39, 43, 88);//for logo/text
g.setColor(Color.white);
g.fillRect(0, 0, d.width, d.height);
//create general gameboy shape
g.setColor(consoleGrey);
g.fillRect(100, 15, d.width/2+50, d.height-60);
//create buttons
g.setColor(buttonRed);
g.fillOval(325, 305, 35, 35);
g.fillOval(275, 345, 35, 35);
g.setColor(buttonBlack);
g.setFont (new Font("TimesRoman", Font.PLAIN, 175));
g.drawString("+", 120, 400);//this draws the dpad
//still need to do the start and select buttons
//create screen with panel and led
int coverWidth = 250;//this is the width of the screen cover
g.setColor(screenGrey);
g.fillRect((d.width/2) - (coverWidth/2), 40, coverWidth, 200);//draws screen cover
g.setColor(screenGreen);//aka puke green
int screenWidth = 150;//this is the width of the screen
g.fillRect((d.width/2) - (screenWidth/2), 65, screenWidth, 150);//draws screen
g.setColor(buttonRed);//for dim led
g.fillOval(145, 115, 10, 10);//draws dim led
g.setColor(Color.black);
//create gameboy logo
g.setColor(textBlue);//this is for gameboy logo/text
g.setFont (new Font("SansSerif", Font.BOLD, 12));//nintendo logo
g.drawString("DAN JOSHWA ", (d.width/2) - (coverWidth/2), 270);//draws my name
g.setFont (new Font("SansSerif", Font.ITALIC + Font.BOLD, 25));
g.drawString("GAMEBOY", 210, 270);//draws "gameboy logo"
try {
img = ImageIO.read(this.getClass().getResource("tetris.png"));//load the tetris img
} catch (IOException e) {
System.out.println("Image could not be read");
}
if (mousePressed)//if the mouse is pressed
{
g.drawImage(img,(d.width/2) - (screenWidth/2), 65, screenWidth, 150, null);//draws the tetris img over the screen
g.setColor(ledRed);
g.fillOval(145, 115, 10, 10);//and makes the led "light up"
}
Toolkit.getDefaultToolkit().sync();
g.dispose();
}
public void run() {
long beforeTime, timeDiff, sleep;
beforeTime = System.currentTimeMillis();
int animationDelay = 50;
long time =
System.currentTimeMillis();
while (true) {//infinite loop
// spriteManager.update();
repaint();
try {
time += animationDelay;
Thread.sleep(Math.max(0,time -
System.currentTimeMillis()));
}catch (InterruptedException e) {
System.out.println(e);
}//end catch
}//end while loop
}//end of run
public void mousePressed(MouseEvent e) {
int x = e.getX();
int y = e.getY();
mousePressed = true;//if the mouse is pressed this is true
}
public void mouseReleased(MouseEvent e) {
mousePressed = false;//once the mouse is released the bool is now false
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
}
}//end of class