Newer
Older
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
package battle;
import asteroids.GameObject;
import asteroids.GameState;
import asteroids.Ship;
import math.Vector2d;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import static asteroids.Constants.*;
import static java.awt.Color.black;
public class BattleView extends JComponent {
static int offset = 0;
int scale;
// static int carSize = 5;
static Color bg = black;
SimpleBattle game;
// Font font;
Ship ship;
static double viewScale = 1.0;
public BattleView(SimpleBattle game) {
this.game = game;
scale = size.width - 2 * offset;
}
public void paintComponent(Graphics gx) {
Graphics2D g = (Graphics2D) gx;
AffineTransform at = g.getTransform();
g.translate((1 - viewScale) * width / 2, (1-viewScale)*height / 2);
// this was an experiment to turn it into a side-scroller
// but it produces a weird moving screen effect
// needs more logic in the drawing process
// to wrap the asteroids that have been projected off the screen
// g.translate(-(game.ship.s.x - width/2), 0);
g.scale(viewScale, viewScale);
game.draw(g);
g.setTransform(at);
paintState(g);
}
public void paintState(Graphics2D g) {
for (GameObject object : game.objects) {
object.draw(g);
}
g.setColor(Color.white);
g.setFont(font);
// String str = "" + game.score + " : " + game.list.nShips() + " : " + game.state
// + " : " + game.list.isSafe(game.ship) + " : " + game.nLives;
// FontMetrics fm = font.
String str = game.stats.get(0) + " " + game.stats.get(1);