-
Notifications
You must be signed in to change notification settings - Fork 2
/
Lives.java
58 lines (54 loc) · 1.4 KB
/
Lives.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
/** the number of laser cannons per game
* author J Halstead
*/
import java.awt.Color;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.Graphics;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.Rectangle;
import java.io.File;
import java.io.IOException;
/**
*
* This class displays the number of lives on the screen to the player
*
*/
public class Lives extends ScreenObject
{
/**
*
* @param location location of the display
* @param size size of the display
*/
public Lives(Point location, Rectangle size)
{
super (location, size);
}
@Override
/**
* Draws the display of lives
*/
public void draw (Graphics g)
{
//import font
try{
Font finalFont = null;
File gameFont = new File("PressStart2P.ttf");
if (gameFont.exists()){
finalFont = Font.createFont(Font.TRUETYPE_FONT, gameFont).deriveFont(Font.PLAIN, 22f);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(finalFont);
}
}catch (FontFormatException e){
e.printStackTrace();
}catch (IOException f){
f.printStackTrace();
}
//draw the LIVES and add the lives from the screen class
g.setColor(Color.white);
g.setFont(new Font("Press Start 2P",Font.BOLD, 24));
g.drawString("LIVES:" + Screen.getLives(), location.x, location.y);
}
}