diff --git a/.gitignore b/.gitignore index 274a748..066ad30 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *~ .project .settings - +.classpath +bin diff --git a/src/de/teamteamteam/spacescooter/Main.java b/src/de/teamteamteam/spacescooter/Main.java new file mode 100644 index 0000000..6c1ea9e --- /dev/null +++ b/src/de/teamteamteam/spacescooter/Main.java @@ -0,0 +1,31 @@ +package de.teamteamteam.spacescooter; + +import java.awt.EventQueue; + +import de.teamteamteam.spacescooter.gui.GameFrame; +import de.teamteamteam.spacescooter.threads.PaintThread; +import de.teamteamteam.spacescooter.threads.UpdateThread; + +public class Main { + + /** + * @param args + */ + public static void main(String[] args) { + final GameFrame gf = new GameFrame(); + + EventQueue.invokeLater(new Runnable() { + public void run() { + gf.init(); + } + }); + + PaintThread pt = new PaintThread(gf); + pt.start(); + + UpdateThread ut = new UpdateThread(gf); + ut.start(); + + } + +} diff --git a/src/de/teamteamteam/spacescooter/entities/Entity.java b/src/de/teamteamteam/spacescooter/entities/Entity.java new file mode 100644 index 0000000..cc0c087 --- /dev/null +++ b/src/de/teamteamteam/spacescooter/entities/Entity.java @@ -0,0 +1,15 @@ +package de.teamteamteam.spacescooter.entities; + +import java.awt.Graphics; + +public abstract class Entity { + + public void update() { + + } + + public void paint(Graphics g) { + + } + +} diff --git a/src/de/teamteamteam/spacescooter/entities/TestEntity.java b/src/de/teamteamteam/spacescooter/entities/TestEntity.java new file mode 100644 index 0000000..493efa9 --- /dev/null +++ b/src/de/teamteamteam/spacescooter/entities/TestEntity.java @@ -0,0 +1,28 @@ +package de.teamteamteam.spacescooter.entities; + +import java.awt.Color; +import java.awt.Graphics; +import java.util.Random; + +public class TestEntity extends Entity { + + private Color color; + private Random random; + + public TestEntity() { + super(); + this.color = new Color(255, 0, 0); + this.random = new Random(); + } + + public void paint(Graphics g) { + g.setColor(this.color); + g.drawRect(100, 200, 300, 300); + } + + public void update() { + System.out.println("TestEntity.update()!"); + this.color = new Color(this.random.nextInt(255),this.random.nextInt(255),this.random.nextInt(255)); + } + +} diff --git a/src/de/teamteamteam/spacescooter/gui/GameFrame.java b/src/de/teamteamteam/spacescooter/gui/GameFrame.java new file mode 100644 index 0000000..c5e47de --- /dev/null +++ b/src/de/teamteamteam/spacescooter/gui/GameFrame.java @@ -0,0 +1,48 @@ +package de.teamteamteam.spacescooter.gui; + +import java.awt.Graphics; +import java.util.ArrayList; +import java.util.Iterator; + +import javax.swing.JFrame; + +import de.teamteamteam.spacescooter.entities.Entity; +import de.teamteamteam.spacescooter.entities.TestEntity; + +public class GameFrame extends JFrame { + + private ArrayList entities; + + public GameFrame() { + super(); + this.entities = new ArrayList(); + + //TODO: Remove this! + TestEntity t = new TestEntity(); + this.entities.add(t); + } + + public ArrayList getEntityList() { + return this.entities; + } + + public void init() { + this.setTitle("Unser schöner Titel"); + this.setSize(800, 600); + this.setUndecorated(false); + this.setDefaultCloseOperation(EXIT_ON_CLOSE); + this.setVisible(true); + } + + @Override + public void paint(Graphics g) { + Iterator i = this.entities.iterator(); + while(i.hasNext()) { + Entity e = i.next(); + e.paint(g); + } + } + + + +} diff --git a/src/de/teamteamteam/spacescooter/threads/PaintThread.java b/src/de/teamteamteam/spacescooter/threads/PaintThread.java new file mode 100644 index 0000000..546edc9 --- /dev/null +++ b/src/de/teamteamteam/spacescooter/threads/PaintThread.java @@ -0,0 +1,23 @@ +package de.teamteamteam.spacescooter.threads; + +import de.teamteamteam.spacescooter.gui.GameFrame; + +public class PaintThread extends Thread { + + private GameFrame gf; + + public PaintThread(GameFrame gf) { + this.gf = gf; + } + + public void run() { + while (true) { + try { + Thread.sleep(16); + } catch (InterruptedException e) { + System.err.println(e); + } + this.gf.repaint(); + } + } +} diff --git a/src/de/teamteamteam/spacescooter/threads/UpdateThread.java b/src/de/teamteamteam/spacescooter/threads/UpdateThread.java new file mode 100644 index 0000000..53454e3 --- /dev/null +++ b/src/de/teamteamteam/spacescooter/threads/UpdateThread.java @@ -0,0 +1,37 @@ +package de.teamteamteam.spacescooter.threads; + +import java.util.ArrayList; +import java.util.Iterator; + + +import de.teamteamteam.spacescooter.entities.Entity; +import de.teamteamteam.spacescooter.gui.GameFrame; + +public class UpdateThread extends Thread { + + private GameFrame gf; + + public UpdateThread(GameFrame gf) { + this.gf = gf; + } + + public void run() { + while (true) { + try { + Thread.sleep(16); + } catch (InterruptedException e) { + System.err.println(e); + } + this.updateEntities(); + } + } + + public void updateEntities() { + ArrayList entityList = this.gf.getEntityList(); + Iterator i = entityList.iterator(); + while(i.hasNext()) { + Entity e = i.next(); + e.update(); + } + } +}