Tile modifying now modifies collision grid
Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
05a4165afc
commit
ed96d43935
@ -12,7 +12,9 @@ import java.util.List;
|
|||||||
import sig.engine.Panel;
|
import sig.engine.Panel;
|
||||||
import sig.engine.Point;
|
import sig.engine.Point;
|
||||||
import sig.engine.objects.Object;
|
import sig.engine.objects.Object;
|
||||||
|
import sig.map.Map;
|
||||||
import sig.map.Maps;
|
import sig.map.Maps;
|
||||||
|
import sig.map.Tile;
|
||||||
import sig.objects.ConfigureControls;
|
import sig.objects.ConfigureControls;
|
||||||
import sig.objects.EditorRenderer;
|
import sig.objects.EditorRenderer;
|
||||||
import sig.objects.LevelRenderer;
|
import sig.objects.LevelRenderer;
|
||||||
@ -58,7 +60,7 @@ public class RabiClone {
|
|||||||
static long lastReportedTime = System.currentTimeMillis();
|
static long lastReportedTime = System.currentTimeMillis();
|
||||||
public static long TIME = 0;
|
public static long TIME = 0;
|
||||||
|
|
||||||
public static boolean COLLISION[] = new boolean[BASE_WIDTH*BASE_HEIGHT];
|
public static boolean COLLISION[] = new boolean[(Tile.TILE_WIDTH*Map.MAP_WIDTH)*(Tile.TILE_HEIGHT*Map.MAP_HEIGHT)];
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.setProperty("sun.java2d.transaccel", "True");
|
System.setProperty("sun.java2d.transaccel", "True");
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package sig.map;
|
package sig.map;
|
||||||
|
|
||||||
public enum CollisionType {
|
public enum CollisionType {
|
||||||
BLOCK,
|
SOLID,
|
||||||
SLOPE,
|
|
||||||
NONE
|
NONE
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ import java.io.FileInputStream;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import sig.RabiClone;
|
||||||
|
|
||||||
public class Map {
|
public class Map {
|
||||||
//Maps contain 512x288 tiles, allowing for 16384x9216 pixels of action per map.
|
//Maps contain 512x288 tiles, allowing for 16384x9216 pixels of action per map.
|
||||||
//Since a screen normally fits 16x9 tiles, you get 32x32 (1024) screens of gameplay per world.
|
//Since a screen normally fits 16x9 tiles, you get 32x32 (1024) screens of gameplay per world.
|
||||||
@ -98,6 +100,16 @@ public class Map {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void ModifyTile(int x,int y,Tile t) {
|
public void ModifyTile(int x,int y,Tile t) {
|
||||||
|
Tile prevTile = Tile.values()[tiles[y*Map.MAP_WIDTH+x]];
|
||||||
|
boolean prevIsCollisionTile=prevTile.getCollision()==CollisionType.SOLID;
|
||||||
|
boolean newIsCollisionTile=t.getCollision()==CollisionType.SOLID;
|
||||||
|
if (prevIsCollisionTile!=newIsCollisionTile) {
|
||||||
|
for (int yy=0;yy<Tile.TILE_HEIGHT;yy++) {
|
||||||
|
for (int xx=0;xx<Tile.TILE_WIDTH;xx++) {
|
||||||
|
RabiClone.COLLISION[(y*Tile.TILE_HEIGHT*Map.MAP_HEIGHT+yy)*Map.MAP_WIDTH+(x*Tile.TILE_WIDTH*Map.MAP_WIDTH+xx)]=newIsCollisionTile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
tiles[y*Map.MAP_WIDTH+x]=(char)(t.ordinal());
|
tiles[y*Map.MAP_WIDTH+x]=(char)(t.ordinal());
|
||||||
//System.out.println("Tile "+(y*MAP_WIDTH+x)+" is now "+tiles[y*MAP_WIDTH+x]+".");
|
//System.out.println("Tile "+(y*MAP_WIDTH+x)+" is now "+tiles[y*MAP_WIDTH+x]+".");
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,17 @@ package sig.map;
|
|||||||
|
|
||||||
public enum Tile {
|
public enum Tile {
|
||||||
VOID(0,0,true,CollisionType.NONE), //File is populated by 0s by default. This represents the void.
|
VOID(0,0,true,CollisionType.NONE), //File is populated by 0s by default. This represents the void.
|
||||||
WALL(0,0,CollisionType.BLOCK),
|
WALL(0,0,CollisionType.SOLID),
|
||||||
FLOOR(1,0,CollisionType.BLOCK),
|
FLOOR(1,0,CollisionType.SOLID),
|
||||||
PLATFORM_LEDGE(2,0,CollisionType.BLOCK),
|
PLATFORM_LEDGE(2,0,CollisionType.SOLID),
|
||||||
INVISIBLE_WALL(0,0,true,CollisionType.NONE),
|
INVISIBLE_WALL(0,0,true,CollisionType.NONE),
|
||||||
HIGHLIGHTED_TILE(3,0,CollisionType.NONE),
|
HIGHLIGHTED_TILE(3,0,CollisionType.NONE),
|
||||||
SMALL_SLOPE_LEFT(0,1,CollisionType.SLOPE),
|
SMALL_SOLID_LEFT(0,1,CollisionType.SOLID),
|
||||||
SMALL_SLOPE_RIGHT(1,1,CollisionType.SLOPE),
|
SMALL_SOLID_RIGHT(1,1,CollisionType.SOLID),
|
||||||
BIG_SLOPE_LEFT1(2,1,CollisionType.SLOPE),
|
BIG_SOLID_LEFT1(2,1,CollisionType.SOLID),
|
||||||
BIG_SLOPE_LEFT2(3,1,CollisionType.SLOPE),
|
BIG_SOLID_LEFT2(3,1,CollisionType.SOLID),
|
||||||
BIG_SLOPE_RIGHT1(0,2,CollisionType.SLOPE),
|
BIG_SOLID_RIGHT1(0,2,CollisionType.SOLID),
|
||||||
BIG_SLOPE_RIGHT2(1,2,CollisionType.SLOPE),
|
BIG_SOLID_RIGHT2(1,2,CollisionType.SOLID),
|
||||||
;
|
;
|
||||||
|
|
||||||
final public static int TILE_WIDTH=32;
|
final public static int TILE_WIDTH=32;
|
||||||
|
@ -73,7 +73,7 @@ public class Player extends AnimatedObject implements CollisionEntity {
|
|||||||
super(Sprite.ERINA, 5, panel);
|
super(Sprite.ERINA, 5, panel);
|
||||||
setX(RabiClone.BASE_WIDTH / 2 - getAnimatedSpr().getWidth() / 2);
|
setX(RabiClone.BASE_WIDTH / 2 - getAnimatedSpr().getWidth() / 2);
|
||||||
setY(RabiClone.BASE_HEIGHT * (2 / 3d) - getAnimatedSpr().getHeight() / 2);
|
setY(RabiClone.BASE_HEIGHT * (2 / 3d) - getAnimatedSpr().getHeight() / 2);
|
||||||
setCollisionBounds(new Rectangle(2,2,28,28));
|
setCollisionBounds(new Rectangle(10,2,12,27));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -395,8 +395,8 @@ public class Player extends AnimatedObject implements CollisionEntity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (y_velocity==0) {
|
if (y_velocity==0) {
|
||||||
if (!(checkCollision(getX()-RabiClone.level_renderer.getX()+getCollisionBox().getX()-getSprite().getWidth()/2+getCollisionBox().getX2(),getY()-RabiClone.level_renderer.getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()+1)||
|
if (!(checkCollision(getX()-RabiClone.level_renderer.getX()-getSprite().getWidth()/2+getCollisionBox().getX2(),getY()-RabiClone.level_renderer.getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()+1)||
|
||||||
checkCollision(getX()-RabiClone.level_renderer.getX()+getCollisionBox().getX()-getSprite().getWidth()/2+getCollisionBox().getX(),getY()-RabiClone.level_renderer.getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()+1))) {
|
checkCollision(getX()-RabiClone.level_renderer.getX()-getSprite().getWidth()/2+getCollisionBox().getX(),getY()-RabiClone.level_renderer.getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()+1))) {
|
||||||
groundCollision=false;
|
groundCollision=false;
|
||||||
} else {
|
} else {
|
||||||
groundCollision=true;
|
groundCollision=true;
|
||||||
@ -428,11 +428,12 @@ public class Player extends AnimatedObject implements CollisionEntity {
|
|||||||
if (y==getY()) {
|
if (y==getY()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (checkCollision(getX()-RabiClone.level_renderer.getX()-getSprite().getWidth()/2+getCollisionBox().getX2()-1,y-RabiClone.level_renderer.getY()+getCollisionBox().getY2()-getSprite().getHeight()/2)||
|
if (checkCollision(getX()-RabiClone.level_renderer.getX()-getSprite().getWidth()/2+getCollisionBox().getX2()-1,y-RabiClone.level_renderer.getY()+getCollisionBox().getY()-getSprite().getHeight()/2)||
|
||||||
checkCollision(getX()-RabiClone.level_renderer.getX()-getSprite().getWidth()/2+getCollisionBox().getX()+1,y-RabiClone.level_renderer.getY()+getCollisionBox().getY2()-getSprite().getHeight()/2)) {
|
checkCollision(getX()-RabiClone.level_renderer.getX()-getSprite().getWidth()/2+getCollisionBox().getX()+1,y-RabiClone.level_renderer.getY()+getCollisionBox().getY()-getSprite().getHeight()/2)) {
|
||||||
setY(y+1);
|
setY(y+1);
|
||||||
y_acceleration = 0;
|
y_acceleration = 0;
|
||||||
y_velocity = 0;
|
y_velocity = 0;
|
||||||
|
groundCollision = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -456,69 +457,6 @@ public class Player extends AnimatedObject implements CollisionEntity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkCollision(double x,double y) {
|
|
||||||
int index = (int)y*RabiClone.BASE_WIDTH+(int)x;
|
|
||||||
if (index>=0&&index<RabiClone.COLLISION.length) {
|
|
||||||
return RabiClone.COLLISION[index];
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private double ySlopeCollisionPoint(Tile tile) {
|
|
||||||
switch (tile) {
|
|
||||||
case BIG_SLOPE_LEFT1:
|
|
||||||
return -(getX() % Tile.TILE_WIDTH / 2)
|
|
||||||
+ (int) (getY() + getAnimatedSpr().getHeight() / 2) / Tile.TILE_HEIGHT * Tile.TILE_HEIGHT
|
|
||||||
+ (getAnimatedSpr().getHeight() / 2 - 4);
|
|
||||||
|
|
||||||
case BIG_SLOPE_LEFT2:
|
|
||||||
return -(getX() % Tile.TILE_WIDTH / 2)
|
|
||||||
+ (int) (getY() + getAnimatedSpr().getHeight() / 2) / Tile.TILE_HEIGHT * Tile.TILE_HEIGHT
|
|
||||||
+ (getAnimatedSpr().getHeight() / 2 - 4) - Tile.TILE_WIDTH / 2;
|
|
||||||
|
|
||||||
case BIG_SLOPE_RIGHT1:
|
|
||||||
return (getX() % Tile.TILE_WIDTH / 2)
|
|
||||||
+ (int) (getY() + getAnimatedSpr().getHeight() / 2) / Tile.TILE_HEIGHT * Tile.TILE_HEIGHT
|
|
||||||
+ (getAnimatedSpr().getHeight() / 2 - 4) - Tile.TILE_WIDTH;
|
|
||||||
|
|
||||||
case BIG_SLOPE_RIGHT2:
|
|
||||||
return (getX() % Tile.TILE_WIDTH / 2)
|
|
||||||
+ (int) (getY() + getAnimatedSpr().getHeight() / 2) / Tile.TILE_HEIGHT * Tile.TILE_HEIGHT
|
|
||||||
+ (getAnimatedSpr().getHeight() / 2 - 4) - Tile.TILE_WIDTH + Tile.TILE_WIDTH / 2;
|
|
||||||
|
|
||||||
case SMALL_SLOPE_LEFT:
|
|
||||||
return -(getX() % Tile.TILE_WIDTH)
|
|
||||||
+ (int) (getY() + getAnimatedSpr().getHeight() / 2) / Tile.TILE_HEIGHT * Tile.TILE_HEIGHT
|
|
||||||
+ (getAnimatedSpr().getHeight() / 2 - 4);
|
|
||||||
|
|
||||||
case SMALL_SLOPE_RIGHT:
|
|
||||||
return (getX() % Tile.TILE_WIDTH)
|
|
||||||
+ (int) (getY() + getAnimatedSpr().getHeight() / 2) / Tile.TILE_HEIGHT * Tile.TILE_HEIGHT
|
|
||||||
+ (getAnimatedSpr().getHeight() / 2 - 4) - Tile.TILE_WIDTH;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void moveUpSlope(Tile checked_tile_bottom_center) {
|
|
||||||
setY(ySlopeCollisionPoint(checked_tile_bottom_center));
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean groundCollision(double check_distance_y) {
|
|
||||||
boolean collisionOccured;
|
|
||||||
setY((getY() - check_distance_y));
|
|
||||||
y_acceleration = 0;
|
|
||||||
y_velocity = 0;
|
|
||||||
groundCollision = true;
|
|
||||||
collisionOccured = true;
|
|
||||||
if (state != State.SLIDE) {
|
|
||||||
state = State.IDLE;
|
|
||||||
}
|
|
||||||
return collisionOccured;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleKeyboardMovement(double updateMult, int movement, double friction, double drag) {
|
private void handleKeyboardMovement(double updateMult, int movement, double friction, double drag) {
|
||||||
if (movement != 0 && Math.abs(x_velocity) < WALKING_SPEED_LIMIT) {
|
if (movement != 0 && Math.abs(x_velocity) < WALKING_SPEED_LIMIT) {
|
||||||
x_acceleration = drag * (movement);
|
x_acceleration = drag * (movement);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user