Refactored and cleaned up code. Modernized some constructs.

This commit is contained in:
cognitivegears
2014-04-08 22:04:44 -05:00
parent 5db7d9b43f
commit 0786afb4d9
178 changed files with 31022 additions and 32600 deletions

View File

@@ -4,54 +4,52 @@ import java.awt.Color;
import java.awt.Graphics;
import java.io.Serializable;
public class Arrow implements Serializable
{
public static int DIR_UP = 0;
public static int DIR_RIGHT = 1;
public static int DIR_DOWN = 2;
public static int DIR_LEFT = 3;
public int direction;
public int length;
public int x;
public int y;
public Color color;
public class Arrow implements Serializable {
public static int DIR_UP = 0;
public static int DIR_RIGHT = 1;
public static int DIR_DOWN = 2;
public static int DIR_LEFT = 3;
public int direction;
private int length;
private int x;
public int y;
private Color color;
public Arrow() {}
public Arrow() {
}
public Arrow(int X, int Y, int dir, int len, Color c)
{
x=X; y=Y;
direction = dir;
length = len;
color = c;
}
public Arrow(int X, int Y, int dir, int len, Color c) {
x = X;
y = Y;
direction = dir;
length = len;
color = c;
}
public void Draw(Graphics g)
{
g.setColor(color);
switch(direction)
{
case 0:
g.drawLine(x,y,x-8,y+8);
g.drawLine(x,y,x+8,y+8);
g.drawLine(x,y,x,y+length);
break;
case 1:
g.drawLine(x,y,x-8,y-8);
g.drawLine(x,y,x-8,y+8);
g.drawLine(x,y,x-length,y);
break;
case 2:
g.drawLine(x,y,x-8,y-8);
g.drawLine(x,y,x+8,y-8);
g.drawLine(x,y,x,y-length);
break;
case 3:
g.drawLine(x,y,x+8,y-8);
g.drawLine(x,y,x+8,y+8);
g.drawLine(x,y,x+length,y);
break;
}
}
public void Draw(Graphics g) {
g.setColor(color);
switch (direction) {
case 0:
g.drawLine(x, y, x - 8, y + 8);
g.drawLine(x, y, x + 8, y + 8);
g.drawLine(x, y, x, y + length);
break;
case 1:
g.drawLine(x, y, x - 8, y - 8);
g.drawLine(x, y, x - 8, y + 8);
g.drawLine(x, y, x - length, y);
break;
case 2:
g.drawLine(x, y, x - 8, y - 8);
g.drawLine(x, y, x + 8, y - 8);
g.drawLine(x, y, x, y - length);
break;
case 3:
g.drawLine(x, y, x + 8, y - 8);
g.drawLine(x, y, x + 8, y + 8);
g.drawLine(x, y, x + length, y);
break;
}
}
}

View File

@@ -7,126 +7,128 @@ import javax.swing.ImageIcon;
import com.droidquest.RoomDisplay;
public class Graphix implements Serializable
{
public String[] filenames;
transient protected ImageIcon[] icons; // Array of images for this item
transient ImageIcon icon;
int animationState;
public int x; // Current position
int y;
int behavior; // Overall behavior (SIT, CYCLE, BOUNCE)
int current=1; // Current behavior; 1=move forward, -1=move backward
int dx, dy; // Direction of "forward"
public int count;
int length; // Number of times the Graphix moves forward
public static int SIT=0;
public static int CYCLE=1;
public static int BOUNCE=2;
public class Graphix implements Serializable {
public String[] filenames;
private transient ImageIcon[] icons; // Array of images for this item
private transient ImageIcon icon;
private int animationState;
public int x; // Current position
private int y;
private int behavior; // Overall behavior (SIT, CYCLE, BOUNCE)
private int current = 1; // Current behavior; 1=move forward, -1=move backward
private int dx;
private int dy; // Direction of "forward"
public int count;
private int length; // Number of times the Graphix moves forward
private static int SIT = 0;
public static int CYCLE = 1;
public static int BOUNCE = 2;
public Graphix() {}
public Graphix() {
}
public Graphix(int X, int Y)
{
x=X; y=Y;
GenerateIcons();
}
public Graphix(int X, int Y) {
x = X;
y = Y;
GenerateIcons();
}
public Graphix(String file, int X, int Y)
{
filenames = new String[1];
filenames[0] = new String(file);
behavior = SIT;
x=X; y=Y;
GenerateIcons();
}
public Graphix(String file, int X, int Y) {
filenames = new String[1];
filenames[0] = file;
behavior = SIT;
x = X;
y = Y;
GenerateIcons();
}
public Graphix(String[] files, int X, int Y)
{
x=X; y=Y;
filenames = files;
behavior = SIT;
GenerateIcons();
}
public Graphix(String[] files, int X, int Y) {
x = X;
y = Y;
filenames = files;
behavior = SIT;
GenerateIcons();
}
public Graphix(String file, int X, int Y, int b, int DX, int DY, int L)
{
filenames = new String[1];
filenames[0] = new String(file);
x=X; y=Y;
behavior = b;
dx=DX; dy=DY;
length = L;
GenerateIcons();
}
public Graphix(String file, int X, int Y, int b, int DX, int DY, int L) {
filenames = new String[1];
filenames[0] = file;
x = X;
y = Y;
behavior = b;
dx = DX;
dy = DY;
length = L;
GenerateIcons();
}
public Graphix(String[] files, int X, int Y, int b, int DX, int DY, int L)
{
filenames = files;
x=X; y=Y;
behavior = b;
dx=DX; dy=DY;
length = L;
GenerateIcons();
}
public Graphix(String[] files, int X, int Y, int b, int DX, int DY, int L) {
filenames = files;
x = X;
y = Y;
behavior = b;
dx = DX;
dy = DY;
length = L;
GenerateIcons();
}
public void GenerateIcons()
{
int numfiles = filenames.length;
icons = new ImageIcon[numfiles];
for (int a=0; a< numfiles; a++)
icons[a] = new ImageIcon("images/"+ filenames[a]);
icon = icons[0];
}
public void GenerateIcons() {
int numfiles = filenames.length;
icons = new ImageIcon[numfiles];
for (int a = 0; a < numfiles; a++) {
icons[a] = new ImageIcon("images/" + filenames[a]);
}
icon = icons[0];
}
public void Draw(Graphics g, RoomDisplay rd)
{
if (icon != null)
g.drawImage(icon.getImage(), x, y, rd);
}
public void Draw(Graphics g, RoomDisplay rd) {
if (icon != null) {
g.drawImage(icon.getImage(), x, y, rd);
}
}
public void Animate()
{
int numfiles = filenames.length;
animationState++;
if (animationState==numfiles)
animationState=0;
icon = icons[animationState];
if (behavior==CYCLE)
{
if (count==length)
{
x-=dx*length;
y-=dy*length;
count=0;
}
else
{
x+=dx; y+=dy;
count++;
}
}
if (behavior==BOUNCE)
if (current==1)
{
if (count==length)
current=-1;
else
{
x+=dx; y+=dy;
count++;
}
}
else
{
if (count==0)
current=1;
else
{
x-=dx; y-=dy;
count--;
}
}
}
public void Animate() {
int numfiles = filenames.length;
animationState++;
if (animationState == numfiles) {
animationState = 0;
}
icon = icons[animationState];
if (behavior == CYCLE) {
if (count == length) {
x -= dx * length;
y -= dy * length;
count = 0;
}
else {
x += dx;
y += dy;
count++;
}
}
if (behavior == BOUNCE) {
if (current == 1) {
if (count == length) {
current = -1;
}
else {
x += dx;
y += dy;
count++;
}
}
else {
if (count == 0) {
current = 1;
}
else {
x -= dx;
y -= dy;
count--;
}
}
}
}
}

View File

@@ -6,39 +6,43 @@ import java.io.Serializable;
import com.droidquest.Room;
public class Spark implements Serializable
{
public int x,y;
public int dx,dy;
public int age;
public Room room;
public class Spark implements Serializable {
public int x, y;
private int dx;
private int dy;
public int age;
public Room room;
public Spark() {}
public Spark(int X, int Y, int Dx, int Dy, Room r)
{
x=X; y=Y;
dx = Dx; dy= Dy;
room = r;
age=0;
}
public Spark(int X, int Y, int Dx, int Dy, Room r) {
x = X;
y = Y;
dx = Dx;
dy = Dy;
room = r;
age = 0;
}
public void Age()
{
x += dx; y+= dy;
if (x<0 || x>560 || y<0 || y>384) room=null;
age++;
}
public void Age() {
x += dx;
y += dy;
if (x < 0 || x > 560 || y < 0 || y > 384) {
room = null;
}
age++;
}
public void Draw(Graphics g)
{
if (age<2)
g.setColor(Color.white);
else if (age>=2 && age<4)
g.setColor(Color.yellow);
else
g.setColor(Color.red);
g.fillRect(x,y,2,2);
}
public void Draw(Graphics g) {
if (age < 2) {
g.setColor(Color.white);
}
else if (age >= 2 && age < 4) {
g.setColor(Color.yellow);
}
else {
g.setColor(Color.red);
}
g.fillRect(x, y, 2, 2);
}
}

View File

@@ -2,26 +2,27 @@ package com.droidquest.decorations;
import java.io.Serializable;
public class TextBox implements Serializable
{
public String textString;
public int x; // Position
public int y;
public int width; // Size
public class TextBox implements Serializable {
public String textString;
public int x; // Position
public int y;
public int width; // Size
public TextBox() {}
public TextBox() {
}
public TextBox(String t, int X, int Y, int W)
{
textString = t;
x=X; y=Y; width=W;
}
public TextBox(String t, int X, int Y, int W) {
textString = t;
x = X;
y = Y;
width = W;
}
public TextBox(String t, int X, int Y)
{
textString = t;
x=X; y=Y;
width=500;
}
public TextBox(String t, int X, int Y) {
textString = t;
x = X;
y = Y;
width = 500;
}
}