Implement object system
Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
f2a3ba9fd6
commit
868d5ac87d
@ -14,7 +14,10 @@ public class DrawLoop {
|
||||
p[y*panel.getWidth()+x]=(0<<16)+(0<<8)+0;//RGB
|
||||
}
|
||||
}
|
||||
Draw_Sprite(panel.nanaX,panel.nanaY,Sprite.NANA);
|
||||
|
||||
for (int i=0;i<RabiClone.OBJ.size();i++) {
|
||||
RabiClone.OBJ.get(i).draw(p);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Draw_Sprite(double x, double y, Sprite sprite){
|
||||
|
@ -1,7 +1,6 @@
|
||||
package sig;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -32,6 +31,18 @@ public class RabiClone {
|
||||
|
||||
p.render();
|
||||
|
||||
OBJ.add(new Player(p));
|
||||
OBJ.add(new Player(p));
|
||||
OBJ.add(new Player(p));
|
||||
OBJ.add(new Player(p));
|
||||
OBJ.add(new Player(p));
|
||||
OBJ.add(new Player(p));
|
||||
OBJ.add(new Player(p));
|
||||
OBJ.add(new Player(p));
|
||||
OBJ.add(new Player(p));
|
||||
OBJ.add(new Player(p));
|
||||
OBJ.add(new Player(p));
|
||||
OBJ.add(new Player(p));
|
||||
OBJ.add(new Player(p));
|
||||
|
||||
long lastGameTime = System.nanoTime();
|
||||
@ -40,8 +51,11 @@ public class RabiClone {
|
||||
lastGameTime=System.nanoTime();
|
||||
double updateMult = timePassed/1000000000d;
|
||||
|
||||
for (Object o : OBJ) {
|
||||
o.update(updateMult);
|
||||
for (int i=0;i<OBJ.size();i++) {
|
||||
OBJ.get(i).update(updateMult);
|
||||
if (OBJ.get(i).isMarkedForDeletion()) {
|
||||
OBJ.remove(i--);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,15 @@ public abstract class Object implements GameEntity{
|
||||
double x,y;
|
||||
Sprite spr;
|
||||
Panel panel;
|
||||
boolean markedForDeletion;
|
||||
|
||||
public boolean isMarkedForDeletion() {
|
||||
return markedForDeletion;
|
||||
}
|
||||
|
||||
public void setMarkedForDeletion(boolean markedForDeletion) {
|
||||
this.markedForDeletion = markedForDeletion;
|
||||
}
|
||||
|
||||
protected Object(Panel panel) {
|
||||
this.panel=panel;
|
||||
|
@ -29,6 +29,38 @@ public enum Sprite{
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("Loaded sprite for "+this+".");
|
||||
}
|
||||
|
||||
public BufferedImage getImg() {
|
||||
return img;
|
||||
}
|
||||
|
||||
public void setImg(BufferedImage img) {
|
||||
this.img = img;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public int[] getBi_array() {
|
||||
return bi_array;
|
||||
}
|
||||
|
||||
public void setBi_array(int[] bi_array) {
|
||||
this.bi_array = bi_array;
|
||||
};
|
||||
|
||||
}
|
@ -11,6 +11,8 @@ public class Player extends Object{
|
||||
public Player(Panel panel) {
|
||||
super(panel);
|
||||
this.setSprite(Sprite.NANA);
|
||||
setX(Math.random()*panel.getWidth());
|
||||
setY(Math.random()*panel.getHeight());
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user