Add in data tile event collisions with player
Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
2d2b6d0844
commit
9bef6c0caf
@ -6,5 +6,10 @@ public class DataEvent implements Event{
|
||||
public boolean perform(int x, int y) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performCollision(int x, int y) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,9 +2,19 @@ package sig.events;
|
||||
|
||||
public interface Event{
|
||||
/**
|
||||
* Perform this event at position {@code (x,y)}.
|
||||
* Runs a constant update event on this tile at the given position.
|
||||
* @param x The X Coordinate in pixel space the event is occuring in. (NOT Tile coordinates)
|
||||
* @param y The Y Coordinate in pixel space the event is occuring in. (NOT Tile coordinates)
|
||||
* @return {@code True} to keep this event alive after it runs.
|
||||
* {@code False} to remove this event from the game after it runs.
|
||||
*/
|
||||
public boolean perform(int x, int y);
|
||||
/**
|
||||
* Runs a player collision event on this tile at the given position.
|
||||
* @param x The X Coordinate in pixel space the event is occuring in. (NOT Tile coordinates)
|
||||
* @param y The Y Coordinate in pixel space the event is occuring in. (NOT Tile coordinates)
|
||||
* @return {@code True} to keep this event alive after it runs.
|
||||
* {@code False} to remove this event from the game after it runs.
|
||||
*/
|
||||
public boolean performCollision(int x, int y);
|
||||
}
|
||||
|
@ -24,5 +24,10 @@ public class SpawnEvent implements Event{
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performCollision(int x, int y) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,17 +1,25 @@
|
||||
package sig.events;
|
||||
|
||||
import sig.RabiClone;
|
||||
import sig.map.Tile;
|
||||
|
||||
public class WaterEvent implements Event{
|
||||
|
||||
@Override
|
||||
public boolean perform(int x, int y) {
|
||||
char val1=RabiClone.CURRENT_MAP.getMap().getDataTileValue(x+1, y);
|
||||
char val2=RabiClone.CURRENT_MAP.getMap().getDataTileValue(x, y+1);
|
||||
if (val1!=0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performCollision(int x, int y) {
|
||||
char val1=RabiClone.CURRENT_MAP.getMap().getDataTileValue(x/Tile.TILE_WIDTH+1, y/Tile.TILE_HEIGHT);
|
||||
char val2=RabiClone.CURRENT_MAP.getMap().getDataTileValue(x/Tile.TILE_WIDTH, y/Tile.TILE_HEIGHT+1);
|
||||
if (val1!=Character.MAX_VALUE) {
|
||||
RabiClone.CURRENT_MAP.getMap().setWaterLevel(val1);
|
||||
System.out.println("Water level set to "+(int)RabiClone.CURRENT_MAP.getMap().getWaterLevel());
|
||||
} else {
|
||||
RabiClone.CURRENT_MAP.getMap().setWaterLevel(val2);
|
||||
System.out.println("Water level set to "+(int)RabiClone.CURRENT_MAP.getMap().getWaterLevel());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public enum DataTile {
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public boolean perform(int x, int y) {
|
||||
return event.perform(x, y);
|
||||
public Event getEvent() {
|
||||
return event;
|
||||
}
|
||||
}
|
||||
|
@ -266,12 +266,16 @@ public class Map {
|
||||
this.waterLevel = waterLevel;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* This will return the tile's value minus 8192.
|
||||
* This value represents a data tile value, but not
|
||||
* necessarily a data tile.
|
||||
*/
|
||||
public char getDataTileValue(int x,int y) {
|
||||
return (char)(data[y*Map.MAP_WIDTH+x]-8192);
|
||||
if (data[y*Map.MAP_WIDTH+x]>=8192) {
|
||||
return (char)(data[y*Map.MAP_WIDTH+x]-8192);
|
||||
} else {
|
||||
return Character.MAX_VALUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,11 @@ public enum Maps {
|
||||
}
|
||||
}
|
||||
|
||||
public char getDataTileValue(int x, int y) {
|
||||
/**
|
||||
* This will return the tile's raw data value.
|
||||
* Data Tile values will not have 8192 subtracted from itself through this function.
|
||||
*/
|
||||
public char getDataTileRawValue(int x, int y) {
|
||||
int index = y*Map.MAP_WIDTH+x;
|
||||
if (index<0||index>=this.map.data.length) {
|
||||
return (char)DataTile.NULL.ordinal();
|
||||
|
@ -146,8 +146,8 @@ public class EditorRenderer extends LevelRenderer{
|
||||
}
|
||||
if (dataTileView) {
|
||||
drawMapTileForDataTileMode(p,x,y);
|
||||
if (RabiClone.CURRENT_MAP.getDataTileValue(x, y)>=8192) {
|
||||
DrawDataTileValue(p,x*Tile.TILE_WIDTH-this.getX(),y*Tile.TILE_HEIGHT-this.getY(),RabiClone.CURRENT_MAP.getDataTileValue(x, y));
|
||||
if (RabiClone.CURRENT_MAP.getDataTileRawValue(x, y)>=8192) {
|
||||
DrawDataTileValue(p,x*Tile.TILE_WIDTH-this.getX(),y*Tile.TILE_HEIGHT-this.getY(),RabiClone.CURRENT_MAP.getDataTileRawValue(x, y));
|
||||
} else if (RabiClone.CURRENT_MAP.getDataTile(x, y)!=DataTile.NULL) {
|
||||
DrawDataTile(p,x*Tile.TILE_WIDTH-this.getX(),y*Tile.TILE_HEIGHT-this.getY(),RabiClone.CURRENT_MAP.getDataTile(x, y));
|
||||
}
|
||||
|
@ -45,8 +45,8 @@ public class LevelRenderer extends Object{
|
||||
if (x<0||x>Map.MAP_WIDTH) {
|
||||
continue;
|
||||
}
|
||||
if (RabiClone.CURRENT_MAP.getDataTileValue(x,y)<8192&&RabiClone.CURRENT_MAP.getDataTile(x,y)!=DataTile.NULL) {
|
||||
if (!RabiClone.CURRENT_MAP.getDataTile(x,y).perform(x*Tile.TILE_WIDTH,y*Tile.TILE_HEIGHT)) {
|
||||
if (RabiClone.CURRENT_MAP.getDataTileRawValue(x,y)<8192&&RabiClone.CURRENT_MAP.getDataTile(x,y)!=DataTile.NULL) {
|
||||
if (!RabiClone.CURRENT_MAP.getDataTile(x,y).getEvent().perform(x*Tile.TILE_WIDTH,y*Tile.TILE_HEIGHT)) {
|
||||
RabiClone.CURRENT_MAP.ModifyDataTile(x, y, DataTile.NULL);
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import sig.engine.Rectangle;
|
||||
import sig.engine.Sprite;
|
||||
import sig.engine.Transform;
|
||||
import sig.engine.objects.AnimatedObject;
|
||||
import sig.map.DataTile;
|
||||
import sig.map.Map;
|
||||
import sig.map.Tile;
|
||||
import sig.map.View;
|
||||
@ -81,6 +82,7 @@ public class Player extends PhysicsObject{
|
||||
super.update(updateMult);
|
||||
handleCameraRoomMovement();
|
||||
handleCollisionBatch();
|
||||
handleEventCollisions();
|
||||
|
||||
switch (state) {
|
||||
case ATTACK:
|
||||
@ -214,6 +216,19 @@ public class Player extends PhysicsObject{
|
||||
// System.out.println(state);
|
||||
}
|
||||
|
||||
private void handleEventCollisions() {
|
||||
int x = (int)getX()/Tile.TILE_WIDTH;
|
||||
int y = (int)getY()/Tile.TILE_HEIGHT;
|
||||
if (x>=0&&x<Map.MAP_WIDTH&&y>=0&&y<Map.MAP_HEIGHT) {
|
||||
char dataTileValue = RabiClone.CURRENT_MAP.getDataTileRawValue((int)getX()/Tile.TILE_WIDTH, (int)getY()/Tile.TILE_HEIGHT);
|
||||
if (dataTileValue<8192&&dataTileValue!=0) {
|
||||
if (!RabiClone.CURRENT_MAP.getDataTile(x, y).getEvent().performCollision((int)getX(), (int)getY())) {
|
||||
RabiClone.CURRENT_MAP.ModifyDataTile(x, y, DataTile.NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleCollisionBatch() {
|
||||
for (int p=0;p<collisionBatch.size();p++) {
|
||||
PhysicsObject pobj = collisionBatch.get(p);
|
||||
|
Loading…
x
Reference in New Issue
Block a user