Modify and generate tiles on the map
Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
4f8552bd3c
commit
d5fd02c7da
Binary file not shown.
BIN
maps/world1.map
BIN
maps/world1.map
Binary file not shown.
@ -6,7 +6,9 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import sig.engine.Panel;
|
import sig.engine.Panel;
|
||||||
|
import sig.map.Map;
|
||||||
import sig.map.Maps;
|
import sig.map.Maps;
|
||||||
|
import sig.map.Tile;
|
||||||
import sig.objects.Player;
|
import sig.objects.Player;
|
||||||
import sig.engine.Object;
|
import sig.engine.Object;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
@ -42,10 +44,21 @@ public class RabiClone{
|
|||||||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
f.setVisible(true);
|
f.setVisible(true);
|
||||||
|
|
||||||
p.render();
|
|
||||||
|
|
||||||
OBJ.add(new Player(p));
|
OBJ.add(new Player(p));
|
||||||
|
|
||||||
|
for (int i=0;i<12;i++) {
|
||||||
|
CURRENT_MAP.getMap().ModifyTile(0, i, Tile.WALL);
|
||||||
|
}
|
||||||
|
for (int i=0;i<36;i++) {
|
||||||
|
CURRENT_MAP.getMap().ModifyTile(i, 11, Tile.FLOOR);
|
||||||
|
}
|
||||||
|
for (int i=0;i<10;i++) {
|
||||||
|
CURRENT_MAP.getMap().ModifyTile(i+5, 8, Tile.PLATFORM_LEDGE);
|
||||||
|
}
|
||||||
|
Map.SaveMap(CURRENT_MAP);
|
||||||
|
|
||||||
|
p.render();
|
||||||
|
|
||||||
long lastGameTime = System.nanoTime();
|
long lastGameTime = System.nanoTime();
|
||||||
while (true) {
|
while (true) {
|
||||||
long timePassed = System.nanoTime()-lastGameTime;
|
long timePassed = System.nanoTime()-lastGameTime;
|
||||||
|
@ -2,7 +2,6 @@ package sig.map;
|
|||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -17,10 +16,10 @@ public class Map {
|
|||||||
|
|
||||||
char[] tiles = new char[MAP_WIDTH*MAP_HEIGHT];
|
char[] tiles = new char[MAP_WIDTH*MAP_HEIGHT];
|
||||||
|
|
||||||
public static Map LoadMap(File mapFile) {
|
public static Map LoadMap(Maps map) {
|
||||||
try {
|
try {
|
||||||
Map newMap = new Map();
|
Map newMap = new Map();
|
||||||
DataInputStream stream = new DataInputStream(new FileInputStream(mapFile));
|
DataInputStream stream = new DataInputStream(new FileInputStream(map.getFile()));
|
||||||
int marker=0;
|
int marker=0;
|
||||||
while (stream.available()!=0) {
|
while (stream.available()!=0) {
|
||||||
newMap.tiles[marker++]=stream.readChar();
|
newMap.tiles[marker++]=stream.readChar();
|
||||||
@ -33,12 +32,12 @@ public class Map {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SaveMap(Map map, File mapFile) {
|
public static void SaveMap(Maps map) {
|
||||||
try {
|
try {
|
||||||
int marker=0;
|
int marker=0;
|
||||||
DataOutputStream stream = new DataOutputStream(new FileOutputStream(mapFile));
|
DataOutputStream stream = new DataOutputStream(new FileOutputStream(map.getFile()));
|
||||||
while (marker<map.tiles.length) {
|
while (marker<map.getMap().tiles.length) {
|
||||||
stream.writeChar(map.tiles[marker++]);
|
stream.writeChar(map.getMap().tiles[marker++]);
|
||||||
}
|
}
|
||||||
stream.close();
|
stream.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -47,6 +46,7 @@ public class Map {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void ModifyTile(int x,int y,Tile t) {
|
public void ModifyTile(int x,int y,Tile t) {
|
||||||
tiles[y*MAP_WIDTH+x]=(char)t.ordinal();
|
tiles[y*MAP_WIDTH+x]=(char)(t.ordinal());
|
||||||
|
//System.out.println("Tile "+(y*MAP_WIDTH+x)+" is now "+tiles[y*MAP_WIDTH+x]+".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,10 +9,15 @@ public enum Maps {
|
|||||||
|
|
||||||
final public static String MAPS_DIR = "maps";
|
final public static String MAPS_DIR = "maps";
|
||||||
Map map;
|
Map map;
|
||||||
|
File file;
|
||||||
|
|
||||||
Maps(String filename) {
|
Maps(String filename) {
|
||||||
File map_loc = new File(new File("..",MAPS_DIR),filename);
|
file=new File(new File("..",MAPS_DIR),filename);
|
||||||
this.map=Map.LoadMap(map_loc);
|
this.map=Map.LoadMap(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getFile() {
|
||||||
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map getMap() {
|
public Map getMap() {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package sig.map;
|
package sig.map;
|
||||||
|
|
||||||
public enum Tile {
|
public enum Tile {
|
||||||
|
VOID(0,0,true), //File is populated by 0s by default. This represents the void.
|
||||||
WALL(0,0),
|
WALL(0,0),
|
||||||
FLOOR(1,0),
|
FLOOR(1,0),
|
||||||
PLATFORM_LEDGE(2,0),
|
PLATFORM_LEDGE(2,0),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user