2022-05-24 20:17:56 +00:00
|
|
|
package sig.objects;
|
|
|
|
|
2022-06-13 17:28:30 +00:00
|
|
|
import java.awt.event.KeyEvent;
|
|
|
|
|
2022-05-24 20:17:56 +00:00
|
|
|
import sig.RabiClone;
|
2022-06-13 17:28:30 +00:00
|
|
|
import sig.engine.Action;
|
2022-05-30 03:16:04 -05:00
|
|
|
import sig.engine.Alpha;
|
2022-06-09 18:29:40 +00:00
|
|
|
import sig.engine.Font;
|
2022-06-13 17:28:30 +00:00
|
|
|
import sig.engine.Key;
|
2022-06-11 17:58:41 -05:00
|
|
|
import sig.engine.PaletteColor;
|
2022-05-24 20:17:56 +00:00
|
|
|
import sig.engine.Panel;
|
|
|
|
import sig.engine.Sprite;
|
2022-06-05 10:04:30 +03:00
|
|
|
import sig.engine.Transform;
|
2022-06-11 18:06:41 -05:00
|
|
|
import sig.engine.objects.AnimatedObject;
|
|
|
|
import sig.engine.objects.Object;
|
2022-06-09 18:29:40 +00:00
|
|
|
import sig.engine.String;
|
2022-06-03 16:44:55 -05:00
|
|
|
import sig.map.Background;
|
2022-06-13 18:17:02 +00:00
|
|
|
import sig.map.DataTile;
|
2022-05-29 12:50:06 -05:00
|
|
|
import sig.map.Map;
|
2022-05-24 20:17:56 +00:00
|
|
|
import sig.map.Tile;
|
2022-06-21 15:48:32 +00:00
|
|
|
import sig.objects.actor.PhysicsObject;
|
2022-06-13 19:02:42 +00:00
|
|
|
import sig.objects.actor.RenderedObject;
|
2022-06-21 15:48:32 +00:00
|
|
|
import sig.objects.actor.State;
|
|
|
|
import sig.utils.TimeUtils;
|
2022-05-24 20:17:56 +00:00
|
|
|
|
|
|
|
public class LevelRenderer extends Object{
|
|
|
|
|
2022-06-21 15:48:32 +00:00
|
|
|
final static long staggerJitterWaitTime=TimeUtils.millisToNanos(200);
|
|
|
|
|
|
|
|
long staggerTimer=0;
|
|
|
|
int staggerOffsetX=2;
|
|
|
|
|
2022-05-24 20:17:56 +00:00
|
|
|
public LevelRenderer(Panel panel) {
|
|
|
|
super(panel);
|
|
|
|
this.setSprite(Sprite.TILE_SHEET);
|
|
|
|
}
|
|
|
|
|
2022-05-29 20:13:45 +03:00
|
|
|
@Override
|
2022-06-11 17:58:41 -05:00
|
|
|
public void update(double updateMult) {
|
2022-06-13 16:57:53 -05:00
|
|
|
for (int y=(int)(this.getY()/Tile.TILE_HEIGHT)-RabiClone.EVENT_BOUNDARY_RANGE;y<(int)(RabiClone.BASE_HEIGHT/Tile.TILE_HEIGHT+this.getY()/Tile.TILE_HEIGHT+1+RabiClone.EVENT_BOUNDARY_RANGE);y++) {
|
2022-06-13 19:02:42 +00:00
|
|
|
if (y<0||y>Map.MAP_HEIGHT) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-06-13 16:57:53 -05:00
|
|
|
for (int x=(int)(0+this.getX()/Tile.TILE_WIDTH)-RabiClone.EVENT_BOUNDARY_RANGE;x<(int)(RabiClone.BASE_WIDTH/Tile.TILE_WIDTH+this.getX()/Tile.TILE_WIDTH+1+RabiClone.EVENT_BOUNDARY_RANGE);x++) {
|
2022-06-13 19:02:42 +00:00
|
|
|
if (x<0||x>Map.MAP_WIDTH) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (RabiClone.CURRENT_MAP.getDataTile(x,y)!=DataTile.NULL) {
|
2022-06-13 19:14:50 +00:00
|
|
|
if (!RabiClone.CURRENT_MAP.getDataTile(x,y).perform(x*Tile.TILE_WIDTH,y*Tile.TILE_HEIGHT)) {
|
|
|
|
RabiClone.CURRENT_MAP.ModifyDataTile(x, y, DataTile.NULL);
|
|
|
|
}
|
2022-06-13 19:02:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-21 15:48:32 +00:00
|
|
|
if (RabiClone.TIME-staggerTimer>staggerJitterWaitTime) {
|
|
|
|
staggerOffsetX*=-1;
|
|
|
|
}
|
2022-06-11 17:58:41 -05:00
|
|
|
}
|
2022-05-24 20:17:56 +00:00
|
|
|
|
|
|
|
@Override
|
2022-05-30 03:16:04 -05:00
|
|
|
public void draw(byte[] p) {
|
2022-05-29 20:13:45 +03:00
|
|
|
for (int y=(int)(this.getY()/Tile.TILE_HEIGHT);y<(int)(RabiClone.BASE_HEIGHT/Tile.TILE_HEIGHT+this.getY()/Tile.TILE_HEIGHT+1);y++) {
|
2022-05-29 12:50:06 -05:00
|
|
|
if (y<0||y>Map.MAP_HEIGHT) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-05-24 20:17:56 +00:00
|
|
|
for (int x=(int)(0+this.getX()/Tile.TILE_WIDTH);x<(int)(RabiClone.BASE_WIDTH/Tile.TILE_WIDTH+this.getX()/Tile.TILE_WIDTH+1);x++) {
|
2022-05-29 12:50:06 -05:00
|
|
|
if (x<0||x>Map.MAP_WIDTH) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-05-24 20:17:56 +00:00
|
|
|
if (RabiClone.CURRENT_MAP.getTile(x,y)!=Tile.VOID) {
|
|
|
|
DrawTile(x*Tile.TILE_WIDTH-this.getX(),y*Tile.TILE_HEIGHT-this.getY(),RabiClone.CURRENT_MAP.getTile(x,y));
|
|
|
|
//System.out.println((x*Tile.TILE_WIDTH+(this.getX()%Tile.TILE_WIDTH) )+","+(y*Tile.TILE_HEIGHT+(this.getY()%Tile.TILE_HEIGHT)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-13 19:02:42 +00:00
|
|
|
for (int i=0;i<RabiClone.OBJ.size();i++) {
|
|
|
|
Object o = RabiClone.OBJ.get(i);
|
|
|
|
if (o instanceof RenderedObject) {
|
|
|
|
if (o instanceof AnimatedObject) {
|
2022-06-13 19:14:50 +00:00
|
|
|
Draw_Animated_Object((AnimatedObject)o,o.getSpriteTransform());
|
2022-06-13 19:02:42 +00:00
|
|
|
} else {
|
2022-06-13 19:14:50 +00:00
|
|
|
Draw_Object(o,o.getSpriteTransform());
|
2022-06-13 19:02:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-02 21:24:38 -05:00
|
|
|
if (RabiClone.player!=null) {
|
2022-06-14 20:30:36 -05:00
|
|
|
Draw_Text(4,4,new String(RabiClone.player.getYVelocity()),Font.PROFONT_12);
|
2022-06-13 15:13:52 +00:00
|
|
|
Draw_Text(4,4+Font.PROFONT_12.getGlyphHeight(),new String(RabiClone.scaleTime),Font.PROFONT_12);
|
2022-06-02 21:24:38 -05:00
|
|
|
}
|
2022-06-11 18:06:41 -05:00
|
|
|
}
|
|
|
|
|
2022-06-13 17:33:08 +00:00
|
|
|
@SuppressWarnings("unused")
|
2022-06-11 18:06:41 -05:00
|
|
|
private void RenderCollisionGrid(byte[] p) {
|
2022-06-11 17:58:41 -05:00
|
|
|
for (int y=0;y<RabiClone.BASE_HEIGHT;y++) {
|
|
|
|
for (int x=0;x<RabiClone.BASE_WIDTH;x++) {
|
2022-06-11 21:58:17 -05:00
|
|
|
if (RabiClone.COLLISION[((int)getY()+y)*RabiClone.BASE_WIDTH*Tile.TILE_WIDTH+((int)getX()+x)]) {
|
2022-06-11 17:58:41 -05:00
|
|
|
p[y*RabiClone.BASE_WIDTH+x]=(byte)PaletteColor.CRIMSON.ordinal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-31 23:37:32 -05:00
|
|
|
}
|
|
|
|
|
2022-06-03 16:22:30 -05:00
|
|
|
@Override
|
|
|
|
public void drawBackground(byte[] p) {
|
2022-06-03 16:44:55 -05:00
|
|
|
int screenX = (int)(getX())/Tile.TILE_WIDTH;
|
|
|
|
int screenY = (int)(getY())/Tile.TILE_HEIGHT;
|
|
|
|
Background targetBackground = RabiClone.CURRENT_MAP.getBackground(screenX, screenY);
|
2022-06-03 16:22:30 -05:00
|
|
|
for (int y=0;y<RabiClone.BASE_HEIGHT;y++) {
|
|
|
|
for (int x=0;x<RabiClone.BASE_WIDTH;x++) {
|
2022-06-03 16:44:55 -05:00
|
|
|
int index = y*RabiClone.BASE_WIDTH+x;
|
|
|
|
p[index] = targetBackground.getPixels()[
|
|
|
|
((y+(int)(getY()*targetBackground.getScrollSpeed()))%targetBackground.getHeight())*targetBackground.getWidth()+((x+(int)(getX()*targetBackground.getScrollSpeed()))%targetBackground.getWidth())
|
|
|
|
];
|
2022-06-03 16:22:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-11 21:58:17 -05:00
|
|
|
@Override
|
|
|
|
public void drawOverlay(byte[] p) {
|
|
|
|
//RenderCollisionGrid(p);
|
2022-06-15 19:55:40 +00:00
|
|
|
//RenderPlayerCollisionGrid(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
private void RenderPlayerCollisionGrid(byte[] p) {
|
|
|
|
for (int y=0;y<RabiClone.BASE_HEIGHT;y++) {
|
|
|
|
for (int x=0;x<RabiClone.BASE_WIDTH;x++) {
|
|
|
|
if (RabiClone.PLAYER_COLLISION[y*RabiClone.BASE_WIDTH+x]) {
|
|
|
|
p[y*RabiClone.BASE_WIDTH+x]=(byte)PaletteColor.MANTIS.ordinal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-11 21:58:17 -05:00
|
|
|
}
|
|
|
|
|
2022-05-31 23:37:32 -05:00
|
|
|
/**
|
|
|
|
* Draws an object where its sprite is centered among its position and drawn relative to the camera position.
|
|
|
|
* @param object
|
|
|
|
*/
|
|
|
|
protected void Draw_Object(Object object) {
|
2022-06-02 22:30:07 -05:00
|
|
|
super.Draw_Sprite(object.getX()-this.getX()-object.getSprite().getWidth()/2, Math.round(object.getY()-this.getY()-object.getSprite().getHeight()/2), object.getSprite());
|
2022-05-24 20:17:56 +00:00
|
|
|
}
|
|
|
|
|
2022-06-13 19:02:42 +00:00
|
|
|
protected void Draw_Object(Object object, Transform transform) {
|
|
|
|
super.Draw_Sprite(object.getX()-this.getX()-object.getSprite().getWidth()/2, Math.round(object.getY()-this.getY()-object.getSprite().getHeight()/2), object.getSprite(), transform);
|
|
|
|
}
|
|
|
|
|
2022-06-04 05:44:05 -05:00
|
|
|
protected void Draw_Animated_Object(AnimatedObject object) {
|
2022-06-05 10:04:30 +03:00
|
|
|
Draw_Animated_Object(object,Transform.NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void Draw_Animated_Object(AnimatedObject object, Transform transform){
|
2022-06-21 15:48:32 +00:00
|
|
|
if (object instanceof PhysicsObject) {
|
|
|
|
PhysicsObject po = (PhysicsObject)object;
|
|
|
|
super.Draw_Animated_Sprite(object.getX()-this.getX()-object.getAnimatedSpr().getWidth()/2+(po.state==State.STAGGER?staggerOffsetX:0), Math.round(object.getY()-this.getY()-object.getAnimatedSpr().getHeight()/2), object.getAnimatedSpr(), object.getCurrentFrame(), transform);
|
|
|
|
} else {
|
|
|
|
super.Draw_Animated_Sprite(object.getX()-this.getX()-object.getAnimatedSpr().getWidth()/2, Math.round(object.getY()-this.getY()-object.getAnimatedSpr().getHeight()/2), object.getAnimatedSpr(), object.getCurrentFrame(), transform);
|
|
|
|
}
|
2022-06-04 05:44:05 -05:00
|
|
|
}
|
|
|
|
|
2022-05-24 20:17:56 +00:00
|
|
|
private void DrawTile(double x, double y, Tile tile) {
|
2022-06-05 10:04:30 +03:00
|
|
|
Draw_Sprite_Partial(x,y, tile.getSpriteSheetX()*tile.getTileWidth(), tile.getSpriteSheetY()*tile.getTileHeight(), tile.getTileWidth(), tile.getTileHeight(), getSprite(), 0, Transform.NONE);
|
2022-05-24 20:17:56 +00:00
|
|
|
}
|
2022-05-29 12:50:06 -05:00
|
|
|
|
2022-06-01 16:37:01 -05:00
|
|
|
protected void DrawTransparentTile(double x, double y, Tile tile, Alpha alpha) {
|
2022-06-05 10:04:30 +03:00
|
|
|
Draw_Sprite_Partial_Ext(x,y, tile.getSpriteSheetX()*tile.getTileWidth(), tile.getSpriteSheetY()*tile.getTileHeight(), tile.getTileWidth(), tile.getTileHeight(), getSprite(), alpha, Transform.NONE);
|
2022-05-29 12:50:06 -05:00
|
|
|
}
|
2022-06-13 17:28:30 +00:00
|
|
|
|
|
|
|
@Override
|
2022-06-13 17:36:24 +00:00
|
|
|
@SuppressWarnings("incomplete-switch")
|
2022-06-13 17:28:30 +00:00
|
|
|
public void KeyPressed(Action a) {
|
2022-06-13 17:36:24 +00:00
|
|
|
switch(a) {
|
|
|
|
case LEVEL_EDITOR:{
|
|
|
|
RabiClone.OBJ.clear();
|
|
|
|
RabiClone.ResetGame();
|
2022-06-13 16:51:04 -05:00
|
|
|
Map.LoadMap(RabiClone.CURRENT_MAP);
|
2022-06-13 17:36:24 +00:00
|
|
|
RabiClone.OBJ.add(RabiClone.level_renderer = new EditorRenderer(RabiClone.p));
|
|
|
|
}break;
|
2022-06-13 17:28:30 +00:00
|
|
|
}
|
|
|
|
if (Key.isKeyHeld(KeyEvent.VK_F3)) {
|
|
|
|
RabiClone.OBJ.clear();
|
|
|
|
RabiClone.ResetGame();
|
|
|
|
RabiClone.OBJ.add(RabiClone.control_settings_menu = new ConfigureControls(RabiClone.p));
|
|
|
|
}
|
|
|
|
}
|
2022-05-24 20:17:56 +00:00
|
|
|
|
2022-06-13 19:14:50 +00:00
|
|
|
@Override
|
|
|
|
public Transform getSpriteTransform() {
|
|
|
|
return Transform.NONE;
|
|
|
|
}
|
2022-05-24 20:17:56 +00:00
|
|
|
}
|