Question: Hello, I ' m coding a simple tanks game in Java and and trying to draw, render and smooth the terrain from reading from a

Hello, I'm coding a simple tanks game in Java and and trying to draw, render and smooth the terrain from reading from a text file where X denotes the height of the terrain, T is the trees, and alphabet letters are the tanks default positions. The 2nd image is what my code currently outputs but i need the terrain to be smoothed accordingly as it shows in the first image. Here's my current code, could you please help me smooth my current terrains so it looks like the output in the first image? Thank you.
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.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
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 =32; //8;
public static final int CELLHEIGHT =32;
public static final int CELLAVG =32;
public static final int TOPBAR =0;
public static int WIDTH =864; //CELLSIZE*BOARD_WIDTH;
public static int HEIGHT =640; //BOARD_HEIGHT*CELLSIZE+TOPBAR;
public static final int BOARD_WIDTH = WIDTH/CELLSIZE;
public static final int BOARD_HEIGHT =20;
public static final int INITIAL_PARACHUTES =1;
public static final int FPS =30;
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(){
size(WIDTH, 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(){
size(WIDTH, HEIGHT);
terrainHeights = new float[BOARD_WIDTH];
Arrays.fill(terrainHeights, HEIGHT);
frameRate(FPS);
desertImage = loadImage(getClass().getResource("/Tanks/desert.png").getPath());
forestImage = loadImage(getClass().getResource("/Tanks/forest.png").getPath());
snowImage = loadImage(getClass().getResource("/Tanks/snow.png").getPath());
treeOneImage = loadImage(getClass().getResource("/Tanks/tree1.png").getPath());
treeTwoImage = loadImage(getClass().getResource("/Tanks/tree2.png").getPath());
try {
BufferedReader reader = new BufferedReader(new FileReader("level1.txt"));
String line;
int lineCount =0;
ArrayList lines = new ArrayList>();
while ((line = reader.readLine())!= null){
lines.add(line); // Collect all lines to process from top to bottom
}
// Process lines from bottom to top
for (int y = lines.size()-1; y >=0; y--){
line = lines.get(y);
for (int x =0; x Math.min(line.length(), BOARD_WIDTH); x++){
if (line.charAt(x)=='X'){
terrainHeights[x]= HEIGHT -(lines.size()- y)* CELLHEIGHT +2*CELLHEIGHT;
}
}
}
reader.close();
} catch (IOException e){
e.printStackTrace();
}
//See PApplet javadoc:
//loadJSONObject(configPath)
//loadImage(this.getClass().getResource(filename).getPath().toLowerCase(Locale.ROOT).replace("%20",""));
}
/**
* Receive key pressed signal from the keyboard.
*/
@Override
public void keyPressed(KeyEvent event){
}
/**
* Receive key released signal from the keyboard.
*/
@Override
public void keyReleased(){
}
@Override
public void mousePressed(MouseEvent e){
//TODO - powerups, like repair and extra fuel and teleport
}
@Override
public void mouseReleased(MouseEvent e){
}
float[] terrainHeights;
/**
* Draw all elements in the game by current frame.
*/
@Override
public void draw(){
image(snowImage,0,0, WIDTH, HEIGHT);
fill(255); // snow white color of this terrain
noStroke();
beginShape();
vertex(0, HEIGHT); // Start at bottom left
for (int x =0; x BOARD_WIDTH; x++){
vertex(x * CELLSIZE, terrainHeights[x]);
 Hello, I'm coding a simple tanks game in Java and and

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!