Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a6d3d0d
Showing
9 changed files
with
255 additions
and
0 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,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
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 @@ | ||
bin |
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,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>obviam-mvc-droids</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
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,58 @@ | ||
package net.obviam.droids; | ||
|
||
import java.applet.Applet; | ||
import java.awt.Color; | ||
import java.awt.Event; | ||
import java.awt.Graphics; | ||
import java.awt.image.BufferedImage; | ||
|
||
public class Droids extends Applet implements Runnable { | ||
|
||
private static final long serialVersionUID = -2472397668493332423L; | ||
|
||
public void start() { | ||
new Thread(this).start(); | ||
} | ||
|
||
public void run() { | ||
|
||
setSize(480, 320); // For AppletViewer, remove later. | ||
|
||
// Set up the graphics stuff, double-buffering. | ||
BufferedImage screen = new BufferedImage(480, 320, BufferedImage.TYPE_INT_RGB); | ||
Graphics g = screen.getGraphics(); | ||
Graphics appletGraphics = getGraphics(); | ||
|
||
long delta = 0l; | ||
|
||
// Game loop. | ||
while (true) { | ||
long lastTime = System.nanoTime(); | ||
|
||
g.setColor(Color.black); | ||
g.fillRect(0, 0, 480, 320); | ||
|
||
// Draw the entire results on the screen. | ||
appletGraphics.drawImage(screen, 0, 0, null); | ||
|
||
// Lock the frame rate | ||
delta = System.nanoTime() - lastTime; | ||
if (delta < 20000000L) { | ||
try { | ||
Thread.sleep((20000000L - delta) / 1000000L); | ||
} catch (Exception e) { | ||
// It's an interrupted exception, and nobody cares | ||
} | ||
} | ||
|
||
if (!isActive()) { | ||
return; | ||
} | ||
} | ||
} | ||
|
||
public boolean handleEvent(Event e) { | ||
return false; | ||
} | ||
|
||
} |
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,30 @@ | ||
package net.obviam.droids.controller; | ||
|
||
import java.awt.Event; | ||
|
||
public class GameController { | ||
|
||
public boolean handleEvent(Event e) { | ||
switch (e.id) { | ||
case Event.KEY_PRESS: | ||
case Event.KEY_ACTION: | ||
// key pressed | ||
break; | ||
case Event.KEY_RELEASE: | ||
// key released | ||
break; | ||
case Event.MOUSE_DOWN: | ||
// mouse button pressed | ||
break; | ||
case Event.MOUSE_UP: | ||
// mouse button released | ||
break; | ||
case Event.MOUSE_MOVE: | ||
break; | ||
case Event.MOUSE_DRAG: | ||
break; | ||
} | ||
return false; | ||
} | ||
|
||
} |
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,57 @@ | ||
package net.obviam.droids.model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
public class Arena { | ||
|
||
public static final int WIDTH = 480 / 32; | ||
public static final int HEIGHT = 320 / 32; | ||
|
||
private static Random random = new Random(System.currentTimeMillis()); | ||
|
||
private Object[][] grid; | ||
private List<Obstacle> obstacles = new ArrayList<Obstacle>(); | ||
private List<Enemy> enemies = new ArrayList<Enemy>(); | ||
private Droid droid; | ||
|
||
public Arena(Droid droid) { | ||
this.droid = droid; | ||
|
||
grid = new Object[HEIGHT][WIDTH]; | ||
for (int i = 0; i < WIDTH; i++) { | ||
for (int j = 0; j < HEIGHT; j++) { | ||
grid[j][i] = null; | ||
} | ||
} | ||
// add 5 obstacles and 5 enemies at random positions | ||
for (int i = 0; i < 5; i++) { | ||
int x = random.nextInt(WIDTH); | ||
int y = random.nextInt(HEIGHT); | ||
while (grid[y][x] != null) { | ||
x = random.nextInt(WIDTH); | ||
y = random.nextInt(HEIGHT); | ||
} | ||
grid[y][x] = new Obstacle(x, y); | ||
obstacles.add((Obstacle) grid[y][x]); | ||
while (grid[y][x] != null) { | ||
x = random.nextInt(WIDTH); | ||
y = random.nextInt(HEIGHT); | ||
} | ||
grid[y][x] = new Enemy(x, y); | ||
enemies.add((Enemy) grid[y][x]); | ||
} | ||
} | ||
|
||
public List<Obstacle> getObstacles() { | ||
return obstacles; | ||
} | ||
public List<Enemy> getEnemies() { | ||
return enemies; | ||
} | ||
public Droid getDroid() { | ||
return droid; | ||
} | ||
|
||
} |
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,41 @@ | ||
package net.obviam.droids.model; | ||
|
||
public class Droid { | ||
|
||
private float x; | ||
private float y; | ||
private float speed = 2f; | ||
private float rotation = 0f; | ||
private float damage = 2f; | ||
|
||
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 getSpeed() { | ||
return speed; | ||
} | ||
public void setSpeed(float speed) { | ||
this.speed = speed; | ||
} | ||
public float getRotation() { | ||
return rotation; | ||
} | ||
public void setRotation(float rotation) { | ||
this.rotation = rotation; | ||
} | ||
public float getDamage() { | ||
return damage; | ||
} | ||
public void setDamage(float damage) { | ||
this.damage = damage; | ||
} | ||
} |
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,26 @@ | ||
package net.obviam.droids.model; | ||
|
||
public class Enemy { | ||
|
||
private float x; | ||
private float y; | ||
private int hitpoints = 10; | ||
|
||
public Enemy(float x, float y) { | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
public float getX() { | ||
return x; | ||
} | ||
public float getY() { | ||
return y; | ||
} | ||
public int getHitpoints() { | ||
return hitpoints; | ||
} | ||
public void setHitpoints(int hitpoints) { | ||
this.hitpoints = hitpoints; | ||
} | ||
} |
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,19 @@ | ||
package net.obviam.droids.model; | ||
|
||
public class Obstacle { | ||
|
||
private float x; | ||
private float y; | ||
|
||
public Obstacle(float x, float y) { | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
public float getX() { | ||
return x; | ||
} | ||
public float getY() { | ||
return y; | ||
} | ||
} |