Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GameObj, ObjectID,GameController e rederizando Objetos
- Loading branch information
1 parent
8d9d3cf
commit 4310e0e
Showing
6 changed files
with
152 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.ks2002br.frameworks; | ||
|
||
import java.awt.Color; | ||
import java.awt.Graphics; | ||
|
||
public class Cobaia extends GameObject { | ||
|
||
public Cobaia(float x, float y, ObjectId id) { | ||
super(x, y, id); | ||
} | ||
|
||
|
||
public void tick() { | ||
x++; | ||
} | ||
|
||
|
||
public void render(Graphics g) { | ||
g.setColor(Color.blue); | ||
g.fillRect((int)x, (int)y,128, 128); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.ks2002br.frameworks; | ||
|
||
import java.awt.Graphics; | ||
import java.util.LinkedList; | ||
|
||
public class GameController { | ||
|
||
private LinkedList<GameObject> obj = new LinkedList<>(); | ||
|
||
private GameObject tempObj; | ||
|
||
public void update() { | ||
for (int i = 0; i < obj.size(); i++) { | ||
tempObj = obj.get(i); | ||
tempObj.tick(); | ||
} | ||
} | ||
|
||
public void draw(Graphics g) { | ||
for (int i = 0; i < obj.size(); i++) { | ||
tempObj = obj.get(i); | ||
tempObj.render(g); | ||
} | ||
} | ||
|
||
public void addObj(GameObject obj) { | ||
this.obj.add(obj); | ||
System.out.println("[DEBUG GameController] UM OBJETO FOI CRIADO"); | ||
} | ||
|
||
public void removeObj(GameObject obj) { | ||
this.obj.remove(obj); | ||
System.out.println("[DEBUG GameController] UM OBJETO FOI REMOVIDO"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.ks2002br.frameworks; | ||
|
||
import java.awt.Graphics; | ||
|
||
public abstract class GameObject { | ||
|
||
protected ObjectId id; // Id do objeto | ||
protected float x,y; // posicao x e y na tela | ||
protected float spdX,spdY; // velocidade x e y | ||
|
||
//construtor | ||
public GameObject(float x, float y, ObjectId id) { | ||
this.x = x; | ||
this.y = y; | ||
this.id = id; | ||
} | ||
|
||
public abstract void tick(); | ||
public abstract void render(Graphics g); | ||
|
||
public ObjectId getId() { | ||
return id; | ||
} | ||
|
||
// public void setId(ObjectId id) { | ||
// this.id = id; | ||
// } | ||
|
||
public float getX() { | ||
return x; | ||
} | ||
|
||
public void setX(float x) { | ||
this.x = x; | ||
} | ||
|
||
public float getY() { | ||
return y; | ||
} | ||
|
||
public void setY(float y) { | ||
this.y = y; | ||
} | ||
|
||
public float getSpdX() { | ||
return spdX; | ||
} | ||
|
||
public void setSpdX(float spdX) { | ||
this.spdX = spdX; | ||
} | ||
|
||
public float getSpdY() { | ||
return spdY; | ||
} | ||
|
||
public void setSpdY(float spdY) { | ||
this.spdY = spdY; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.ks2002br.frameworks; | ||
|
||
public enum ObjectId { | ||
|
||
COBAIA, | ||
PLAYER, | ||
ENEMY, | ||
ARMA, | ||
BALA, | ||
SOLIDO; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters