Created map structure and load/unload filesystem
Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
9ba0af090e
commit
8d943ef526
Binary file not shown.
23
src/sig/Maps.java
Normal file
23
src/sig/Maps.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package sig;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import sig.engine.Map;
|
||||||
|
|
||||||
|
public enum Maps {
|
||||||
|
|
||||||
|
WORLD1("world1.map"),
|
||||||
|
;
|
||||||
|
|
||||||
|
final public static String MAPS_DIR = "maps";
|
||||||
|
Map map;
|
||||||
|
|
||||||
|
Maps(String filename) {
|
||||||
|
File map_loc = new File(new File("..",MAPS_DIR),filename);
|
||||||
|
this.map=Map.LoadMap(map_loc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map getMap() {
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
}
|
@ -22,6 +22,8 @@ public class RabiClone{
|
|||||||
|
|
||||||
public static int BASE_WIDTH=512;
|
public static int BASE_WIDTH=512;
|
||||||
public static int BASE_HEIGHT=288;
|
public static int BASE_HEIGHT=288;
|
||||||
|
|
||||||
|
public static Maps CURRENT_MAP = Maps.WORLD1;
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
RabiClone r = new RabiClone();
|
RabiClone r = new RabiClone();
|
||||||
@ -43,9 +45,7 @@ public class RabiClone{
|
|||||||
|
|
||||||
p.render();
|
p.render();
|
||||||
|
|
||||||
for (int i=0;i<10;i++) {
|
OBJ.add(new Player(p));
|
||||||
OBJ.add(new Player(p));
|
|
||||||
}
|
|
||||||
|
|
||||||
long lastGameTime = System.nanoTime();
|
long lastGameTime = System.nanoTime();
|
||||||
while (true) {
|
while (true) {
|
||||||
|
44
src/sig/engine/Map.java
Normal file
44
src/sig/engine/Map.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package sig.engine;
|
||||||
|
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class Map {
|
||||||
|
//Maps contain 512x288 tiles, allowing for 16384x9216 pixels of action per map.
|
||||||
|
//294912 bytes = 294KB of memory storage per map.
|
||||||
|
//Since a screen normally fits 16x9 tiles, you get 32x32 (1024) screens of gameplay per world.
|
||||||
|
char[] tiles = new char[512*288];
|
||||||
|
|
||||||
|
public static Map LoadMap(File mapFile) {
|
||||||
|
try {
|
||||||
|
Map newMap = new Map();
|
||||||
|
DataInputStream stream = new DataInputStream(new FileInputStream(mapFile));
|
||||||
|
int marker=0;
|
||||||
|
while (stream.available()!=0) {
|
||||||
|
newMap.tiles[marker++]=stream.readChar();
|
||||||
|
}
|
||||||
|
stream.close();
|
||||||
|
return newMap;
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void SaveMap(Map map, File mapFile) {
|
||||||
|
try {
|
||||||
|
int marker=0;
|
||||||
|
DataOutputStream stream = new DataOutputStream(new FileOutputStream(mapFile));
|
||||||
|
while (marker<map.tiles.length) {
|
||||||
|
stream.writeChar(map.tiles[marker++]);
|
||||||
|
}
|
||||||
|
stream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,7 +11,7 @@ public class Player extends Object{
|
|||||||
|
|
||||||
public Player(Panel panel) {
|
public Player(Panel panel) {
|
||||||
super(panel);
|
super(panel);
|
||||||
this.setSprite(Sprite.NANA);
|
this.setSprite(Sprite.NANA_SMALL);
|
||||||
setX(Math.random()*RabiClone.BASE_WIDTH);
|
setX(Math.random()*RabiClone.BASE_WIDTH);
|
||||||
setY(Math.random()*RabiClone.BASE_HEIGHT);
|
setY(Math.random()*RabiClone.BASE_HEIGHT);
|
||||||
}
|
}
|
||||||
@ -27,7 +27,7 @@ public class Player extends Object{
|
|||||||
setX(getX()+(right-left)*32*updateMult);
|
setX(getX()+(right-left)*32*updateMult);
|
||||||
}
|
}
|
||||||
if (up-down!=0) {
|
if (up-down!=0) {
|
||||||
setY(getY()+(up-down)*32*updateMult);
|
setY(getY()+(down-up)*32*updateMult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
world1.map
Normal file
BIN
world1.map
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user