Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Hello, I ' m trying to code a simple tanks game in java that looks like this. It's basically the tanks game on mathsisfun.com, I
Hello, Im trying to code a simple tanks game in java that looks like this. It's basically the tanks game on mathsisfun.com, Im trying to draw and render the terrain by reading it from a txt file where X represents the height of the terrain, T represents trees, and alphabet letters represents the default positions of the player tanks as shown in the photo.
Here's my current code, how do i read the leveltxt file and then draw the terrain by reading that file? Each level is read from a text file of characters x The size of the window should be x meaning each character in the file corresponds to x pixels. The terrain should comprise of a smooth curve that is formed from computing the moving average of values twice.
Current code:
App.java
package Tanks;
import org.checkerframework.checker.units.qual.A;
import processing.core.PApplet;
import processing.core.PImage;
import processing.data.JSONArray;
import processing.data.JSONObject;
import processing.event.KeyEvent;
import processing.event.MouseEvent;
import java.awt.;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io;
import java.util.;
public class App extends PApplet
public static final int CELLSIZE ; ;
public static final int CELLHEIGHT ;
public static final int CELLAVG ;
public static final int TOPBAR ;
public static int WIDTH ; CELLSIZEBOARDWIDTH;
public static int HEIGHT ; BOARDHEIGHTCELLSIZETOPBAR;
public static final int BOARDWIDTH WIDTHCELLSIZE;
public static final int BOARDHEIGHT ;
public static final int INITIALPARACHUTES ;
public static final int FPS ;
public String configPath;
public static Random random new Random;
Feel free to add any additional methods or attributes you want. Please put classes in different files.
public App
this.configPath "config.json";
Initialise the setting of the window size.
@Override
public void settings
sizeWIDTH HEIGHT;
Load all resources such as images. Initialise the elements such as the player and map elements.
PImage desertImage;
PImage forestImage;
PImage snowImage;
PImage treeOneImage;
PImage treeTwoImage;
@Override
public void setup
frameRateFPS;
desertImage loadImagegetClassgetResourceTanksdesertpnggetPath;
forestImage loadImagegetClassgetResourceTanksforestpnggetPath;
snowImage loadImagegetClassgetResourceTankssnowpnggetPath;
treeOneImage loadImagegetClassgetResourceTankstreepnggetPath;
treeTwoImage loadImagegetClassgetResourceTankstreepnggetPath;
See PApplet javadoc:
loadJSONObjectconfigPath
loadImagethisgetClassgetResourcefilenamegetPathtoLowerCaseLocaleROOTreplace;
Receive key pressed signal from the keyboard.
@Override
public void keyPressedKeyEvent event
Receive key released signal from the keyboard.
@Override
public void keyReleased
@Override
public void mousePressedMouseEvent e
TODO powerups, like repair and extra fuel and teleport
@Override
public void mouseReleasedMouseEvent e
float terrainHeights;
Draw all elements in the game by current frame.
@Override
public void draw
imagesnowImage WIDTH, HEIGHT;
display HUD:
TODO
display scoreboard:
TODO
TODO: Check user action
public static void mainString args
PApplet.mainTanksApp";
I attached a photo of the "leveltxt file that needs to be read and used to draw and render the terrain. Please help.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started