Add in spawners that can create things. Make it so rendered objects will render with the camera view

Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2, Sig, Sigo 2 years ago committed by GitHub
parent aa41f52bbd
commit cb04afe469
  1. 4
      src/sig/engine/objects/Object.java
  2. 8
      src/sig/events/Event.java
  3. 34
      src/sig/events/SpawnEvent.java
  4. 15
      src/sig/map/DataTile.java
  5. 11
      src/sig/objects/Erinoah.java
  6. 29
      src/sig/objects/LevelRenderer.java
  7. 3
      src/sig/objects/Player.java
  8. 5
      src/sig/objects/actor/RenderedObject.java

@ -92,6 +92,10 @@ public abstract class Object implements GameEntity{
DrawLoop.Draw_Sprite(x,y,sprite); DrawLoop.Draw_Sprite(x,y,sprite);
} }
protected void Draw_Sprite(double x, double y, Sprite sprite, Transform transform){
DrawLoop.Draw_Sprite(x,y,sprite,transform);
}
protected void Draw_Animated_Sprite(double x, double y, AnimatedSprite sprite, double frameIndex){ protected void Draw_Animated_Sprite(double x, double y, AnimatedSprite sprite, double frameIndex){
DrawLoop.Draw_Animated_Sprite(x,y,sprite,frameIndex); DrawLoop.Draw_Animated_Sprite(x,y,sprite,frameIndex);
} }

@ -0,0 +1,8 @@
package sig.events;
import sig.engine.String;
public interface Event{
public String getDescription();
public void perform(int x, int y);
}

@ -0,0 +1,34 @@
package sig.events;
import java.lang.reflect.InvocationTargetException;
import sig.RabiClone;
import sig.engine.String;
import sig.engine.objects.Object;
public class SpawnEvent implements Event{
Class<?> entity;
String description;
public SpawnEvent(java.lang.String description,Class<?> o) {
this.entity=o;
this.description=new String(description);
}
@Override
public String getDescription() {
return description;
}
@Override
public void 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();
}
}
}

@ -1,19 +1,22 @@
package sig.map; package sig.map;
import sig.engine.String; import sig.engine.String;
import sig.events.Event;
import sig.events.SpawnEvent;
import sig.objects.Erinoah;
public enum DataTile { public enum DataTile {
NULL, //File is populated by 0s by default. This represents nothing. NULL, //File is populated by 0s by default. This represents nothing.
BUN1("Spawns a blue bun"), BUN1(new SpawnEvent("Spawns a blue bun",Erinoah.class)),
BUN2("Spawns a green bun"), BUN2(new SpawnEvent("Spawns a green bun",Erinoah.class)),
BUN3("Spawns a yellow bun"), BUN3(new SpawnEvent("Spawns a yellow bun",Erinoah.class)),
BUN4("Spawns a red bun"); BUN4(new SpawnEvent("Spawns a red bun",Erinoah.class));
String description; String description;
DataTile(){} DataTile(){}
DataTile(java.lang.String s) { DataTile(Event e) {
this.description=new String(s); this.description=e.getDescription();
} }
public String getDescription() { public String getDescription() {
return description; return description;

@ -1,13 +1,16 @@
package sig.objects; package sig.objects;
import sig.engine.Panel; import sig.RabiClone;
import sig.engine.Sprite; import sig.engine.Sprite;
import sig.engine.objects.AnimatedObject; import sig.engine.objects.AnimatedObject;
import sig.objects.actor.RenderedObject;
public class Erinoah extends AnimatedObject{ public class Erinoah extends AnimatedObject implements RenderedObject{
public Erinoah(Panel panel) { public Erinoah(double x, double y) {
super(Sprite.ERINOAH, 6.5, panel); super(Sprite.ERINOAH,6.5,RabiClone.p);
setX(x);
setY(y);
} }
@Override @Override

@ -18,6 +18,7 @@ import sig.map.Background;
import sig.map.DataTile; import sig.map.DataTile;
import sig.map.Map; import sig.map.Map;
import sig.map.Tile; import sig.map.Tile;
import sig.objects.actor.RenderedObject;
public class LevelRenderer extends Object{ public class LevelRenderer extends Object{
@ -28,6 +29,19 @@ public class LevelRenderer extends Object{
@Override @Override
public void update(double updateMult) { public void update(double updateMult) {
for (int y=(int)(this.getY()/Tile.TILE_HEIGHT);y<(int)(RabiClone.BASE_HEIGHT/Tile.TILE_HEIGHT+this.getY()/Tile.TILE_HEIGHT+1);y++) {
if (y<0||y>Map.MAP_HEIGHT) {
continue;
}
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++) {
if (x<0||x>Map.MAP_WIDTH) {
continue;
}
if (RabiClone.CURRENT_MAP.getDataTile(x,y)!=DataTile.NULL) {
}
}
}
} }
@Override @Override
@ -49,8 +63,17 @@ public class LevelRenderer extends Object{
} }
} }
} }
for (int i=0;i<RabiClone.OBJ.size();i++) {
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);
} else {
Draw_Object(o,RabiClone.player.facing_direction?Transform.HORIZONTAL:Transform.NONE);
}
}
}
if (RabiClone.player!=null) { if (RabiClone.player!=null) {
Draw_Animated_Object(RabiClone.player,RabiClone.player.facing_direction?Transform.HORIZONTAL:Transform.NONE);
Draw_Text(4,4,new String(RabiClone.player.y_velocity),Font.PROFONT_12); Draw_Text(4,4,new String(RabiClone.player.y_velocity),Font.PROFONT_12);
Draw_Text(4,4+Font.PROFONT_12.getGlyphHeight(),new String(RabiClone.scaleTime),Font.PROFONT_12); Draw_Text(4,4+Font.PROFONT_12.getGlyphHeight(),new String(RabiClone.scaleTime),Font.PROFONT_12);
} }
@ -95,6 +118,10 @@ public class LevelRenderer extends Object{
super.Draw_Sprite(object.getX()-this.getX()-object.getSprite().getWidth()/2, Math.round(object.getY()-this.getY()-object.getSprite().getHeight()/2), object.getSprite()); super.Draw_Sprite(object.getX()-this.getX()-object.getSprite().getWidth()/2, Math.round(object.getY()-this.getY()-object.getSprite().getHeight()/2), object.getSprite());
} }
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);
}
protected void Draw_Animated_Object(AnimatedObject object) { protected void Draw_Animated_Object(AnimatedObject object) {
Draw_Animated_Object(object,Transform.NONE); Draw_Animated_Object(object,Transform.NONE);
} }

@ -10,10 +10,11 @@ import sig.engine.objects.CollisionEntity;
import sig.map.Map; import sig.map.Map;
import sig.map.Tile; import sig.map.Tile;
import sig.map.View; import sig.map.View;
import sig.objects.actor.RenderedObject;
import sig.objects.actor.State; import sig.objects.actor.State;
import sig.utils.TimeUtils; import sig.utils.TimeUtils;
public class Player extends AnimatedObject implements CollisionEntity { public class Player extends AnimatedObject implements CollisionEntity,RenderedObject{
final static double GRAVITY = 1300; final static double GRAVITY = 1300;
final static double NORMAL_FRICTION = 6400; final static double NORMAL_FRICTION = 6400;
final static double NORMAL_JUMP_VELOCITY = -300; final static double NORMAL_JUMP_VELOCITY = -300;

@ -0,0 +1,5 @@
package sig.objects.actor;
public interface RenderedObject {
}
Loading…
Cancel
Save