Modify and generate tiles on the map

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
Nic0Nic0Nii 3 years ago
parent 4f8552bd3c
commit d5fd02c7da
  1. BIN
      bin/RabiClone.jar
  2. BIN
      maps/world1.map
  3. 17
      src/sig/RabiClone.java
  4. 16
      src/sig/map/Map.java
  5. 9
      src/sig/map/Maps.java
  6. 1
      src/sig/map/Tile.java

Binary file not shown.

Binary file not shown.

@ -6,7 +6,9 @@ import java.util.ArrayList;
import java.util.List;
import sig.engine.Panel;
import sig.map.Map;
import sig.map.Maps;
import sig.map.Tile;
import sig.objects.Player;
import sig.engine.Object;
import java.awt.Toolkit;
@ -42,10 +44,21 @@ public class RabiClone{
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
p.render();
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();
while (true) {
long timePassed = System.nanoTime()-lastGameTime;

@ -2,7 +2,6 @@ package sig.map;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
@ -17,10 +16,10 @@ public class Map {
char[] tiles = new char[MAP_WIDTH*MAP_HEIGHT];
public static Map LoadMap(File mapFile) {
public static Map LoadMap(Maps map) {
try {
Map newMap = new Map();
DataInputStream stream = new DataInputStream(new FileInputStream(mapFile));
DataInputStream stream = new DataInputStream(new FileInputStream(map.getFile()));
int marker=0;
while (stream.available()!=0) {
newMap.tiles[marker++]=stream.readChar();
@ -33,12 +32,12 @@ public class Map {
return null;
}
public static void SaveMap(Map map, File mapFile) {
public static void SaveMap(Maps map) {
try {
int marker=0;
DataOutputStream stream = new DataOutputStream(new FileOutputStream(mapFile));
while (marker<map.tiles.length) {
stream.writeChar(map.tiles[marker++]);
DataOutputStream stream = new DataOutputStream(new FileOutputStream(map.getFile()));
while (marker<map.getMap().tiles.length) {
stream.writeChar(map.getMap().tiles[marker++]);
}
stream.close();
} catch (IOException e) {
@ -47,6 +46,7 @@ public class Map {
}
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";
Map map;
File file;
Maps(String filename) {
File map_loc = new File(new File("..",MAPS_DIR),filename);
this.map=Map.LoadMap(map_loc);
file=new File(new File("..",MAPS_DIR),filename);
this.map=Map.LoadMap(this);
}
public File getFile() {
return file;
}
public Map getMap() {

@ -1,6 +1,7 @@
package sig.map;
public enum Tile {
VOID(0,0,true), //File is populated by 0s by default. This represents the void.
WALL(0,0),
FLOOR(1,0),
PLATFORM_LEDGE(2,0),

Loading…
Cancel
Save