The Geek Biker

Rambles of a geek that rides a bike

Java Ascii Maze game – The map

Cool, so we got the basic framework down. Actually, let me rephrase…we got the basic blueprint down.

Now we need to start adding some flesh to the skeleton.

One of the main issues I found working with ascii type games is the framerate limit. ultimate you are working with ascii characters as ‘sprites’ that don’t animate and also only move a block at a time. This has a major impact on your map limit. A lot of rogue like games that rely on graphics allow the user to move to the edge of the visible screen and then let the virtual map scroll until the dude hits an obstacle or the edge of the map.

I think it easier to have an ascii player jump to the next ‘screen map’ on the ‘world map’. This seems easier, but there are a few things to consider. When you hit the western edge of your screen map, then you want to flip to the new screen map, but start the player on the eastern edge. What if there was an obstacle generated on the new screen’s spawn point? Does that mean you have to look into the next map first to figure out if you can go there, and if you can’t, how do you ‘inform’ the player that there might be an obstacle on the other side?

Pretty sure we will hit this obstacle in the near future, but lets first get the basics down of the world map. Since I’m not planning this at all, we might see some major re-factoring in the later posts.

So lets create a world map object thing…After a bit of a refresher on lists.

/*
 * Here be the world map. Will consist of many screen maps. Should probably use
 * some sort of map of map of objects to grow this world dynamically. DAMN.
 */
package asciimaze.someobjects;

import java.util.ArrayList;
import java.util.List;

/**
 * This will probably change in the future
 * @author LordFluffyGoggles
 */
public class WorldMap {
 private List<List<Object>> worldMapX;
 private List<Object> worldMapY;
 
 public WorldMap(){
 worldMapY = new ArrayList<>();
 worldMapX = new ArrayList<>();
 worldMapX.add(worldMapY);
 }

 /**
 * Get the screenmap at some coordinates.
 * @param x
 * @param y
 * @return 
 */
 public Object getScreenMapAt(int x, int y){
 return worldMapX.get(x).get(y); //This will blow up on a null..boo..
 }
 
 
 /**
 * @return the worldMapX
 */
 public List<List<Object>> getWorldMapX() {
 return worldMapX;
 }

 /**
 * @param worldMapX the worldMapX to set
 */
 public void setWorldMapX(List<List<Object>> worldMapX) {
 this.worldMapX = worldMapX;
 }

 /**
 * @return the worldMapY
 */
 public List<Object> getWorldMapY() {
 return worldMapY;
 }

 /**
 * @param worldMapY the worldMapY to set
 */
 public void setWorldMapY(List<Object> worldMapY) {
 this.worldMapY = worldMapY;
 }
 
}

Now we need some game stuff to get cracking on. I’ll use this uber class to store the game stuff in. Including the wordmap, dude object etc.

/*
 * Storing the game stuff in here so we don't clutter teh awesome AsciiMaze 
 * class.
 */
package asciimaze.someobjects;

/**
 * Here goes everything
 * @author LordFluffyGoggles
 */
public class GameStuff {
 
 private WorldMap worldMap;
 
 public GameStuff(){
 worldMap = new WorldMap();
 }

 /**
 * @return the worldMap
 */
 public WorldMap getWorldMap() {
 return worldMap;
 }

 /**
 * @param worldMap the worldMap to set
 */
 public void setWorldMap(WorldMap worldMap) {
 this.worldMap = worldMap;
 }
 
}

Now to update the main class to get the game stuff initialised. Also, I shifted a few things around a bit.

/*
 * The uber main class
 * and open the template in the editor.
 */
package asciimaze;

import asciimaze.someobjects.GameStuff;
import net.slashie.libjcsi.ConsoleSystemInterface;
import net.slashie.libjcsi.wswing.WSwingConsoleInterface;

/**
 * Still the uber main class
 * @author Tertius
 */
public class AsciiMaze {
 //Initialised this bad ass ascii interface. 
 private ConsoleSystemInterface csi = new WSwingConsoleInterface("Ascii Maze");
 private GameStuff gameStuff;
 /**
 * @param args the command line arguments -- meh, not going to use this
 */
 public static void main(String[] args) {
 new AsciiMaze().run();
 }
 
 public void run () {
 //Need to initialise stuff
 initialiseStuff();
 //Need to create a map
 //Need to save the map into some sort of buffer
 //Need to get the key pressed
 //Need the check where the dude is going to move to
 //Need to check if the dude can move there
 //Move the dude if all is well on the western front (all fronts really)
 //Do some more buffer stuff
 //Probably need to put all of this in some sort of a loop. 
 }
 
 private void initialiseStuff(){
 gameStuff = new GameStuff(); 
 }
}


Next time, I’ll try to create a screen map and get something on screen to show for all this work.

 

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: