Erster Prototyp
This commit is contained in:
parent
7b4429b931
commit
5ec52879ac
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
*~
|
||||
.project
|
||||
.settings
|
||||
|
||||
.classpath
|
||||
bin
|
||||
|
31
src/de/teamteamteam/spacescooter/Main.java
Normal file
31
src/de/teamteamteam/spacescooter/Main.java
Normal file
@ -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();
|
||||
|
||||
}
|
||||
|
||||
}
|
15
src/de/teamteamteam/spacescooter/entities/Entity.java
Normal file
15
src/de/teamteamteam/spacescooter/entities/Entity.java
Normal file
@ -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) {
|
||||
|
||||
}
|
||||
|
||||
}
|
28
src/de/teamteamteam/spacescooter/entities/TestEntity.java
Normal file
28
src/de/teamteamteam/spacescooter/entities/TestEntity.java
Normal file
@ -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));
|
||||
}
|
||||
|
||||
}
|
48
src/de/teamteamteam/spacescooter/gui/GameFrame.java
Normal file
48
src/de/teamteamteam/spacescooter/gui/GameFrame.java
Normal file
@ -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<Entity> entities;
|
||||
|
||||
public GameFrame() {
|
||||
super();
|
||||
this.entities = new ArrayList<Entity>();
|
||||
|
||||
//TODO: Remove this!
|
||||
TestEntity t = new TestEntity();
|
||||
this.entities.add(t);
|
||||
}
|
||||
|
||||
public ArrayList<Entity> 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<Entity> i = this.entities.iterator();
|
||||
while(i.hasNext()) {
|
||||
Entity e = i.next();
|
||||
e.paint(g);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
23
src/de/teamteamteam/spacescooter/threads/PaintThread.java
Normal file
23
src/de/teamteamteam/spacescooter/threads/PaintThread.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
37
src/de/teamteamteam/spacescooter/threads/UpdateThread.java
Normal file
37
src/de/teamteamteam/spacescooter/threads/UpdateThread.java
Normal file
@ -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<Entity> entityList = this.gf.getEntityList();
|
||||
Iterator<Entity> i = entityList.iterator();
|
||||
while(i.hasNext()) {
|
||||
Entity e = i.next();
|
||||
e.update();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user