Simple demo using the screens.
This commit is contained in:
parent
b118a5a024
commit
5004e2cc0e
@ -0,0 +1,35 @@
|
||||
package de.teamteamteam.spacescooter.entity;
|
||||
|
||||
|
||||
public abstract class CollidableEntity extends Entity {
|
||||
|
||||
/**
|
||||
* Position of the Entity
|
||||
*/
|
||||
protected int x;
|
||||
protected int y;
|
||||
|
||||
/**
|
||||
* Dimensions of the Entity
|
||||
*/
|
||||
protected int width;
|
||||
protected int height;
|
||||
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return this.width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return this.width;
|
||||
}
|
||||
|
||||
}
|
@ -5,7 +5,6 @@ import java.util.ArrayList;
|
||||
public abstract class Entity implements Updateable, Paintable {
|
||||
|
||||
public static ArrayList<Entity> entities = null;
|
||||
private static boolean isEnemy = false;
|
||||
|
||||
/**
|
||||
* We need to initialize the ArrayList, so the EntityUpdateThread won't beat us.
|
||||
@ -14,15 +13,6 @@ public abstract class Entity implements Updateable, Paintable {
|
||||
Entity.entities = new ArrayList<Entity>();
|
||||
}
|
||||
|
||||
|
||||
public static boolean isEnemy() {
|
||||
return isEnemy;
|
||||
}
|
||||
|
||||
protected void setEnemy(boolean isEnemy) {
|
||||
this.isEnemy = isEnemy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* All entities are within a static array list for our convenience.
|
||||
|
@ -2,29 +2,26 @@ package de.teamteamteam.spacescooter.entity;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import de.teamteamteam.spacescooter.control.Keyboard;
|
||||
|
||||
public class TestEntity extends Entity {
|
||||
|
||||
private Color color;
|
||||
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
public TestEntity() {
|
||||
super();
|
||||
this.setEnemy(true);
|
||||
this.color = new Color(255, 0, 0);
|
||||
}
|
||||
|
||||
public void paint(Graphics g) {
|
||||
g.setColor(this.color);
|
||||
g.fillRect(300, 300, 100, 100);
|
||||
g.fillRect(300, 300, 10, 10);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) {
|
||||
System.out.println("Hallo Welt!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,28 +1,36 @@
|
||||
package de.teamteamteam.spacescooter.screen;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import de.teamteamteam.spacescooter.background.StarBackground;
|
||||
import de.teamteamteam.spacescooter.control.Keyboard;
|
||||
import de.teamteamteam.spacescooter.utility.GameConfig;
|
||||
import de.teamteamteam.spacescooter.entity.Entity;
|
||||
import de.teamteamteam.spacescooter.entity.Player;
|
||||
import de.teamteamteam.spacescooter.entity.TestEntity;
|
||||
|
||||
public class GameScreen extends Screen {
|
||||
|
||||
public GameScreen(Screen parent) {
|
||||
super(parent);
|
||||
this.entities.add(new StarBackground());
|
||||
this.entities.add(new Player());
|
||||
this.entities.add(new TestEntity());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paint(Graphics g) {
|
||||
g.fillRect(0, 0, GameConfig.windowWidth, GameConfig.windowHeight);
|
||||
g.setColor(new Color(255,0,255));
|
||||
g.drawRect(100, 200, 150, 75);
|
||||
for(Entity e : this.entities) {
|
||||
e.paint(g);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void update() {
|
||||
for(Entity e : this.entities) {
|
||||
e.update();
|
||||
}
|
||||
if(Keyboard.isKeyDown(KeyEvent.VK_ESCAPE)) {
|
||||
this.parent.setOverlay(new MainMenuScreen(this.parent));
|
||||
}
|
||||
|
@ -1,25 +1,29 @@
|
||||
package de.teamteamteam.spacescooter.screen;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import de.teamteamteam.spacescooter.background.StarBackground;
|
||||
import de.teamteamteam.spacescooter.control.Keyboard;
|
||||
import de.teamteamteam.spacescooter.entity.Entity;
|
||||
import de.teamteamteam.spacescooter.utility.GameConfig;
|
||||
|
||||
public class MainMenuScreen extends Screen {
|
||||
|
||||
public MainMenuScreen(Screen parent) {
|
||||
super(parent);
|
||||
this.addEntity(new StarBackground());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
for(Entity entity : this.entities) {
|
||||
entity.paint(g);
|
||||
}
|
||||
g.setColor(new Color(0,0,120));
|
||||
g.fillRect(0, 0, GameConfig.windowWidth, GameConfig.windowHeight);
|
||||
g.setColor(new Color(255,255,255));
|
||||
g.setFont(new Font("Monospace", 0, 50));
|
||||
g.drawString("Main Menu. LOL", 100, 100);
|
||||
g.drawString("Press space to play!", 100, 400);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -30,6 +34,9 @@ public class MainMenuScreen extends Screen {
|
||||
if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) {
|
||||
this.parent.setOverlay(new GameScreen(this.parent));
|
||||
}
|
||||
if(Keyboard.isKeyDown(KeyEvent.VK_ESCAPE)) {
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ public class GraphicsSettings {
|
||||
this.height = dm.getHeight();
|
||||
this.width = dm.getWidth();
|
||||
|
||||
System.out.println("Display Mode " + i + ": " + this.width + "x" + this.height+ "@" + this.refreshRate + "Hz, " + this.bitDepth + " bit");
|
||||
//System.out.println("Display Mode " + i + ": " + this.width + "x" + this.height+ "@" + this.refreshRate + "Hz, " + this.bitDepth + " bit");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user