Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
obviam committed Feb 3, 2012
0 parents commit a6d3d0d
Show file tree
Hide file tree
Showing 9 changed files with 255 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .classpath
@@ -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>
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
bin
17 changes: 17 additions & 0 deletions .project
@@ -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>
58 changes: 58 additions & 0 deletions src/net/obviam/droids/Droids.java
@@ -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;
}

}
30 changes: 30 additions & 0 deletions src/net/obviam/droids/controller/GameController.java
@@ -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;
}

}
57 changes: 57 additions & 0 deletions src/net/obviam/droids/model/Arena.java
@@ -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;
}

}
41 changes: 41 additions & 0 deletions src/net/obviam/droids/model/Droid.java
@@ -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;
}
}
26 changes: 26 additions & 0 deletions src/net/obviam/droids/model/Enemy.java
@@ -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;
}
}
19 changes: 19 additions & 0 deletions src/net/obviam/droids/model/Obstacle.java
@@ -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;
}
}

0 comments on commit a6d3d0d

Please sign in to comment.