-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRenderMap.java
More file actions
70 lines (62 loc) · 2.63 KB
/
RenderMap.java
File metadata and controls
70 lines (62 loc) · 2.63 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
// Copyright 2010 owners of the AI Challenge project
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
// of the License at http://www.apache.org/licenses/LICENSE-2.0 . Unless
// required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.
//
// Author: Jeff Cameron (jeff@jpcameron.com)
//
// This class is for testing the map rendering code. It loads one game state
// from a file and renders it.
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import java.awt.*;
import java.util.ArrayList;
public class RenderMap {
public static void main(String[] args) {
try {
if (args.length != 2) {
System.err.println("USAGE: java RenderMap map.txt image.png");
System.exit(1);
}
Game game = new Game(args[0], 100, 0, null);
if (game.Init() == 0) {
System.err.println("Error while loading map " + args[0]);
System.exit(1);
}
ArrayList<Color> colors = new ArrayList<Color>();
colors.add(new Color(106, 74, 60));
colors.add(new Color(74, 166, 60));
colors.add(new Color(204, 51, 63));
colors.add(new Color(235, 104, 65));
colors.add(new Color(237, 201, 81) );
Color bgColor = new Color(188, 189, 172);
Color textColor = Color.BLACK;
Font planetFont = new Font("Sans Serif", Font.BOLD, 11);
Font fleetFont = new Font("Sans serif", Font.PLAIN, 7);
GraphicsConfiguration gc = GraphicsEnvironment
.getLocalGraphicsEnvironment().getDefaultScreenDevice()
.getDefaultConfiguration();
BufferedImage image = gc.createCompatibleImage(640, 480);
Graphics2D _g = (Graphics2D)image.createGraphics();
// Turn on AA/Speed
_g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
_g.setRenderingHint(RenderingHints.KEY_RENDERING,
RenderingHints.VALUE_RENDER_SPEED);
_g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
//game.Render(640, 480, 0.0, null, colors, bgColor, textColor, planetFont, fleetFont, _g);
game.Render(640, 480, 0.0, null, colors, _g);
File file = new File(args[1]);
ImageIO.write(image, "png", file);
} catch (Exception e) {
System.err.println(e);
}
}
}