Cause events to trigger when within camera range
Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
cb04afe469
commit
ba41219add
@ -1,6 +1,9 @@
|
||||
package sig.engine.objects;
|
||||
|
||||
import sig.engine.Transform;
|
||||
|
||||
public interface GameEntity {
|
||||
public void update(double updateMult);
|
||||
public void draw(byte[] p);
|
||||
public Transform getSpriteTransform();
|
||||
}
|
||||
|
@ -4,5 +4,10 @@ import sig.engine.String;
|
||||
|
||||
public interface Event{
|
||||
public String getDescription();
|
||||
public void perform(int x, int y);
|
||||
/**
|
||||
* Perform this event at position {@code (x,y)}.
|
||||
* @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);
|
||||
}
|
||||
|
@ -22,13 +22,14 @@ public class SpawnEvent implements Event{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform(int x, int y) {
|
||||
public boolean perform(int x, int y) {
|
||||
try {
|
||||
RabiClone.OBJ.add((Object)entity.getDeclaredConstructor(new Class<?>[]{Double.class,Double.class}).newInstance(x,y));
|
||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
|
||||
| NoSuchMethodException | SecurityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,12 +13,17 @@ public enum DataTile {
|
||||
BUN4(new SpawnEvent("Spawns a red bun",Erinoah.class));
|
||||
|
||||
String description;
|
||||
Event event;
|
||||
|
||||
DataTile(){}
|
||||
DataTile(Event e) {
|
||||
this.description=e.getDescription();
|
||||
this.event=e;
|
||||
}
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public boolean perform(int x, int y) {
|
||||
return event.perform(x, y);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package sig.objects;
|
||||
|
||||
import sig.RabiClone;
|
||||
import sig.engine.Sprite;
|
||||
import sig.engine.Transform;
|
||||
import sig.engine.objects.AnimatedObject;
|
||||
import sig.objects.actor.RenderedObject;
|
||||
|
||||
@ -23,4 +24,9 @@ public class Erinoah extends AnimatedObject implements RenderedObject{
|
||||
Draw_Animated_Sprite(16, 16, getAnimatedSpr(), getCurrentFrame());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Transform getSpriteTransform() {
|
||||
return Transform.NONE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -38,7 +38,9 @@ public class LevelRenderer extends Object{
|
||||
continue;
|
||||
}
|
||||
if (RabiClone.CURRENT_MAP.getDataTile(x,y)!=DataTile.NULL) {
|
||||
|
||||
if (!RabiClone.CURRENT_MAP.getDataTile(x,y).perform(x*Tile.TILE_WIDTH,y*Tile.TILE_HEIGHT)) {
|
||||
RabiClone.CURRENT_MAP.ModifyDataTile(x, y, DataTile.NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -67,9 +69,9 @@ public class LevelRenderer extends Object{
|
||||
Object o = RabiClone.OBJ.get(i);
|
||||
if (o instanceof RenderedObject) {
|
||||
if (o instanceof AnimatedObject) {
|
||||
Draw_Animated_Object((AnimatedObject)o,RabiClone.player.facing_direction?Transform.HORIZONTAL:Transform.NONE);
|
||||
Draw_Animated_Object((AnimatedObject)o,o.getSpriteTransform());
|
||||
} else {
|
||||
Draw_Object(o,RabiClone.player.facing_direction?Transform.HORIZONTAL:Transform.NONE);
|
||||
Draw_Object(o,o.getSpriteTransform());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -158,4 +160,8 @@ public class LevelRenderer extends Object{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Transform getSpriteTransform() {
|
||||
return Transform.NONE;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import sig.engine.Action;
|
||||
import sig.engine.Panel;
|
||||
import sig.engine.Rectangle;
|
||||
import sig.engine.Sprite;
|
||||
import sig.engine.Transform;
|
||||
import sig.engine.objects.AnimatedObject;
|
||||
import sig.engine.objects.CollisionEntity;
|
||||
import sig.map.Map;
|
||||
@ -530,4 +531,8 @@ public class Player extends AnimatedObject implements CollisionEntity,RenderedOb
|
||||
setCollisionBox(bounds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Transform getSpriteTransform() {
|
||||
return facing_direction?Transform.HORIZONTAL:Transform.NONE;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user