Home / Expert Answers / Computer Science / need-to-build-game-using-java-code-with-the-given-scaffold-nbsp-map-consists-of-a-grid-of-tiles-pa440

(Solved): need to build game using java code with the given scaffold:   map: consists of a grid of tiles ...



need to build game using java code with the given scaffold:

 

map:

consists of a grid of tiles 33x36

Each tile is 20x20 pixels, so the total is 720x660 pixels

The player always begins in the top-left corner of this grid

However, the bottom 60 pixels of the window are reserved for the information bar which contains text to display the current number of lives, spell cast cooldown bar, current level number, and timer remaining on the powerup's effect.

The window size is therefore 720x720

config:

The config file is in located in config.json in the root directory of the project

map layout:

X = stone walls, G is where gremlins should be placed,  B = brick walls, W is where the player starts from, E is the exit goal the player must reach to end the level and progress on to the next one

\( \equiv \) level1.txt
\( 33 \quad \) XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

wizard:

The player character is controlled using the arrow keys (up, down, left, right)

Movement should be smoothly transitioning from one tile space to another

The player begins in the tile 'W' on the map layout. The user must be actively holding the movement key for movement to occur, otherwise movement stops (when it reaches the next whole tile). The wizard may only stop movement on a whole tile space, not part-way between tiles

The wizard sprite should change depending on the direction they are facing:

The wizard can shoot fireballs by pressing the space bar. Fireballs travel in the direction the wizard is currently facing, until they hit an object

Fireballs can destroy brick walls, triggering the following animated destruction sequence,   with each image lasting for 4 frames.

After a fireball spell is cast, the wizard must wait for their mana to recharge as shown with a progress bar in the bottom right-hand corner of the screen. Different levels may make it more difficult or easier for the wizard to cast spells (cooldown is specified in the config per level)

gremlins:

When hit by a wizard's fireball, it will disappear and respawn in another empty area of the map, at least 10 tiles radius away from the player (in the process, absorbing the fireball).

Each gremlin throws slime projectiles in the direction of their current movement, with a frequency in seconds specified in the configuration JSON for that level.

If the gremlin hits a wall with more than one possible new direction to go in, it will randomly choose a new direction but won't go back the way it just came.

If the wizard comes into contact with a gremlin or its slime, they lose a life and the level is reset to its original state. If the wizard's fireball hits a gremlin's slime, the slime absorbs the fireball, and in the process is itself vapourised.

win lose conditons:

The current level is completed when the player reaches the exit. If there is another level, that level is then loaded with the player starting in the position defined in the map layout. The player retains the number of lives they had previously.

If there are no more levels and the player wins, display a screen saying "You win".

If the player loses all of their lives, display a screen saying "Game over".

CODE SCAFFOLD:

package gremlins;

import processing.core.PApplet;
import processing.core.PImage;
import processing.data.JSONObject;
import processing.data.JSONArray;

import java.util.Random;
import java.io.*;


public class App extends PApplet {

    public static final int WIDTH = 720;
    public static final int HEIGHT = 720;
    public static final int SPRITESIZE = 20;
    public static final int BOTTOMBAR = 60;

    public static final int FPS = 60;

    public static final Random randomGenerator = new Random();

    public String configPath;
    
    public PImage brickwall;
    public PImage stonewall;
    public PImage gremlin; 
    public PImage slime;
    public PImage fireball;


    public App() {
        this.configPath = "config.json";
    }

    /**
     * Initialise the setting of the window size.
    */
    public void settings() {
        size(WIDTH, HEIGHT);

    }

    /**
     * Load all resources such as images. Initialise the elements such as the player, enemies and map elements.
    */
    public void setup() {
        frameRate(FPS);

        // Load images during setup
        this.stonewall = loadImage(this.getClass().getResource("stonewall.png").getPath().replace("%20", " "));
        this.brickwall = loadImage(this.getClass().getResource("brickwall.png").getPath().replace("%20", " "));
        this.gremlin = loadImage(this.getClass().getResource("gremlin.png").getPath().replace("%20", " "));
        this.slime = loadImage(this.getClass().getResource("slime.png").getPath().replace("%20", " "));
        this.fireball = loadImage(this.getClass().getResource("fireball.png").getPath().replace("%20", " "));
        

        JSONObject conf = loadJSONObject(new File(this.configPath));


    }

    /**
     * Receive key pressed signal from the keyboard.
    */
    public void keyPressed(){

    }
    
    /**
     * Receive key released signal from the keyboard.
    */
    public void keyReleased(){

    }


    /**
     * Draw all elements in the game by current frame. 
         */
    public void draw() {
        
    }

    public static void main(String[] args) {
        PApplet.main("gremlins.App");
    }
}

you are provided with images of different walls, and gremlins and wizards 

end product should look like:

\( \equiv \) level1.txt \( 33 \quad \) XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


We have an Answer from Expert

View Expert Answer

Expert Answer


Window.java: import javax.swing.JFrame; public class Window extends JFrame { public Window() { setTitle("Project"); setSize(500, 400); setLocationRela
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe