The Geek Biker

Rambles of a geek that rides a bike

Monthly Archives: March 2015

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

Java ASCII Maze game

Every now and then I get an urge to code. But I don’t care about the big long lasting-big thinking projects. Just something to keep me busy. So I thought I’d get my hands dirty in the world of ASCII mazes.

I’ve used libjcsi before in the past when I write TextWorld. It is pretty awesome and easy. So lets step through it.

So I’ve started Netbeans and started coding away without any planning on where I’m going with this.

/*
 * A small little game for me to ponder over and play around a bit.
 */
package asciimaze;

/**
 * The uber main class.
 * @author Tertius
 */
public class AsciiMaze {

 /**
 * @param args the command line arguments // meh- won't need these.
 */
 public static void main(String[] args) {
 // TODO code application logic here
 }
 
}

Cool…so probably need to download and start importing the libjcsi packages. Initialise it and use it.

So, what did I end up with for now:

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

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");
 /**
 * @param args the command line arguments -- meh, not going to use this
 */
 public static void main(String[] args) {
 //Need to initialise stuff
 //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.
 }
 
}

Think I’m almost done.