Changeset 8edd04e in lost-haven
- Timestamp:
- Jun 7, 2020, 3:04:32 PM (4 years ago)
- Branches:
- master
- Children:
- a49176d
- Parents:
- 155577b
- Files:
-
- 38 added
- 2 deleted
- 33 edited
Legend:
- Unmodified
- Added
- Removed
-
.gitignore
r155577b r8edd04e 1 1 *.class 2 2 LostHaven.jar 3 save.txt 4 savedItems.txt 3 5 err.txt -
gamegui/Animation.java
r155577b r8edd04e 1 1 package gamegui; 2 2 3 import java.awt. *;4 import java.awt.image. *;5 import java.util. *;3 import java.awt.Graphics; 4 import java.awt.image.BufferedImage; 5 import java.util.ArrayList; 6 6 7 public class Animation extends Member 8 { 9 ArrayList<BufferedImage> frames; 10 int currentFrame; 11 int drawInterval; 12 long lastFrameChange; 13 14 public Animation(String newName, int newX, int newY, int newWidth, int newHeight, int newInterval) 15 { 16 super(newName, newX, newY, newWidth, newHeight); 17 18 frames = new ArrayList<BufferedImage>(); 19 currentFrame = 0; 20 drawInterval = newInterval; 21 lastFrameChange = 0; 22 } 23 24 public void addFrame(BufferedImage newFrame) 25 { 26 frames.add(newFrame); 27 } 28 29 public void draw(Graphics g) 30 { 31 if(System.currentTimeMillis() - lastFrameChange > drawInterval) 32 { 33 currentFrame++; 34 if(currentFrame >= frames.size()) 35 currentFrame = 0; 36 37 lastFrameChange = System.currentTimeMillis(); 38 } 39 40 g.drawImage(frames.get(currentFrame), getX(), getY(), null); 41 } 7 public class Animation extends Member { 8 9 public ArrayList<BufferedImage> frames; 10 public long drawInterval; 11 public boolean wrap; 12 13 int currentFrame; 14 long lastFrameChange; 15 boolean reachedEnd; 16 17 public Animation(String newName, int newX, int newY, int newWidth, int newHeight, int newInterval, boolean wrap) { 18 super(newName, newX, newY, newWidth, newHeight); 19 this.frames = new ArrayList<BufferedImage>(); 20 this.currentFrame = 0; 21 this.drawInterval = newInterval; 22 this.lastFrameChange = 0L; 23 this.reachedEnd = false; 24 this.wrap = wrap; 25 } 26 27 public Animation(Animation copy) { 28 super(copy.getName(), copy.getX(), copy.getY(), copy.getWidth(), copy.getHeight()); 29 this.frames = copy.frames; 30 this.currentFrame = copy.currentFrame; 31 this.drawInterval = copy.drawInterval; 32 this.lastFrameChange = 0L; 33 this.reachedEnd = false; 34 this.wrap = copy.wrap; 35 } 36 37 public void addFrame(BufferedImage newFrame) { 38 this.frames.add(newFrame); 39 setWidth(newFrame.getWidth()); 40 setHeight(newFrame.getHeight()); 41 } 42 43 public void draw(Graphics g) { 44 if (this.lastFrameChange == 0L) 45 this.lastFrameChange = System.currentTimeMillis(); 46 if (System.currentTimeMillis() - this.lastFrameChange > this.drawInterval) { 47 this.currentFrame++; 48 if (this.currentFrame >= this.frames.size()) { 49 if (this.wrap) { 50 this.currentFrame = 0; 51 } else { 52 this.currentFrame--; 53 } 54 this.reachedEnd = true; 55 } 56 this.lastFrameChange = System.currentTimeMillis(); 57 } 58 g.drawImage(this.frames.get(this.currentFrame), getX(), getY(), null); 59 } 60 61 public void draw(Graphics g, int x, int y) { 62 if (this.lastFrameChange == 0L) 63 this.lastFrameChange = System.currentTimeMillis(); 64 if (System.currentTimeMillis() - this.lastFrameChange > this.drawInterval) { 65 this.currentFrame++; 66 if (this.currentFrame >= this.frames.size()) { 67 if (this.wrap) { 68 this.currentFrame = 0; 69 } else { 70 this.currentFrame--; 71 } 72 this.reachedEnd = true; 73 } 74 this.lastFrameChange = System.currentTimeMillis(); 75 } 76 g.drawImage(this.frames.get(this.currentFrame), getX() + x - ((BufferedImage)this.frames.get(this.currentFrame)).getWidth() / 2, getY() + y - ((BufferedImage)this.frames.get(this.currentFrame)).getHeight(), null); 77 } 78 79 public boolean reachedEnd() { 80 return this.reachedEnd; 81 } 82 83 public void reset() { 84 this.reachedEnd = false; 85 this.currentFrame = 0; 86 this.lastFrameChange = 0L; 87 } 88 89 public int getWidth() { 90 return ((BufferedImage)this.frames.get(this.currentFrame)).getWidth(); 91 } 92 93 public int getHeight() { 94 return ((BufferedImage)this.frames.get(this.currentFrame)).getHeight(); 95 } 42 96 } -
gamegui/Button.java
r155577b r8edd04e 2 2 3 3 import java.awt.*; 4 import java.awt.image.BufferedImage; 4 5 5 public class Button extends Member 6 { 7 private String text; 8 private Font font; 9 10 public Button(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont) 11 { 12 super(newName, newX, newY, newWidth, newHeight); 13 14 text = newText; 15 font = newFont; 16 } 17 18 public void draw(Graphics g) 19 { 20 FontMetrics metrics = g.getFontMetrics(font); 21 22 g.setColor(Color.red); 23 g.drawRect(getX(), getY(), getWidth(), getHeight()); 24 25 g.setColor(Color.green); 26 g.setFont(font); 27 g.drawString(text, getX() + (getWidth() - metrics.stringWidth(text))/2, getY() + (getHeight() + metrics.getHeight())/2 - 2); 28 } 29 30 public boolean isClicked(int xCoord, int yCoord) 31 { 32 if(xCoord < getX() || getX() + getWidth() < xCoord) 33 return false; 34 if(yCoord < getY() || getY() + getHeight() < yCoord) 35 return false; 36 37 return true; 38 } 6 public class Button extends Member { 7 8 private String text; 9 private Font font; 10 private BufferedImage img; 11 private Align alignment; 12 13 public Button(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont) { 14 super(newName, newX, newY, newWidth, newHeight); 15 this.text = newText; 16 this.font = newFont; 17 this.img = null; 18 this.alignment = Align.Left; 19 } 20 21 public Button(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont, Align alignment) { 22 super(newName, newX, newY, newWidth, newHeight); 23 this.text = newText; 24 this.font = newFont; 25 this.img = null; 26 this.alignment = alignment; 27 } 28 29 public Button(String newName, int newX, int newY, int newWidth, int newHeight, BufferedImage img) { 30 super(newName, newX, newY, newWidth, newHeight); 31 this.text = ""; 32 this.font = null; 33 this.img = img; 34 this.alignment = Align.Left; 35 } 36 37 public void draw(Graphics g) { 38 if (this.img == null) { 39 FontMetrics metrics = g.getFontMetrics(this.font); 40 g.setColor(Color.red); 41 g.drawRect(getX(), getY(), getWidth(), getHeight()); 42 g.setColor(Color.green); 43 g.setFont(this.font); 44 switch (this.alignment) { 45 case Center: 46 g.drawString(this.text, getX() + (getWidth() - metrics.stringWidth(this.text)) / 2, getY() + (getHeight() + metrics.getHeight()) / 2 - 2); 47 break; 48 case Right: 49 g.drawString(this.text, getX() + getWidth() - metrics.stringWidth(this.text), getY() + (getHeight() + metrics.getHeight()) / 2 - 2); 50 break; 51 case Left: 52 g.drawString(this.text, getX() + (getWidth() - metrics.stringWidth(this.text)) / 2, getY() + (getHeight() + metrics.getHeight()) / 2 - 2); 53 break; 54 } 55 } else { 56 g.drawImage(this.img, getX() + (getWidth() - this.img.getWidth()) / 2, getY() + (getHeight() - this.img.getHeight()) / 2 - 2, null); 57 } 58 } 39 59 } -
gamegui/Label.java
r155577b r8edd04e 3 3 import java.awt.*; 4 4 5 public class Label extends Member 6 { 7 private String text; 8 private Font font; 9 private boolean centered; 10 private boolean fixed; 11 12 public Label(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont, boolean centered) { 13 super(newName, newX, newY, newWidth, newHeight); 14 15 text = newText; 16 font = newFont; 17 this.centered = centered; 18 fixed = false; 19 } 20 21 public Label(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont, boolean centered, boolean fixed) { 22 super(newName, newX, newY, newWidth, newHeight); 23 24 text = newText; 25 font = newFont; 26 this.centered = centered; 27 this.fixed = fixed; 28 } 29 30 public void setText(String s) { 31 text = s; 32 } 33 34 public void draw(Graphics g) { 35 FontMetrics metrics = g.getFontMetrics(font); 36 37 g.setColor(Color.green); 38 g.setFont(font); 39 40 if(centered) 41 g.drawString(text, getX() + (getWidth() - metrics.stringWidth(text))/2, getY() + (getHeight() + metrics.getHeight())/2 - 2); 42 else if(fixed) 43 g.drawString(text, getX(), getY()); 44 else 45 g.drawString(text, getX(), getY() + (getHeight() + metrics.getHeight())/2 - 2); 46 } 5 public class Label extends Member { 6 7 private String text; 8 private Font font; 9 private Align alignment; 10 11 public Label(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont) { 12 super(newName, newX, newY, newWidth, newHeight); 13 this.text = newText; 14 this.font = newFont; 15 this.alignment = Align.Center; 16 } 17 18 public Label(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont, Align alignment) { 19 super(newName, newX, newY, newWidth, newHeight); 20 this.text = newText; 21 this.font = newFont; 22 this.alignment = alignment; 23 } 24 25 public void setText(String s) { 26 this.text = s; 27 } 28 29 public void draw(Graphics g) { 30 FontMetrics metrics = g.getFontMetrics(this.font); 31 g.setColor(Color.green); 32 g.setFont(this.font); 33 switch (this.alignment) { 34 case Center: 35 g.drawString(this.text, getX() + (getWidth() - metrics.stringWidth(this.text)) / 2, getY() + (getHeight() + metrics.getHeight()) / 2 - 2); 36 break; 37 case Right: 38 g.drawString(this.text, getX() + getWidth() - metrics.stringWidth(this.text), getY() + (getHeight() + metrics.getHeight()) / 2 - 2); 39 break; 40 case Left: 41 g.drawString(this.text, getX(), getY() + (getHeight() + metrics.getHeight()) / 2 - 2); 42 break; 43 } 44 } 47 45 } -
gamegui/Listable.java
r155577b r8edd04e 1 1 package gamegui; 2 2 3 import java.awt. *;3 import java.awt.Graphics; 4 4 5 5 public interface Listable { 6 public void drawListString(int x, int y, Graphics g); 6 7 void draw(int paramInt1, int paramInt2, Graphics paramGraphics); 8 int getHeight(); 9 int getWidth(); 10 int getXOffset(); 11 int getYOffset(); 7 12 } -
gamegui/Member.java
r155577b r8edd04e 1 1 package gamegui; 2 2 3 import java.awt. *;4 import java.awt.event. *;3 import java.awt.Graphics; 4 import java.awt.event.MouseEvent; 5 5 6 6 public class Member { 7 private String name;8 private int x;9 private int y;10 private int width;11 private int height;12 private ScrollBar scrollbar;13 14 public Member(String newName, int newX, int newY, int newWidth, int newHeight) {15 name = newName;16 x = newX;17 y = newY;18 width = newWidth;19 height = newHeight;20 }21 22 public void draw(Graphics g) {23 7 24 } 25 26 public boolean handleEvent(MouseEvent e) { 27 return false; 28 } 29 30 public boolean isClicked(int xCoord, int yCoord) { 31 return x <= xCoord && xCoord <= x+width && y <= yCoord && yCoord <= y+height; 32 } 33 34 public void clear() { 35 36 } 37 38 public String getName() { 39 return name; 40 } 41 42 public int getX() { 43 return x; 44 } 45 46 public int getY() { 47 return y; 48 } 49 50 public int getWidth() { 51 return width; 52 } 53 54 public int getHeight() { 55 return height; 56 } 57 58 public ScrollBar getScrollBar() { 59 return scrollbar; 60 } 8 private String name; 9 private int x; 10 private int y; 11 private int width; 12 private int height; 13 private ScrollBar scrollbar; 61 14 62 public void addScrollBar(ScrollBar newBar) { 63 newBar.offset(x, y); 64 scrollbar = newBar; 65 } 66 67 protected void offset(int xOffset, int yOffset) { 68 x += xOffset; 69 y += yOffset; 70 71 if(scrollbar != null) 72 scrollbar.offset(xOffset, yOffset); 73 } 15 public Member(String newName, int newX, int newY, int newWidth, int newHeight) { 16 this.name = newName; 17 this.x = newX; 18 this.y = newY; 19 this.width = newWidth; 20 this.height = newHeight; 21 } 22 23 public void draw(Graphics g) {} 24 25 public boolean handleEvent(MouseEvent e) { 26 return false; 27 } 28 29 public boolean isClicked(int xCoord, int yCoord) { 30 return (this.x <= xCoord && xCoord <= this.x + this.width && this.y <= yCoord && yCoord <= this.y + this.height); 31 } 32 33 public void clear() { 34 } 35 36 public String getName() { 37 return this.name; 38 } 39 40 public int getX() { 41 return this.x; 42 } 43 44 public int getY() { 45 return this.y; 46 } 47 48 public int getWidth() { 49 return this.width; 50 } 51 52 public int getHeight() { 53 return this.height; 54 } 55 56 public ScrollBar getScrollBar() { 57 return this.scrollbar; 58 } 59 60 public void setWidth(int width) { 61 this.width = width; 62 } 63 64 public void setHeight(int height) { 65 this.height = height; 66 } 67 68 public void addScrollBar(ScrollBar newBar) { 69 newBar.offset(this.x, this.y); 70 this.scrollbar = newBar; 71 } 72 73 protected void offset(int xOffset, int yOffset) { 74 this.x += xOffset; 75 this.y += yOffset; 76 if (this.scrollbar != null) { 77 this.scrollbar.offset(xOffset, yOffset); 78 } 79 } 74 80 } -
gamegui/Menu.java
r155577b r8edd04e 1 1 package gamegui; 2 2 3 import java.awt.*; 4 import java.awt.event.*; 5 import java.util.*; 3 import java.awt.Color; 4 import java.awt.Font; 5 import java.awt.FontMetrics; 6 import java.awt.Graphics; 7 import java.awt.event.MouseEvent; 8 import java.util.ArrayList; 6 9 7 10 public class Menu extends Member { 8 private ArrayList<String> items; 9 private int selectedIndex; 10 private String label; 11 private Font font; 12 private boolean open; //determines if the menu is pulled down 13 private FontMetrics metrics; 14 15 public Menu(String newName, int newX, int newY, int newWidth, int newHeight, String newLabel, Font newFont) { 16 super(newName, newX, newY, newWidth, newHeight); 17 18 items = new ArrayList<String>(); 19 selectedIndex = -1; 20 label = newLabel; 21 font = newFont; 22 open = false; 23 } 24 25 public boolean handleEvent(MouseEvent e) { 26 if(getX()+metrics.stringWidth(label)+4 <= e.getX() && e.getX() <= getX()+getWidth() && getY()+getHeight() <= e.getY() && e.getY() <= getY()+getHeight()+15*items.size() && open) { 27 selectedIndex = (e.getY()-getY()-getHeight())/15; 28 open = false; 29 return true; 30 } 31 32 if(getX()+getWidth()-getHeight() <= e.getX() && e.getX() <= getX()+getWidth() && getY() <= e.getY() && e.getY() <= getY()+getHeight()) { 33 open = !open; 34 return true; 35 } 36 37 return false; 38 } 39 40 public void clear() { 41 if(selectedIndex != -1) 42 selectedIndex = 0; 43 } 44 45 public void draw(Graphics g) 46 { 47 metrics = g.getFontMetrics(font); 48 49 g.setColor(Color.black); 50 g.fillRect(getX(), getY(), getWidth(), getHeight()); 51 52 g.setColor(Color.red); 53 g.drawRect(getX(), getY(), getWidth(), getHeight()); 54 55 g.drawLine(getX()+metrics.stringWidth(label)+4, getY(), getX()+metrics.stringWidth(label)+4, getY()+getHeight()); 56 g.drawLine(getX()+getWidth()-getHeight(), getY(), getX()+getWidth()-getHeight(), getY()+getHeight()); 57 58 g.drawLine(getX()+getWidth()-getHeight()*17/20, getY()+getHeight()*3/20, getX()+getWidth()-getHeight()*3/20, getY()+getHeight()*3/20); 59 g.drawLine(getX()+getWidth()-getHeight()*17/20, getY()+getHeight()*3/20, getX()+getWidth()-getHeight()/2, getY()+getHeight()*17/20); 60 g.drawLine(getX()+getWidth()-getHeight()/2, getY()+getHeight()*17/20, getX()+getWidth()-getHeight()*3/20, getY()+getHeight()*3/20); 61 62 g.setColor(Color.green); 63 g.setFont(font); 64 g.drawString(label, getX()+2, getY()+(getHeight()+metrics.getHeight())/2-2); 65 g.drawString(items.get(selectedIndex), getX()+metrics.stringWidth(label)+8, getY()+(getHeight()+metrics.getHeight())/2-2); 66 67 if(open) { 68 g.setColor(Color.black); 69 g.fillRect(getX()+metrics.stringWidth(label)+4, getY()+getHeight(), getWidth()-metrics.stringWidth(label)-4, items.size()*15); 70 71 g.setColor(Color.red); 72 g.drawRect(getX()+metrics.stringWidth(label)+4, getY()+getHeight(), getWidth()-metrics.stringWidth(label)-4, items.size()*15); 73 74 if(selectedIndex != -1) { 75 g.setColor(Color.blue); 76 g.fillRect(getX()+metrics.stringWidth(label)+5, getY()+getHeight()+1+15*selectedIndex, getWidth()-metrics.stringWidth(label)-5, 14); 77 } 78 79 g.setColor(Color.green); 80 for(int x=0; x<items.size(); x++) 81 g.drawString(items.get(x), getX()+metrics.stringWidth(label)+8, getY()+(getHeight()+metrics.getHeight())/2+15*(x+1)); 82 } 83 } 84 85 public void add(String newString) { 86 selectedIndex = 0; 87 items.add(newString); 88 } 89 90 public String getSelected() { 91 return items.get(selectedIndex); 92 } 11 12 private ArrayList<String> items; 13 private int selectedIndex; 14 private String label; 15 private Font font; 16 private boolean open; 17 private FontMetrics metrics; 18 19 public Menu(String newName, int newX, int newY, int newWidth, int newHeight, String newLabel, Font newFont) { 20 super(newName, newX, newY, newWidth, newHeight); 21 this.items = new ArrayList<String>(); 22 this.selectedIndex = -1; 23 this.label = newLabel; 24 this.font = newFont; 25 this.open = false; 26 } 27 28 public boolean handleEvent(MouseEvent e) { 29 if (getX() + this.metrics.stringWidth(this.label) + 4 <= e.getX() && e.getX() <= getX() + getWidth() && getY() + getHeight() <= e.getY() && e.getY() <= getY() + getHeight() + 15 * this.items.size() && this.open) { 30 this.selectedIndex = (e.getY() - getY() - getHeight()) / 15; 31 this.open = false; 32 return true; 33 } 34 if (getX() + getWidth() - getHeight() <= e.getX() && e.getX() <= getX() + getWidth() && getY() <= e.getY() && e.getY() <= getY() + getHeight()) { 35 this.open = !this.open; 36 return true; 37 } 38 return false; 39 } 40 41 public void clear() { 42 if (this.selectedIndex != -1) 43 this.selectedIndex = 0; 44 } 45 46 public void draw(Graphics g) { 47 this.metrics = g.getFontMetrics(this.font); 48 g.setColor(Color.black); 49 g.fillRect(getX(), getY(), getWidth(), getHeight()); 50 g.setColor(Color.red); 51 g.drawRect(getX(), getY(), getWidth(), getHeight()); 52 g.drawLine(getX() + this.metrics.stringWidth(this.label) + 4, getY(), getX() + this.metrics.stringWidth(this.label) + 4, getY() + getHeight()); 53 g.drawLine(getX() + getWidth() - getHeight(), getY(), getX() + getWidth() - getHeight(), getY() + getHeight()); 54 g.drawLine(getX() + getWidth() - getHeight() * 17 / 20, getY() + getHeight() * 3 / 20, getX() + getWidth() - getHeight() * 3 / 20, getY() + getHeight() * 3 / 20); 55 g.drawLine(getX() + getWidth() - getHeight() * 17 / 20, getY() + getHeight() * 3 / 20, getX() + getWidth() - getHeight() / 2, getY() + getHeight() * 17 / 20); 56 g.drawLine(getX() + getWidth() - getHeight() / 2, getY() + getHeight() * 17 / 20, getX() + getWidth() - getHeight() * 3 / 20, getY() + getHeight() * 3 / 20); 57 g.setColor(Color.green); 58 g.setFont(this.font); 59 g.drawString(this.label, getX() + 2, getY() + (getHeight() + this.metrics.getHeight()) / 2 - 2); 60 g.drawString(this.items.get(this.selectedIndex), getX() + this.metrics.stringWidth(this.label) + 8, getY() + (getHeight() + this.metrics.getHeight()) / 2 - 2); 61 if (this.open) { 62 g.setColor(Color.black); 63 g.fillRect(getX() + this.metrics.stringWidth(this.label) + 4, getY() + getHeight(), getWidth() - this.metrics.stringWidth(this.label) - 4, this.items.size() * 15); 64 g.setColor(Color.red); 65 g.drawRect(getX() + this.metrics.stringWidth(this.label) + 4, getY() + getHeight(), getWidth() - this.metrics.stringWidth(this.label) - 4, this.items.size() * 15); 66 if (this.selectedIndex != -1) { 67 g.setColor(Color.blue); 68 g.fillRect(getX() + this.metrics.stringWidth(this.label) + 5, getY() + getHeight() + 1 + 15 * this.selectedIndex, getWidth() - this.metrics.stringWidth(this.label) - 5, 14); 69 } 70 g.setColor(Color.green); 71 for (int x = 0; x < this.items.size(); x++) 72 g.drawString(this.items.get(x), getX() + this.metrics.stringWidth(this.label) + 8, getY() + (getHeight() + this.metrics.getHeight()) / 2 + 15 * (x + 1)); 73 } 74 } 75 76 public void add(String newString) { 77 this.selectedIndex = 0; 78 this.items.add(newString); 79 } 80 81 public String getSelected() { 82 return this.items.get(this.selectedIndex); 83 } 93 84 } -
gamegui/MultiTextbox.java
r155577b r8edd04e 3 3 import java.awt.*; 4 4 import java.awt.event.*; 5 import java.awt.image. *;6 import java.util. *;5 import java.awt.image.BufferedImage; 6 import java.util.ArrayList; 7 7 8 8 public class MultiTextbox extends Textbox { 9 ArrayList<String> lstStrings;10 FontMetrics metrics;11 boolean active;12 13 public MultiTextbox(String newName, int newX, int newY, int newWidth, int newHeight, String newLabel, boolean isActive, Font newFont, FontMetrics newMetrics) {14 super(newName, newX, newY, newWidth, newHeight, newLabel, newFont, false);15 16 lstStrings = new ArrayList<String>();17 metrics = newMetrics;18 active = isActive;19 20 splitString();21 }22 23 public void append(String str) {24 if(getText().equals(""))25 setText(str);26 else27 setText(getText() + "\n" + str);28 29 splitString();30 31 if(lstStrings.size()*15+6 > getHeight())32 getScrollBar().setSize(getScrollBar().getMaxSize()*getHeight()/(lstStrings.size()*15+6));33 else34 getScrollBar().setSize(getScrollBar().getMaxSize());35 36 getScrollBar().setPosition(getScrollBar().getMaxSize()-getScrollBar().getSize());37 }38 39 public void clear() {40 super.clear();41 lstStrings = new ArrayList<String>();42 }43 9 44 public boolean handleEvent(MouseEvent e) { 45 if(!getScrollBar().handleEvent(e)) 46 return false; 47 48 if(e.getY() < getY()+getWidth()) { 49 changeTextStart(-30); 50 }else if(getY()+getHeight()-getWidth() < e.getY()) { 51 changeTextStart(30); 52 } 53 54 return true; 55 } 56 57 public void handleEvent(KeyEvent e) { 58 if(!active) 59 return; 60 61 super.handleEvent(e); 62 63 splitString(); 64 65 if(lstStrings.size()*15+6 > getHeight()) 66 getScrollBar().setSize(getScrollBar().getMaxSize()*getHeight()/(lstStrings.size()*15+6)); 67 else 68 getScrollBar().setSize(getScrollBar().getMaxSize()); 69 70 getScrollBar().setPosition(getScrollBar().getMaxSize()-getScrollBar().getSize()); 71 } 72 73 private void changeTextStart(int increment) { 74 setTextStart(getTextStart()+increment); 75 76 if(lstStrings.size()*15+6>getHeight() && getTextStart() >= lstStrings.size()*15+6-getHeight()) { 77 setTextStart(lstStrings.size()*15+6-getHeight()); 78 getScrollBar().setPosition(getScrollBar().getMaxSize()-getScrollBar().getSize()); 79 }else if(getTextStart() < 0 || lstStrings.size()*15+6<=getHeight()) { 80 setTextStart(0); 81 getScrollBar().setPosition(0); 82 }else 83 getScrollBar().setPosition(getTextStart()*getScrollBar().getMaxSize()/(lstStrings.size()*15+6)); 84 } 10 ArrayList<String> lstStrings; 11 FontMetrics metrics; 12 boolean active; 85 13 86 private void splitString() { 87 String drawnString = getText(); 88 89 ArrayList<String> lstTemp = new ArrayList<String>(); 90 do { 91 int x = 0; 92 while(x<drawnString.length() && metrics.stringWidth(drawnString.substring(0, x+1))<=getWidth()-10 && !drawnString.substring(x, x+1).equals("\n")) { 93 x++; 94 } 95 96 lstTemp.add(drawnString.substring(0, x)); 97 98 if(drawnString.length()>x && drawnString.substring(x, x+1).equals("\n")) 99 drawnString = drawnString.substring(x+1); 100 else 101 drawnString = drawnString.substring(x); 102 }while(metrics.stringWidth(drawnString)>0); 103 104 if(lstTemp.size()*15-getHeight()+6 > 0) 105 setTextStart(lstTemp.size()*15-getHeight()+6); 106 else 107 setTextStart(0); 108 109 lstStrings = lstTemp; 110 } 111 112 public void draw(Graphics g) { 113 GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); 114 GraphicsDevice device = env.getDefaultScreenDevice(); 115 GraphicsConfiguration gc = device.getDefaultConfiguration(); 116 117 BufferedImage source = gc.createCompatibleImage(getWidth(), getHeight()); 118 Graphics2D srcGraphics = source.createGraphics(); 119 120 if(isSelected() && System.currentTimeMillis() - getLastCursorChange() > getBlinkInterval()) 121 { 122 if(getCursorState() == 0) 123 setCursorState(1); 124 else 125 setCursorState(0); 126 127 setLastCursorChange(System.currentTimeMillis()); 128 } 129 130 srcGraphics.setColor(Color.green); 131 srcGraphics.setFont(getFont()); 132 133 int x; 134 for(x=0; x<lstStrings.size(); x++) 135 srcGraphics.drawString(lstStrings.get(x), 5, metrics.getHeight()+x*15-getTextStart()); 14 public MultiTextbox(String newName, int newX, int newY, int newWidth, int newHeight, String newLabel, boolean isActive, Font newFont, FontMetrics newMetrics) { 15 super(newName, newX, newY, newWidth, newHeight, newLabel, newFont, false); 16 this.lstStrings = new ArrayList<String>(); 17 this.metrics = newMetrics; 18 this.active = isActive; 19 splitString(); 20 } 136 21 137 x--; 138 if(isSelected() && getCursorState() == 1) 139 srcGraphics.drawLine(metrics.stringWidth(lstStrings.get(x))+6, 5+x*15-getTextStart(), metrics.stringWidth(lstStrings.get(x))+6, metrics.getHeight()+x*15-getTextStart()); 140 141 g.setColor(Color.green); 142 g.setFont(getFont()); 143 144 g.drawImage(source, getX(), getY(), null); 145 g.drawString(getLabel(), getX() - metrics.stringWidth(getLabel()) - 10, getY() + (getHeight() + metrics.getHeight())/2 - 2); 146 147 g.setColor(Color.red); 148 g.drawRect(getX(), getY(), getWidth(), getHeight()); 149 150 getScrollBar().draw(g); 151 } 22 public void append(String str) { 23 if (getText().equals("")) { 24 setText(str); 25 } else { 26 setText(String.valueOf(getText()) + "\n" + str); 27 } 28 splitString(); 29 if (this.lstStrings.size() * 15 + 6 > getHeight()) { 30 getScrollBar().setSize(getScrollBar().getMaxSize() * getHeight() / (this.lstStrings.size() * 15 + 6)); 31 } else { 32 getScrollBar().setSize(getScrollBar().getMaxSize()); 33 } 34 getScrollBar().setPosition(getScrollBar().getMaxSize() - getScrollBar().getSize()); 35 } 36 37 public void setText(String s) { 38 super.setText(s); 39 splitString(); 40 } 41 42 public void clear() { 43 super.clear(); 44 this.lstStrings = new ArrayList<String>(); 45 } 46 47 public boolean handleEvent(MouseEvent e) { 48 if (!getScrollBar().handleEvent(e)) { 49 return false; 50 } 51 if (e.getY() < getY() + getWidth()) { 52 changeTextStart(-30); 53 } else if (getY() + getHeight() - getWidth() < e.getY()) { 54 changeTextStart(30); 55 } 56 return true; 57 } 58 59 public void handleEvent(KeyEvent e) { 60 if (!this.active) { 61 return; 62 } 63 super.handleEvent(e); 64 splitString(); 65 if (this.lstStrings.size() * 15 + 6 > getHeight()) { 66 getScrollBar().setSize(getScrollBar().getMaxSize() * getHeight() / (this.lstStrings.size() * 15 + 6)); 67 } else { 68 getScrollBar().setSize(getScrollBar().getMaxSize()); 69 } 70 getScrollBar().setPosition(getScrollBar().getMaxSize() - getScrollBar().getSize()); 71 } 72 73 private void changeTextStart(int increment) { 74 setTextStart(getTextStart() + increment); 75 if (this.lstStrings.size() * 15 + 6 > getHeight() && getTextStart() >= this.lstStrings.size() * 15 + 6 - getHeight()) { 76 setTextStart(this.lstStrings.size() * 15 + 6 - getHeight()); 77 getScrollBar().setPosition(getScrollBar().getMaxSize() - getScrollBar().getSize()); 78 } else if (getTextStart() < 0 || this.lstStrings.size() * 15 + 6 <= getHeight()) { 79 setTextStart(0); 80 getScrollBar().setPosition(0); 81 } else { 82 getScrollBar().setPosition(getTextStart() * getScrollBar().getMaxSize() / (this.lstStrings.size() * 15 + 6)); 83 } 84 } 85 86 private void splitString() { 87 String drawnString = getText(); 88 ArrayList<String> lstTemp = new ArrayList<String>(); 89 do { 90 int x = 0, lastSpace = -1; 91 while (x < drawnString.length() && this.metrics.stringWidth(drawnString.substring(0, x + 1)) <= getWidth() - 10 && !drawnString.substring(x, x + 1).equals("\n")) { 92 if (drawnString.charAt(x) == ' ') { 93 lastSpace = x; 94 } 95 x++; 96 } 97 int xReal = x; 98 if (lastSpace > 0 && drawnString.length() > x) { 99 x = lastSpace + 1; 100 } 101 if (drawnString.length() > xReal && drawnString.substring(xReal, xReal + 1).equals("\n")) { 102 lstTemp.add(drawnString.substring(0, xReal)); 103 drawnString = drawnString.substring(xReal + 1); 104 } else { 105 lstTemp.add(drawnString.substring(0, x)); 106 drawnString = drawnString.substring(x); 107 } 108 } while (this.metrics.stringWidth(drawnString) > 0); 109 if (lstTemp.size() * 15 - getHeight() + 6 > 0) { 110 setTextStart(lstTemp.size() * 15 - getHeight() + 6); 111 } else { 112 setTextStart(0); 113 } 114 this.lstStrings = lstTemp; 115 } 116 117 public void draw(Graphics g) { 118 GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); 119 GraphicsDevice device = env.getDefaultScreenDevice(); 120 GraphicsConfiguration gc = device.getDefaultConfiguration(); 121 BufferedImage source = gc.createCompatibleImage(getWidth(), getHeight()); 122 Graphics2D srcGraphics = source.createGraphics(); 123 if (isSelected() && System.currentTimeMillis() - getLastCursorChange() > getBlinkInterval()) { 124 if (getCursorState() == 0) { 125 setCursorState(1); 126 } else { 127 setCursorState(0); 128 } 129 setLastCursorChange(System.currentTimeMillis()); 130 } 131 srcGraphics.setColor(Color.green); 132 srcGraphics.setFont(getFont()); 133 int x; 134 for (x = 0; x < this.lstStrings.size(); x++) { 135 srcGraphics.drawString(this.lstStrings.get(x), 5, this.metrics.getHeight() + x * 15 - getTextStart()); 136 } 137 x--; 138 if (isSelected() && getCursorState() == 1) { 139 srcGraphics.drawLine(this.metrics.stringWidth(this.lstStrings.get(x)) + 6, 5 + x * 15 - getTextStart(), this.metrics.stringWidth(this.lstStrings.get(x)) + 6, this.metrics.getHeight() + x * 15 - getTextStart()); 140 } 141 g.setColor(Color.green); 142 g.setFont(getFont()); 143 g.drawImage(source, getX(), getY(), null); 144 g.drawString(getLabel(), getX() - this.metrics.stringWidth(getLabel()) - 10, getY() + (getHeight() + this.metrics.getHeight()) / 2 - 2); 145 g.setColor(Color.red); 146 if (!this.noBorder) { 147 g.drawRect(getX(), getY(), getWidth(), getHeight()); 148 } 149 if (getScrollBar() != null) { 150 getScrollBar().draw(g); 151 } 152 } 152 153 } -
gamegui/ProgressBar.java
r155577b r8edd04e 5 5 6 6 public class ProgressBar extends Member { 7 private int max; 8 private int current; 9 10 public ProgressBar(String newName, int newX, int newY, int newWidth, int newHeight) { 11 super(newName, newX, newY, newWidth, newHeight); 12 13 max = 1; 14 current = 0; 15 } 16 17 public int getMax() { 18 return max; 19 } 20 21 public int getCurrent() { 22 return current; 23 } 24 25 public void setMax(int max) { 26 this.max = max; 27 } 28 29 public void setCurrent(int current) { 30 this.current = current; 31 } 32 33 public void draw(Graphics g) { 34 g.setColor(Color.black); 35 g.fillRect(getX(), getY(), getWidth(), getHeight()); 36 37 g.setColor(Color.blue); 38 g.fillRect(getX(), getY(), getWidth()*current/max, getHeight()); 39 g.setColor(Color.red); 40 g.drawRect(getX(), getY(), getWidth(), getHeight()); 41 } 7 8 private int max; 9 private int current; 10 11 public ProgressBar(String newName, int newX, int newY, int newWidth, int newHeight) { 12 super(newName, newX, newY, newWidth, newHeight); 13 this.max = 1; 14 this.current = 0; 15 } 16 17 public int getMax() { 18 return this.max; 19 } 20 21 public int getCurrent() { 22 return this.current; 23 } 24 25 public void setMax(int max) { 26 this.max = max; 27 } 28 29 public void setCurrent(int current) { 30 this.current = current; 31 } 32 33 public void draw(Graphics g) { 34 g.setColor(Color.black); 35 g.fillRect(getX(), getY(), getWidth(), getHeight()); 36 g.setColor(Color.blue); 37 g.fillRect(getX(), getY(), getWidth() * this.current / this.max, getHeight()); 38 g.setColor(Color.red); 39 g.drawRect(getX(), getY(), getWidth(), getHeight()); 40 } 42 41 } -
gamegui/RadioButton.java
r155577b r8edd04e 1 1 package gamegui; 2 2 3 import java.awt.*; 3 import java.awt.Color; 4 import java.awt.Font; 5 import java.awt.FontMetrics; 6 import java.awt.Graphics; 4 7 5 public class RadioButton extends Member 6 { 7 private String text; 8 private Font font; 9 private boolean textAfter; 10 private boolean selected; 11 12 public RadioButton(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont, boolean isTextAfter) 13 { 14 super(newName, newX, newY, newWidth, newHeight); 15 16 text = newText; 17 font = newFont; 18 textAfter = isTextAfter; 19 } 20 21 public void draw(Graphics g) 22 { 23 FontMetrics metrics = g.getFontMetrics(font); 24 25 g.setColor(Color.red); 26 g.drawOval(getX(), getY(), getWidth(), getHeight()); 27 28 if(selected) 29 { 30 g.setColor(Color.green); 31 g.fillOval(getX() + 5, getY() + 5, getWidth() - 10, getHeight() - 10); 32 } 33 34 g.setColor(Color.green); 35 g.setFont(font); 36 37 if(textAfter) 38 g.drawString(text, getX() + getWidth() + 7, getY() + (getHeight() + metrics.getHeight())/2 - 2); 39 else 40 g.drawString(text, getX() - metrics.stringWidth(text) - 7, getY() + (getHeight() + metrics.getHeight())/2 - 2); 41 } 42 43 public void clear() 44 { 45 selected = false; 46 } 47 48 public String getLabel() { 49 return text; 50 } 51 52 public boolean isClicked(int xCoord, int yCoord) 53 { 54 double distance = Math.sqrt(Math.pow(getX() + getWidth()/2 - xCoord, 2) + Math.pow(getY() +getHeight()/2 - yCoord, 2)); 55 56 return !(distance > getWidth() / 2); 57 } 58 59 public boolean isSelected() 60 { 61 return selected; 62 } 63 64 public void setSelected(boolean isSelected) 65 { 66 selected = isSelected; 67 } 8 public class RadioButton extends Member { 9 10 private String text; 11 private Font font; 12 private boolean textAfter; 13 private boolean selected; 14 15 public RadioButton(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont, boolean isTextAfter) { 16 super(newName, newX, newY, newWidth, newHeight); 17 this.text = newText; 18 this.font = newFont; 19 this.textAfter = isTextAfter; 20 } 21 22 public void draw(Graphics g) { 23 FontMetrics metrics = g.getFontMetrics(this.font); 24 g.setColor(Color.red); 25 g.drawOval(getX(), getY(), getWidth(), getHeight()); 26 if (this.selected) { 27 g.setColor(Color.green); 28 g.fillOval(getX() + 5, getY() + 5, getWidth() - 10, getHeight() - 10); 29 } 30 g.setColor(Color.green); 31 g.setFont(this.font); 32 if (this.textAfter) { 33 g.drawString(this.text, getX() + getWidth() + 7, getY() + (getHeight() + metrics.getHeight()) / 2 - 2); 34 } else { 35 g.drawString(this.text, getX() - metrics.stringWidth(this.text) - 7, getY() + (getHeight() + metrics.getHeight()) / 2 - 2); 36 } 37 } 38 39 public void clear() { 40 this.selected = false; 41 } 42 43 public String getLabel() { 44 return this.text; 45 } 46 47 public boolean isClicked(int xCoord, int yCoord) { 48 double distance = Math.sqrt(Math.pow((getX() + getWidth() / 2 - xCoord), 2.0D) + Math.pow((getY() + getHeight() / 2 - yCoord), 2.0D)); 49 return !(distance > (getWidth() / 2)); 50 } 51 52 public boolean isSelected() { 53 return this.selected; 54 } 55 56 public void setSelected(boolean isSelected) { 57 this.selected = isSelected; 58 } 68 59 } -
gamegui/RadioGroup.java
r155577b r8edd04e 1 1 package gamegui; 2 2 3 import java.awt.*; 4 import java.awt.event.*; 5 import java.util.*; 3 import java.awt.Color; 4 import java.awt.Font; 5 import java.awt.FontMetrics; 6 import java.awt.Graphics; 7 import java.awt.event.MouseEvent; 8 import java.util.ArrayList; 6 9 10 public class RadioGroup extends Member { 7 11 8 public class RadioGroup extends Member 9 { 10 private ArrayList<RadioButton> buttons; 11 private RadioButton selected; 12 private String text; 13 private Font font; 14 15 public RadioGroup(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont) { 16 super(newName, newX, newY, newWidth, newHeight); 17 18 buttons = new ArrayList<RadioButton>(); 19 selected = null; 20 text = newText; 21 font = newFont; 22 } 23 24 public boolean handleEvent(MouseEvent e) { 25 if(selected != null) 26 selected.clear(); 27 28 for(int x=0; x < buttons.size(); x++) 29 if(((RadioButton)buttons.get(x)).isClicked(e.getX(), e.getY())) { 30 selected = buttons.get(x); 31 selected.setSelected(true); 32 return true; 33 } 34 35 return false; 36 } 37 38 public void draw(Graphics g) 39 { 40 FontMetrics metrics = g.getFontMetrics(font); 41 42 g.setColor(Color.green); 43 g.setFont(font); 44 45 g.drawString(text, getX() - metrics.stringWidth(text) - 10, getY() + (getHeight() + metrics.getHeight())/2 - 2); 46 47 for(int x=0; x < buttons.size(); x++) 48 ((RadioButton)(buttons.get(x))).draw(g); 49 } 50 51 public void clear() 52 { 53 for(int x=0; x < buttons.size(); x++) 54 ((RadioButton)(buttons.get(x))).clear(); 55 } 56 57 public void add(RadioButton aButton) { 58 buttons.add(aButton); 59 } 60 61 public RadioButton getButton(String aName) { 62 for(int x=0; x < buttons.size(); x++) 63 if(buttons.get(x).getName().equals(aName)) 64 return (RadioButton)buttons.get(x); 65 66 return null; 67 } 68 69 public String getSelected() { 70 if(selected != null) 71 return selected.getName(); 72 else 73 return "None"; 74 } 75 76 public void setSelected(String button) { 77 clear(); 78 79 for(int x=0; x < buttons.size(); x++) 80 if(buttons.get(x).getName().equals(button)) 81 buttons.get(x).setSelected(true); 82 } 12 private ArrayList<RadioButton> buttons; 13 private RadioButton selected; 14 private String text; 15 private Font font; 16 17 public RadioGroup(String newName, int newX, int newY, int newWidth, int newHeight, String newText, Font newFont) { 18 super(newName, newX, newY, newWidth, newHeight); 19 this.buttons = new ArrayList<RadioButton>(); 20 this.selected = null; 21 this.text = newText; 22 this.font = newFont; 23 } 24 25 public boolean handleEvent(MouseEvent e) { 26 if (this.selected != null) 27 this.selected.clear(); 28 for (int x = 0; x < this.buttons.size(); x++) { 29 if (((RadioButton)this.buttons.get(x)).isClicked(e.getX(), e.getY())) { 30 this.selected = this.buttons.get(x); 31 this.selected.setSelected(true); 32 return true; 33 } 34 } 35 return false; 36 } 37 38 public void draw(Graphics g) { 39 FontMetrics metrics = g.getFontMetrics(this.font); 40 g.setColor(Color.green); 41 g.setFont(this.font); 42 g.drawString(this.text, getX() - metrics.stringWidth(this.text) - 10, getY() + (getHeight() + metrics.getHeight()) / 2 - 2); 43 for (int x = 0; x < this.buttons.size(); x++) { 44 ((RadioButton)this.buttons.get(x)).draw(g); 45 } 46 } 47 48 public void clear() { 49 for (int x = 0; x < this.buttons.size(); x++) {} 50 ((RadioButton)this.buttons.get(x)).clear(); 51 } 52 } 53 54 public void add(RadioButton aButton) { 55 this.buttons.add(aButton); 56 } 57 58 public RadioButton getButton(String aName) { 59 for (int x = 0; x < this.buttons.size(); x++) { 60 if (((RadioButton)this.buttons.get(x)).getName().equals(aName)) 61 return this.buttons.get(x); 62 } 63 return null; 64 } 65 66 public String getSelected() { 67 if (this.selected != null) { 68 return this.selected.getName(); 69 } 70 return "None"; 71 } 72 73 public void setSelected(String button) { 74 clear(); 75 for (int x = 0; x < this.buttons.size(); x++) { 76 if (((RadioButton)this.buttons.get(x)).getName().equals(button)) 77 ((RadioButton)this.buttons.get(x)).setSelected(true); 78 } 79 } 83 80 } -
gamegui/ScrollBar.java
r155577b r8edd04e 2 2 3 3 import java.awt.*; 4 import java.awt.event. *;4 import java.awt.event.MouseEvent; 5 5 6 6 public class ScrollBar extends Member { 7 int size;8 int position;9 int scrollSpeed;10 11 public ScrollBar(String newName, int newX, int newY, int newWidth, int newHeight, int newScrollSpeed) {12 super(newName, newX, newY, newWidth, newHeight);13 14 size = 0;15 position = 0;16 scrollSpeed = newScrollSpeed;17 }18 19 public void clear() {20 size = 0;21 position = 0;22 }23 24 public boolean handleEvent(MouseEvent e) {25 if(!(getX() < e.getX() && e.getX() < getX()+getWidth() && getY() < e.getY() && e.getY() < getY()+getHeight()))26 return false;27 else28 return true;29 }30 31 public void draw(Graphics g) {32 g.setColor(Color.black);33 g.fillRect(getX(), getY(), getWidth(), getHeight());34 35 g.setColor(Color.red);36 g.drawRect(getX(), getY(), getWidth(), getHeight());37 38 g.drawLine(getX(), getY()+getWidth(), getX()+getWidth(), getY()+getWidth());39 g.drawLine(getX(), getY()+getHeight()-getWidth(), getX()+getWidth(), getY()+getHeight()-getWidth());40 41 g.drawLine(getX(), getY()+getWidth()+position, getX()+getWidth(), getY()+getWidth()+position);42 g.drawLine(getX(), getY()+getWidth()+position+size, getX()+getWidth(), getY()+getWidth()+position+size);43 44 g.drawLine(getX()+getWidth()*3/20, getY()+getWidth()*17/20, getX()+getWidth()*17/20, getY()+getWidth()*17/20);45 g.drawLine(getX()+getWidth()*17/20, getY()+getWidth()*17/20, getX()+getWidth()/2, getY()+getWidth()*3/20);46 g.drawLine(getX()+getWidth()/2, getY()+getWidth()*3/20, getX()+getWidth()*3/20, getY()+getWidth()*17/20);47 48 g.drawLine(getX()+getWidth()*3/20, getY()+getHeight()-getWidth()*17/20, getX()+getWidth()*17/20, getY()+getHeight()-getWidth()*17/20);49 g.drawLine(getX()+getWidth()*17/20, getY()+getHeight()-getWidth()*17/20, getX()+getWidth()/2, getY()+getHeight()-getWidth()*3/20);50 g.drawLine(getX()+getWidth()/2, getY()+getHeight()-getWidth()*3/20, getX()+getWidth()*3/20, getY()+getHeight()-getWidth()*17/20);51 }52 7 53 public int getPosition() { 54 returnposition;55 } 8 int size; 9 int position; 10 int scrollSpeed; 56 11 57 public int getScrollSpeed() { 58 return scrollSpeed; 59 } 12 public ScrollBar(String newName, int newX, int newY, int newWidth, int newHeight, int newScrollSpeed) { 13 super(newName, newX, newY, newWidth, newHeight); 14 this.size = 0; 15 this.position = 0; 16 this.scrollSpeed = newScrollSpeed; 17 } 60 18 61 public int getSize() { 62 return size; 63 } 64 65 public int getMaxSize() { 66 return getHeight()-2*getWidth(); 67 } 19 public void clear() { 20 this.size = 0; 21 this.position = 0; 22 } 68 23 69 public void setPosition(int position) { 70 this.position = position; 71 } 72 73 public void setSize(int size) { 74 this.size = size; 75 } 24 public boolean handleEvent(MouseEvent e) { 25 if (getX() >= e.getX() || e.getX() >= getX() + getWidth() || getY() >= e.getY() || e.getY() >= getY() + getHeight()) { 26 return false; 27 } 28 return true; 29 } 30 31 public void draw(Graphics g) { 32 g.setColor(Color.black); 33 g.fillRect(getX(), getY(), getWidth(), getHeight()); 34 g.setColor(Color.red); 35 g.drawRect(getX(), getY(), getWidth(), getHeight()); 36 g.drawLine(getX(), getY() + getWidth(), getX() + getWidth(), getY() + getWidth()); 37 g.drawLine(getX(), getY() + getHeight() - getWidth(), getX() + getWidth(), getY() + getHeight() - getWidth()); 38 g.drawLine(getX(), getY() + getWidth() + this.position, getX() + getWidth(), getY() + getWidth() + this.position); 39 g.drawLine(getX(), getY() + getWidth() + this.position + this.size, getX() + getWidth(), getY() + getWidth() + this.position + this.size); 40 g.drawLine(getX() + getWidth() * 3 / 20, getY() + getWidth() * 17 / 20, getX() + getWidth() * 17 / 20, getY() + getWidth() * 17 / 20); 41 g.drawLine(getX() + getWidth() * 17 / 20, getY() + getWidth() * 17 / 20, getX() + getWidth() / 2, getY() + getWidth() * 3 / 20); 42 g.drawLine(getX() + getWidth() / 2, getY() + getWidth() * 3 / 20, getX() + getWidth() * 3 / 20, getY() + getWidth() * 17 / 20); 43 g.drawLine(getX() + getWidth() * 3 / 20, getY() + getHeight() - getWidth() * 17 / 20, getX() + getWidth() * 17 / 20, getY() + getHeight() - getWidth() * 17 / 20); 44 g.drawLine(getX() + getWidth() * 17 / 20, getY() + getHeight() - getWidth() * 17 / 20, getX() + getWidth() / 2, getY() + getHeight() - getWidth() * 3 / 20); 45 g.drawLine(getX() + getWidth() / 2, getY() + getHeight() - getWidth() * 3 / 20, getX() + getWidth() * 3 / 20, getY() + getHeight() - getWidth() * 17 / 20); 46 } 47 48 public int getPosition() { 49 return this.position; 50 } 51 52 public int getScrollSpeed() { 53 return this.scrollSpeed; 54 } 55 56 public int getSize() { 57 return this.size; 58 } 59 60 public int getMaxSize() { 61 return getHeight() - 2 * getWidth(); 62 } 63 64 public void setPosition(int position) { 65 this.position = position; 66 } 67 68 public void setSize(int size) { 69 this.size = size; 70 } 76 71 } -
gamegui/ScrollList.java
r155577b r8edd04e 2 2 3 3 import java.awt.*; 4 import java.awt.event. *;4 import java.awt.event.MouseEvent; 5 5 import java.awt.image.BufferedImage; 6 import java.util. *;6 import java.util.ArrayList; 7 7 8 8 public class ScrollList extends Member { 9 private ArrayList<Listable> lstObjects; 10 private Listable selectedItem; 11 private Font font; 12 private FontMetrics metrics; 13 private int textStart; 14 private boolean change; 15 16 public ScrollList(String newName, int newX, int newY, int newWidth, int newHeight, Font font, FontMetrics metrics) { 17 super(newName, newX, newY, newWidth, newHeight); 18 19 lstObjects = new ArrayList<Listable>(); 20 selectedItem = null; 21 this.font = font; 22 this.metrics = metrics; 23 textStart = 0; 24 change = false; 25 } 26 27 public ArrayList<Listable> getList() { 28 return lstObjects; 29 } 30 31 public Listable getSelected() { 32 return selectedItem; 33 } 34 35 public boolean isChanged() { 36 return change; 37 } 38 39 public void changeHandled() { 40 change = false; 41 } 42 43 public void deselect() { 44 selectedItem = null; 45 } 46 47 public void clear() { 48 lstObjects = new ArrayList<Listable>(); 49 selectedItem = null; 50 textStart = 0; 51 changeHandled(); 52 } 53 54 public boolean handleEvent(MouseEvent e) { 55 if(getX() < e.getX() && e.getX() < getX()+getWidth()) { 56 if(getY() < e.getY() && getY()-textStart+2 < e.getY() && e.getY() < getY()+getHeight() && e.getY() < getY()+lstObjects.size()*15-textStart+2) { 57 selectedItem = lstObjects.get((e.getY()-getY()+textStart-2)/15); 58 change = true; 59 return true; 60 } 61 } 62 63 if(!getScrollBar().handleEvent(e)) 64 return false; 65 66 if(e.getY() < getY()+getScrollBar().getWidth()) { 67 changeTextStart(-30); 68 }else if(getY()+getHeight()-getScrollBar().getWidth() < e.getY()) { 69 changeTextStart(30); 70 } 71 72 return true; 73 } 74 75 private void changeTextStart(int increment) { 76 textStart += increment; 77 78 if(lstObjects.size()*15+6>getHeight() && textStart >= lstObjects.size()*15+6-getHeight()) { 79 textStart = lstObjects.size()*15+6-getHeight(); 80 getScrollBar().setPosition(getScrollBar().getMaxSize()-getScrollBar().getSize()); 81 }else if(textStart < 0 || lstObjects.size()*15+6<=getHeight()) { 82 textStart = 0; 83 getScrollBar().setPosition(0); 84 }else 85 getScrollBar().setPosition(textStart*getScrollBar().getMaxSize()/(lstObjects.size()*15+6)); 86 } 87 88 public void draw(Graphics g) { 89 GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); 90 GraphicsDevice device = env.getDefaultScreenDevice(); 91 GraphicsConfiguration gc = device.getDefaultConfiguration(); 92 93 BufferedImage source = gc.createCompatibleImage(getWidth(), getHeight()); 94 Graphics2D srcGraphics = source.createGraphics(); 95 96 srcGraphics.setColor(Color.green); 97 srcGraphics.setFont(font); 98 99 for(int x=0; x<lstObjects.size(); x++) { 100 if(selectedItem != null && selectedItem.equals(lstObjects.get(x))) { 101 srcGraphics.setColor(Color.blue); 102 srcGraphics.fillRect(0, x*15-textStart+3, getWidth(), 15); 103 srcGraphics.setColor(Color.green); 104 } 105 106 lstObjects.get(x).drawListString(5, metrics.getHeight()+x*15-textStart, srcGraphics); 107 } 108 109 g.drawImage(source, getX(), getY(), null); 110 111 g.setColor(Color.red); 112 g.drawRect(getX(), getY(), getWidth(), getHeight()); 113 114 if(lstObjects.size()*15+6 > getHeight()) 115 getScrollBar().setSize(getScrollBar().getMaxSize()*getHeight()/(lstObjects.size()*15+6)); 116 else 117 getScrollBar().setSize(getScrollBar().getMaxSize()); 118 119 getScrollBar().draw(g); 120 } 9 10 private ArrayList<Listable> lstObjects; 11 private Listable selectedItem; 12 private Font font; 13 private int fontHeight; 14 private int textStart; 15 private boolean change; 16 17 public ScrollList(String newName, int newX, int newY, int newWidth, int newHeight, Font font, FontMetrics metrics) { 18 super(newName, newX, newY, newWidth, newHeight); 19 this.lstObjects = new ArrayList<Listable>(); 20 this.selectedItem = null; 21 this.font = font; 22 if (metrics == null) { 23 this.fontHeight = 0; 24 } else { 25 this.fontHeight = metrics.getHeight(); 26 } 27 this.textStart = 0; 28 this.change = false; 29 } 30 31 public ArrayList<Listable> getList() { 32 return this.lstObjects; 33 } 34 35 public Listable getSelected() { 36 return this.selectedItem; 37 } 38 39 public boolean isChanged() { 40 return this.change; 41 } 42 43 public void changeHandled() { 44 this.change = false; 45 } 46 47 public void deselect() { 48 this.selectedItem = null; 49 } 50 51 public void clear() { 52 this.lstObjects.clear(); 53 this.selectedItem = null; 54 this.textStart = 0; 55 changeHandled(); 56 } 57 58 public boolean handleEvent(MouseEvent e) { 59 if (!getScrollBar().handleEvent(e)) 60 return false; 61 if (e.getY() < getY() + getScrollBar().getWidth()) { 62 changeTextStart(-30); 63 } else if (getY() + getHeight() - getScrollBar().getWidth() < e.getY()) { 64 changeTextStart(30); 65 } 66 return true; 67 } 68 69 private void changeTextStart(int increment) { 70 this.textStart += increment; 71 int listHeight = 0; 72 if (this.lstObjects.size() > 0) { 73 Listable e = this.lstObjects.get(0); 74 listHeight = e.getHeight() * (int)Math.ceil(this.lstObjects.size() / (getWidth() / e.getWidth())) + e.getYOffset(); 75 } 76 if (listHeight > getHeight() && this.textStart >= listHeight - getHeight()) { 77 this.textStart = listHeight - getHeight(); 78 getScrollBar().setPosition(getScrollBar().getMaxSize() - getScrollBar().getSize()); 79 } else if (this.textStart < 0 || listHeight <= getHeight()) { 80 this.textStart = 0; 81 getScrollBar().setPosition(0); 82 } else { 83 getScrollBar().setPosition(this.textStart * getScrollBar().getMaxSize() / listHeight); 84 } 85 } 86 87 public int getTextStart() { 88 return this.textStart; 89 } 90 91 public void draw(Graphics g) { 92 GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); 93 GraphicsDevice device = env.getDefaultScreenDevice(); 94 GraphicsConfiguration gc = device.getDefaultConfiguration(); 95 BufferedImage source = gc.createCompatibleImage(getWidth(), getHeight()); 96 Graphics2D srcGraphics = source.createGraphics(); 97 srcGraphics.setColor(Color.green); 98 if (this.font != null) { 99 srcGraphics.setFont(this.font); 100 } 101 int listHeight = 0; 102 Listable e = null; 103 if (this.lstObjects.size() > 0) { 104 e = this.lstObjects.get(0); 105 listHeight = e.getHeight() * (int)Math.ceil(this.lstObjects.size() / (getWidth() / e.getWidth())) + e.getYOffset(); 106 } 107 int numPerRow = 0; 108 if (e != null) { 109 numPerRow = getWidth() / e.getWidth(); 110 } 111 for (int x = 0; x < this.lstObjects.size(); x++) { 112 ((Listable)this.lstObjects.get(x)).draw(e.getHeight() * x % numPerRow + e.getXOffset(), this.fontHeight + x / numPerRow * e.getHeight() - this.textStart, srcGraphics); 113 } 114 g.drawImage(source, getX(), getY(), null); 115 g.setColor(Color.red); 116 g.drawRect(getX(), getY(), getWidth(), getHeight()); 117 if (listHeight > getHeight()) { 118 getScrollBar().setSize(getScrollBar().getMaxSize() * getHeight() / listHeight); 119 } else { 120 getScrollBar().setSize(getScrollBar().getMaxSize()); 121 } 122 getScrollBar().draw(g); 123 } 121 124 } -
gamegui/TabbedWindow.java
r155577b r8edd04e 1 1 package gamegui; 2 2 3 import java.awt.*; 4 import java.awt.event.*; 5 import java.util.*; 3 import java.awt.Color; 4 import java.awt.Font; 5 import java.awt.FontMetrics; 6 import java.awt.Graphics; 7 import java.awt.event.MouseEvent; 8 import java.util.ArrayList; 6 9 7 10 public class TabbedWindow extends Member { 8 private ArrayList<Window> windows; 9 private ArrayList<String> windowLabels; 10 private Window activeWindow; 11 private int tabHeight; 12 private Font tabFont; 13 14 public TabbedWindow(String newName, int newX, int newY, int newWidth, int newHeight, int newTabHeight, Font newFont) { 15 super(newName, newX, newY, newWidth, newHeight); 16 17 windows = new ArrayList<Window>(); 18 windowLabels = new ArrayList<String>(); 19 tabHeight = newTabHeight; 20 activeWindow = null; 21 tabFont = newFont; 22 } 23 24 public void add(Window newWindow, String name) { 25 newWindow.offset(getX(), getY()+tabHeight); 26 27 if(activeWindow == null) 28 activeWindow = newWindow; 29 windows.add(newWindow); 30 windowLabels.add(name); 31 } 32 33 public void clear() { 34 activeWindow = windows.get(0); 35 for(int x=0; x < windows.size(); x++) 36 windows.get(x).clear(); 37 } 38 39 public void offset(int xOffset, int yOffset) { 40 super.offset(xOffset, yOffset); 41 42 for(int x=0; x < windows.size(); x++) 43 windows.get(x).offset(xOffset, yOffset); 44 } 45 46 public Window getWindow(String aName) { 47 for(int x=0; x < windows.size(); x++) 48 if(windows.get(x).getName().equals(aName)) 49 return (Window)windows.get(x); 50 51 return null; 52 } 53 54 public boolean handleEvent(MouseEvent e) { 55 for(int x=0; x < windows.size(); x++) { 56 if(isClicked(getX() + x*getWidth()/windows.size(), getY(), getWidth()/windows.size(), tabHeight, e.getX(), e.getY())) { 57 activeWindow = windows.get(x); 58 return true; 59 } 60 } 61 62 return activeWindow.handleEvent(e); 63 } 64 65 private boolean isClicked(int x, int y, int width, int height, int mouseX, int mouseY) { 66 return x <= mouseX && mouseX <= x+width && y <= mouseY && mouseY <= y+height; 67 } 68 69 public void draw(Graphics g) { 70 FontMetrics metrics = g.getFontMetrics(tabFont); 71 72 g.setColor(Color.black); 73 g.fillRect(getX(), getY(), getWidth(), getHeight()); 74 75 g.setFont(tabFont); 76 for(int x=0; x < windows.size(); x++) 77 { 78 g.setColor(Color.green); 79 g.drawString(windowLabels.get(x), getX()+x*getWidth()/windows.size()+(getWidth()/windows.size()-metrics.stringWidth(windowLabels.get(x)))/2, getY() + (tabHeight + metrics.getHeight())/2 - 2); 80 81 g.setColor(Color.red); 82 g.drawLine(getX()+x*getWidth()/windows.size(), getY(), getX()+x*getWidth()/windows.size(), getY()+tabHeight); 83 84 if(windows.get(x).equals(activeWindow)) { 85 ((Member)(windows.get(x))).draw(g); 86 g.setColor(Color.red); 87 g.drawRect(getX(), getY(), getWidth(), getHeight()); 88 g.drawLine(getX(), getY()+tabHeight, getX()+x*getWidth()/windows.size(), getY()+tabHeight); 89 g.drawLine(getX()+(x+1)*getWidth()/windows.size(), getY()+tabHeight, getX()+getWidth(), getY()+tabHeight); 90 } 91 } 92 } 93 94 public String getActive() { 95 if(activeWindow != null) 96 return activeWindow.getName(); 97 else 98 return ""; 99 } 11 12 private ArrayList<Window> windows; 13 private ArrayList<String> windowLabels; 14 private Window activeWindow; 15 private int tabHeight; 16 private Font tabFont; 17 18 public TabbedWindow(String newName, int newX, int newY, int newWidth, int newHeight, int newTabHeight, Font newFont) { 19 super(newName, newX, newY, newWidth, newHeight); 20 this.windows = new ArrayList<Window>(); 21 this.windowLabels = new ArrayList<String>(); 22 this.tabHeight = newTabHeight; 23 this.activeWindow = null; 24 this.tabFont = newFont; 25 } 26 27 public void add(Window newWindow, String name) { 28 newWindow.offset(getX(), getY() + this.tabHeight); 29 if (this.activeWindow == null) { 30 this.activeWindow = newWindow; 31 } 32 this.windows.add(newWindow); 33 this.windowLabels.add(name); 34 } 35 36 public void clear() { 37 this.activeWindow = this.windows.get(0); 38 for (int x = 0; x < this.windows.size(); x++) { 39 ((Window)this.windows.get(x)).clear(); 40 } 41 } 42 43 public void offset(int xOffset, int yOffset) { 44 super.offset(xOffset, yOffset); 45 for (int x = 0; x < this.windows.size(); x++) { 46 ((Window)this.windows.get(x)).offset(xOffset, yOffset); 47 } 48 } 49 50 public Window getWindow(String aName) { 51 for (int x = 0; x < this.windows.size(); x++) { 52 if (((Window)this.windows.get(x)).getName().equals(aName)) { 53 return this.windows.get(x); 54 } 55 } 56 return null; 57 } 58 59 public boolean handleEvent(MouseEvent e) { 60 for (int x = 0; x < this.windows.size(); x++) { 61 if (isClicked(getX() + x * getWidth() / this.windows.size(), getY(), getWidth() / this.windows.size(), this.tabHeight, e.getX(), e.getY())) { 62 this.activeWindow = this.windows.get(x); 63 return true; 64 } 65 } 66 return this.activeWindow.handleEvent(e); 67 } 68 69 private boolean isClicked(int x, int y, int width, int height, int mouseX, int mouseY) { 70 return (x <= mouseX && mouseX <= x + width && y <= mouseY && mouseY <= y + height); 71 } 72 73 public void draw(Graphics g) { 74 FontMetrics metrics = g.getFontMetrics(this.tabFont); 75 g.setColor(Color.black); 76 g.fillRect(getX(), getY(), getWidth(), getHeight()); 77 g.setFont(this.tabFont); 78 for (int x = 0; x < this.windows.size(); x++) { 79 g.setColor(Color.green); 80 g.drawString(this.windowLabels.get(x), getX() + x * getWidth() / this.windows.size() + (getWidth() / this.windows.size() - metrics.stringWidth(this.windowLabels.get(x))) / 2, getY() + (this.tabHeight + metrics.getHeight()) / 2 - 2); 81 g.setColor(Color.red); 82 g.drawLine(getX() + x * getWidth() / this.windows.size(), getY(), getX() + x * getWidth() / this.windows.size(), getY() + this.tabHeight); 83 if (((Window)this.windows.get(x)).equals(this.activeWindow)) { 84 ((Member)this.windows.get(x)).draw(g); 85 g.setColor(Color.red); 86 g.drawRect(getX(), getY(), getWidth(), getHeight()); 87 g.drawLine(getX(), getY() + this.tabHeight, getX() + x * getWidth() / this.windows.size(), getY() + this.tabHeight); 88 g.drawLine(getX() + (x + 1) * getWidth() / this.windows.size(), getY() + this.tabHeight, getX() + getWidth(), getY() + this.tabHeight); 89 } 90 } 91 } 92 93 public String getActive() { 94 if (this.activeWindow != null) { 95 return this.activeWindow.getName(); 96 } 97 return ""; 98 } 100 99 } -
gamegui/Textbox.java
r155577b r8edd04e 2 2 3 3 import java.awt.*; 4 import java.awt. image.*;5 import java.awt. event.*;4 import java.awt.event.KeyEvent; 5 import java.awt.image.BufferedImage; 6 6 7 public class Textbox extends Member 8 { 9 private String label; 10 private String text; 11 private Font font; 12 private int textStart; 13 private boolean selected; 14 private int cursorState; 15 private int blinkInterval; 16 private long lastCursorChange; 17 private boolean password; 18 19 public Textbox(String newName, int newX, int newY, int newWidth, int newHeight, String newLabel, Font newFont, boolean isPass) { 20 super(newName, newX, newY, newWidth, newHeight); 21 22 label = new String(newLabel); 23 text = new String(); 24 font = newFont; 25 textStart = 0; 26 selected = false; 27 cursorState = 0; 28 blinkInterval = 1000/2; 29 password = isPass; 30 } 31 32 public void handleEvent(KeyEvent e) { 33 if(32 <= e.getKeyCode() && e.getKeyCode() <= 127) 34 { 35 if(e.getKeyCode() == 127) 36 { 37 if(text.length() > 0) 38 text = text.substring(0, text.length() - 1); 39 } 40 else 41 text = text + Character.toString(e.getKeyChar()); 7 public class Textbox extends Member { 42 8 43 } 44 else if(e.getKeyCode() == 8) 45 { 46 if(text.length() > 0) 47 text = text.substring(0, text.length() - 1);48 } 49 } 50 51 public void draw(Graphics g) { 52 String drawnString = new String();53 FontMetrics metrics = g.getFontMetrics(font); 54 55 GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();56 GraphicsDevice device = env.getDefaultScreenDevice();57 GraphicsConfiguration gc = device.getDefaultConfiguration();58 59 BufferedImage source = gc.createCompatibleImage(getWidth(), getHeight());60 Graphics2D srcGraphics = source.createGraphics();61 62 if(selected && System.currentTimeMillis() - lastCursorChange > blinkInterval)63 { 64 if(cursorState == 0) 65 cursorState = 1; 66 else 67 cursorState = 0; 68 69 lastCursorChange = System.currentTimeMillis(); 70 } 71 72 if(password)73 74 for(int x=0;x<text.length();x++)75 drawnString+="*";9 private String label; 10 private String text; 11 private Font font; 12 private int textStart; 13 private boolean selected; 14 private int cursorState; 15 private int blinkInterval; 16 private long lastCursorChange; 17 private boolean password; 18 protected boolean noBorder; 19 20 public Textbox(String newName, int newX, int newY, int newWidth, int newHeight, String newLabel, Font newFont, boolean isPass) { 21 super(newName, newX, newY, newWidth, newHeight); 22 this.label = new String(newLabel); 23 this.text = new String(); 24 this.font = newFont; 25 this.textStart = 0; 26 this.selected = false; 27 this.cursorState = 0; 28 this.blinkInterval = 500; 29 this.password = isPass; 30 this.noBorder = false; 31 } 32 33 public void setBorder(boolean b) { 34 this.noBorder = !b; 35 } 36 37 public void handleEvent(KeyEvent e) { 38 if (32 <= e.getKeyCode() && e.getKeyCode() <= 127) { 39 if (e.getKeyCode() == 127) { 40 if (this.text.length() > 0) { 41 this.text = this.text.substring(0, this.text.length() - 1); 76 42 } 77 else 78 drawnString = text; 79 80 if(metrics.stringWidth(drawnString) + 9 > getWidth()) 81 textStart = metrics.stringWidth(drawnString)+9-getWidth(); 82 else 83 textStart = 0; 84 85 g.setColor(Color.green); 86 g.setFont(font); 87 srcGraphics.setColor(Color.green); 88 srcGraphics.setFont(font); 43 } else { 44 this.text = String.valueOf(this.text) + Character.toString(e.getKeyChar()); 45 } 46 } else if (e.getKeyCode() == 8) { 47 if (this.text.length() > 0) { 48 this.text = this.text.substring(0, this.text.length() - 1); 49 } 50 } 51 } 89 52 90 srcGraphics.drawString(drawnString, 5-textStart, (getHeight() + metrics.getHeight())/2 - 2); 91 92 g.drawImage(source, getX(), getY(), null); 93 g.drawString(label, getX() - metrics.stringWidth(label) - 10, getY() + (getHeight() + metrics.getHeight())/2 - 2); 94 95 if(selected && cursorState == 1) 96 g.drawLine(getX() + metrics.stringWidth(drawnString) - textStart + 6, getY() + 5, getX() + metrics.stringWidth(drawnString) - textStart + 6, getY() + getHeight() - 5); 97 98 g.setColor(Color.red); 99 g.drawRect(getX(), getY(), getWidth(), getHeight()); 100 } 101 102 public boolean isClicked(int xCoord, int yCoord) { 103 if(xCoord < getX() || getX() + getWidth() < xCoord) 104 return false; 105 if(yCoord < getY() || getY() + getHeight() < yCoord) 106 return false; 107 108 return true; 109 } 110 111 public void clear() { 112 text = ""; 113 textStart = 0; 114 selected = false; 115 } 53 public void draw(Graphics g) { 54 String drawnString = new String(); 55 FontMetrics metrics = g.getFontMetrics(this.font); 56 GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); 57 GraphicsDevice device = env.getDefaultScreenDevice(); 58 GraphicsConfiguration gc = device.getDefaultConfiguration(); 59 BufferedImage source = gc.createCompatibleImage(getWidth(), getHeight()); 60 Graphics2D srcGraphics = source.createGraphics(); 61 if (this.selected && System.currentTimeMillis() - this.lastCursorChange > this.blinkInterval) { 62 if (this.cursorState == 0) { 63 this.cursorState = 1; 64 } else { 65 this.cursorState = 0; 66 } 67 this.lastCursorChange = System.currentTimeMillis(); 68 } 69 if (this.password) { 70 for (int x = 0; x < this.text.length(); x++) { 71 drawnString = String.valueOf(drawnString) + "*"; 72 } 73 } else { 74 drawnString = this.text; 75 } 76 if (metrics.stringWidth(drawnString) + 9 > getWidth()) { 77 this.textStart = metrics.stringWidth(drawnString) + 9 - getWidth(); 78 } else { 79 this.textStart = 0; 80 } 81 g.setColor(Color.green); 82 g.setFont(this.font); 83 srcGraphics.setColor(Color.green); 84 srcGraphics.setFont(this.font); 85 srcGraphics.drawString(drawnString, 5 - this.textStart, (getHeight() + metrics.getHeight()) / 2 - 2); 86 g.drawImage(source, getX(), getY(), null); 87 g.drawString(this.label, getX() - metrics.stringWidth(this.label) - 10, getY() + (getHeight() + metrics.getHeight()) / 2 - 2); 88 if (this.selected && this.cursorState == 1) { 89 g.drawLine(getX() + metrics.stringWidth(drawnString) - this.textStart + 6, getY() + 5, getX() + metrics.stringWidth(drawnString) - this.textStart + 6, getY() + getHeight() - 5); 90 } 91 g.setColor(Color.red); 92 if (!this.noBorder) { 93 g.drawRect(getX(), getY(), getWidth(), getHeight()); 94 } 95 } 116 96 117 public int getBlinkInterval() { 118 return blinkInterval; 119 } 97 public boolean isClicked(int xCoord, int yCoord) { 98 if (xCoord < getX() || getX() + getWidth() < xCoord) { 99 return false; 100 } 101 if (yCoord < getY() || getY() + getHeight() < yCoord) { 102 return false; 103 } 104 return true; 105 } 120 106 121 public int getCursorState() { 122 return cursorState; 123 } 107 public void clear() { 108 this.text = ""; 109 this.textStart = 0; 110 this.selected = false; 111 } 124 112 125 public Font getFont() {126 return font;127 113 public int getBlinkInterval() { 114 return this.blinkInterval; 115 } 128 116 129 public String getLabel() {130 return label;131 117 public int getCursorState() { 118 return this.cursorState; 119 } 132 120 133 public long getLastCursorChange() {134 return lastCursorChange;135 121 public Font getFont() { 122 return this.font; 123 } 136 124 137 public boolean isSelected() {138 return selected;139 125 public String getLabel() { 126 return this.label; 127 } 140 128 141 public String getText() {142 return text;143 129 public long getLastCursorChange() { 130 return this.lastCursorChange; 131 } 144 132 145 public int getTextStart() { 146 return textStart; 147 } 148 149 public void setText(String newText) { 150 text = newText; 151 } 152 153 public void setSelected(boolean isSelected) { 154 selected = isSelected; 155 } 133 public boolean isSelected() { 134 return this.selected; 135 } 156 136 157 public void setTextStart(int textStart) { 158 this.textStart = textStart; 159 } 160 161 public void setCursorState(int cursorState) { 162 this.cursorState = cursorState; 163 } 137 public String getText() { 138 return this.text; 139 } 164 140 165 public void setLastCursorChange(long lastCursorChange) { 166 this.lastCursorChange = lastCursorChange; 167 } 141 public int getTextStart() { 142 return this.textStart; 143 } 144 145 public void setText(String newText) { 146 this.text = newText; 147 } 148 149 public void setSelected(boolean isSelected) { 150 this.selected = isSelected; 151 } 152 153 public void setTextStart(int textStart) { 154 this.textStart = textStart; 155 } 156 157 public void setCursorState(int cursorState) { 158 this.cursorState = cursorState; 159 } 160 161 public void setLastCursorChange(long lastCursorChange) { 162 this.lastCursorChange = lastCursorChange; 163 } 168 164 } -
gamegui/Window.java
r155577b r8edd04e 3 3 import java.awt.*; 4 4 import java.awt.event.MouseEvent; 5 import java.util. *;5 import java.util.ArrayList; 6 6 7 public class Window extends Member 8 { 9 ArrayList<Member> members; 10 boolean fullscreen; 11 12 public Window(String newName, int newX, int newY, int newWidth, int newHeight) { 13 super(newName, newX, newY, newWidth, newHeight); 14 15 members = new ArrayList<Member>(); 16 } 17 18 public Window(String newName, int newX, int newY, int newWidth, int newHeight, boolean full) { 19 super(newName, newX, newY, newWidth, newHeight); 20 21 members = new ArrayList<Member>(); 22 fullscreen = full; 23 } 24 25 public void draw(Graphics g) { 26 g.setColor(Color.black); 27 g.fillRect(getX(), getY(), getWidth(), getHeight()); 28 29 if(!fullscreen) 30 { 31 g.setColor(Color.red); 32 g.drawRect(getX(), getY(), getWidth(), getHeight()); 33 } 34 35 for(int x=0; x < members.size(); x++) 36 members.get(x).draw(g); 37 } 38 39 public boolean handleEvent(MouseEvent e) { 40 boolean val = false; 41 42 for(int x=0; x < members.size(); x++) 43 val = val || members.get(x).handleEvent(e); 44 45 return val; 46 } 47 48 public void clear() { 49 for(int x=0; x < members.size(); x++) 50 members.get(x).clear(); 51 } 52 53 public void add(Member aMember) { 54 aMember.offset(getX(), getY()); 55 56 members.add(aMember); 57 } 58 59 public void offset(int xOffset, int yOffset) { 60 super.offset(xOffset, yOffset); 61 62 for(int x=0; x < members.size(); x++) 63 members.get(x).offset(xOffset, yOffset); 64 } 65 66 public Member getMember(String aName) { 67 for(int x=0; x < members.size(); x++) 68 if(members.get(x).getName().equals(aName)) 69 return (Member)members.get(x); 70 71 return null; 72 } 7 public class Window extends Member { 8 9 ArrayList<Member> members; 10 boolean fullscreen; 11 12 public Window(String newName, int newX, int newY, int newWidth, int newHeight) { 13 super(newName, newX, newY, newWidth, newHeight); 14 this.members = new ArrayList<Member>(); 15 } 16 17 public Window(String newName, int newX, int newY, int newWidth, int newHeight, boolean full) { 18 super(newName, newX, newY, newWidth, newHeight); 19 this.members = new ArrayList<Member>(); 20 this.fullscreen = full; 21 } 22 23 public void draw(Graphics g) { 24 g.setColor(Color.black); 25 g.fillRect(getX(), getY(), getWidth(), getHeight()); 26 if (!this.fullscreen) { 27 g.setColor(Color.red); 28 g.drawRect(getX(), getY(), getWidth(), getHeight()); 29 } 30 for (int x = 0; x < this.members.size(); x++) { 31 ((Member)this.members.get(x)).draw(g); 32 } 33 } 34 35 public boolean handleEvent(MouseEvent e) { 36 boolean val = false; 37 for (int x = 0; x < this.members.size(); x++) { 38 val = !(!val && !((Member)this.members.get(x)).handleEvent(e)); 39 } 40 return val; 41 } 42 43 public void clear() { 44 for (int x = 0; x < this.members.size(); x++) { 45 ((Member)this.members.get(x)).clear(); 46 } 47 } 48 49 public void add(Member aMember) { 50 aMember.offset(getX(), getY()); 51 this.members.add(aMember); 52 } 53 54 public void offset(int xOffset, int yOffset) { 55 super.offset(xOffset, yOffset); 56 for (int x = 0; x < this.members.size(); x++) { 57 ((Member)this.members.get(x)).offset(xOffset, yOffset); 58 } 59 } 60 61 public Member getMember(String aName) { 62 for (int x = 0; x < this.members.size(); x++) { 63 if (((Member)this.members.get(x)).getName().equals(aName)) { 64 return this.members.get(x); 65 } 66 } 67 return null; 68 } 73 69 } -
main/AuxState.java
r155577b r8edd04e 2 2 3 3 public enum AuxState { 4 5 4 None, 5 MsgBox 6 6 } -
main/Creature.java
r155577b r8edd04e 1 1 package main; 2 2 3 import java.awt.image.*; 4 5 public class Creature { 6 private String name; 7 private CreatureType type; 8 private BufferedImage img; 9 private Gender gender; 10 private int level; 11 private Point loc; 12 private int speed; 13 private long lastMoved; 14 private int attackSpeed; 15 private int damage; 16 private long lastAttacked; 17 private int strength; 18 private int dexterity; 19 private int constitution; 20 private int charisma; 21 private int wisdom; 22 private int intelligence; 23 private int hitpoints; 24 private int manapoints; 25 private int maxHitpoints; 26 private int maxManapoints; 27 28 public Creature() { 29 name = ""; 30 gender = Gender.None; 31 loc = new Point(0, 0); 32 } 33 34 public Creature(String name) { 35 this.name = name; 36 loc = new Point(0, 0); 37 } 38 39 public Creature(String name, Gender gender) { 40 this.name = name; 41 this.gender = gender; 42 loc = new Point(0, 0); 43 } 44 45 public int getAttackSpeed() { 46 return attackSpeed; 47 } 48 49 public int getCharisma() { 50 return charisma; 51 } 52 53 public int getConstitution() { 54 return constitution; 55 } 56 57 public int getDamage() { 58 return damage; 59 } 60 61 public int getDexterity() { 62 return dexterity; 63 } 64 65 public Gender getGender() { 66 return gender; 67 } 68 69 public int getHitpoints() { 70 return hitpoints; 71 } 72 73 public BufferedImage getImg() { 74 return img; 75 } 76 77 public int getIntelligence() { 78 return intelligence; 79 } 80 81 public long getLastAttacked() { 82 return lastAttacked; 83 } 84 85 public long getLastMoved() { 86 return lastMoved; 87 } 88 89 public int getLevel() { 90 return level; 91 } 92 93 public Point getLoc() { 94 return loc; 95 } 96 97 public int getManapoints() { 98 return manapoints; 99 } 100 101 public int getMaxHitpoints() { 102 return maxHitpoints; 103 } 104 105 public int getMaxManapoints() { 106 return maxManapoints; 107 } 108 109 public String getName() { 110 return name; 111 } 112 113 public int getSpeed() { 114 return speed; 115 } 116 117 public int getStrength() { 118 return strength; 119 } 120 121 public CreatureType getType() { 122 return type; 123 } 124 125 public int getWisdom() { 126 return wisdom; 127 } 128 129 public void setAttackSpeed(int attackSpeed) { 130 this.attackSpeed = attackSpeed; 131 } 132 133 public void setCharisma(int charisma) { 134 this.charisma = charisma; 135 } 136 137 public void setConstitution(int constitution) { 138 this.constitution = constitution; 139 } 140 141 public void setDamage(int damage) { 142 this.damage = damage; 143 } 144 145 public void setDexterity(int dexterity) { 146 this.dexterity = dexterity; 147 } 148 149 public void setGender(Gender gender) { 150 this.gender = gender; 151 } 152 153 public void setHitpoints(int hitpoints) { 154 this.hitpoints = hitpoints; 155 } 156 157 public void setImg(BufferedImage img) { 158 this.img = img; 159 } 160 161 public void setIntelligence(int intelligence) { 162 this.intelligence = intelligence; 163 } 164 165 public void setLastAttacked(long lastAttacked) { 166 this.lastAttacked = lastAttacked; 167 } 168 169 public void setLastMoved(long lastMoved) { 170 this.lastMoved = lastMoved; 171 } 172 173 public void setLevel(int level) { 174 this.level = level; 175 } 176 177 public void setLoc(Point loc) { 178 this.loc = loc; 179 } 180 181 public void setManapoints(int manapoints) { 182 this.manapoints = manapoints; 183 } 184 185 public void setMaxHitpoints(int maxHitpoints) { 186 this.maxHitpoints = maxHitpoints; 187 } 188 189 public void setMaxManapoints(int maxManapoints) { 190 this.maxManapoints = maxManapoints; 191 } 192 193 public void setName(String name) { 194 this.name = name; 195 } 196 197 public void setSpeed(int speed) { 198 this.speed = speed; 199 } 200 201 public void setStrength(int strength) { 202 this.strength = strength; 203 } 204 205 public void setType(CreatureType type) { 206 this.type = type; 207 } 208 209 public void setWisdom(int wisdom) { 210 this.wisdom = wisdom; 211 } 212 213 public String toString() { 214 return name; 215 } 216 217 public boolean equals(Object c) { 218 return name.trim().equals(((Creature)c).name.trim()); 219 } 3 import java.awt.*; 4 import java.awt.image.BufferedImage; 5 import java.io.*; 6 import java.util.*; 7 import javax.imageio.ImageIO; 8 9 import gamegui.Animation; 10 11 public class Creature implements Comparable<Creature> { 12 13 public int passive; 14 public int thorns; 15 public int confused; 16 public int sand; 17 18 protected String name; 19 protected CreatureType type; 20 protected Model model; 21 protected int level; 22 protected Point loc; 23 protected int[] attributes; 24 protected int hitpoints; 25 protected int manapoints; 26 protected int maxHitpoints; 27 protected int maxManapoints; 28 protected int experience; 29 protected EquippedWeapon weapon; 30 protected EquippedWeapon spell; 31 32 private Point target; 33 private Creature enemyTarget; 34 private int speed; 35 private long lastMoved; 36 private long lastAttacked; 37 private LinkedList<ItemDrop> drops; 38 private LinkedList<EffectTimer> effectTimers; 39 private boolean disabled; 40 private SpawnPoint spawnPoint; 41 private boolean dying; 42 43 public Creature() { 44 this.name = ""; 45 this.loc = new Point(0, 0); 46 this.target = this.loc; 47 this.attributes = new int[4]; 48 this.experience = 0; 49 this.weapon = null; 50 this.spell = null; 51 this.drops = new LinkedList<ItemDrop>(); 52 this.effectTimers = new LinkedList<EffectTimer>(); 53 this.disabled = false; 54 this.spawnPoint = null; 55 this.passive = 0; 56 this.thorns = 0; 57 this.confused = 0; 58 this.sand = 0; 59 this.dying = false; 60 } 61 62 public Creature(String name, CreatureType type) { 63 this.name = name; 64 this.type = type; 65 this.loc = new Point(0, 0); 66 this.target = this.loc; 67 this.attributes = new int[4]; 68 this.experience = 0; 69 this.weapon = null; 70 this.spell = null; 71 this.drops = new LinkedList<ItemDrop>(); 72 this.effectTimers = new LinkedList<EffectTimer>(); 73 this.disabled = false; 74 this.spawnPoint = null; 75 this.passive = 0; 76 this.thorns = 0; 77 this.confused = 0; 78 this.sand = 0; 79 this.dying = false; 80 } 81 82 public Creature(Creature cr) { 83 this.name = cr.name; 84 this.type = cr.type; 85 this.model = new Model(cr.model); 86 this.level = cr.level; 87 this.loc = new Point(cr.loc); 88 this.target = cr.target; 89 this.speed = cr.speed; 90 this.lastMoved = cr.lastMoved; 91 this.lastAttacked = cr.lastAttacked; 92 this.attributes = (int[])cr.attributes.clone(); 93 this.hitpoints = cr.hitpoints; 94 this.manapoints = cr.manapoints; 95 this.maxHitpoints = cr.maxHitpoints; 96 this.maxManapoints = cr.maxManapoints; 97 this.experience = cr.experience; 98 this.weapon = cr.weapon.copy((Point)null); 99 if (cr.spell != null) 100 this.spell = cr.spell.copy((Point)null); 101 this.drops = cr.drops; 102 this.effectTimers = new LinkedList<EffectTimer>(cr.effectTimers); 103 this.disabled = cr.disabled; 104 this.spawnPoint = null; 105 this.passive = cr.passive; 106 this.thorns = cr.thorns; 107 this.confused = cr.confused; 108 this.sand = cr.sand; 109 this.dying = cr.dying; 110 } 111 112 public Creature copy() { 113 return new Creature(this); 114 } 115 116 public void setDying(boolean dying) { 117 if (!this.model.hasDeath()) 118 return; 119 if (dying) { 120 this.model.setAction(Action.Dying); 121 } else { 122 this.model.getAnimation(Direction.West, Action.Dying).reset(); 123 } 124 this.dying = dying; 125 } 126 127 public boolean isDying() { 128 return this.dying; 129 } 130 131 public void checkTimedEffects() { 132 Iterator<EffectTimer> iter = this.effectTimers.iterator(); 133 while (iter.hasNext()) { 134 EffectTimer cur = iter.next(); 135 if (cur.expired()) { 136 cur.getEffect().cancelEffect(this); 137 iter.remove(); 138 } 139 } 140 } 141 142 public void addEffect(TimedEffect e) { 143 this.effectTimers.add(new EffectTimer(e, e.getDuration())); 144 } 145 146 public Point move() { 147 Point newLoc; 148 double dist = (this.speed * (System.currentTimeMillis() - this.lastMoved) / 1000L); 149 if (this.lastMoved == 0L) { 150 dist = 0.0D; 151 } 152 if (this.enemyTarget != null) { 153 this.target = this.enemyTarget.loc; 154 } 155 this.lastMoved = System.currentTimeMillis(); 156 if (Point.dist(this.loc, this.target) <= dist) { 157 newLoc = this.target; 158 if (this.model.getAction() != Action.Attacking) { 159 this.model.setAction(Action.Standing); 160 } 161 } else { 162 if (this.model.getAction() != Action.Attacking) { 163 this.model.setAction(Action.Walking); 164 } 165 int xDif = (int)(Point.xDif(this.loc, this.target) * dist / Point.dist(this.loc, this.target)); 166 int yDif = (int)(Point.yDif(this.loc, this.target) * dist / Point.dist(this.loc, this.target)); 167 newLoc = new Point(this.loc.getX(), this.loc.getXMin() + xDif, this.loc.getY(), this.loc.getYMin() + yDif); 168 newLoc.setX(newLoc.getX() + newLoc.getXMin() / 100); 169 newLoc.setXMin(newLoc.getXMin() % 100); 170 newLoc.setY(newLoc.getY() + newLoc.getYMin() / 100); 171 newLoc.setYMin(newLoc.getYMin() % 100); 172 if (newLoc.getXMin() < 0) { 173 newLoc.setX(newLoc.getX() - 1); 174 newLoc.setXMin(newLoc.getXMin() + 100); 175 } else if (newLoc.getYMin() < 0) { 176 newLoc.setY(newLoc.getY() - 1); 177 newLoc.setYMin(newLoc.getYMin() + 100); 178 } 179 this.model.setDirection(calcDirection()); 180 } 181 return newLoc; 182 } 183 184 private Direction calcDirection() { 185 Direction dir; 186 int xDif2 = Point.xDif(this.loc, this.target); 187 int yDif2 = Point.yDif(this.target, this.loc); 188 double angle = 1.5707963267948966D; 189 if (xDif2 == 0) { 190 if (yDif2 != 0) { 191 angle *= Math.abs(yDif2 / yDif2); 192 } 193 } else { 194 angle = Math.atan(yDif2 / xDif2); 195 } 196 if (angle >= 0.7853981633974483D) { 197 dir = Direction.North; 198 } else if (-0.7853981633974483D <= angle && angle <= 0.7853981633974483D) { 199 dir = Direction.East; 200 } else { 201 dir = Direction.South; 202 } 203 if (xDif2 < 0) 204 switch (dir) { 205 case North: 206 dir = Direction.South; 207 break; 208 case South: 209 dir = Direction.North; 210 break; 211 case East: 212 dir = Direction.West; 213 break; 214 } 215 return dir; 216 } 217 218 public Projectile attack(Creature enemy, AttackType attType) { 219 Weapon weap = selectWeapon(attType); 220 if (System.currentTimeMillis() - this.lastAttacked >= (weap.getAttackSpeed() * 100) && !this.disabled) { 221 this.lastAttacked = System.currentTimeMillis(); 222 Point oldTarget = this.target; 223 this.target = enemy.getLoc(); 224 this.model.setDirection(calcDirection()); 225 this.target = oldTarget; 226 if (attType != AttackType.Spell) { 227 this.model.setAction(Action.Attacking); 228 this.model.getAnimation(this.model.getDirection(), this.model.getAction()).reset(); 229 } 230 if (weap.getType() == ItemType.RangedWeapon || weap.getType() == ItemType.Spell) { 231 Point loc = new Point(this.loc); 232 loc.setY(loc.getY() - 55); 233 return weap.spawnProjectile(loc, enemy.getLoc()); 234 } 235 weap.applyContactEffects(enemy); 236 } 237 return null; 238 } 239 240 public Projectile attack(Point targ, AttackType attType) { 241 Weapon weap = selectWeapon(attType); 242 if ((System.currentTimeMillis() - this.lastAttacked) / 100L >= weap.getAttackSpeed() && !this.disabled) { 243 this.lastAttacked = System.currentTimeMillis(); 244 Point oldTarget = this.target; 245 this.target = targ; 246 this.model.setDirection(calcDirection()); 247 this.target = oldTarget; 248 if (attType != AttackType.Spell) { 249 this.model.setAction(Action.Attacking); 250 this.model.getAnimation(this.model.getDirection(), this.model.getAction()).reset(); 251 } 252 if (weap.getType() == ItemType.RangedWeapon || weap.getType() == ItemType.Spell) { 253 Point loc = new Point(this.loc); 254 loc.setY(loc.getY() - 30); 255 return weap.spawnProjectile(loc, targ); 256 } 257 } 258 return null; 259 } 260 261 private Weapon selectWeapon(AttackType attType) { 262 switch (attType) { 263 case Weapon: 264 return this.weapon; 265 case Spell: 266 return this.spell; 267 } 268 return this.weapon; 269 } 270 271 public void addDrop(ItemDrop item) { 272 this.drops.add(item); 273 } 274 275 public LinkedList<ItemDrop> getDrops() { 276 return this.drops; 277 } 278 279 public LinkedList<Item> spawnDrops() { 280 LinkedList<Item> newDrops = new LinkedList<Item>(); 281 Iterator<ItemDrop> iter = this.drops.iterator(); 282 Random gen = new Random(); 283 while (iter.hasNext()) { 284 ItemDrop cur = iter.next(); 285 if (gen.nextDouble() <= cur.getDropChance()) { 286 newDrops.add(cur.getItem()); 287 } 288 } 289 return newDrops; 290 } 291 292 public void draw(Graphics g, int playerX, int playerY) { 293 if (this.passive > 0) { 294 g.drawImage(LostHavenRPG.passiveAura, 375 + this.loc.getX() - playerX, 300 - this.model.getHeight() + this.loc.getY() - playerY, null); 295 } 296 if (this.thorns > 0) { 297 g.drawImage(LostHavenRPG.thornsAura, 375 + this.loc.getX() - playerX, 300 - this.model.getHeight() + this.loc.getY() - playerY, null); 298 } 299 this.model.draw(g, 400 + this.loc.getX() - playerX, 300 + this.loc.getY() - playerY); 300 if (this.confused > 0) { 301 g.drawImage(LostHavenRPG.confuseAura, 375 + this.loc.getX() - playerX, 300 - this.model.getHeight() + this.loc.getY() - playerY, null); 302 } 303 if (this.sand > 0) { 304 g.drawImage(LostHavenRPG.sandAura, 375 + this.loc.getX() - playerX, 300 - this.model.getHeight() + this.loc.getY() - playerY, null); 305 } 306 g.setColor(Color.red); 307 g.fillRect(360 + this.loc.getX() - playerX, 290 - this.model.getHeight() + this.loc.getY() - playerY, 80 * this.hitpoints / this.maxHitpoints, 10); 308 g.setColor(Color.black); 309 Font font12 = new Font("Arial", 0, 12); 310 FontMetrics metrics = g.getFontMetrics(font12); 311 g.setFont(font12); 312 g.drawString(this.name, 400 + this.loc.getX() - playerX - metrics.stringWidth(this.name) / 2, 300 - this.model.getHeight() + this.loc.getY() - playerY); 313 } 314 315 public void save(PrintWriter out) { 316 out.println(this.type); 317 if (this.spawnPoint == null) { 318 out.println(-1); 319 } else { 320 out.println(this.spawnPoint.idNum); 321 } 322 out.println(String.valueOf(this.loc.getX()) + "," + this.loc.getY()); 323 out.println(this.model.getDirection()); 324 out.println(this.model.getAction()); 325 out.println(this.hitpoints); 326 out.println(this.manapoints); 327 out.println(this.passive); 328 out.println(this.thorns); 329 out.println(this.confused); 330 out.println(this.sand); 331 if (this.weapon == null) { 332 out.println("None"); 333 } else { 334 out.println(this.weapon.getName()); 335 } 336 } 337 338 public static Creature loadTemplate(BufferedReader in) { 339 Creature cr = new Creature(); 340 BufferedImage[] imgProj = new BufferedImage[8]; 341 try { 342 cr.name = in.readLine(); 343 cr.type = CreatureType.valueOf(cr.name); 344 if (cr.type == CreatureType.Player) { 345 cr = Player.loadTemplate(in); 346 } 347 cr.setSpeed(Integer.parseInt(in.readLine())); 348 cr.setAttribute(Attribute.Strength, Integer.parseInt(in.readLine())); 349 cr.setAttribute(Attribute.Dexterity, Integer.parseInt(in.readLine())); 350 cr.setAttribute(Attribute.Constitution, Integer.parseInt(in.readLine())); 351 cr.setAttribute(Attribute.Wisdom, Integer.parseInt(in.readLine())); 352 ItemType wType = ItemType.valueOf(in.readLine()); 353 if (wType == ItemType.RangedWeapon) { 354 imgProj = LostHavenRPG.imgBow; 355 } else if (wType == ItemType.Spell) { 356 imgProj[0] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png")); 357 imgProj[1] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png")); 358 imgProj[2] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png")); 359 imgProj[3] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png")); 360 imgProj[4] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png")); 361 imgProj[5] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png")); 362 imgProj[6] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png")); 363 imgProj[7] = ImageIO.read(cr.getClass().getResource("../images/" + cr.type.toString() + "/proj.png")); 364 } 365 cr.model = cr.loadModel(cr.type.toString()); 366 cr.setWeapon(new Weapon("None", wType, "Dagger.png", imgProj, 10, Integer.parseInt(in.readLine()), Integer.parseInt(in.readLine()))); 367 cr.setExperience(Integer.parseInt(in.readLine())); 368 } catch (IOException ioe) { 369 ioe.printStackTrace(); 370 } 371 return cr; 372 } 373 374 public Model loadModel(String folder) { 375 boolean noAnims = false; 376 Animation anmStandN = new Animation("north", 0, 0, 40, 60, 300, true); 377 Animation anmStandS = new Animation("south", 0, 0, 40, 60, 300, true); 378 Animation anmStandE = new Animation("east", 0, 0, 40, 60, 300, true); 379 Animation anmStandW = new Animation("west", 0, 0, 40, 60, 300, true); 380 Animation anmWalkN = new Animation("north", 0, 0, 40, 60, 300, true); 381 Animation anmWalkS = new Animation("south", 0, 0, 40, 60, 300, true); 382 Animation anmWalkE = new Animation("east", 0, 0, 40, 60, 300, true); 383 Animation anmWalkW = new Animation("west", 0, 0, 40, 60, 300, true); 384 Animation anmAttackN = new Animation("north", 0, 0, 40, 60, 500, false); 385 Animation anmAttackS = new Animation("south", 0, 0, 40, 60, 500, false); 386 Animation anmAttackE = new Animation("east", 0, 0, 40, 60, 500, false); 387 Animation anmAttackW = new Animation("west", 0, 0, 40, 60, 500, false); 388 Animation anmDeath = new Animation("west", 0, 0, 40, 60, 1000, false); 389 BufferedImage walkN = null; 390 BufferedImage walkS = null; 391 BufferedImage walkE = null; 392 BufferedImage walkW = null; 393 boolean hasDeathAnim = (getClass().getResource("../images/" + folder + "/Death1.png") != null); 394 try { 395 if (getClass().getResource("../images/" + folder + "/WalkN.png") != null) { 396 walkN = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkN.png")); 397 anmWalkN.addFrame(walkN); 398 walkS = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkS.png")); 399 anmWalkS.addFrame(walkS); 400 walkE = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkE.png")); 401 anmWalkE.addFrame(walkE); 402 walkW = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkW.png")); 403 anmWalkW.addFrame(walkW); 404 } else if (getClass().getResource("../images/" + folder + "/WalkN1.png") != null) { 405 walkN = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkN1.png")); 406 anmWalkN.addFrame(walkN); 407 anmWalkN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkN2.png"))); 408 walkS = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkS1.png")); 409 anmWalkS.addFrame(walkS); 410 anmWalkS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkS2.png"))); 411 walkE = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkE1.png")); 412 anmWalkE.addFrame(walkE); 413 anmWalkE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkE2.png"))); 414 walkW = ImageIO.read(getClass().getResource("../images/" + folder + "/WalkW1.png")); 415 anmWalkW.addFrame(walkW); 416 anmWalkW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkW2.png"))); 417 } else { 418 noAnims = true; 419 anmStandN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png"))); 420 anmStandS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png"))); 421 anmStandE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png"))); 422 anmStandW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png"))); 423 anmWalkN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png"))); 424 anmWalkN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png"))); 425 anmWalkS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png"))); 426 anmWalkS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png"))); 427 anmWalkE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png"))); 428 anmWalkE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png"))); 429 anmWalkW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png"))); 430 anmWalkW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png"))); 431 anmAttackN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png"))); 432 anmAttackS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png"))); 433 anmAttackE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png"))); 434 anmAttackW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/" + folder + ".png"))); 435 } 436 if (!noAnims) { 437 BufferedImage standN, standS, standE, standW; 438 if (getClass().getResource("../images/" + folder + "/StandN.png") == null) { 439 standN = walkN; 440 standS = walkS; 441 standE = walkE; 442 standW = walkW; 443 } else { 444 standN = ImageIO.read(getClass().getResource("../images/" + folder + "/StandN.png")); 445 standS = ImageIO.read(getClass().getResource("../images/" + folder + "/StandS.png")); 446 standE = ImageIO.read(getClass().getResource("../images/" + folder + "/StandE.png")); 447 standW = ImageIO.read(getClass().getResource("../images/" + folder + "/StandW.png")); 448 anmWalkN = new Animation("north", 0, 0, 40, 60, 150, true); 449 anmWalkS = new Animation("south", 0, 0, 40, 60, 150, true); 450 anmWalkE = new Animation("east", 0, 0, 40, 60, 150, true); 451 anmWalkW = new Animation("west", 0, 0, 40, 60, 150, true); 452 anmWalkN.addFrame(walkN); 453 anmWalkN.addFrame(standN); 454 anmWalkN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkN2.png"))); 455 anmWalkN.addFrame(standN); 456 anmWalkS.addFrame(walkS); 457 anmWalkS.addFrame(standS); 458 anmWalkS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkS2.png"))); 459 anmWalkS.addFrame(standS); 460 anmWalkE.addFrame(walkE); 461 anmWalkE.addFrame(standE); 462 anmWalkE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkE2.png"))); 463 anmWalkE.addFrame(standE); 464 anmWalkW.addFrame(walkW); 465 anmWalkW.addFrame(standW); 466 anmWalkW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/WalkW2.png"))); 467 anmWalkW.addFrame(standW); 468 } 469 anmStandN.addFrame(standN); 470 anmStandS.addFrame(standS); 471 anmStandE.addFrame(standE); 472 anmStandW.addFrame(standW); 473 if (getClass().getResource("../images/" + folder + "/AttackN.png") != null) { 474 anmAttackN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackN.png"))); 475 anmAttackN.addFrame(standN); 476 anmAttackS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackS.png"))); 477 anmAttackS.addFrame(standS); 478 anmAttackE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackE.png"))); 479 anmAttackE.addFrame(standE); 480 anmAttackW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackW.png"))); 481 anmAttackW.addFrame(standW); 482 } else if (getClass().getResource("../images/" + folder + "/AttackN1.png") != null) { 483 anmAttackN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackN1.png"))); 484 anmAttackN.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackN2.png"))); 485 anmAttackS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackS1.png"))); 486 anmAttackS.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackS2.png"))); 487 anmAttackE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackE1.png"))); 488 anmAttackE.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackE2.png"))); 489 anmAttackW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackW1.png"))); 490 anmAttackW.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/AttackW2.png"))); 491 } else { 492 anmAttackN.addFrame(standN); 493 anmAttackS.addFrame(standS); 494 anmAttackE.addFrame(standE); 495 anmAttackW.addFrame(standW); 496 } 497 if (hasDeathAnim) { 498 anmDeath.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/Death1.png"))); 499 anmDeath.addFrame(ImageIO.read(getClass().getResource("../images/" + folder + "/Death2.png"))); 500 } 501 } 502 } catch (IOException ioe) { 503 ioe.printStackTrace(); 504 } 505 Model model = new Model(hasDeathAnim); 506 model.addAnimation(Direction.North, Action.Standing, anmStandN); 507 model.addAnimation(Direction.South, Action.Standing, anmStandS); 508 model.addAnimation(Direction.East, Action.Standing, anmStandE); 509 model.addAnimation(Direction.West, Action.Standing, anmStandW); 510 model.addAnimation(Direction.North, Action.Walking, anmWalkN); 511 model.addAnimation(Direction.South, Action.Walking, anmWalkS); 512 model.addAnimation(Direction.East, Action.Walking, anmWalkE); 513 model.addAnimation(Direction.West, Action.Walking, anmWalkW); 514 model.addAnimation(Direction.North, Action.Attacking, anmAttackN); 515 model.addAnimation(Direction.South, Action.Attacking, anmAttackS); 516 model.addAnimation(Direction.East, Action.Attacking, anmAttackE); 517 model.addAnimation(Direction.West, Action.Attacking, anmAttackW); 518 if (hasDeathAnim) { 519 model.addAnimation(Direction.West, Action.Dying, anmDeath); 520 } 521 return model; 522 } 523 524 public void load(BufferedReader in) { 525 try { 526 this.spawnPoint = LostHavenRPG.getSpawnPoint(Integer.parseInt(in.readLine())); 527 if (this.spawnPoint != null) { 528 this.spawnPoint.numSpawns++; 529 } 530 String strLoc = in.readLine(); 531 getLoc().setX(Integer.valueOf(strLoc.substring(0, strLoc.indexOf(","))).intValue()); 532 getLoc().setY(Integer.valueOf(strLoc.substring(strLoc.indexOf(",") + 1)).intValue()); 533 getModel().setDirection(Direction.valueOf(in.readLine())); 534 getModel().setAction(Action.valueOf(in.readLine())); 535 setHitpoints(Integer.valueOf(in.readLine()).intValue()); 536 setManapoints(Integer.valueOf(in.readLine()).intValue()); 537 this.passive = Integer.valueOf(in.readLine()).intValue(); 538 this.thorns = Integer.valueOf(in.readLine()).intValue(); 539 this.confused = Integer.valueOf(in.readLine()).intValue(); 540 this.sand = Integer.valueOf(in.readLine()).intValue(); 541 String strWeapon = in.readLine(); 542 if (!strWeapon.equals("None")) { 543 setWeapon((Weapon)LostHavenRPG.items.get(strWeapon)); 544 } 545 } catch (IOException ioe) { 546 ioe.printStackTrace(); 547 } 548 } 549 550 protected int attributeIndex(Attribute attribute) { 551 switch (attribute) { 552 case Strength: 553 return 0; 554 case Dexterity: 555 return 1; 556 case Constitution: 557 return 2; 558 case Wisdom: 559 return 3; 560 } 561 return -1; 562 } 563 564 public int getAttribute(Attribute attribute) { 565 return this.attributes[attributeIndex(attribute)]; 566 } 567 568 public void setAttribute(Attribute attribute, int num) { 569 this.attributes[attributeIndex(attribute)] = num; 570 updateStats(); 571 } 572 573 private void updateStats() { 574 this.hitpoints = 2 * this.attributes[2]; 575 this.maxHitpoints = 2 * this.attributes[2]; 576 this.manapoints = 2 * this.attributes[3]; 577 this.maxManapoints = 2 * this.attributes[3]; 578 } 579 580 public Creature getEnemyTarget() { 581 return this.enemyTarget; 582 } 583 584 public int getExperience() { 585 return this.experience; 586 } 587 588 public int getHitpoints() { 589 return this.hitpoints; 590 } 591 592 public Model getModel() { 593 return this.model; 594 } 595 596 public long getLastAttacked() { 597 return this.lastAttacked; 598 } 599 600 public long getLastMoved() { 601 return this.lastMoved; 602 } 603 604 public int getLevel() { 605 return this.level; 606 } 607 608 public Point getLoc() { 609 return this.loc; 610 } 611 612 public int getManapoints() { 613 return this.manapoints; 614 } 615 616 public int getMaxHitpoints() { 617 return this.maxHitpoints; 618 } 619 620 public int getMaxManapoints() { 621 return this.maxManapoints; 622 } 623 624 public String getName() { 625 return this.name; 626 } 627 628 public int getSpeed() { 629 return this.speed; 630 } 631 632 public Point getTarget() { 633 return this.target; 634 } 635 636 public CreatureType getType() { 637 return this.type; 638 } 639 640 public EquippedWeapon getWeapon() { 641 return this.weapon; 642 } 643 644 public EquippedWeapon getSpell() { 645 return this.spell; 646 } 647 648 public void setEnemyTarget(Creature enemyTarget) { 649 this.enemyTarget = enemyTarget; 650 } 651 652 public void setExperience(int experience) { 653 this.experience = experience; 654 } 655 656 public void setHitpoints(int hitpoints) { 657 if (hitpoints > 0) { 658 this.hitpoints = hitpoints; 659 } else { 660 this.hitpoints = 0; 661 } 662 } 663 664 public void setModel(Model model) { 665 this.model = model; 666 } 667 668 public void setLastAttacked(long lastAttacked) { 669 this.lastAttacked = lastAttacked; 670 } 671 672 public void setLastMoved(long lastMoved) { 673 this.lastMoved = lastMoved; 674 } 675 676 public void setLevel(int level) { 677 this.level = level; 678 } 679 680 public void setLoc(Point loc) { 681 this.loc = loc; 682 } 683 684 public void setManapoints(int manapoints) { 685 if (manapoints > 0) { 686 this.manapoints = manapoints; 687 } else { 688 this.manapoints = 0; 689 } 690 } 691 692 public void setMaxHitpoints(int maxHitpoints) { 693 this.maxHitpoints = maxHitpoints; 694 } 695 696 public void setMaxManapoints(int maxManapoints) { 697 this.maxManapoints = maxManapoints; 698 } 699 700 public void setName(String name) { 701 this.name = name; 702 } 703 704 public void setSpeed(int speed) { 705 this.speed = speed; 706 } 707 708 public void setTarget(Point target) { 709 this.target = target; 710 } 711 712 public void setType(CreatureType type) { 713 this.type = type; 714 } 715 716 public void setWeapon(Weapon weapon) { 717 this.weapon = new EquippedWeapon(this, weapon); 718 this.weapon.update(); 719 (this.model.getAnimation(Direction.North, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.North, Action.Attacking)).frames.size()); 720 (this.model.getAnimation(Direction.South, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.South, Action.Attacking)).frames.size()); 721 (this.model.getAnimation(Direction.East, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.East, Action.Attacking)).frames.size()); 722 (this.model.getAnimation(Direction.West, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.West, Action.Attacking)).frames.size()); 723 } 724 725 public void setSpell(Weapon spell) { 726 this.spell = new EquippedWeapon(this, spell); 727 this.spell.update(); 728 } 729 730 public SpawnPoint getSpawnPoint() { 731 return this.spawnPoint; 732 } 733 734 public void setSpawnPoint(SpawnPoint sp) { 735 this.spawnPoint = sp; 736 } 737 738 public boolean farFromSpawnPoint() { 739 if (this.spawnPoint == null) 740 return false; 741 return (Point.dist(this.spawnPoint.getLoc(), this.loc) > 800.0D); 742 } 743 744 public boolean closerToSpawnPoint(Point newLoc) { 745 if (this.spawnPoint == null) 746 return false; 747 return (Point.dist(this.spawnPoint.getLoc(), this.loc) >= Point.dist(this.spawnPoint.getLoc(), newLoc)); 748 } 749 750 public void disable() { 751 this.disabled = true; 752 } 753 754 public void enable() { 755 this.disabled = false; 756 } 757 758 public String toString() { 759 return this.name; 760 } 761 762 public int compareTo(Creature c) { 763 return 0; 764 } 220 765 } -
main/CreatureType.java
r155577b r8edd04e 2 2 3 3 public enum CreatureType { 4 4 Archer, 5 Bandit, 6 Blob, 7 BlueBlob, 8 Specter, 9 CrystalGuard, 10 DesertAmbusher, 11 Ghost, 12 Goblin, 13 Golem, 14 Guardian, 15 Player, 16 Pyromancer, 17 RustedArmor, 18 BurningCorpse, 19 Wight, 20 Zombie 5 21 } -
main/GameState.java
r155577b r8edd04e 2 2 3 3 public enum GameState { 4 Main, 5 CreateAccount, 6 CreateClass, 7 LoadGame, 8 Info, 9 Credits, 10 Game, 11 GameMenu, 12 GameInventory, 13 GameStats 4 Main, 5 CreateAccount, 6 LoadGame, 7 Info, 8 Credits, 9 Game, 10 GameIntro, 11 GameInfo, 12 GameMenu, 13 GameStats, 14 GameGems, 15 GameInventory, 16 GameMap, 17 Victory 14 18 } -
main/Gender.java
r155577b r8edd04e 2 2 3 3 public enum Gender { 4 5 6 4 None, 5 Male, 6 Female 7 7 } -
main/Job.java
r155577b r8edd04e 2 2 3 3 public enum Job { 4 5 6 7 8 9 10 4 None, 5 Fighter, 6 Ranger, 7 Barbarian, 8 Sorceror, 9 Druid, 10 Wizard 11 11 } -
main/Land.java
r155577b r8edd04e 1 1 package main; 2 2 3 import java.awt.image. *;3 import java.awt.image.BufferedImage; 4 4 5 5 public class Land extends MapElement { 6 private LandType type;7 8 public Land(LandType type, BufferedImage img, boolean passable) {9 super(img, passable);10 6 11 this.type = type; 12 } 13 14 public Land(LandType type, String imgFile, boolean passable) { 15 super(imgFile, passable); 16 17 this.type = type; 18 } 19 20 public LandType getType() { 21 return type; 22 } 7 private LandType type; 8 9 public Land(LandType type, BufferedImage img, boolean passable) { 10 super(img, passable); 11 this.type = type; 12 } 13 14 public Land(LandType type, String imgFile, boolean passable) { 15 super(imgFile, passable); 16 this.type = type; 17 } 18 19 public Land(Land copy) { 20 super(copy); 21 this.type = copy.type; 22 } 23 24 public LandType getType() { 25 return this.type; 26 } 23 27 } -
main/LandType.java
r155577b r8edd04e 2 2 3 3 public enum LandType { 4 Grass, 5 Ocean 4 Lava, 5 Metal, 6 Charred, 7 Swamp, 8 Vines, 9 Crystal, 10 CrystalFormation, 11 Water, 12 Forest, 13 Tree, 14 Plains, 15 Desert, 16 Mountains, 17 Cave, 18 Ocean, 19 Snow, 20 Steam; 6 21 } -
main/Location.java
r155577b r8edd04e 1 1 package main; 2 2 3 import java.util. *;3 import java.util.PriorityQueue; 4 4 5 5 public class Location { 6 private Land land;7 private Structure structure;8 private PriorityQueue<Creature> creatures;9 10 public Location(Land land, Structure structure) {11 this.land = land;12 this.structure = structure;13 this.creatures = new PriorityQueue<Creature>();14 }15 6 16 public void addCreature(Creature creature) { 17 creatures.add(creature); 18 } 19 20 public Land getLand() { 21 return land; 22 } 7 private Land land; 8 private Structure structure; 9 private PriorityQueue<Creature> creatures; 23 10 24 public Structure getStruct() { 25 return structure; 26 } 27 28 public void setLand(Land type) { 29 land = type; 30 } 31 32 public void setStruct(Structure type) { 33 structure = type; 34 } 35 36 public boolean isPassable() { 37 return land.isPassable() && structure.isPassable(); 38 } 11 public Location(Land land, Structure structure) { 12 this.land = land; 13 this.structure = structure; 14 this.creatures = new PriorityQueue<Creature>(); 15 } 16 17 public void addCreature(Creature creature) { 18 this.creatures.add(creature); 19 } 20 21 public void spawnCreature(Creature creature, Point loc) { 22 Creature newC = creature.copy(); 23 newC.setLoc(loc); 24 this.creatures.add(newC); 25 } 26 27 public Land getLand() { 28 return this.land; 29 } 30 31 public Structure getStruct() { 32 return this.structure; 33 } 34 35 public PriorityQueue<Creature> getCreatures() { 36 return this.creatures; 37 } 38 39 public void setLand(Land type) { 40 this.land = type; 41 } 42 43 public void setStruct(Structure type) { 44 this.structure = type; 45 } 46 47 public boolean isPassable() { 48 return (this.land.isPassable() && this.structure.isPassable()); 49 } 39 50 } -
main/LostHavenRPG.java
r155577b r8edd04e 1 1 package main; 2 2 3 import java.awt.*; 3 import java.awt.Color; 4 import java.awt.DisplayMode; 5 import java.awt.Font; 6 import java.awt.FontMetrics; 7 import java.awt.Frame; 8 import java.awt.Graphics; 9 import java.awt.GraphicsConfiguration; 10 import java.awt.GraphicsDevice; 11 import java.awt.GraphicsEnvironment; 12 import java.awt.MouseInfo; 13 import java.awt.event.*; 4 14 import java.awt.image.*; 5 import java.awt.event.*;6 15 import java.io.*; 7 import java.util.*; 8 import javax.imageio.*; 9 import java.text.*; 16 import java.text.SimpleDateFormat; 17 import java.util.Date; 18 import java.util.HashMap; 19 import java.util.Iterator; 20 import java.util.LinkedList; 21 22 import javax.imageio.ImageIO; 10 23 11 24 import gamegui.*; 12 25 13 /* 14 * This is the main class in the project. It initializes wide-screen mode and is responsible for drawing to the screen and handling 15 * input. 16 * 17 * The classes in the gamegui folder are similar to the Swing classes in that they help in building a gui. They are all extended from 18 * the Member class and instances of each of them can be added to a Window class. They also have input-handling functionality. 19 */ 26 public class LostHavenRPG implements KeyListener, MouseListener { 20 27 21 public class LostHavenRPG implements KeyListener, MouseListener { 22 private static DisplayMode[] BEST_DISPLAY_MODES = new DisplayMode[] { 23 new DisplayMode(800, 600, 32, 0), 24 new DisplayMode(800, 600, 16, 0), 25 new DisplayMode(800, 600, 8, 0) 28 private static DisplayMode[] BEST_DISPLAY_MODES = new DisplayMode[] { 29 new DisplayMode(800, 600, 32, 0), 30 new DisplayMode(800, 600, 16, 0), 31 new DisplayMode(800, 600, 8, 0) 26 32 }; 27 28 boolean done;29 boolean changePending;30 31 Player player;32 Map map;33 34 //all "types" should be enums so it's easier to see all possible values while programming35 HashMap<LandType, Land> landMap;36 HashMap<StructureType, Structure> structMap;37 HashMap<CreatureType, Creature> creatureMap;38 39 BufferedImage girl;40 BufferedImage guy;41 42 public GameState gameState;43 public AuxState auxState;44 45 //GUI elements46 Frame frmMain;47 48 gamegui.Window wndMain;49 gamegui.Window wndCreateAccount;50 gamegui.Window wndChooseClass;51 gamegui.Window wndGameInfo;52 gamegui.Window wndCredits;53 54 RadioGroup rdgGenderSelection;55 RadioGroup rdgClassSelection;56 57 gamegui.Window wndMessage;58 gamegui.Window wndProgress;59 gamegui.Window wndConnecting;60 61 Textbox selectedText;62 33 63 public LostHavenRPG(GraphicsDevice device) { 64 try { 65 GraphicsConfiguration gc = device.getDefaultConfiguration(); 66 frmMain = new Frame(gc); 67 frmMain.setUndecorated(true); 68 frmMain.setIgnoreRepaint(true); 69 device.setFullScreenWindow(frmMain); 70 71 if (device.isDisplayChangeSupported()) { 72 chooseBestDisplayMode(device); 73 } 74 75 frmMain.addMouseListener(this); 76 frmMain.addKeyListener(this); 77 frmMain.createBufferStrategy(2); 78 BufferStrategy bufferStrategy = frmMain.getBufferStrategy(); 34 public static Map map; 35 public static HashMap<LandType, Land> landMap; 36 public static HashMap<StructureType, Structure> structMap; 37 public static HashMap<CreatureType, Creature> creatureMap; 38 public static HashMap<String, Item> items; 39 public static LinkedList<RespawnPoint> respawnPoints; 40 public static LinkedList<SpawnPoint> spawnPoints; 79 41 80 player = new Player(); 81 done = false; 82 changePending = false; 83 84 gameState = GameState.Main; 85 auxState = AuxState.None; 86 87 loadMap(); 88 map = new Map("mapInfo.txt", "structInfo.txt", landMap, structMap); 89 map.getLoc(10, 10).addCreature(new Creature()); 90 initGUIElements(); 91 92 while (!done) { 93 Graphics g = bufferStrategy.getDrawGraphics(); 94 move(); 95 render(g); 96 g.dispose(); 97 bufferStrategy.show(); 98 } 99 } 100 catch (Exception e) { 101 e.printStackTrace(); 102 } 103 finally { 104 device.setFullScreenWindow(null); 105 } 42 public static BufferedImage[] airSprites; 43 public static BufferedImage[] earthSprites; 44 public static BufferedImage[] fireSprites; 45 public static BufferedImage[] waterSprites; 46 public static BufferedImage[] imgBow; 47 public static BufferedImage passiveAura; 48 public static BufferedImage thornsAura; 49 public static BufferedImage confuseAura; 50 public static BufferedImage sandAura; 51 public static Model rangedModel; 52 public static Model meleeModel; 53 public static ScrollList lstInventory; 54 public static ScrollList lstGems; 55 public static Frame frmMain; 56 57 public GameState gameState; 58 public AuxState auxState; 59 60 boolean done; 61 boolean changePending; 62 Player player; 63 64 LinkedList<Gem> gems; 65 LinkedList<Item> drops; 66 LinkedList<Projectile> projectiles; 67 68 BufferedImage imgMap; 69 70 Window wndMain; 71 Window wndCreateAccount; 72 Window wndGameIntro; 73 Window wndGameInfo; 74 Window wndCredits; 75 Window wndStatDisplay; 76 Window wndGameInventory; 77 Window wndGameGems; 78 Window wndGameStats; 79 Window wndGameMap; 80 Window wndVictory; 81 Window[] wndTutorials; 82 Window wndTutOptions; 83 Window wndMessage; 84 85 int wndTutCur; 86 boolean infoStart; 87 88 Button btnMenu; 89 Button btnStats; 90 Button btnGems; 91 Button btnInventory; 92 Button btnMap; 93 94 Label lblGemVal; 95 Label lblSpellCost; 96 97 Graphics g; 98 99 Point startPoint; 100 101 Textbox selectedText; 102 103 boolean started = false; 104 105 public LostHavenRPG(GraphicsDevice device) { 106 try { 107 GraphicsConfiguration gc = device.getDefaultConfiguration(); 108 frmMain = new Frame(gc); 109 frmMain.setUndecorated(true); 110 frmMain.setIgnoreRepaint(true); 111 device.setFullScreenWindow(frmMain); 112 if (device.isDisplayChangeSupported()) 113 chooseBestDisplayMode(device); 114 frmMain.addMouseListener(this); 115 frmMain.addKeyListener(this); 116 frmMain.createBufferStrategy(2); 117 BufferStrategy bufferStrategy = frmMain.getBufferStrategy(); 118 this.g = bufferStrategy.getDrawGraphics(); 119 this.done = false; 120 this.changePending = false; 121 this.gameState = GameState.Main; 122 this.auxState = AuxState.None; 123 loadMapElements(); 124 this.imgMap = ImageIO.read(getClass().getResource("../images/mapLarge.png")); 125 map = new Map("map.png", "structInfo2.txt", landMap, structMap, true); 126 this.startPoint = new Point(7050, 6150); 127 loadItems(); 128 loadCreatures(); 129 loadSpawnPoints(); 130 loadSpellSprites(); 131 initGUIElements(); 132 this.started = true; 133 while (!this.done) { 134 this.g = bufferStrategy.getDrawGraphics(); 135 handleEvents(); 136 render(this.g); 137 this.g.dispose(); 138 bufferStrategy.show(); 139 } 140 } catch (Exception e) { 141 e.printStackTrace(); 142 } finally { 143 device.setFullScreenWindow(null); 144 } 145 } 146 147 private void initGUIElements() { 148 Font font11 = new Font("Arial", 0, 11); 149 Font font12 = new Font("Arial", 0, 12); 150 Font font14 = new Font("Arial", 0, 14); 151 Font font24 = new Font("Arial", 0, 24); 152 BufferedImage imgSub = null; 153 BufferedImage imgAdd = null; 154 BufferedImage imgSkillSub = null; 155 BufferedImage imgSkillAdd = null; 156 String strengthDesc = "Raises damage inflicted by melee weapons."; 157 String dexterityDesc = "Lowers cooldown of all weapons."; 158 String constitutionDesc = "Raises starting hitpoints and hitpoints gained per level."; 159 String wisdomDesc = "Raises starting manapoints and manapoints gained per level."; 160 String lightWeaponDesc = "Raises damage inflicted by light weapons."; 161 String heavyWeaponDesc = "Raises damage inflicted by heavy weapons."; 162 String rangedWeaponDesc = "Raises damage inflicted by ranged weapons."; 163 String evocationDesc = "Raises the possible number of activated gems."; 164 this.wndMain = new Window("main", 0, 0, 800, 600, true); 165 Animation anmTitle = new Animation("title", 144, 0, 512, 95, 83, true); 166 try { 167 anmTitle.addFrame(ImageIO.read(getClass().getResource("../images/Frame1.png"))); 168 anmTitle.addFrame(ImageIO.read(getClass().getResource("../images/Frame2.png"))); 169 anmTitle.addFrame(ImageIO.read(getClass().getResource("../images/Frame3.png"))); 170 anmTitle.addFrame(ImageIO.read(getClass().getResource("../images/Frame4.png"))); 171 anmTitle.addFrame(ImageIO.read(getClass().getResource("../images/Frame5.png"))); 172 imgSub = ImageIO.read(getClass().getResource("../images/imgSub.png")); 173 imgAdd = ImageIO.read(getClass().getResource("../images/imgAdd.png")); 174 imgSkillSub = ImageIO.read(getClass().getResource("../images/imgSkillSub.png")); 175 imgSkillAdd = ImageIO.read(getClass().getResource("../images/imgSkillAdd.png")); 176 } catch (IOException ioe) { 177 ioe.printStackTrace(); 178 } 179 this.wndMain.add(anmTitle); 180 this.wndMain.add(new Button("new game", 500, 140, 200, 40, "New Game", font12)); 181 this.wndMain.add(new Button("load game", 500, 230, 200, 40, "Load Game", font12)); 182 this.wndMain.add(new Button("game info", 500, 320, 200, 40, "Game Information", font12)); 183 this.wndMain.add(new Button("credits", 500, 410, 200, 40, "Credits", font12)); 184 this.wndMain.add(new Button("quit", 500, 500, 200, 40, "Quit", font12)); 185 this.wndStatDisplay = new Window("stat display", 0, 550, 799, 49, false); 186 this.wndGameStats = new Window("game stats", 0, 125, 320, 425); 187 this.wndGameGems = new Window("inventory", 359, 299, 220, 251); 188 lstGems = new ScrollList("gem list", 0, 0, 200, 251, null, null); 189 lstGems.addScrollBar(new ScrollBar("scrollgem", 200, 0, 20, 251, 3)); 190 this.wndGameGems.add(lstGems); 191 this.wndGameInventory = new Window("inventory", 579, 299, 220, 251); 192 lstInventory = new ScrollList("inventory list", 0, 0, 200, 251, null, null); 193 lstInventory.addScrollBar(new ScrollBar("scrollinv", 200, 0, 20, 251, 3)); 194 this.wndGameInventory.add(lstInventory); 195 this.wndGameMap = new Window("inventory", 443, 357, 356, 193); 196 this.btnMenu = new Button("main menu", 360, 10, 80, 20, "Main Menu", font12); 197 this.btnStats = new Button("stats", 600, 5, 80, 16, "Character", font12); 198 this.btnInventory = new Button("inventory", 700, 5, 80, 16, "Inventory", font12); 199 this.btnGems = new Button("gems", 600, 29, 80, 16, "Gems", font12); 200 this.btnMap = new Button("map", 700, 29, 80, 16, "Map", font12); 201 this.lblGemVal = new Label("gemVal", 515, 5, 67, 20, "Gem Value: 0", font12, Align.Right); 202 this.lblSpellCost = new Label("spellCost", 515, 24, 67, 20, "Spell Cost: 0", font12, Align.Right); 203 this.wndStatDisplay.add(this.btnMenu); 204 this.wndStatDisplay.add(this.btnStats); 205 this.wndStatDisplay.add(this.btnGems); 206 this.wndStatDisplay.add(this.btnInventory); 207 this.wndStatDisplay.add(this.btnMap); 208 this.wndStatDisplay.add(this.lblGemVal); 209 this.wndStatDisplay.add(this.lblSpellCost); 210 this.wndGameStats.add(new Label("strength", 10, 20, 70, 30, "Strength", font12, Align.Left)); 211 this.wndGameStats.add(new Label("strengthDesc", 20, 45, 70, 15, strengthDesc, font11, Align.Left)); 212 this.wndGameStats.add(new Label("dexterity", 10, 65, 70, 30, "Dexterity", font12, Align.Left)); 213 this.wndGameStats.add(new Label("dexterityDesc", 20, 90, 70, 15, dexterityDesc, font11, Align.Left)); 214 this.wndGameStats.add(new Label("constitution", 10, 110, 70, 30, "Constitution", font12, Align.Left)); 215 this.wndGameStats.add(new Label("constitutionDesc", 20, 135, 70, 15, constitutionDesc, font11, Align.Left)); 216 this.wndGameStats.add(new Label("wisdom", 10, 155, 70, 30, "Wisdom", font12, Align.Left)); 217 this.wndGameStats.add(new Label("wisdomDesc", 20, 180, 70, 15, wisdomDesc, font11, Align.Left)); 218 this.wndGameStats.add(new Label("strVal", 220, 20, 70, 30, "0", font12, Align.Left)); 219 this.wndGameStats.add(new Label("dexVal", 220, 65, 70, 30, "0", font12, Align.Left)); 220 this.wndGameStats.add(new Label("conVal", 220, 110, 70, 30, "0", font12, Align.Left)); 221 this.wndGameStats.add(new Label("wisVal", 220, 155, 70, 30, "0", font12, Align.Left)); 222 this.wndGameStats.add(new Label("light weapons", 10, 220, 70, 30, "Light Weapons", font12, Align.Left)); 223 this.wndGameStats.add(new Label("lightWeaponDesc", 20, 245, 70, 15, lightWeaponDesc, font11, Align.Left)); 224 this.wndGameStats.add(new Label("heavy weapons", 10, 265, 70, 30, "Heavy Weapons", font12, Align.Left)); 225 this.wndGameStats.add(new Label("heavyWeaponDesc", 20, 290, 70, 15, heavyWeaponDesc, font11, Align.Left)); 226 this.wndGameStats.add(new Label("ranged weapons", 10, 310, 70, 30, "Ranged Weapons", font12, Align.Left)); 227 this.wndGameStats.add(new Label("rangedWeaponDesc", 20, 335, 70, 15, rangedWeaponDesc, font11, Align.Left)); 228 this.wndGameStats.add(new Label("evocation", 10, 355, 70, 30, "Evocation", font12, Align.Left)); 229 this.wndGameStats.add(new Label("evocationDesc", 20, 380, 70, 15, evocationDesc, font11, Align.Left)); 230 this.wndGameStats.add(new Label("lightWeaponVal", 220, 220, 70, 30, "0", font12, Align.Left)); 231 this.wndGameStats.add(new Label("heavyWeaponVal", 220, 265, 70, 30, "0", font12, Align.Left)); 232 this.wndGameStats.add(new Label("rangedWeaponVal", 220, 310, 70, 30, "0", font12, Align.Left)); 233 this.wndGameStats.add(new Label("evocationVal", 220, 355, 70, 30, "0", font12, Align.Left)); 234 this.wndGameStats.add(new Label("skillVal", 130, 395, 70, 30, "0", font12, Align.Left)); 235 this.wndGameStats.add(new Button("lightWeapon+", 265, 230, 20, 20, imgSkillAdd)); 236 this.wndGameStats.add(new Button("heavyWeapon+", 265, 275, 20, 20, imgSkillAdd)); 237 this.wndGameStats.add(new Button("rangedWeapon+", 265, 320, 20, 20, imgSkillAdd)); 238 this.wndGameStats.add(new Button("evocation+", 265, 365, 20, 20, imgSkillAdd)); 239 this.wndGameStats.add(new Label("skilllPoints", 50, 395, 70, 30, "Remaining Points:", font12, Align.Right)); 240 this.wndCreateAccount = new Window("create account", 0, 0, 800, 600, true); 241 this.wndCreateAccount.add(new Label("title", 250, 15, 300, 20, "Create an Account", font24)); 242 this.wndCreateAccount.add(new Textbox("user", 340, 100, 190, 30, "Username:", font12, false)); 243 this.wndCreateAccount.add(new Label("strength", 90, 190, 70, 30, "Strength", font12, Align.Left)); 244 this.wndCreateAccount.add(new Label("strengthDesc", 115, 220, 70, 15, strengthDesc, font11, Align.Left)); 245 this.wndCreateAccount.add(new Label("dexterity", 90, 250, 70, 30, "Dexterity", font12, Align.Left)); 246 this.wndCreateAccount.add(new Label("dexterityDesc", 115, 280, 70, 15, dexterityDesc, font11, Align.Left)); 247 this.wndCreateAccount.add(new Label("constitution", 90, 310, 70, 30, "Constitution", font12, Align.Left)); 248 this.wndCreateAccount.add(new Label("constitutionDesc", 115, 340, 70, 15, constitutionDesc, font11, Align.Left)); 249 this.wndCreateAccount.add(new Label("wisdom", 90, 370, 70, 30, "Wisdom", font12, Align.Left)); 250 this.wndCreateAccount.add(new Label("wisdomDesc", 115, 400, 70, 15, wisdomDesc, font11, Align.Left)); 251 this.wndCreateAccount.add(new Label("attPoints", 110, 430, 70, 30, "Remaining Points:", font12, Align.Right)); 252 this.wndCreateAccount.add(new Label("strVal", 264, 190, 70, 30, "0", font12, Align.Left)); 253 this.wndCreateAccount.add(new Label("dexVal", 264, 250, 70, 30, "0", font12, Align.Left)); 254 this.wndCreateAccount.add(new Label("conVal", 264, 310, 70, 30, "0", font12, Align.Left)); 255 this.wndCreateAccount.add(new Label("wisVal", 264, 370, 70, 30, "0", font12, Align.Left)); 256 this.wndCreateAccount.add(new Label("attVal", 215, 430, 70, 30, "0", font12, Align.Left)); 257 this.wndCreateAccount.add(new Button("strength-", 205, 198, 20, 20, imgSub)); 258 this.wndCreateAccount.add(new Button("strength+", 315, 198, 20, 20, imgAdd)); 259 this.wndCreateAccount.add(new Button("dexterity-", 205, 258, 20, 20, imgSub)); 260 this.wndCreateAccount.add(new Button("dexterity+", 315, 258, 20, 20, imgAdd)); 261 this.wndCreateAccount.add(new Button("constitution-", 205, 318, 20, 20, imgSub)); 262 this.wndCreateAccount.add(new Button("constitution+", 315, 318, 20, 20, imgAdd)); 263 this.wndCreateAccount.add(new Button("wisdom-", 205, 378, 20, 20, imgSub)); 264 this.wndCreateAccount.add(new Button("wisdom+", 315, 378, 20, 20, imgAdd)); 265 this.wndCreateAccount.add(new Label("light weapons", 450, 190, 70, 30, "Light Weapons", font12, Align.Left)); 266 this.wndCreateAccount.add(new Label("lightWeaponDesc", 475, 220, 70, 15, lightWeaponDesc, font11, Align.Left)); 267 this.wndCreateAccount.add(new Label("heavy weapons", 450, 250, 70, 30, "Heavy Weapons", font12, Align.Left)); 268 this.wndCreateAccount.add(new Label("heavyWeaponDesc", 475, 280, 70, 15, heavyWeaponDesc, font11, Align.Left)); 269 this.wndCreateAccount.add(new Label("ranged weapons", 450, 310, 70, 30, "Ranged Weapons", font12, Align.Left)); 270 this.wndCreateAccount.add(new Label("rangedWeaponDesc", 475, 340, 70, 15, rangedWeaponDesc, font11, Align.Left)); 271 this.wndCreateAccount.add(new Label("evocation", 450, 370, 70, 30, "Evocation", font12, Align.Left)); 272 this.wndCreateAccount.add(new Label("evocationDesc", 475, 400, 70, 15, evocationDesc, font11, Align.Left)); 273 this.wndCreateAccount.add(new Label("skilllPoints", 475, 430, 70, 30, "Remaining Points:", font12, Align.Right)); 274 this.wndCreateAccount.add(new Label("lightWeaponVal", 620, 190, 70, 30, "0", font12, Align.Left)); 275 this.wndCreateAccount.add(new Label("heavyWeaponVal", 620, 250, 70, 30, "0", font12, Align.Left)); 276 this.wndCreateAccount.add(new Label("rangedWeaponVal", 620, 310, 70, 30, "0", font12, Align.Left)); 277 this.wndCreateAccount.add(new Label("evocationVal", 620, 370, 70, 30, "0", font12, Align.Left)); 278 this.wndCreateAccount.add(new Label("skillVal", 575, 430, 70, 30, "0", font12, Align.Left)); 279 this.wndCreateAccount.add(new Button("lightWeapon-", 565, 198, 20, 20, imgSkillSub)); 280 this.wndCreateAccount.add(new Button("lightWeapon+", 675, 198, 20, 20, imgSkillAdd)); 281 this.wndCreateAccount.add(new Button("heavyWeapon-", 565, 258, 20, 20, imgSkillSub)); 282 this.wndCreateAccount.add(new Button("heavyWeapon+", 675, 258, 20, 20, imgSkillAdd)); 283 this.wndCreateAccount.add(new Button("rangedWeapon-", 565, 318, 20, 20, imgSkillSub)); 284 this.wndCreateAccount.add(new Button("rangedWeapon+", 675, 318, 20, 20, imgSkillAdd)); 285 this.wndCreateAccount.add(new Button("evocation-", 565, 378, 20, 20, imgSkillSub)); 286 this.wndCreateAccount.add(new Button("evocation+", 675, 378, 20, 20, imgSkillAdd)); 287 this.wndCreateAccount.add(new Button("create", 245, 520, 140, 30, "Create", font12)); 288 this.wndCreateAccount.add(new Button("cancel", 415, 520, 140, 30, "Cancel", font12)); 289 this.wndCredits = new Window("main", 0, 0, 800, 600, true); 290 this.wndCredits.add(new Label("title", 250, 15, 300, 20, "Credits", font24)); 291 this.wndCredits.add(new Label("1", 250, 160, 300, 20, "Dmitry Portnoy", font14)); 292 this.wndCredits.add(new Label("2", 250, 180, 300, 20, "Team Leader", font12)); 293 this.wndCredits.add(new Label("3", 250, 195, 300, 20, "Programmer", font12)); 294 this.wndCredits.add(new Label("4", 250, 235, 300, 20, "Daniel Vu", font14)); 295 this.wndCredits.add(new Label("5", 250, 255, 300, 20, "Graphic Artist", font12)); 296 this.wndCredits.add(new Label("6", 250, 295, 300, 20, "Jason Cooper", font14)); 297 this.wndCredits.add(new Label("7", 250, 315, 300, 20, "Designer", font12)); 298 this.wndCredits.add(new Label("8", 250, 355, 300, 20, "Special thanks to", font14)); 299 this.wndCredits.add(new Label("9", 250, 375, 300, 20, "The Game Creation Society", font12)); 300 this.wndTutorials = new Window[13]; 301 String[] text = new String[13]; 302 this.wndTutOptions = new Window("tut", 300, 0, 499, 140, false); 303 this.wndTutOptions.add(new Button("previous", 260, 110, 60, 20, "Previous", font12, Align.Center)); 304 this.wndTutOptions.add(new Button("next", 340, 110, 60, 20, "Next", font12, Align.Center)); 305 this.wndTutOptions.add(new Button("skip", 420, 110, 60, 20, "Skip", font12, Align.Center)); 306 this.wndTutOptions.add(new Label("num", 200, 110, 60, 20, "1 / 13", font12, Align.Center)); 307 text[0] = "When you die, you will be resurrected with no penalty at the closest purple pedestal you have activated. To activate a pedestal, you must walk over it. If you have not activated any purple pedestals, you will resurrect where you started the game. It is important to activate any purple pedestals you see to save you time when you die. You can also use purple pedestals to replenish all of your HP and MP by stepping on them."; 308 text[1] = "When you kill enemies, they sometimes drop items. Left-click on an item to pick it up and place it in your inventory. Be careful when picking up items while there are many enemies around because they might kill you."; 309 text[2] = "You can open your inventory from the bar at the bottom of the screen. You can mouse over any item in your inventory and see a description and relevant stats. Left-clicking any weapon in your inventory will equip it and unequip your previously equiped weapon. Left-clicking a gem will activate it provided you have enough evocation skill to do so. "; 310 text[3] = "You can equip both melee and ranged weapons. If you have a ranged weapon, like this bow, you can fire at enemies from a safe distance. Ranged weapons never run out of ammunition. However, they cannot shoot through most obstacles."; 311 text[4] = "Melee weapons are divided into light and heavy weapons. Heavy weapons are slower, but deal much more damage when they hit. Anyone can equip light weapons, but only players with at least 12 Strenth can use heavy weapons. The damage bonus from Strength is also greater for heavy weapons. The heavy weapon skill also adds more damage per hit than the light weapon skill."; 312 text[5] = "You can open the Character window from the bottom bar. The character window shows the levels of all your skills and attributes. When you level up, you get two extra skill points and you can spend them here. Choose your skills carefully since you can't repick your skills later. You also get HP equal to your constitution and MP equal to your wisdom when you level up."; 313 text[6] = "Assuming you have at least one gem activated and enough mana, you can cast spells by right-clicking anywhere on the map. The total mana cost of your spell is half of the value of all the gems used to cast it.Any enemies that your spell collides with will be affected. However, you use MP every time you cast a spell, so you have to be careful not run out of MP in a battle. There are many gems with different effects and you should carefully choose which gems you want to use for your spell."; 314 text[7] = "The Gems window is accessible from the bottom bar. Activated gems will appear in this window and will contribute their effects to any spells you cast. Each gem has a set amount of energy that is displayed if you mouse over it. Your evocation skill limits the amount of gems you can activate at once, so you should raise it to increase the power of your spells. You can left-click on any gem in the Gems window to place it back in your inventory if you want to activate a different gem."; 315 text[8] = "The images under the Blob indicate that it is afflicted with some status effects. Status effects caused by spells usually last a few seconds, but it varies depending on the gem."; 316 text[9] = "You can activate mutliple gems of the same type to get increased effects. Gems that have one-time effects, like dealing damage, will simply do more of that. Gems that cause the target to gain a temporary status effect will make that effect last longer if multiple gems are used."; 317 text[10] = "These red portals will open your way out of this world. However, they have been protected by the magic of powerful artifacts. These artifacts are scattered throughout the land and you will need at least four to break the enchantment and activate these portals."; 318 text[11] = "Yellow pedestals are portals to the aforementioned artifacts. Be warned that these artifacts are well-guarded and capturing them could prove deadly. To view this tutorial again, click on Game Information from the main menu. Good luck!"; 319 text[12] = "You can access the world map from the bottom bar. However, it does not show the locations of respawn or teleportation points. The Rectangular areas on top of the screen are the locations of the relics, but you must use teleportation points to get to them."; 320 FontMetrics metrics = this.g.getFontMetrics(font12); 321 try { 322 for (int x = 0; x < this.wndTutorials.length; x++) { 323 this.wndTutorials[x] = new Window("tut" + x, 0, 0, 800, 600, true); 324 this.wndTutorials[x].add(new Button("screen", 0, 0, 800, 600, ImageIO.read(getClass().getResource("../images/Tutorial/ss" + (x + 1) + ".png")))); 325 this.wndTutorials[x].add(this.wndTutOptions); 326 MultiTextbox multiTextbox = new MultiTextbox("text", 305, 5, 490, 100, "", false, font12, metrics); 327 multiTextbox.setBorder(false); 328 multiTextbox.setText(text[x]); 329 this.wndTutorials[x].add(multiTextbox); 330 } 331 this.wndTutCur = 0; 332 this.wndGameIntro = new Window("intro", 0, 0, 800, 600, true); 333 this.wndGameIntro.add(new Label("intro", 250, 15, 300, 20, "Introduction", font24)); 334 MultiTextbox txt = new MultiTextbox("text", 50, 150, 650, 350, "", false, font12, metrics); 335 txt.setBorder(false); 336 txt.setText("You suddenly wake up in a strange place you do not recognize. You must find some weapons and some way to get out.\n\nKill creatures to get gems to power your spells and weapons to defend yourself with.\n\nTo get out of this world, you must unlock a portal that is protected by powerful artifacts. Each artifact can be accessed by a yellow portal somewhere in the world. You must collect at least four artifacts to unlock the portal."); 337 this.wndGameIntro.add(txt); 338 this.wndVictory = new Window("victory", 0, 0, 800, 600, true); 339 this.wndVictory.add(new Label("victory", 250, 15, 300, 20, "Victory", font24)); 340 MultiTextbox txtV = new MultiTextbox("text", 50, 150, 650, 350, "", false, font12, metrics); 341 txtV.setBorder(false); 342 txtV.setText("As you strike the final blow, the specter's body evaporates, leaving behind a pile of torn clothing. In the last seconds of its existance, you manage to peer under its hood and catch a glimpse of your own face. Was that simply proof of your failing psyche or does some darker secret lie behind that horrible monster? When you once again become aware of your surroundings, you find yourself alone in a forest clearing. There is no sign of hostile monsters and the only indications of your ordeal are your incredible fatigue and a pile of rags a few feet away from you. Was the world you were trapped in merely an illusion or is there some other explanation? You cannot be sure, but you hope to never have to remember that place again."); 343 this.wndVictory.add(txtV); 344 } catch (IOException ioe) { 345 ioe.printStackTrace(); 346 } 347 this.wndMessage = new Window("message", 290, 135, 220, 160); 348 this.wndMessage.add(new Label("label", 20, 15, 180, 12, "none", font12)); 349 this.wndMessage.add(new Button("button", 70, 115, 80, 30, "OK", font12)); 350 } 351 352 private void loadMapElements() { 353 landMap = new HashMap<LandType, Land>(); 354 structMap = new HashMap<StructureType, Structure>(); 355 respawnPoints = new LinkedList<RespawnPoint>(); 356 BufferedImage nullImg = null; 357 landMap.put(LandType.Lava, new Land(LandType.Lava, "Terrain/orange.png", true)); 358 landMap.put(LandType.Metal, new Land(LandType.Metal, "Terrain/darkRed.png", true)); 359 landMap.put(LandType.Charred, new Land(LandType.Charred, "Terrain/red.png", true)); 360 landMap.put(LandType.Swamp, new Land(LandType.Swamp, "Terrain/lightBrown.png", true)); 361 landMap.put(LandType.Vines, new Land(LandType.Vines, "Terrain/darkBrown.png", true)); 362 landMap.put(LandType.Crystal, new Land(LandType.Crystal, "Terrain/purple.png", true)); 363 landMap.put(LandType.CrystalFormation, new Land(LandType.CrystalFormation, "Terrain/darkPurple.png", false)); 364 landMap.put(LandType.Water, new Land(LandType.Water, "Terrain/blue.png", true)); 365 landMap.put(LandType.Forest, new Land(LandType.Forest, "Terrain/darkGreen.png", true)); 366 landMap.put(LandType.Tree, new Land(LandType.Tree, "Terrain/brown.png", false)); 367 landMap.put(LandType.Plains, new Land(LandType.Plains, "Terrain/lightGreen.png", true)); 368 landMap.put(LandType.Desert, new Land(LandType.Desert, "Terrain/yellow.png", true)); 369 landMap.put(LandType.Mountains, new Land(LandType.Mountains, "Terrain/mountain.png", false)); 370 landMap.put(LandType.Cave, new Land(LandType.Cave, "Terrain/mountain.png", false)); 371 landMap.put(LandType.Ocean, new Land(LandType.Ocean, "Terrain/darkBlue.png", false)); 372 landMap.put(LandType.Snow, new Land(LandType.Snow, "Terrain/lightBlue.png", true)); 373 landMap.put(LandType.Steam, new Land(LandType.Steam, "Terrain/lightGray.png", true)); 374 structMap.put(StructureType.None, new Structure(StructureType.None, nullImg, true)); 375 structMap.put(StructureType.LoginPedestal, new Structure(StructureType.LoginPedestal, "YellowPedestal.png", true)); 376 structMap.put(StructureType.RejuvenationPedestal, new Structure(StructureType.RejuvenationPedestal, "PurplePedestal.png", true)); 377 structMap.put(StructureType.LifePedestal, new Structure(StructureType.LifePedestal, "RedPedestal.png", true)); 378 structMap.put(StructureType.ManaPedestal, new Structure(StructureType.ManaPedestal, "BluePedestal.png", true)); 379 structMap.put(StructureType.RespawnPoint, new RespawnPoint(StructureType.RespawnPoint, "PurplePedestal.png", true)); 380 structMap.put(StructureType.ArtifactPoint, new ArtifactPoint(StructureType.ArtifactPoint, "YellowPedestal.png", true)); 381 structMap.put(StructureType.BossPoint, new ArtifactPoint(StructureType.BossPoint, "RedPedestal.png", true)); 382 } 383 384 private void loadCreatures() { 385 creatureMap = new HashMap<CreatureType, Creature>(); 386 try { 387 BufferedReader in = new BufferedReader(new FileReader("creatures.txt")); 388 while (in.ready()) { 389 Creature cr = Creature.loadTemplate(in); 390 String strItem; 391 while (!(strItem = in.readLine()).equals("---")) 392 cr.addDrop(new ItemDrop(items.get(strItem.substring(0, strItem.indexOf(","))), Integer.valueOf(strItem.substring(strItem.indexOf(",") + 2)).intValue())); 393 creatureMap.put(cr.getType(), cr); 394 } 395 in.close(); 396 } catch (IOException ioe) { 397 ioe.printStackTrace(); 398 } 399 ((Player)creatureMap.get(CreatureType.Player)).initGems(this.gems); 400 meleeModel = ((Player)creatureMap.get(CreatureType.Player)).loadModel("Player"); 401 rangedModel = ((Player)creatureMap.get(CreatureType.Player)).loadModel("Player/ranged"); 402 } 403 404 private void loadSpawnPoints() { 405 spawnPoints = new LinkedList<SpawnPoint>(); 406 try { 407 BufferedReader in = new BufferedReader(new FileReader("spawnPoints.txt")); 408 while (in.ready()) { 409 Creature type = creatureMap.get(CreatureType.valueOf(in.readLine())); 410 String strLoc = in.readLine(); 411 int x = Integer.parseInt(strLoc.substring(0, strLoc.indexOf(","))); 412 strLoc = strLoc.substring(strLoc.indexOf(",") + 1); 413 int y = Integer.parseInt(strLoc.substring(0, strLoc.indexOf(","))); 414 strLoc = strLoc.substring(strLoc.indexOf(",") + 1); 415 int xMin = Integer.parseInt(strLoc.substring(0, strLoc.indexOf(","))); 416 int yMin = Integer.parseInt(strLoc.substring(strLoc.indexOf(",") + 1)); 417 Point loc = new Point(x * 100 + xMin, y * 100 + yMin); 418 SpawnPoint sp = new SpawnPoint(type, loc, Integer.parseInt(in.readLine()), Integer.parseInt(in.readLine())); 419 spawnPoints.add(sp); 420 } 421 in.close(); 422 } catch (IOException ioe) { 423 ioe.printStackTrace(); 424 } 425 } 426 427 private void loadItems() { 428 items = new HashMap<String, Item>(); 429 this.drops = new LinkedList<Item>(); 430 this.projectiles = new LinkedList<Projectile>(); 431 this.gems = new LinkedList<Gem>(); 432 try { 433 imgBow = new BufferedImage[8]; 434 imgBow[0] = ImageIO.read(getClass().getResource("../images/projectiles/bowNN.png")); 435 imgBow[1] = ImageIO.read(getClass().getResource("../images/projectiles/bowNE.png")); 436 imgBow[2] = ImageIO.read(getClass().getResource("../images/projectiles/bowEE.png")); 437 imgBow[3] = ImageIO.read(getClass().getResource("../images/projectiles/bowSE.png")); 438 imgBow[4] = ImageIO.read(getClass().getResource("../images/projectiles/bowSS.png")); 439 imgBow[5] = ImageIO.read(getClass().getResource("../images/projectiles/bowSW.png")); 440 imgBow[6] = ImageIO.read(getClass().getResource("../images/projectiles/bowWW.png")); 441 imgBow[7] = ImageIO.read(getClass().getResource("../images/projectiles/bowNW.png")); 442 BufferedReader in = new BufferedReader(new FileReader("items.txt")); 443 while (in.ready()) { 444 Item item; 445 int attackSpeed, range, damage, value; 446 String name = in.readLine(); 447 String img = String.valueOf(in.readLine()) + ".png"; 448 ItemType type = ItemType.valueOf(in.readLine()); 449 String desc = in.readLine(); 450 BufferedImage[] imgProj = new BufferedImage[8]; 451 switch (type) { 452 case LightWeapon: 453 case HeavyWeapon: 454 attackSpeed = Integer.valueOf(in.readLine()).intValue(); 455 damage = Integer.valueOf(in.readLine()).intValue(); 456 item = new Weapon(name, type, img, null, attackSpeed, 55, damage); 457 break; 458 case RangedWeapon: 459 attackSpeed = Integer.valueOf(in.readLine()).intValue(); 460 range = Integer.valueOf(in.readLine()).intValue(); 461 damage = Integer.valueOf(in.readLine()).intValue(); 462 imgProj = imgBow; 463 item = new Weapon(name, type, img, imgProj, attackSpeed, range, damage); 464 break; 465 case Gem: 466 value = Integer.valueOf(in.readLine()).intValue(); 467 item = new Gem(name, img, value, null); 468 this.gems.add((Gem)item); 469 break; 470 default: 471 item = new Item(name, type, img); 472 break; 473 } 474 item.setDescription(desc); 475 items.put(name, item); 476 } 477 in.close(); 478 } catch (IOException ioe) { 479 ioe.printStackTrace(); 480 } 481 } 482 483 private void loadSpellSprites() { 484 airSprites = loadSprites("air"); 485 earthSprites = loadSprites("earth"); 486 fireSprites = loadSprites("fire"); 487 waterSprites = loadSprites("water"); 488 try { 489 passiveAura = ImageIO.read(getClass().getResource("../images/spells/auras/passiveAura.png")); 490 thornsAura = ImageIO.read(getClass().getResource("../images/spells/auras/thornsAura.png")); 491 confuseAura = ImageIO.read(getClass().getResource("../images/spells/auras/confuseAura.png")); 492 sandAura = ImageIO.read(getClass().getResource("../images/spells/auras/sandAura.png")); 493 } catch (IOException ioe) { 494 ioe.printStackTrace(); 495 } 496 } 497 498 private BufferedImage[] loadSprites(String name) { 499 BufferedImage[] sprites = new BufferedImage[8]; 500 try { 501 sprites[0] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellNN.png")); 502 sprites[1] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellNE.png")); 503 sprites[2] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellEE.png")); 504 sprites[3] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellSE.png")); 505 sprites[4] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellSS.png")); 506 sprites[5] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellSW.png")); 507 sprites[6] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellWW.png")); 508 sprites[7] = ImageIO.read(getClass().getResource("../images/spells/" + name + "/" + name + "SpellNW.png")); 509 } catch (IOException ioe) { 510 ioe.printStackTrace(); 511 } 512 return sprites; 513 } 514 515 public static SpawnPoint getSpawnPoint(int idNum) { 516 if (idNum == -1) 517 return null; 518 Iterator<SpawnPoint> iter = spawnPoints.iterator(); 519 while (iter.hasNext()) { 520 SpawnPoint sp; 521 if ((sp = iter.next()).idNum == idNum) 522 return sp; 523 } 524 return null; 525 } 526 527 private void spawnCreatures() { 528 Iterator<SpawnPoint> iter = spawnPoints.iterator(); 529 while (iter.hasNext()) { 530 SpawnPoint sp = iter.next(); 531 if (Point.dist(this.player.getLoc(), sp.getLoc()) >= 600.0D) { 532 Creature cr = sp.spawn(); 533 if (cr != null) 534 map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100).addCreature(cr); 535 } 536 } 537 } 538 539 private void moveCreatures() { 540 int xLow = this.player.getLoc().getX() / 100 - 8; 541 int xHigh = xLow + 17; 542 int yLow = this.player.getLoc().getY() / 100 - 6; 543 int yHigh = yLow + 13; 544 if (xLow < 0) 545 xLow = 0; 546 if (xHigh > map.getLength()) 547 xHigh = map.getLength(); 548 if (yLow < 0) 549 yLow = 0; 550 if (yHigh > map.getHeight()) 551 yHigh = map.getHeight(); 552 for (int x = 0; x < map.getLength(); x++) { 553 for (int y = 0; y < map.getHeight(); y++) { 554 Iterator<Creature> iter = map.getLoc(x, y).getCreatures().iterator(); 555 while (iter.hasNext()) { 556 Creature cr = iter.next(); 557 if (cr != this.player) 558 if (cr.confused > 0) { 559 cr.setEnemyTarget(findClosestTarget(cr)); 560 } else { 561 cr.setEnemyTarget(this.player); 562 } 563 if (cr.isDying() && cr.getModel().getAnimation(Direction.West, Action.Dying).reachedEnd()) { 564 cr.setDying(false); 565 if (cr == this.player) { 566 respawnPlayer(); 567 continue; 568 } 569 if (cr.getType() == CreatureType.Specter) 570 this.gameState = GameState.Victory; 571 continue; 572 } 573 if (!cr.getModel().hasDeath() && cr.getHitpoints() <= 0) { 574 iter.remove(); 575 continue; 576 } 577 move(cr); 578 if (cr.getLoc().getX() / 100 != x || cr.getLoc().getY() / 100 != y) { 579 iter.remove(); 580 map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100).addCreature(cr); 581 } 582 } 583 } 584 } 585 } 586 587 private void move(Creature cr) { 588 if (cr.isDying()) 589 return; 590 Point newLoc = cr.move(); 591 int minDist = 50; 592 boolean creatureBlocking = false; 593 cr.checkTimedEffects(); 594 Iterator<Item> itemIter = this.drops.iterator(); 595 while (itemIter.hasNext()) { 596 Item item = itemIter.next(); 597 if (item.getLoc().equals(this.player.getLoc())) { 598 this.player.pickUp(item); 599 itemIter.remove(); 600 } 601 } 602 int xLow = newLoc.getX() / 100 - 2; 603 int xHigh = xLow + 5; 604 int yLow = newLoc.getY() / 100 - 2; 605 int yHigh = yLow + 5; 606 if (xLow < 0) 607 xLow = 0; 608 if (xHigh > map.getLength()) 609 xHigh = map.getLength(); 610 if (yLow < 0) 611 yLow = 0; 612 if (yHigh > map.getHeight()) 613 yHigh = map.getHeight(); 614 for (int x = xLow; x < xHigh; x++) { 615 for (int y = yLow; y < yHigh; y++) { 616 Iterator<Creature> iter = map.getLoc(x, y).getCreatures().iterator(); 617 while (iter.hasNext()) { 618 Creature temp = iter.next(); 619 if (cr.getEnemyTarget() == temp && Point.dist(temp.getLoc(), newLoc) <= cr.getWeapon().getRange()) { 620 creatureBlocking = true; 621 if (temp != this.player || !temp.isDying()) { 622 Projectile proj = cr.attack(temp, AttackType.Weapon); 623 if (proj != null) { 624 proj.setCreator(cr); 625 proj.applySpawnEffects(); 626 addProjectile(proj); 627 continue; 628 } 629 if (temp.getHitpoints() <= 0) { 630 temp.setDying(true); 631 if (temp != this.player) { 632 killCreature(temp); 633 this.player.setEnemyTarget(null); 634 this.player.setTarget(this.player.getLoc()); 635 } 636 } 637 } 638 continue; 639 } 640 if (temp != cr && Point.dist(temp.getLoc(), newLoc) < minDist) 641 creatureBlocking = true; 642 } 643 } 644 } 645 if (map.getLoc(newLoc.getX() / 100, newLoc.getY() / 100).isPassable() && !creatureBlocking && (!cr.farFromSpawnPoint() || cr.closerToSpawnPoint(newLoc))) { 646 Location oldLoc = map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100); 647 cr.setLoc(newLoc); 648 if (cr == this.player) 649 switch (map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100).getStruct().getType()) { 650 case RespawnPoint: 651 ((RespawnPoint)map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100).getStruct()).mark(); 652 case RejuvenationPedestal: 653 this.player.setManapoints(this.player.getMaxManapoints()); 654 case LifePedestal: 655 this.player.setHitpoints(this.player.getMaxHitpoints()); 656 break; 657 case ManaPedestal: 658 this.player.setManapoints(this.player.getMaxManapoints()); 659 break; 660 case BossPoint: 661 if (!this.player.readyForBoss()) 662 break; 663 case ArtifactPoint: 664 if (oldLoc != map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100)) { 665 this.player.setLoc(((ArtifactPoint)map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100).getStruct()).getTarget()); 666 this.player.setTarget(this.player.getLoc()); 667 } 668 break; 669 } 670 } else { 671 cr.setTarget(cr.getLoc()); 672 if (cr.getModel().getAction() != Action.Attacking) 673 cr.getModel().setAction(Action.Standing); 674 } 675 } 676 677 private Creature findClosestTarget(Creature cr) { 678 int xLow = cr.getLoc().getX() / 100 - 5; 679 int xHigh = xLow + 11; 680 int yLow = cr.getLoc().getY() / 100 - 5; 681 int yHigh = yLow + 11; 682 Creature closestCr = this.player; 683 double minDist = Point.dist(cr.getLoc(), this.player.getLoc()); 684 if (xLow < 0) 685 xLow = 0; 686 if (xHigh > map.getLength()) 687 xHigh = map.getLength(); 688 if (yLow < 0) 689 yLow = 0; 690 if (yHigh > map.getHeight()) 691 yHigh = map.getHeight(); 692 for (int x = xLow; x < xHigh; x++) { 693 for (int y = yLow; y < yHigh; y++) { 694 Iterator<Creature> iter = map.getLoc(x, y).getCreatures().iterator(); 695 while (iter.hasNext()) { 696 Creature cur = iter.next(); 697 if (cr != cur && minDist > Point.dist(cr.getLoc(), cur.getLoc())) { 698 minDist = Point.dist(cr.getLoc(), cur.getLoc()); 699 closestCr = cur; 700 } 701 } 702 } 703 } 704 return closestCr; 705 } 706 707 private synchronized void addProjectile(Projectile proj) { 708 this.projectiles.add(proj); 709 } 710 711 private synchronized void moveProjectiles() { 712 Iterator<Projectile> iter = this.projectiles.iterator(); 713 while (iter.hasNext()) { 714 Projectile proj = iter.next(); 715 move(proj); 716 if (proj.isDone()) 717 iter.remove(); 718 } 719 } 720 721 private void move(Projectile proj) { 722 Point newLoc = proj.move(); 723 int minDist = 50; 724 for (int x = 0; x < map.getLength(); x++) { 725 for (int y = 0; y < map.getHeight(); y++) { 726 Iterator<Creature> iter = map.getLoc(x, y).getCreatures().iterator(); 727 while (iter.hasNext()) { 728 Creature cr = iter.next(); 729 if (Point.dist(cr.getLoc(), newLoc) < minDist && ((cr == this.player && !proj.isPlayerOwned()) || (cr != this.player && proj.isPlayerOwned()))) { 730 if (!proj.penetrates()) 731 proj.setDone(true); 732 if (!proj.creatureIsEffected(cr)) { 733 proj.applyContactEffects(cr); 734 proj.effectCreature(cr); 735 } 736 if (cr.getHitpoints() <= 0) { 737 cr.setDying(true); 738 if (cr != this.player) { 739 killCreature(cr); 740 this.player.setEnemyTarget(null); 741 this.player.setTarget(this.player.getLoc()); 742 } 743 } 744 } 745 } 746 } 747 } 748 Location curLoc = map.getLoc(newLoc.getX() / 100, newLoc.getY() / 100); 749 if (proj.getTarget().equals(newLoc) || (!curLoc.isPassable() && curLoc.getLand().getType() != LandType.Ocean)) { 750 proj.setDone(true); 751 } else { 752 proj.setLoc(newLoc); 753 } 754 } 755 756 private void killCreature(Creature cr) { 757 Iterator<Item> itemIter = cr.spawnDrops().iterator(); 758 while (itemIter.hasNext()) 759 this.drops.add(((Item)itemIter.next()).copy(cr.getLoc())); 760 if (cr.getSpawnPoint() != null) 761 cr.getSpawnPoint().removeCreature(); 762 this.player.setExperience(this.player.getExperience() + cr.getExperience()); 763 if (this.player.getExperience() >= (Math.pow(this.player.getLevel(), 2.0D) + this.player.getLevel()) * 500.0D) { 764 this.player.setExperience(this.player.getExperience() - (int)((Math.pow(this.player.getLevel(), 2.0D) + this.player.getLevel()) * 500.0D)); 765 this.player.increaseLevel(); 766 } 767 } 768 769 public void respawnPlayer() { 770 Iterator<RespawnPoint> iter = respawnPoints.iterator(); 771 RespawnPoint closest = null; 772 double dist = 0.0D; 773 this.player.setHitpoints(this.player.getMaxHitpoints()); 774 this.player.setManapoints(this.player.getMaxManapoints()); 775 while (iter.hasNext()) { 776 RespawnPoint cur = iter.next(); 777 if (cur.isMarked() && (closest == null || dist > Point.dist(cur.getLoc(), this.player.getLoc()))) { 778 closest = cur; 779 dist = Point.dist(cur.getLoc(), this.player.getLoc()); 780 } 781 } 782 if (closest == null) { 783 this.player.setLoc(this.startPoint); 784 } else { 785 this.player.setLoc(closest.getLoc()); 786 } 787 this.player.setEnemyTarget(null); 788 this.player.setTarget(this.player.getLoc()); 789 } 790 791 private void handleEvents() { 792 switch (this.gameState) { 793 case Game: 794 case GameMenu: 795 case GameStats: 796 case GameGems: 797 case GameInventory: 798 case GameMap: 799 spawnCreatures(); 800 moveCreatures(); 801 moveProjectiles(); 802 break; 803 } 804 } 805 806 private void render(Graphics g) { 807 g.setColor(Color.black); 808 g.fillRect(0, 0, 800, 600); 809 switch (this.gameState) { 810 case Main: 811 drawMain(g); 812 break; 813 case CreateAccount: 814 drawCreateAccount(g); 815 break; 816 case LoadGame: 817 drawLoadGame(g); 818 break; 819 case Info: 820 drawInfo(g); 821 break; 822 case Credits: 823 drawCredits(g); 824 break; 825 case Victory: 826 this.wndVictory.draw(g); 827 break; 828 case GameIntro: 829 this.wndGameIntro.draw(g); 830 break; 831 case GameInfo: 832 this.wndTutorials[this.wndTutCur].draw(g); 833 break; 834 case Game: 835 drawMap(g); 836 drawItems(g); 837 drawCreatures(g); 838 drawProjectiles(g); 839 drawStatDisplay(g); 840 break; 841 case GameMenu: 842 drawMap(g); 843 drawItems(g); 844 drawCreatures(g); 845 drawProjectiles(g); 846 drawStatDisplay(g); 847 drawGameMenu(g); 848 break; 849 case GameStats: 850 drawMap(g); 851 drawItems(g); 852 drawCreatures(g); 853 drawProjectiles(g); 854 drawStatDisplay(g); 855 drawGameStats(g); 856 break; 857 case GameGems: 858 drawMap(g); 859 drawItems(g); 860 drawCreatures(g); 861 drawProjectiles(g); 862 drawStatDisplay(g); 863 drawGameGems(g); 864 break; 865 case GameInventory: 866 drawMap(g); 867 drawItems(g); 868 drawCreatures(g); 869 drawProjectiles(g); 870 drawStatDisplay(g); 871 drawGameInventory(g); 872 break; 873 case GameMap: 874 drawMap(g); 875 drawItems(g); 876 drawCreatures(g); 877 drawProjectiles(g); 878 drawStatDisplay(g); 879 drawGameMap(g); 880 break; 881 } 882 switch (this.auxState) { 883 case MsgBox: 884 this.wndMessage.draw(g); 885 break; 886 } 887 } 888 889 public void save() { 890 PrintWriter out = null; 891 try { 892 out = new PrintWriter(new FileWriter("save.txt")); 893 for (int x = 0; x < map.getLength(); x++) { 894 for (int y = 0; y < map.getHeight(); y++) { 895 Iterator<Creature> iter = map.getLoc(x, y).getCreatures().iterator(); 896 while (iter.hasNext()) { 897 Creature cr = iter.next(); 898 cr.save(out); 899 } 900 } 901 } 902 out.close(); 903 out = new PrintWriter(new FileWriter("savedItems.txt")); 904 Iterator<Item> itrItem = this.drops.iterator(); 905 while (itrItem.hasNext()) { 906 Item cur = itrItem.next(); 907 out.println(cur.getName()); 908 out.println(String.valueOf(cur.getLoc().getX()) + "," + cur.getLoc().getY()); 909 } 910 out.close(); 911 } catch (IOException ioe) { 912 ioe.printStackTrace(); 913 } 914 } 915 916 public void reset() { 917 this.drops.clear(); 918 this.projectiles.clear(); 919 map.clearCreatures(); 920 lstInventory.clear(); 921 Iterator<SpawnPoint> iter = spawnPoints.iterator(); 922 while (iter.hasNext()) 923 ((SpawnPoint)iter.next()).clear(); 924 SpawnPoint.numSpawnPoints = 0; 925 Iterator<RespawnPoint> rpIter = respawnPoints.iterator(); 926 while (rpIter.hasNext()) 927 ((RespawnPoint)rpIter.next()).unmark(); 928 } 929 930 public void placeQuestObjects() { 931 this.drops.add(((Item)items.get("Power Sword")).copy(new Point(1650, 150))); 932 this.drops.add(((Item)items.get("Ice Scroll")).copy(new Point(3250, 150))); 933 this.drops.add(((Item)items.get("BNW Shirt")).copy(new Point(4950, 250))); 934 this.drops.add(((Item)items.get("Studded Leather Armor")).copy(new Point(6750, 150))); 935 this.drops.add(((Item)items.get("Patched Leather")).copy(new Point(8450, 150))); 936 this.drops.add(((Item)items.get("Fire Scroll")).copy(new Point(1650, 1450))); 937 Creature cr = ((Creature)creatureMap.get(CreatureType.Specter)).copy(); 938 cr.setLoc(new Point(15850, 350)); 939 map.getLoc(158, 3).addCreature(cr); 940 } 941 942 public boolean load() { 943 reset(); 944 try { 945 BufferedReader in = new BufferedReader(new FileReader("save.txt")); 946 while (in.ready()) { 947 CreatureType type = CreatureType.valueOf(in.readLine()); 948 Creature cr = ((Creature)creatureMap.get(type)).copy(); 949 cr.load(in); 950 if (cr.getType() == CreatureType.Player) 951 this.player = (Player)cr; 952 map.getLoc(cr.getLoc().getX() / 100, cr.getLoc().getY() / 100).addCreature(cr); 953 } 954 Iterator<Creature> iter = map.getLoc(this.player.getTarget().getX() / 100, this.player.getTarget().getY() / 100).getCreatures().iterator(); 955 while (iter.hasNext()) { 956 Creature cr2 = iter.next(); 957 if (cr2.getLoc().equals(this.player.getTarget()) && cr2 != this.player) 958 this.player.setEnemyTarget(cr2); 959 } 960 in.close(); 961 in = new BufferedReader(new FileReader("savedItems.txt")); 962 while (in.ready()) { 963 Item cur = items.get(in.readLine()); 964 String loc = in.readLine(); 965 int x = Integer.parseInt(loc.substring(0, loc.indexOf(","))); 966 int y = Integer.parseInt(loc.substring(loc.indexOf(",") + 1)); 967 this.drops.add(cur.copy(new Point(x, y))); 968 } 969 in.close(); 970 } catch (FileNotFoundException fnfe) { 971 showMessage("There is no saved game to load"); 972 return false; 973 } catch (IOException ioe) { 974 ioe.printStackTrace(); 975 return false; 976 } 977 return true; 978 } 979 980 public static String dateString() { 981 return (new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")).format(new Date()); 982 } 983 984 public void showMessage(String text) { 985 this.auxState = AuxState.MsgBox; 986 ((Label)this.wndMessage.getMember("label")).setText(text); 987 } 988 989 private void drawMain(Graphics g) { 990 this.wndMain.draw(g); 991 g.setColor(Color.red); 992 g.drawRect(10, 100, 380, 490); 993 g.drawRect(410, 100, 380, 490); 994 } 995 996 private void drawCreateAccount(Graphics g) { 997 ((Label)this.wndCreateAccount.getMember("strVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Strength))); 998 ((Label)this.wndCreateAccount.getMember("dexVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Dexterity))); 999 ((Label)this.wndCreateAccount.getMember("conVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Constitution))); 1000 ((Label)this.wndCreateAccount.getMember("wisVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Wisdom))); 1001 ((Label)this.wndCreateAccount.getMember("attVal")).setText(Integer.toString(this.player.getAttributePoints())); 1002 ((Label)this.wndCreateAccount.getMember("lightWeaponVal")).setText(Integer.toString(this.player.getSkill(Skill.LightWeapons))); 1003 ((Label)this.wndCreateAccount.getMember("heavyWeaponVal")).setText(Integer.toString(this.player.getSkill(Skill.HeavyWeapons))); 1004 ((Label)this.wndCreateAccount.getMember("rangedWeaponVal")).setText(Integer.toString(this.player.getSkill(Skill.RangedWeapons))); 1005 ((Label)this.wndCreateAccount.getMember("evocationVal")).setText(Integer.toString(this.player.getSkill(Skill.Evocation))); 1006 ((Label)this.wndCreateAccount.getMember("skillVal")).setText(Integer.toString(this.player.getSkillPoints())); 1007 this.wndCreateAccount.draw(g); 1008 } 1009 1010 private void drawLoadGame(Graphics g) { 1011 Font tempFont = new Font("Arial", 0, 12); 1012 FontMetrics metrics = g.getFontMetrics(tempFont); 1013 g.setFont(tempFont); 1014 g.setColor(Color.green); 1015 g.drawString("There is not a whole lot here right now. You can click anywhere on the screen to get back to the main menu.", 0, metrics.getHeight()); 1016 } 1017 1018 private void drawInfo(Graphics g) { 1019 if (this.infoStart) { 1020 this.wndGameIntro.draw(g); 1021 } else { 1022 this.wndTutorials[this.wndTutCur].draw(g); 1023 } 1024 } 1025 1026 private void drawCredits(Graphics g) { 1027 this.wndCredits.draw(g); 1028 } 1029 1030 private void drawMap(Graphics g) { 1031 int locX = this.player.getLoc().getX(); 1032 int locY = this.player.getLoc().getY(); 1033 int xLow = locX / 100 - 5; 1034 int xHigh = xLow + 11; 1035 int yLow = locY / 100 - 4; 1036 int yHigh = yLow + 9; 1037 if (xLow < 0) 1038 xLow = 0; 1039 if (xHigh > map.getLength()) 1040 xHigh = map.getLength(); 1041 if (yLow < 0) 1042 yLow = 0; 1043 if (yHigh > map.getHeight()) 1044 yHigh = map.getHeight(); 1045 int x; 1046 for (x = xLow; x < xHigh; x++) { 1047 for (int y = yLow; y < yHigh; y++) { 1048 if (map.getLoc(x, y).getLand().getType() != LandType.Mountains && map.getLoc(x, y).getLand().getType() != LandType.Cave) { 1049 g.drawImage(map.getLoc(x, y).getLand().getImg(), 400 + x * 100 - locX, 300 + y * 100 - locY, null); 1050 g.drawImage(map.getLoc(x, y).getStruct().getImg(), 400 + x * 100 - locX, 300 + y * 100 - locY, null); 1051 } else { 1052 g.drawImage(((Land)landMap.get(LandType.Metal)).getImg(), 400 + x * 100 - locX, 300 + y * 100 - locY, null); 1053 } 1054 } 1055 } 1056 for (x = xLow; x < xHigh; x++) { 1057 for (int y = yLow; y < yHigh; y++) { 1058 if (map.getLoc(x, y).getLand().getType() == LandType.Mountains || map.getLoc(x, y).getLand().getType() == LandType.Cave) 1059 g.drawImage(map.getLoc(x, y).getLand().getImg(), 390 + x * 100 - locX, 290 + y * 100 - locY, null); 1060 } 1061 } 1062 } 1063 1064 private void drawItems(Graphics g) { 1065 Iterator<Item> iter = this.drops.iterator(); 1066 while (iter.hasNext()) 1067 ((Item)iter.next()).draw(g, this.player.getLoc().getX(), this.player.getLoc().getY()); 1068 } 1069 1070 private synchronized void drawProjectiles(Graphics g) { 1071 Iterator<Projectile> iter = this.projectiles.iterator(); 1072 while (iter.hasNext()) 1073 ((Projectile)iter.next()).draw(g, this.player.getLoc().getX(), this.player.getLoc().getY()); 1074 } 1075 1076 private void drawCreatures(Graphics g) { 1077 int xLow = this.player.getLoc().getX() / 100 - 5; 1078 int xHigh = xLow + 11; 1079 int yLow = this.player.getLoc().getY() / 100 - 4; 1080 int yHigh = yLow + 9; 1081 if (xLow < 0) 1082 xLow = 0; 1083 if (xHigh > map.getLength()) 1084 xHigh = map.getLength(); 1085 if (yLow < 0) 1086 yLow = 0; 1087 if (yHigh > map.getHeight()) 1088 yHigh = map.getHeight(); 1089 for (int x = xLow; x < xHigh; x++) { 1090 for (int y = yLow; y < yHigh; y++) { 1091 Iterator<Creature> iter = map.getLoc(x, y).getCreatures().iterator(); 1092 while (iter.hasNext()) 1093 ((Creature)iter.next()).draw(g, this.player.getLoc().getX(), this.player.getLoc().getY()); 1094 } 1095 } 1096 } 1097 1098 private void drawStatDisplay(Graphics g) { 1099 this.lblGemVal.setText("Gem Value: " + this.player.getGemValue()); 1100 this.lblSpellCost.setText("Spell Cost: " + ((this.player.getGemValue() + 1) / 2)); 1101 this.wndStatDisplay.draw(g); 1102 g.drawString(this.player.getName(), 20, 562); 1103 g.drawString("Level " + this.player.getLevel(), 20, 574); 1104 g.drawString("Relics Acquired: " + this.player.getRelicCount() + "/4", 20, 591); 1105 g.setColor(Color.yellow); 1106 g.drawRect(240, 578, 80, 15); 1107 g.fillRect(240, 578, 80 * this.player.getExperience() / (int)((Math.pow(this.player.getLevel(), 2.0D) + this.player.getLevel()) * 500.0D), 15); 1108 g.setColor(Color.green); 1109 g.drawRect(125, 557, 80, 15); 1110 g.fillRect(125, 557, 80 * this.player.getHitpoints() / this.player.getMaxHitpoints(), 15); 1111 g.setColor(Color.blue); 1112 g.drawRect(240, 557, 80, 15); 1113 g.fillRect(240, 557, 80 * this.player.getManapoints() / this.player.getMaxManapoints(), 15); 1114 g.setColor(Color.red); 1115 g.drawString("HP:", 100, 569); 1116 g.drawString("MP:", 215, 569); 1117 g.drawString("Experience:", 170, 591); 1118 g.drawString(String.valueOf(this.player.getExperience()) + "/" + ((int)(Math.pow(this.player.getLevel(), 2.0D) + this.player.getLevel()) * 500), 245, 590); 1119 g.drawString(String.valueOf(this.player.getHitpoints()) + "/" + this.player.getMaxHitpoints(), 130, 569); 1120 g.drawString(String.valueOf(this.player.getManapoints()) + "/" + this.player.getMaxManapoints(), 245, 569); 1121 this.player.getWeapon().drawStatic(g, 450 + this.wndStatDisplay.getX(), this.wndStatDisplay.getY()); 1122 int mouseX = (MouseInfo.getPointerInfo().getLocation()).x; 1123 int mouseY = (MouseInfo.getPointerInfo().getLocation()).y; 1124 if (450 + this.wndStatDisplay.getX() <= mouseX && mouseX < 500 + this.wndStatDisplay.getX() && this.wndStatDisplay.getY() <= mouseY && mouseY < 50 + this.wndStatDisplay.getY()) { 1125 String itemType; 1126 Item i = (this.player.getWeapon()).baseWeapon; 1127 Window popup = new Window("popup", mouseX - 126, mouseY - 100, 126, 100, false); 1128 Font font12 = new Font("Arial", 0, 12); 1129 switch (i.getType()) { 1130 case LightWeapon: 1131 itemType = "Light Weapon"; 1132 break; 1133 case HeavyWeapon: 1134 itemType = "Heavy Weapon"; 1135 break; 1136 case RangedWeapon: 1137 itemType = "Ranged Weapon"; 1138 break; 1139 default: 1140 itemType = i.getType().toString(); 1141 break; 1142 } 1143 popup.add(new Label("info", 8, 5, 110, 15, "Equipped Weapon", font12)); 1144 popup.add(new Label("name", 8, 20, 110, 15, i.getName(), font12)); 1145 popup.add(new Label("type", 8, 50, 110, 15, itemType, font12)); 1146 popup.add(new Label("damage", 8, 65, 110, 15, "Damage: " + ((Weapon)i).getDamage() + "(" + this.player.getWeapon().getDamage() + ")", font12)); 1147 popup.add(new Label("damage", 8, 80, 110, 15, "Cooldown: " + (((Weapon)i).getAttackSpeed() / 10.0D) + "(" + (this.player.getWeapon().getAttackSpeed() / 10.0D) + ")" + " s", font12)); 1148 popup.draw(g); 1149 } 1150 } 1151 1152 private void drawGameMenu(Graphics g) {} 1153 1154 private void drawGameStats(Graphics g) { 1155 ((Label)this.wndGameStats.getMember("strVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Strength))); 1156 ((Label)this.wndGameStats.getMember("dexVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Dexterity))); 1157 ((Label)this.wndGameStats.getMember("conVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Constitution))); 1158 ((Label)this.wndGameStats.getMember("wisVal")).setText(Integer.toString(this.player.getAttribute(Attribute.Wisdom))); 1159 ((Label)this.wndGameStats.getMember("lightWeaponVal")).setText(Integer.toString(this.player.getSkill(Skill.LightWeapons))); 1160 ((Label)this.wndGameStats.getMember("heavyWeaponVal")).setText(Integer.toString(this.player.getSkill(Skill.HeavyWeapons))); 1161 ((Label)this.wndGameStats.getMember("rangedWeaponVal")).setText(Integer.toString(this.player.getSkill(Skill.RangedWeapons))); 1162 ((Label)this.wndGameStats.getMember("evocationVal")).setText(Integer.toString(this.player.getSkill(Skill.Evocation))); 1163 ((Label)this.wndGameStats.getMember("skillVal")).setText(Integer.toString(this.player.getSkillPoints())); 1164 this.wndGameStats.draw(g); 1165 } 1166 1167 private void drawGameGems(Graphics g) { 1168 this.wndGameGems.draw(g); 1169 int mouseX = (MouseInfo.getPointerInfo().getLocation()).x; 1170 int mouseY = (MouseInfo.getPointerInfo().getLocation()).y; 1171 Window w = this.wndGameGems; 1172 if (w.getX() < mouseX && mouseX < w.getX() + w.getWidth() - 20 && w.getY() < mouseY && mouseY < w.getY() + w.getHeight()) 1173 this.player.drawInventory(g, lstGems, this.wndGameGems.getX() + 1, this.wndGameGems.getY() + 1); 1174 } 1175 1176 private void drawGameInventory(Graphics g) { 1177 this.wndGameInventory.draw(g); 1178 int mouseX = (MouseInfo.getPointerInfo().getLocation()).x; 1179 int mouseY = (MouseInfo.getPointerInfo().getLocation()).y; 1180 Window w = this.wndGameInventory; 1181 if (w.getX() < mouseX && mouseX < w.getX() + w.getWidth() - 20 && w.getY() < mouseY && mouseY < w.getY() + w.getHeight()) 1182 this.player.drawInventory(g, lstInventory, this.wndGameInventory.getX() + 1, this.wndGameInventory.getY() + 1); 1183 } 1184 1185 private void drawGameMap(Graphics g) { 1186 this.wndGameMap.draw(g); 1187 g.drawImage(this.imgMap, this.wndGameMap.getX() + 10, this.wndGameMap.getY() + 10, null); 1188 } 1189 1190 private void selectText(Textbox text) { 1191 if (this.selectedText != null) 1192 this.selectedText.setSelected(false); 1193 this.selectedText = text; 1194 if (text != null) 1195 text.setSelected(true); 1196 } 1197 1198 private static DisplayMode getBestDisplayMode(GraphicsDevice device) { 1199 for (int x = 0; x < BEST_DISPLAY_MODES.length; x++) { 1200 DisplayMode[] modes = device.getDisplayModes(); 1201 for (int i = 0; i < modes.length; i++) { 1202 if (modes[i].getWidth() == BEST_DISPLAY_MODES[x].getWidth() && modes[i].getHeight() == BEST_DISPLAY_MODES[x].getHeight() && modes[i].getBitDepth() == BEST_DISPLAY_MODES[x].getBitDepth()) 1203 return BEST_DISPLAY_MODES[x]; 1204 } 1205 } 1206 return null; 1207 } 1208 1209 public static void chooseBestDisplayMode(GraphicsDevice device) { 1210 DisplayMode best = getBestDisplayMode(device); 1211 if (best != null) 1212 device.setDisplayMode(best); 1213 } 1214 1215 public void mousePressed(MouseEvent e) { 1216 boolean targetSet; 1217 if (!this.started) 1218 return; 1219 switch (this.auxState) { 1220 case None: 1221 switch (this.gameState) { 1222 case Main: 1223 if (this.wndMain.getMember("new game").isClicked(e.getX(), e.getY())) { 1224 this.player = (Player)((Creature)creatureMap.get(CreatureType.Player)).copy(); 1225 this.gameState = GameState.CreateAccount; 1226 break; 1227 } 1228 if (this.wndMain.getMember("load game").isClicked(e.getX(), e.getY())) { 1229 if (load()) { 1230 this.player.setTimeLoggedOn(System.currentTimeMillis()); 1231 this.gameState = GameState.Game; 1232 } 1233 break; 1234 } 1235 if (this.wndMain.getMember("game info").isClicked(e.getX(), e.getY())) { 1236 this.infoStart = true; 1237 this.gameState = GameState.Info; 1238 break; 1239 } 1240 if (this.wndMain.getMember("credits").isClicked(e.getX(), e.getY())) { 1241 this.gameState = GameState.Credits; 1242 break; 1243 } 1244 if (this.wndMain.getMember("quit").isClicked(e.getX(), e.getY())) 1245 this.done = true; 1246 break; 1247 case CreateAccount: 1248 if (this.wndCreateAccount.getMember("user").isClicked(e.getX(), e.getY())) { 1249 selectText((Textbox)this.wndCreateAccount.getMember("user")); 1250 break; 1251 } 1252 if (this.wndCreateAccount.getMember("create").isClicked(e.getX(), e.getY())) { 1253 String user = ((Textbox)this.wndCreateAccount.getMember("user")).getText(); 1254 if (user.equals("")) { 1255 showMessage("The username is empty"); 1256 break; 1257 } 1258 if (this.player.getAttributePoints() > 0) { 1259 showMessage("You still have attribute points remaining"); 1260 break; 1261 } 1262 if (this.player.getSkillPoints() > 0) { 1263 showMessage("You still have skill points remaining"); 1264 break; 1265 } 1266 this.wndCreateAccount.clear(); 1267 reset(); 1268 placeQuestObjects(); 1269 this.player.setName(user); 1270 this.player.setLoc(this.startPoint); 1271 this.player.setTarget(this.player.getLoc()); 1272 this.player.setWeapon((Weapon)items.get("Branch")); 1273 this.player.pickUp((this.player.getWeapon()).baseWeapon); 1274 map.getLoc(this.startPoint.getX() / 100, this.startPoint.getY() / 100).addCreature(this.player); 1275 this.gameState = GameState.GameIntro; 1276 break; 1277 } 1278 if (this.wndCreateAccount.getMember("cancel").isClicked(e.getX(), e.getY())) { 1279 selectText(null); 1280 this.wndCreateAccount.clear(); 1281 this.gameState = GameState.Main; 1282 break; 1283 } 1284 if (this.wndCreateAccount.getMember("strength-").isClicked(e.getX(), e.getY())) { 1285 this.player.repickAttribute(Attribute.Strength); 1286 break; 1287 } 1288 if (this.wndCreateAccount.getMember("strength+").isClicked(e.getX(), e.getY())) { 1289 this.player.allocateAttribute(Attribute.Strength); 1290 break; 1291 } 1292 if (this.wndCreateAccount.getMember("dexterity-").isClicked(e.getX(), e.getY())) { 1293 this.player.repickAttribute(Attribute.Dexterity); 1294 break; 1295 } 1296 if (this.wndCreateAccount.getMember("dexterity+").isClicked(e.getX(), e.getY())) { 1297 this.player.allocateAttribute(Attribute.Dexterity); 1298 break; 1299 } 1300 if (this.wndCreateAccount.getMember("constitution-").isClicked(e.getX(), e.getY())) { 1301 this.player.repickAttribute(Attribute.Constitution); 1302 break; 1303 } 1304 if (this.wndCreateAccount.getMember("constitution+").isClicked(e.getX(), e.getY())) { 1305 this.player.allocateAttribute(Attribute.Constitution); 1306 break; 1307 } 1308 if (this.wndCreateAccount.getMember("wisdom-").isClicked(e.getX(), e.getY())) { 1309 this.player.repickAttribute(Attribute.Wisdom); 1310 break; 1311 } 1312 if (this.wndCreateAccount.getMember("wisdom+").isClicked(e.getX(), e.getY())) { 1313 this.player.allocateAttribute(Attribute.Wisdom); 1314 break; 1315 } 1316 if (this.wndCreateAccount.getMember("lightWeapon-").isClicked(e.getX(), e.getY())) { 1317 this.player.repickSkill(Skill.LightWeapons); 1318 break; 1319 } 1320 if (this.wndCreateAccount.getMember("lightWeapon+").isClicked(e.getX(), e.getY())) { 1321 this.player.allocateSkill(Skill.LightWeapons); 1322 break; 1323 } 1324 if (this.wndCreateAccount.getMember("heavyWeapon-").isClicked(e.getX(), e.getY())) { 1325 this.player.repickSkill(Skill.HeavyWeapons); 1326 break; 1327 } 1328 if (this.wndCreateAccount.getMember("heavyWeapon+").isClicked(e.getX(), e.getY())) { 1329 this.player.allocateSkill(Skill.HeavyWeapons); 1330 break; 1331 } 1332 if (this.wndCreateAccount.getMember("rangedWeapon-").isClicked(e.getX(), e.getY())) { 1333 this.player.repickSkill(Skill.RangedWeapons); 1334 break; 1335 } 1336 if (this.wndCreateAccount.getMember("rangedWeapon+").isClicked(e.getX(), e.getY())) { 1337 this.player.allocateSkill(Skill.RangedWeapons); 1338 break; 1339 } 1340 if (this.wndCreateAccount.getMember("evocation-").isClicked(e.getX(), e.getY())) { 1341 this.player.repickSkill(Skill.Evocation); 1342 break; 1343 } 1344 if (this.wndCreateAccount.getMember("evocation+").isClicked(e.getX(), e.getY())) { 1345 this.player.allocateSkill(Skill.Evocation); 1346 break; 1347 } 1348 this.wndCreateAccount.handleEvent(e); 1349 break; 1350 case Info: 1351 if (this.infoStart) { 1352 this.infoStart = false; 1353 break; 1354 } 1355 if (this.wndTutOptions.getMember("previous").isClicked(e.getX(), e.getY())) { 1356 if (this.wndTutCur != 0) 1357 this.wndTutCur--; 1358 } else if (this.wndTutOptions.getMember("next").isClicked(e.getX(), e.getY())) { 1359 this.wndTutCur++; 1360 if (this.wndTutCur > 12) { 1361 this.gameState = GameState.Main; 1362 this.wndTutCur = 0; 1363 } 1364 } else if (this.wndTutOptions.getMember("skip").isClicked(e.getX(), e.getY())) { 1365 this.gameState = GameState.Main; 1366 this.wndTutCur = 0; 1367 } 1368 ((Label)this.wndTutOptions.getMember("num")).setText(String.valueOf(this.wndTutCur + 1) + " / 13"); 1369 break; 1370 case Credits: 1371 this.gameState = GameState.Main; 1372 break; 1373 case Victory: 1374 this.gameState = GameState.Credits; 1375 break; 1376 case GameIntro: 1377 this.gameState = GameState.GameInfo; 1378 break; 1379 case GameInfo: 1380 if (this.wndTutOptions.getMember("previous").isClicked(e.getX(), e.getY())) { 1381 if (this.wndTutCur != 0) 1382 this.wndTutCur--; 1383 } else if (this.wndTutOptions.getMember("next").isClicked(e.getX(), e.getY())) { 1384 this.wndTutCur++; 1385 if (this.wndTutCur > 12) { 1386 this.gameState = GameState.Game; 1387 this.player.setTimeLoggedOn(System.currentTimeMillis()); 1388 this.wndTutCur = 0; 1389 } 1390 } else if (this.wndTutOptions.getMember("skip").isClicked(e.getX(), e.getY())) { 1391 this.gameState = GameState.Game; 1392 this.player.setTimeLoggedOn(System.currentTimeMillis()); 1393 this.wndTutCur = 0; 1394 } 1395 ((Label)this.wndTutOptions.getMember("num")).setText(String.valueOf(this.wndTutCur + 1) + " / 13"); 1396 break; 1397 case Game: 1398 targetSet = false; 1399 if (e.getY() < 550) { 1400 if (this.player.isDying()) 1401 return; 1402 int newX = this.player.getLoc().getX() + e.getX() - 400; 1403 int newY = this.player.getLoc().getY() + e.getY() - 300; 1404 if (e.getButton() == 1) { 1405 Iterator<Item> itemIter = this.drops.iterator(); 1406 while (itemIter.hasNext()) { 1407 Item item = itemIter.next(); 1408 if (item.getLoc().getX() - 25 <= newX && newX <= item.getLoc().getX() + 25 && 1409 item.getLoc().getY() - 25 <= newY && newY <= item.getLoc().getY() + 25) { 1410 this.player.setTarget(item.getLoc()); 1411 targetSet = true; 1412 } 1413 } 1414 for (int x = 0; x < map.getLength(); x++) { 1415 for (int y = 0; y < map.getHeight(); y++) { 1416 Iterator<Creature> crIter = map.getLoc(x, y).getCreatures().iterator(); 1417 while (crIter.hasNext()) { 1418 Creature cr = crIter.next(); 1419 if (cr.getLoc().getX() - cr.getModel().getWidth() / 2 <= newX && newX <= cr.getLoc().getX() + cr.getModel().getWidth() / 2 && cr != this.player && 1420 cr.getLoc().getY() - cr.getModel().getHeight() <= newY && newY <= cr.getLoc().getY()) { 1421 this.player.setEnemyTarget(cr); 1422 targetSet = true; 1423 } 1424 } 1425 } 1426 } 1427 if (map.getLoc((int)Math.floor((newX / 100)), (int)Math.floor((newY / 100))).isPassable() && !targetSet) { 1428 this.player.setTarget(new Point(newX, newY)); 1429 this.player.setEnemyTarget(null); 1430 } 1431 if (this.player.getEnemyTarget() != null && this.player.getWeapon().getType() == ItemType.RangedWeapon) { 1432 Projectile proj = this.player.attack(this.player.getEnemyTarget(), AttackType.Weapon); 1433 if (proj != null) { 1434 proj.setCreator(this.player); 1435 proj.applySpawnEffects(); 1436 addProjectile(proj); 1437 } 1438 this.player.setTarget(this.player.getLoc()); 1439 this.player.setEnemyTarget(null); 1440 } 1441 break; 1442 } 1443 if (e.getButton() == 3 && 1444 this.player.getSpell() != null && this.player.getManapoints() >= ((ManaDrain)this.player.getSpell().getSpawnEffect(EffectType.ManaDrain)).getMana()) { 1445 Point loc = new Point(this.player.getLoc()); 1446 loc.setY(loc.getY() - 55); 1447 Projectile proj = this.player.attack(new Point(newX, newY), AttackType.Spell); 1448 if (proj != null) { 1449 proj.setCreator(this.player); 1450 proj.applySpawnEffects(); 1451 addProjectile(proj); 1452 } 1453 } 1454 break; 1455 } 1456 if (this.btnMenu.isClicked(e.getX(), e.getY())) { 1457 this.gameState = GameState.Main; 1458 this.player.updateTimePlayed(); 1459 save(); 1460 break; 1461 } 1462 if (this.btnStats.isClicked(e.getX(), e.getY())) { 1463 this.gameState = GameState.GameStats; 1464 break; 1465 } 1466 if (this.btnGems.isClicked(e.getX(), e.getY())) { 1467 this.gameState = GameState.GameGems; 1468 break; 1469 } 1470 if (this.btnInventory.isClicked(e.getX(), e.getY())) { 1471 this.gameState = GameState.GameInventory; 1472 break; 1473 } 1474 if (this.btnMap.isClicked(e.getX(), e.getY())) 1475 this.gameState = GameState.GameMap; 1476 break; 1477 case GameStats: 1478 if (this.wndGameStats.getMember("lightWeapon+").isClicked(e.getX(), e.getY())) { 1479 this.player.allocateSkill(Skill.LightWeapons); 1480 break; 1481 } 1482 if (this.wndGameStats.getMember("heavyWeapon+").isClicked(e.getX(), e.getY())) { 1483 this.player.allocateSkill(Skill.HeavyWeapons); 1484 break; 1485 } 1486 if (this.wndGameStats.getMember("rangedWeapon+").isClicked(e.getX(), e.getY())) { 1487 this.player.allocateSkill(Skill.RangedWeapons); 1488 break; 1489 } 1490 if (this.wndGameStats.getMember("evocation+").isClicked(e.getX(), e.getY())) { 1491 this.player.allocateSkill(Skill.Evocation); 1492 break; 1493 } 1494 this.gameState = GameState.Game; 1495 break; 1496 case GameGems: 1497 if (this.wndGameGems.isClicked(e.getX(), e.getY())) { 1498 if (e.getX() < this.wndGameGems.getX() + this.wndGameGems.getWidth() - 20) { 1499 int x = (e.getX() - this.wndGameGems.getX() - 1) / 50; 1500 int y = (e.getY() - this.wndGameGems.getY() - 1 + lstGems.getTextStart()) / 50; 1501 if (x + 4 * y >= 0 && x + 4 * y < lstGems.getList().size()) { 1502 Item i = this.player.getGems().get(x + y * 4); 1503 switch (i.getType()) { 1504 case Gem: 1505 this.player.deactivateGem((Gem)i); 1506 break; 1507 } 1508 } 1509 } 1510 this.wndGameGems.handleEvent(e); 1511 break; 1512 } 1513 this.gameState = GameState.Game; 1514 break; 1515 case GameInventory: 1516 if (this.wndGameInventory.isClicked(e.getX(), e.getY())) { 1517 if (e.getX() < this.wndGameInventory.getX() + this.wndGameInventory.getWidth() - 20) { 1518 int x = (e.getX() - this.wndGameInventory.getX() - 1) / 50; 1519 int y = (e.getY() - this.wndGameInventory.getY() - 1 + lstInventory.getTextStart()) / 50; 1520 if (x + 4 * y >= 0 && x + 4 * y < this.player.getInventory().size()) { 1521 Item i = this.player.getInventory().get(x + y * 4); 1522 switch (i.getType()) { 1523 case HeavyWeapon: 1524 if (this.player.getAttribute(Attribute.Strength) < 12) { 1525 showMessage("You must have at least 12 Strength"); 1526 break; 1527 } 1528 case LightWeapon: 1529 case RangedWeapon: 1530 this.player.setWeapon((Weapon)i); 1531 break; 1532 case Gem: 1533 if (!this.player.activateGem((Gem)i)) 1534 showMessage("You must have a higher Evocation skill"); 1535 break; 1536 } 1537 } 1538 } 1539 this.wndGameInventory.handleEvent(e); 1540 break; 1541 } 1542 this.gameState = GameState.Game; 1543 break; 1544 case GameMap: 1545 this.gameState = GameState.Game; 1546 break; 1547 } 1548 break; 1549 case MsgBox: 1550 if (this.wndMessage.getMember("button").isClicked(e.getX(), e.getY())) 1551 this.auxState = AuxState.None; 1552 break; 1553 } 1554 } 1555 1556 public void mouseReleased(MouseEvent e) { 1557 } 1558 1559 public void mouseEntered(MouseEvent e) { 1560 } 1561 1562 public void mouseExited(MouseEvent e) { 1563 } 1564 1565 public void mouseClicked(MouseEvent e) { 1566 } 1567 1568 public void keyTyped(KeyEvent e) { 1569 } 1570 1571 public void keyPressed(KeyEvent e) { 1572 if (this.selectedText != null) 1573 this.selectedText.handleEvent(e); 1574 if (e.getKeyCode() == 27) 1575 if (this.gameState == GameState.Game) { 1576 this.gameState = GameState.Main; 1577 save(); 1578 } else { 1579 this.done = true; 1580 } 1581 } 1582 1583 public void keyReleased(KeyEvent e) { 1584 } 1585 1586 public static void main(String[] args) { 1587 try { 1588 PrintStream st = new PrintStream(new FileOutputStream("err.txt", true)); 1589 System.setErr(st); 1590 System.setOut(st); 1591 System.out.println("-----[ Session started on " + dateString() + " ]-----"); 1592 GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); 1593 GraphicsDevice device = env.getDefaultScreenDevice(); 1594 new LostHavenRPG(device); 1595 } catch (Exception e) { 1596 e.printStackTrace(); 106 1597 } 107 108 private void initGUIElements() { 109 Font font10 = new Font("Arial", Font.PLAIN, 10); 110 Font font11 = new Font("Arial", Font.PLAIN, 11); 111 Font font12 = new Font("Arial", Font.PLAIN, 12); 112 Font font14 = new Font("Arial", Font.PLAIN, 14); 113 Font font24 = new Font("Arial", Font.PLAIN, 24); 114 115 wndMain = new gamegui.Window("main", 0, 0, 800, 600, true); 116 117 Animation anmTitle = new Animation("title", 144, 0, 512, 95, 1000/12); 118 119 try { 120 anmTitle.addFrame(ImageIO.read(getClass().getResource("images/Frame1.png"))); 121 anmTitle.addFrame(ImageIO.read(getClass().getResource("images/Frame2.png"))); 122 anmTitle.addFrame(ImageIO.read(getClass().getResource("images/Frame3.png"))); 123 anmTitle.addFrame(ImageIO.read(getClass().getResource("images/Frame4.png"))); 124 anmTitle.addFrame(ImageIO.read(getClass().getResource("images/Frame5.png"))); 125 }catch(IOException ioe) { 126 ioe.printStackTrace(); 127 } 128 wndMain.add(anmTitle); 129 130 wndMain.add(new gamegui.Button("new game", 500, 140, 200, 40, "New Game", font12)); 131 wndMain.add(new gamegui.Button("load game", 500, 230, 200, 40, "Load Game", font12)); 132 wndMain.add(new gamegui.Button("game info", 500, 320, 200, 40, "Game Information", font12)); 133 wndMain.add(new gamegui.Button("credits", 500, 410, 200, 40, "Credits", font12)); 134 wndMain.add(new gamegui.Button("quit", 500, 500, 200, 40, "Quit", font12)); 135 136 wndCreateAccount = new gamegui.Window("create account", 0, 0, 800, 600, true); 137 138 rdgGenderSelection = new RadioGroup("gender selection", 400, 315, 190, 30, "Gender:", font12); 139 140 rdgGenderSelection.add(new RadioButton("male", 438, 318, 24, 24, "Male", font11, false)); 141 rdgGenderSelection.add(new RadioButton("female", 528, 318, 24, 24, "Female", font11, false)); 142 143 wndCreateAccount.add(new gamegui.Label("title", 250, 15, 300, 20, "Create an Account", font24, true)); 144 wndCreateAccount.add(new Textbox("user", 400, 150, 190, 30, "Username:", font12, false)); 145 wndCreateAccount.add(rdgGenderSelection); 146 wndCreateAccount.add(new gamegui.Label("show class", 330, 370, 70, 30, "None", font12, false)); 147 wndCreateAccount.add(new gamegui.Button("choose class", 400, 370, 190, 30, "Choose Your Class", font12)); 148 wndCreateAccount.add(new gamegui.Button("create", 245, 520, 140, 30, "Create", font12)); 149 wndCreateAccount.add(new gamegui.Button("cancel", 415, 520, 140, 30, "Cancel", font12)); 150 151 wndChooseClass = new gamegui.Window("choose class", 0, 0, 800, 600, true); 152 153 rdgClassSelection = new RadioGroup("class selection", 0, 0, 0, 0, "", font12); 154 155 rdgClassSelection.add(new RadioButton("fighter", 138, 88, 24, 24, "Fighter", font14, true)); 156 rdgClassSelection.add(new RadioButton("ranger", 138, 158, 24, 24, "Ranger", font14, true)); 157 rdgClassSelection.add(new RadioButton("barbarian", 138, 228, 24, 24, "Barbarian", font14, true)); 158 rdgClassSelection.add(new RadioButton("sorceror", 138, 298, 24, 24, "Sorceror", font14, true)); 159 rdgClassSelection.add(new RadioButton("druid", 138, 368, 24, 24, "Druid", font14, true)); 160 rdgClassSelection.add(new RadioButton("wizard", 138, 438, 24, 24, "Wizard", font14, true)); 161 162 wndChooseClass.add(new gamegui.Label("title", 250, 15, 300, 20, "Choose a Character", font24, true)); 163 wndChooseClass.add(rdgClassSelection); 164 wndChooseClass.add(new gamegui.Label("fighter", 170, 114, 170, 0, "A resolute and steadfast champion who has perfected the art of battle and his skill in melee weapons", font10, false)); 165 wndChooseClass.add(new gamegui.Label("ranger", 170, 184, 170, 0, "A skilled combatant who sneaks up on his opponents or shoots them from afar before they know it", font10, false)); 166 wndChooseClass.add(new gamegui.Label("barbarian", 170, 254, 170, 0, "A wild warrior who is unstoppable in battle and uses his own fury to strengthen his attacks", font10, false)); 167 wndChooseClass.add(new gamegui.Label("sorceror", 170, 324, 170, 0, "A chaotic spellcaster who uses his charisma and force of will to power his spells", font10, false)); 168 wndChooseClass.add(new gamegui.Label("druid", 170, 394, 170, 0, "A mystical enchanter who relies on the power of nature and his wisdom to work his magic", font10, false)); 169 wndChooseClass.add(new gamegui.Label("wizard", 170, 464, 170, 0, "A methodical and studious character who studies his opponents to know how to best attack them", font10, false)); 170 wndChooseClass.add(new gamegui.Button("select", 245, 520, 140, 30, "Select", font12)); 171 wndChooseClass.add(new gamegui.Button("cancel", 415, 520, 140, 30, "Cancel", font12)); 172 173 wndMessage = new gamegui.Window("message", 290, 135, 220, 160, false); 174 wndMessage.add(new gamegui.Label("label", 70, 15, 80, 12, "none", font12, true)); 175 wndMessage.add(new gamegui.Button("button", 70, 115, 80, 30, "OK", font12)); 176 } 177 178 private void loadMap() { 179 landMap = new HashMap<LandType, Land>(); 180 structMap = new HashMap<StructureType, Structure>(); 181 BufferedImage nullImg = null; 182 183 try { 184 girl = ImageIO.read(getClass().getResource("images/ArmoredGirl.png")); 185 guy = ImageIO.read(getClass().getResource("images/ArmoredGuy.png")); 186 }catch(IOException ioe) { 187 ioe.printStackTrace(); 188 } 189 190 landMap.put(LandType.Ocean, new Land(LandType.Ocean, "Ocean.png", false)); 191 landMap.put(LandType.Grass, new Land(LandType.Grass, "Grass.png", true)); 192 193 structMap.put(StructureType.None, new Structure(StructureType.None, nullImg, true)); 194 structMap.put(StructureType.BlueOrb, new Structure(StructureType.BlueOrb, "Blue Orb.png", false)); 195 structMap.put(StructureType.Cave, new Structure(StructureType.Cave, "Cave.png", false)); 196 structMap.put(StructureType.Gravestone, new Structure(StructureType.Gravestone, "Gravestone.png", false)); 197 structMap.put(StructureType.GraveyardFence1, new Structure(StructureType.GraveyardFence1, "HorGrave.png", false)); 198 structMap.put(StructureType.GraveyardFence2, new Structure(StructureType.GraveyardFence2, "VerGrave.png", false)); 199 structMap.put(StructureType.PicketFence1, new Structure(StructureType.PicketFence1, "HorPalisade.png", false)); 200 structMap.put(StructureType.PicketFence2, new Structure(StructureType.PicketFence2, "VerPalisade.png", false)); 201 structMap.put(StructureType.Hut, new Structure(StructureType.Hut, "Hut.png", false)); 202 structMap.put(StructureType.WitchHut, new Structure(StructureType.WitchHut, "Witch Hut.png", false)); 203 structMap.put(StructureType.Tent, new Structure(StructureType.Tent, "Tent.png", false)); 204 structMap.put(StructureType.LargeTent, new Structure(StructureType.LargeTent, "LargeTent.png", false)); 205 structMap.put(StructureType.House, new Structure(StructureType.House, "House.png", false)); 206 structMap.put(StructureType.Tree, new Structure(StructureType.Tree, "Trees.png", false)); 207 structMap.put(StructureType.BlueOrb, new Structure(StructureType.BlueOrb, "Blue Orb.png", false)); 208 structMap.put(StructureType.RedOrb, new Structure(StructureType.RedOrb, "Red Orb.png", false)); 209 structMap.put(StructureType.LoginPedestal, new Structure(StructureType.LoginPedestal, "YellowPedestal.png", true)); 210 structMap.put(StructureType.RejuvenationPedestal, new Structure(StructureType.RejuvenationPedestal, "PurplePedestal.png", true)); 211 structMap.put(StructureType.LifePedestal, new Structure(StructureType.LifePedestal, "RedPedestal.png", true)); 212 structMap.put(StructureType.ManaPedestal, new Structure(StructureType.ManaPedestal, "BluePedestal.png", true)); 213 } 214 215 private void move() { 216 double dist = player.getSpeed()*(System.currentTimeMillis()-player.getLastMoved())/1000; 217 Point lastLoc = player.getLoc(); 218 Point target = player.getTarget(); 219 Point newLoc; 220 221 player.setLastMoved(System.currentTimeMillis()); 222 if(Point.dist(lastLoc, player.getTarget()) <= dist) 223 player.setLoc(player.getTarget()); 224 else { 225 int xDif = (int)(Point.xDif(lastLoc, target)*dist/Point.dist(lastLoc, target)); 226 int yDif = (int)(Point.yDif(lastLoc, target)*dist/Point.dist(lastLoc, target)); 227 newLoc = new Point(lastLoc.getX(), lastLoc.getXMin()+xDif, lastLoc.getY(), lastLoc.getYMin()+yDif); 228 newLoc.setX(newLoc.getX()+newLoc.getXMin()/100); 229 newLoc.setXMin(newLoc.getXMin()%100); 230 newLoc.setY(newLoc.getY()+newLoc.getYMin()/100); 231 newLoc.setYMin(newLoc.getYMin()%100); 232 if(newLoc.getXMin()<0) { 233 newLoc.setX(newLoc.getX()-1); 234 newLoc.setXMin(newLoc.getXMin()+100); 235 }else if(newLoc.getYMin()<0) { 236 newLoc.setY(newLoc.getY()-1); 237 newLoc.setYMin(newLoc.getYMin()+100); 238 } 239 if(map.getLoc(newLoc.getX()/100, newLoc.getY()/100).isPassable()) 240 player.setLoc(newLoc); 241 else 242 player.setTarget(player.getLoc()); 243 } 244 } 245 246 private void render(Graphics g) { 247 g.setColor(Color.black); 248 g.fillRect(0, 0, 800, 600); 249 250 switch(gameState) { 251 case Main: 252 drawMain(g); 253 break; 254 case CreateAccount: 255 drawCreateAccount(g); 256 break; 257 case CreateClass: 258 drawCreateClass(g); 259 break; 260 case LoadGame: 261 drawLoadGame(g); 262 break; 263 case Info: 264 drawInfo(g); 265 break; 266 case Credits: 267 drawCredits(g); 268 break; 269 case Game: 270 calculateMapVertices(); 271 drawMap(g); 272 drawItems(g); 273 drawCreatures(g); 274 drawChar(g); 275 drawStatDisplay(g); 276 drawChat(g); 277 break; 278 case GameMenu: 279 calculateMapVertices(); 280 drawMap(g); 281 drawItems(g); 282 drawCreatures(g); 283 drawChar(g); 284 drawStatDisplay(g); 285 drawChat(g); 286 drawGameMenu(g); 287 break; 288 case GameInventory: 289 calculateMapVertices(); 290 drawMap(g); 291 drawItems(g); 292 drawCreatures(g); 293 drawChar(g); 294 drawStatDisplay(g); 295 drawChat(g); 296 drawGameInventory(g); 297 break; 298 case GameStats: 299 calculateMapVertices(); 300 drawMap(g); 301 drawItems(g); 302 drawCreatures(g); 303 drawChar(g); 304 drawStatDisplay(g); 305 drawChat(g); 306 drawGameStats(g); 307 break; 308 } 309 310 switch(auxState) { 311 case None: 312 break; 313 case MsgBox: 314 wndMessage.draw(g); 315 break; 316 } 317 } 318 319 public static String dateString() { 320 return new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new Date()); 321 } 322 323 public void showMessage(String text) { 324 auxState = AuxState.MsgBox; 325 ((gamegui.Label)wndMessage.getMember("label")).setText(text); 326 } 327 328 private void calculateMapVertices() { 329 330 } 331 332 private void drawMain(Graphics g) { 333 wndMain.draw(g); 334 335 g.setColor(Color.red); 336 g.drawRect(10, 100, 380, 490); 337 g.drawRect(410, 100, 380, 490); 338 } 339 340 private void drawCreateAccount(Graphics g) { 341 wndCreateAccount.draw(g); 342 } 343 344 private void drawCreateClass(Graphics g) { 345 wndChooseClass.draw(g); 346 } 347 348 private void drawLoadGame(Graphics g) { 349 Font tempFont = new Font("Arial", Font.PLAIN, 12); 350 FontMetrics metrics = g.getFontMetrics(tempFont); 351 352 g.setFont(tempFont); 353 g.setColor(Color.green); 354 g.drawString("There is not a whole lot here right now. You can click anywhere on the screen to get back to the main menu.", 0, metrics.getHeight()); 355 } 356 357 private void drawInfo(Graphics g) { 358 Font tempFont = new Font("Arial", Font.PLAIN, 12); 359 FontMetrics metrics = g.getFontMetrics(tempFont); 360 361 g.setFont(tempFont); 362 g.setColor(Color.green); 363 g.drawString("There is not a whole lot here right now. You can click anywhere on the screen to get back to the main menu.", 0, metrics.getHeight()); 364 } 365 366 private void drawCredits(Graphics g) { 367 Font tempFont = new Font("Arial", Font.PLAIN, 12); 368 FontMetrics metrics = g.getFontMetrics(tempFont); 369 370 g.setFont(tempFont); 371 g.setColor(Color.green); 372 g.drawString("There is not a whole lot here right now. You can click anywhere on the screen to get back to the main menu.", 0, metrics.getHeight()); 373 } 374 375 private void drawMap(Graphics g) { 376 int locX = player.getLoc().getX(); 377 int locY = player.getLoc().getY(); 378 int xLow = locX/100-4; 379 int xHigh = xLow+9; 380 int yLow = locY/100-3; 381 int yHigh = yLow+7; 382 383 if(xLow<0) 384 xLow = 0; 385 if(xHigh>=map.getLength()) 386 xHigh = map.getLength()-1; 387 if(yLow<0) 388 yLow = 0; 389 if(yHigh>=map.getHeight()) 390 yHigh = map.getHeight()-1; 391 392 for(int x=xLow; x<xHigh; x++) { 393 for(int y=yLow; y<yHigh; y++) { 394 g.drawImage(map.getLoc(x, y).getLand().getImg(), 400+x*100-locX, 300+y*100-locY, null); 395 g.drawImage(map.getLoc(x, y).getStruct().getImg(), 400+x*100-locX, 300+y*100-locY, null); 396 } 397 } 398 } 399 400 private void drawItems(Graphics g) { 401 402 } 403 404 private void drawCreatures(Graphics g) { 405 406 } 407 408 private void drawChar(Graphics g) { 409 switch(player.getGender()) { 410 case Female: 411 g.drawImage(girl, 375, 200, null); 412 break; 413 case Male: 414 g.drawImage(guy, 375, 200, null); 415 break; 416 } 417 } 418 419 private void drawStatDisplay(Graphics g) { 420 421 } 422 423 private void drawChat(Graphics g) { 424 425 } 426 427 private void drawGameMenu(Graphics g) { 428 429 } 430 431 private void drawGameInventory(Graphics g) { 432 433 } 434 435 private void drawGameStats(Graphics g) { 436 437 } 438 439 private void selectText(Textbox text) { 440 if(selectedText != null) 441 selectedText.setSelected(false); 442 selectedText = text; 443 444 if(text != null) 445 text.setSelected(true); 446 } 447 448 private static DisplayMode getBestDisplayMode(GraphicsDevice device) { 449 for (int x = 0; x < BEST_DISPLAY_MODES.length; x++) { 450 DisplayMode[] modes = device.getDisplayModes(); 451 for (int i = 0; i < modes.length; i++) { 452 if (modes[i].getWidth() == BEST_DISPLAY_MODES[x].getWidth() 453 && modes[i].getHeight() == BEST_DISPLAY_MODES[x].getHeight() 454 && modes[i].getBitDepth() == BEST_DISPLAY_MODES[x].getBitDepth()) 455 { 456 return BEST_DISPLAY_MODES[x]; 457 } 458 } 459 } 460 return null; 461 } 462 463 public static void chooseBestDisplayMode(GraphicsDevice device) { 464 DisplayMode best = getBestDisplayMode(device); 465 if (best != null) { 466 device.setDisplayMode(best); 467 } 468 } 469 470 public void mousePressed(MouseEvent e) { 471 switch(auxState) { 472 case None: 473 switch(gameState) { 474 case Main: 475 if(wndMain.getMember("new game").isClicked(e.getX(),e.getY())) 476 gameState = GameState.CreateAccount; 477 else if(wndMain.getMember("load game").isClicked(e.getX(),e.getY())) 478 gameState = GameState.LoadGame; 479 else if(wndMain.getMember("game info").isClicked(e.getX(),e.getY())) 480 gameState = GameState.Info; 481 else if(wndMain.getMember("credits").isClicked(e.getX(),e.getY())) 482 gameState = GameState.Credits; 483 else if(wndMain.getMember("quit").isClicked(e.getX(),e.getY())) 484 done = true; 485 break; 486 case CreateAccount: 487 if(wndCreateAccount.getMember("user").isClicked(e.getX(),e.getY())) 488 selectText((Textbox)wndCreateAccount.getMember("user")); 489 else if(wndCreateAccount.getMember("choose class").isClicked(e.getX(),e.getY())) { 490 selectText(null); 491 gameState = GameState.CreateClass; 492 }else if(wndCreateAccount.getMember("create").isClicked(e.getX(),e.getY())) { 493 String user = ((Textbox)wndCreateAccount.getMember("user")).getText(); 494 Gender gender = Gender.valueOf(rdgGenderSelection.getButton(rdgGenderSelection.getSelected()).getLabel()); 495 496 if(user.equals("")) { 497 showMessage("The username is empty"); 498 }else if(gender == Gender.None) { 499 showMessage("No gender has been selected"); 500 }else{ 501 player = new Player(user, gender); 502 player.setSpeed(200); 503 player.setLoc(new Point(750, 860)); 504 player.setTarget(player.getLoc()); 505 gameState = GameState.Game; 506 } 507 }else if(wndCreateAccount.getMember("cancel").isClicked(e.getX(),e.getY())) { 508 selectText(null); 509 wndCreateAccount.clear(); 510 wndChooseClass.clear(); 511 gameState = GameState.Main; 512 }else if(wndCreateAccount.handleEvent(e)) { 513 } 514 break; 515 case CreateClass: 516 if(wndChooseClass.getMember("select").isClicked(e.getX(),e.getY())) { 517 gameState = GameState.CreateAccount; 518 } 519 else if(wndChooseClass.getMember("cancel").isClicked(e.getX(),e.getY())) { 520 gameState = GameState.CreateAccount; 521 }else if(wndChooseClass.handleEvent(e)) { 522 } 523 break; 524 case LoadGame: 525 gameState = GameState.Main; 526 break; 527 case Info: 528 gameState = GameState.Main; 529 break; 530 case Credits: 531 gameState = GameState.Main; 532 break; 533 case Game: 534 int newX = player.getLoc().getX()+e.getX()-400; 535 int newY = player.getLoc().getY()+e.getY()-300; 536 if(map.getLoc((int)(Math.floor(newX/100)), (int)(Math.floor(newY/100))).isPassable()) { 537 player.setTarget(new Point(newX, newY)); 538 player.setLastMoved(System.currentTimeMillis()); 539 } 540 break; 541 case GameMenu: 542 break; 543 case GameInventory: 544 break; 545 case GameStats: 546 break; 547 } 548 break; 549 case MsgBox: 550 if(wndMessage.getMember("button").isClicked(e.getX(), e.getY())) { 551 auxState = AuxState.None; 552 } 553 break; 554 } 555 } 556 557 public void mouseReleased(MouseEvent e) { 558 559 } 560 561 public void mouseEntered(MouseEvent e) { 562 563 } 564 565 public void mouseExited(MouseEvent e) { 566 567 } 568 569 public void mouseClicked(MouseEvent e) { 570 571 } 572 573 public void keyTyped(KeyEvent e) { 574 575 } 576 577 public void keyPressed(KeyEvent e) { 578 if(selectedText != null) 579 selectedText.handleEvent(e); 580 581 if(e.getKeyCode() == KeyEvent.VK_ESCAPE) 582 if(gameState == GameState.Game) 583 gameState = GameState.Main; 584 else 585 done = true; 586 } 587 588 public void keyReleased(KeyEvent e) { 589 590 } 591 592 public static void main(String[] args) { 593 try { 594 PrintStream st = new PrintStream(new FileOutputStream("err.txt", true)); 595 System.setErr(st); 596 System.setOut(st); 597 System.out.println("-----[ Session started on " + dateString() + " ]-----"); 598 599 GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); 600 GraphicsDevice device = env.getDefaultScreenDevice(); 601 new LostHavenRPG(device); 602 } 603 catch (Exception e) { 604 e.printStackTrace(); 605 } 606 System.exit(0); 607 } 1598 System.exit(0); 1599 } 608 1600 } -
main/Map.java
r155577b r8edd04e 1 1 package main; 2 2 3 import java.awt.Color; 4 import java.awt.image.BufferedImage; 3 5 import java.io.*; 4 import java.util.*; 6 import java.util.HashMap; 7 8 import javax.imageio.ImageIO; 5 9 6 10 public class Map { 7 private Location[][] grid; 8 9 public Map(int x, int y) { 10 grid = new Location[x][y]; 11 } 12 13 public Map(String landFile, String structFile, HashMap<LandType, Land> landMap, HashMap<StructureType, Structure> structMap) { 14 try { 15 int length, height, x, y; 16 String str, loc; 17 BufferedReader in = new BufferedReader(new FileReader(landFile)); 18 19 str = in.readLine(); 20 length = Integer.parseInt(str.substring(0, str.indexOf("x"))); 21 height = Integer.parseInt(str.substring(str.indexOf("x")+1)); 22 grid = new Location[length][height]; 23 24 for(x=0; x<height; x++) { 25 str = in.readLine(); 26 for(y=0; y<length; y++) { 27 if(str.indexOf(",") == -1) 28 loc = str; 29 else { 30 loc = str.substring(0, str.indexOf(",")); 31 str = str.substring(str.indexOf(",")+1); 32 } 33 34 if(loc.equals("o")) { 35 loc = "Ocean"; 36 }else if(loc.equals("1")) { 37 loc = "Grass"; 38 } 39 40 grid[y][x] = new Location(landMap.get(LandType.valueOf(loc)), structMap.get(StructureType.None)); 41 } 42 } 43 44 in.close(); 45 46 in = new BufferedReader(new FileReader(structFile)); 47 48 while((loc = in.readLine()) != null) { 49 str = in.readLine(); 50 x = Integer.valueOf(str.substring(0, str.indexOf(","))); 51 y = Integer.valueOf(str.substring(str.indexOf(",")+1)); 52 53 grid[x-1][y-1].setStruct(structMap.get(StructureType.valueOf(loc))); 54 } 55 } catch(IOException ioe) { 56 ioe.printStackTrace(); 57 } 58 } 59 60 public Location getLoc(int x, int y) { 61 return grid[x][y]; 62 } 63 64 public void setLoc(Location loc, int x, int y) { 65 grid[x][y] = loc; 66 } 67 68 public int getLength() { 69 return grid.length; 70 } 71 72 public int getHeight() { 73 if(grid.length>0) 74 return grid[0].length; 75 else 76 return 0; 77 } 11 12 private Location[][] grid; 13 14 public Map(int x, int y) { 15 this.grid = new Location[x][y]; 16 } 17 18 public Map(String mapFile, String structFile, HashMap<LandType, Land> landMap, HashMap<StructureType, Structure> structMap, boolean readMapFromImage) { 19 if (readMapFromImage) { 20 try { 21 BufferedImage img = ImageIO.read(getClass().getResource("../images/" + mapFile)); 22 int length = img.getHeight(); 23 int height = img.getWidth(); 24 this.grid = new Location[height][length]; 25 int x; 26 for (x = 0; x < height; x++) { 27 for (int y = 0; y < length; y++) { 28 String loc; 29 Color clr = new Color(img.getRGB(x, y)); 30 if (clr.getRed() == 243 && clr.getGreen() == 119 && clr.getBlue() == 0) { 31 loc = "Lava"; 32 } else if (clr.getRed() == 128 && clr.getGreen() == 0 && clr.getBlue() == 0) { 33 loc = "Metal"; 34 } else if (clr.getRed() == 255 && clr.getGreen() == 0 && clr.getBlue() == 0) { 35 loc = "Charred"; 36 } else if (clr.getRed() == 95 && clr.getGreen() == 155 && clr.getBlue() == 0) { 37 loc = "Swamp"; 38 } else if (clr.getRed() == 0 && clr.getGreen() == 67 && clr.getBlue() == 0) { 39 loc = "Vines"; 40 } else if (clr.getRed() == 255 && clr.getGreen() == 0 && clr.getBlue() == 255) { 41 loc = "Crystal"; 42 } else if (clr.getRed() == 128 && clr.getGreen() == 0 && clr.getBlue() == 128) { 43 loc = "CrystalFormation"; 44 } else if (clr.getRed() == 0 && clr.getGreen() == 0 && clr.getBlue() == 255) { 45 loc = "Water"; 46 } else if (clr.getRed() == 0 && clr.getGreen() == 128 && clr.getBlue() == 0) { 47 loc = "Forest"; 48 } else if (clr.getRed() == 139 && clr.getGreen() == 63 && clr.getBlue() == 43) { 49 loc = "Tree"; 50 } else if (clr.getRed() == 179 && clr.getGreen() == 247 && clr.getBlue() == 207) { 51 loc = "Plains"; 52 } else if (clr.getRed() == 255 && clr.getGreen() == 255 && clr.getBlue() == 0) { 53 loc = "Desert"; 54 } else if (clr.getRed() == 83 && clr.getGreen() == 83 && clr.getBlue() == 83) { 55 loc = "Mountains"; 56 } else if (clr.getRed() == 8 && clr.getGreen() == 0 && clr.getBlue() == 0) { 57 loc = "Cave"; 58 } else if (clr.getRed() == 0 && clr.getGreen() == 0 && clr.getBlue() == 128) { 59 loc = "Ocean"; 60 } else if (clr.getRed() == 0 && clr.getGreen() == 255 && clr.getBlue() == 255) { 61 loc = "Snow"; 62 } else if (clr.getRed() == 160 && clr.getGreen() == 160 && clr.getBlue() == 164) { 63 loc = "Steam"; 64 } else { 65 loc = "Mountains"; 66 } 67 this.grid[x][y] = new Location(landMap.get(LandType.valueOf(loc)), structMap.get(StructureType.None)); 68 } 69 } 70 BufferedReader in = new BufferedReader(new FileReader(structFile)); 71 String str; 72 while ((str = in.readLine()) != null) { 73 String loc = in.readLine(); 74 x = Integer.valueOf(loc.substring(0, loc.indexOf(","))).intValue(); 75 int y = Integer.valueOf(loc.substring(loc.indexOf(",") + 1)).intValue(); 76 Point loc1 = new Point((x - 1) * 100 + 50, (y - 1) * 100 + 50); 77 if (str.equals("ArtifactPoint") || str.equals("BossPoint")) { 78 String strTarg = in.readLine(); 79 int x2 = Integer.valueOf(strTarg.substring(0, strTarg.indexOf(","))).intValue(); 80 int y2 = Integer.valueOf(strTarg.substring(strTarg.indexOf(",") + 1)).intValue(); 81 Point loc2 = new Point((x2 - 1) * 100 + 50, (y2 - 1) * 100 + 50); 82 ArtifactPoint struct = new ArtifactPoint((ArtifactPoint)structMap.get(StructureType.valueOf(str)), loc1); 83 struct.setTarget(loc2); 84 this.grid[x - 1][y - 1].setStruct(struct); 85 ArtifactPoint struct2 = new ArtifactPoint((ArtifactPoint)structMap.get(StructureType.valueOf(str)), loc2); 86 struct2.setTarget(loc1); 87 this.grid[x2 - 1][y2 - 1].setStruct(struct2); 88 continue; 89 } 90 if (str.equals("RespawnPoint")) { 91 this.grid[x - 1][y - 1].setStruct(new RespawnPoint((RespawnPoint)structMap.get(StructureType.valueOf(str)), loc1)); 92 LostHavenRPG.respawnPoints.add((RespawnPoint)this.grid[x - 1][y - 1].getStruct()); 93 continue; 94 } 95 this.grid[x - 1][y - 1].setStruct(new Structure(structMap.get(StructureType.valueOf(str)), loc1)); 96 } 97 in.close(); 98 } catch (IOException ioe) { 99 ioe.printStackTrace(); 100 } 101 } else { 102 try { 103 BufferedReader in = new BufferedReader(new FileReader("../" + mapFile)); 104 String str = in.readLine(); 105 int length = Integer.parseInt(str.substring(0, str.indexOf("x"))); 106 int height = Integer.parseInt(str.substring(str.indexOf("x") + 1)); 107 this.grid = new Location[length][height]; 108 int x; 109 for (x = 0; x < height; x++) { 110 str = in.readLine(); 111 for (int y = 0; y < length; y++) { 112 String loc; 113 if (str.indexOf(",") == -1) { 114 loc = str; 115 } else { 116 loc = str.substring(0, str.indexOf(",")); 117 str = str.substring(str.indexOf(",") + 1); 118 } 119 if (loc.equals("o")) { 120 loc = "OceanOld"; 121 } else if (loc.equals("1")) { 122 loc = "GrassOld"; 123 } 124 this.grid[y][x] = new Location(landMap.get(LandType.valueOf(loc)), structMap.get(StructureType.None)); 125 } 126 } 127 in.close(); 128 in = new BufferedReader(new FileReader(structFile)); 129 while ((str = in.readLine()) != null) { 130 String loc = in.readLine(); 131 x = Integer.valueOf(loc.substring(0, loc.indexOf(","))).intValue(); 132 int y = Integer.valueOf(loc.substring(loc.indexOf(",") + 1)).intValue(); 133 this.grid[x - 1][y - 1].setStruct(structMap.get(StructureType.valueOf(str))); 134 } 135 in.close(); 136 } catch (IOException ioe) { 137 ioe.printStackTrace(); 138 } 139 } 140 } 141 142 public void clearCreatures() { 143 for (int x = 0; x < getLength(); x++) { 144 for (int y = 0; y < getHeight(); y++) { 145 getLoc(x, y).getCreatures().clear(); 146 } 147 } 148 } 149 150 public Location getLoc(int x, int y) { 151 return this.grid[x][y]; 152 } 153 154 public void setLoc(Location loc, int x, int y) { 155 this.grid[x][y] = loc; 156 } 157 158 public int getLength() { 159 return this.grid.length; 160 } 161 162 public int getHeight() { 163 if (this.grid.length > 0) { 164 return (this.grid[0]).length; 165 } 166 return 0; 167 } 78 168 } -
main/MapElement.java
r155577b r8edd04e 1 1 package main; 2 2 3 import java.awt.image. *;3 import java.awt.image.BufferedImage; 4 4 import java.io.IOException; 5 5 … … 7 7 8 8 public class MapElement { 9 private BufferedImage img; 10 private boolean passable; 11 12 public MapElement(BufferedImage img, boolean passable) { 13 this.img = img; 14 this.passable = passable; 15 } 16 17 public MapElement(String imgFile, boolean passable) { 18 try { 19 img = ImageIO.read(getClass().getResource("images/"+imgFile)); 20 this.passable = passable; 21 }catch(IOException ioe) { 22 ioe.printStackTrace(); 23 } 24 } 25 26 public BufferedImage getImg() { 27 return img; 28 } 29 30 public boolean isPassable() { 31 return passable; 32 } 33 34 public void setImg(BufferedImage img) { 35 this.img = img; 36 } 37 38 public void setPassable(boolean passable) { 39 this.passable = passable; 40 } 9 10 private BufferedImage img; 11 private boolean passable; 12 13 public MapElement(BufferedImage img, boolean passable) { 14 this.img = img; 15 this.passable = passable; 16 } 17 18 public MapElement(String imgFile, boolean passable) { 19 try { 20 this.img = ImageIO.read(getClass().getResource("../images/" + imgFile)); 21 this.passable = passable; 22 } catch (IOException ioe) { 23 ioe.printStackTrace(); 24 } 25 } 26 27 public MapElement(MapElement copy) { 28 this.img = copy.img; 29 this.passable = copy.passable; 30 } 31 32 public BufferedImage getImg() { 33 return this.img; 34 } 35 36 public boolean isPassable() { 37 return this.passable; 38 } 39 40 public void setImg(BufferedImage img) { 41 this.img = img; 42 } 43 44 public void setPassable(boolean passable) { 45 this.passable = passable; 46 } 41 47 } -
main/Player.java
r155577b r8edd04e 1 1 package main; 2 2 3 import java.awt.Font; 4 import java.awt.Graphics; 5 import java.awt.MouseInfo; 6 import java.io.*; 7 import java.util.*; 8 9 import gamegui.*; 10 3 11 public class Player extends Creature { 4 private Point target; 5 private int experience; 6 private int gold; 7 8 public Player() { 9 super(); 10 target = new Point(0, 0); 11 } 12 13 public Player(String name) { 14 super(name); 15 target = new Point(0, 0); 16 } 17 18 public Player(String name, Gender gender) { 19 super(name, gender); 20 target = new Point(0, 0); 21 } 22 23 public int getExperience() { 24 return experience; 25 } 26 27 public int getGold() { 28 return gold; 29 } 30 31 public Point getTarget() { 32 return target; 33 } 34 35 public void setExperience(int experience) { 36 this.experience = experience; 37 } 38 39 public void setGold(int gold) { 40 this.gold = gold; 41 } 42 43 public void setTarget(Point target) { 44 this.target = target; 45 } 12 13 private int gold; 14 private int attributePoints; 15 private int[] skills; 16 private int skillPoints; 17 private LinkedList<Item> inventory; 18 private LinkedList<Item> gemsUsed; 19 private HashMap<Gem, Integer> gems; 20 private int relicCount; 21 private int gemValue; 22 private long timePlayed; 23 private long timeLoggedOn; 24 25 public Player() { 26 this.name = "Player"; 27 this.type = CreatureType.Player; 28 this.skills = new int[9]; 29 this.inventory = new LinkedList<Item>(); 30 this.gemsUsed = new LinkedList<Item>(); 31 this.gems = new HashMap<Gem, Integer>(); 32 this.relicCount = 0; 33 this.gemValue = 0; 34 this.timePlayed = 0L; 35 this.timeLoggedOn = 0L; 36 } 37 38 public Player(Player p) { 39 super(p); 40 this.skills = (int[])p.skills.clone(); 41 this.attributePoints = p.attributePoints; 42 this.skillPoints = p.skillPoints; 43 this.inventory = new LinkedList<Item>(p.inventory); 44 this.gemsUsed = new LinkedList<Item>(p.gemsUsed); 45 this.gems = new HashMap<Gem, Integer>(p.gems); 46 this.relicCount = p.relicCount; 47 this.gemValue = p.gemValue; 48 this.timePlayed = p.timePlayed; 49 this.timeLoggedOn = p.timeLoggedOn; 50 } 51 52 public Player copy() { 53 return new Player(this); 54 } 55 56 public boolean readyForBoss() { 57 return (this.relicCount >= 4); 58 } 59 60 public void setTimeLoggedOn(long time) { 61 this.timeLoggedOn = time; 62 } 63 64 public long getTimePlayed() { 65 return this.timePlayed; 66 } 67 68 public void updateTimePlayed() { 69 this.timePlayed += System.currentTimeMillis() - this.timeLoggedOn; 70 } 71 72 public void drawInventory(Graphics g, ScrollList inv, int x, int y) { 73 int mouseX = (MouseInfo.getPointerInfo().getLocation()).x; 74 int mouseY = (MouseInfo.getPointerInfo().getLocation()).y; 75 int locX = (mouseX - x) / 50; 76 int locY = (mouseY - y + inv.getTextStart()) / 50; 77 if (locX + 4 * locY >= 0 && locX + 4 * locY < inv.getList().size()) { 78 Window popup; 79 String itemType; 80 MultiTextbox desc; 81 Item i = ((ItemImg)inv.getList().get(locX + locY * 4)).getItem(); 82 switch (i.getType()) { 83 case Relic: 84 popup = new Window("popup", mouseX - 100, mouseY - 150, 100, 165, false); 85 break; 86 default: 87 popup = new Window("popup", mouseX - 100, mouseY - 100, 100, 100, false); 88 break; 89 } 90 Font font12 = new Font("Arial", 0, 12); 91 switch (i.getType()) { 92 case LightWeapon: 93 itemType = "Light Weapon"; 94 break; 95 case HeavyWeapon: 96 itemType = "Heavy Weapon"; 97 break; 98 case RangedWeapon: 99 itemType = "Ranged Weapon"; 100 break; 101 default: 102 itemType = i.getType().toString(); 103 break; 104 } 105 popup.add(new Label("name", 5, 5, 90, 15, i.getName(), font12)); 106 popup.add(new Label("type", 5, 35, 90, 15, itemType, font12)); 107 switch (i.getType()) { 108 case LightWeapon: 109 case HeavyWeapon: 110 case RangedWeapon: 111 popup.add(new Label("damage", 5, 50, 90, 15, "Damage: " + ((Weapon)i).getDamage(), font12)); 112 popup.add(new Label("damage", 5, 65, 90, 15, "Cooldown: " + (((Weapon)i).getAttackSpeed() / 10.0D) + " s", font12)); 113 break; 114 case Spell: 115 popup.add(new Label("energy", 5, 50, 90, 15, "Energy: " + ((Gem)i).getValue(), font12)); 116 desc = new MultiTextbox("description", 1, 80, 99, 84, "", false, font12, g.getFontMetrics(font12)); 117 desc.setText(i.getDescription()); 118 desc.setBorder(false); 119 popup.add(desc); 120 break; 121 } 122 popup.draw(g); 123 } 124 } 125 126 public void save(PrintWriter out) { 127 super.save(out); 128 out.println(this.name); 129 out.println(this.level); 130 out.println(this.timePlayed); 131 out.println(this.experience); 132 out.println(String.valueOf(getTarget().getX()) + "," + getTarget().getY()); 133 out.println(getAttribute(Attribute.Strength)); 134 out.println(getAttribute(Attribute.Dexterity)); 135 out.println(getAttribute(Attribute.Constitution)); 136 out.println(getAttribute(Attribute.Wisdom)); 137 out.println(getSkill(Skill.LightWeapons)); 138 out.println(getSkill(Skill.HeavyWeapons)); 139 out.println(getSkill(Skill.RangedWeapons)); 140 out.println(getSkill(Skill.Evocation)); 141 out.println(getSkill(Skill.Enchantment)); 142 out.println(this.attributePoints); 143 out.println(this.skillPoints); 144 out.println(getMaxHitpoints()); 145 out.println(getMaxManapoints()); 146 Object[] arr = LostHavenRPG.respawnPoints.toArray(); 147 for (int x = 0; x < arr.length; x++) { 148 if (((RespawnPoint)arr[x]).isMarked()) 149 out.println(x); 150 } 151 out.println("---"); 152 Iterator<Item> iter = this.inventory.iterator(); 153 while (iter.hasNext()) 154 out.println(((Item)iter.next()).getName()); 155 out.println("---"); 156 iter = this.gemsUsed.iterator(); 157 while (iter.hasNext()) 158 out.println(((Item)iter.next()).getName()); 159 out.println("---"); 160 } 161 162 public static Player loadTemplate(BufferedReader in) { 163 Player p = new Player(); 164 try { 165 p.level = Integer.parseInt(in.readLine()); 166 p.setSkill(Skill.LightWeapons, Integer.parseInt(in.readLine())); 167 p.setSkill(Skill.HeavyWeapons, Integer.parseInt(in.readLine())); 168 p.setSkill(Skill.RangedWeapons, Integer.parseInt(in.readLine())); 169 p.setSkill(Skill.Evocation, Integer.parseInt(in.readLine())); 170 p.setSkill(Skill.Enchantment, Integer.parseInt(in.readLine())); 171 p.attributePoints = Integer.parseInt(in.readLine()); 172 p.skillPoints = Integer.parseInt(in.readLine()); 173 } catch (IOException ioe) { 174 ioe.printStackTrace(); 175 } 176 return p; 177 } 178 179 public void load(BufferedReader in) { 180 try { 181 super.load(in); 182 int hp = getHitpoints(); 183 int mp = getManapoints(); 184 setName(in.readLine()); 185 this.level = Integer.valueOf(in.readLine()).intValue(); 186 this.timePlayed = Long.valueOf(in.readLine()).longValue(); 187 setExperience(Integer.valueOf(in.readLine()).intValue()); 188 String strTarget = in.readLine(); 189 getTarget().setX(Integer.valueOf(strTarget.substring(0, strTarget.indexOf(","))).intValue()); 190 getTarget().setY(Integer.valueOf(strTarget.substring(strTarget.indexOf(",") + 1)).intValue()); 191 setAttribute(Attribute.Strength, Integer.parseInt(in.readLine())); 192 setAttribute(Attribute.Dexterity, Integer.parseInt(in.readLine())); 193 setAttribute(Attribute.Constitution, Integer.parseInt(in.readLine())); 194 setAttribute(Attribute.Wisdom, Integer.parseInt(in.readLine())); 195 setSkill(Skill.LightWeapons, Integer.parseInt(in.readLine())); 196 setSkill(Skill.HeavyWeapons, Integer.parseInt(in.readLine())); 197 setSkill(Skill.RangedWeapons, Integer.parseInt(in.readLine())); 198 setSkill(Skill.Evocation, Integer.parseInt(in.readLine())); 199 setSkill(Skill.Enchantment, Integer.parseInt(in.readLine())); 200 this.attributePoints = Integer.parseInt(in.readLine()); 201 this.skillPoints = Integer.parseInt(in.readLine()); 202 setMaxHitpoints(Integer.parseInt(in.readLine())); 203 setMaxManapoints(Integer.parseInt(in.readLine())); 204 setHitpoints(hp); 205 setManapoints(mp); 206 setWeapon(this.weapon.baseWeapon); 207 String strItem; 208 while (!(strItem = in.readLine()).equals("---")) 209 ((RespawnPoint)LostHavenRPG.respawnPoints.get(Integer.parseInt(strItem))).mark(); 210 this.weapon.update(); 211 while (!(strItem = in.readLine()).equals("---")) 212 pickUp(LostHavenRPG.items.get(strItem)); 213 while (!(strItem = in.readLine()).equals("---")) { 214 pickUp(LostHavenRPG.items.get(strItem)); 215 activateGem((Gem)LostHavenRPG.items.get(strItem)); 216 } 217 } catch (IOException ioe) { 218 ioe.printStackTrace(); 219 } 220 } 221 222 public void pickUp(Item item) { 223 this.inventory.add(item); 224 LostHavenRPG.lstInventory.getList().add(new ItemImg(item)); 225 if (item.isRelic()) { 226 this.relicCount++; 227 } 228 } 229 230 public boolean activateGem(Gem item) { 231 if (this.gemValue + item.getValue() > getSkill(Skill.Evocation)) 232 return false; 233 this.gemsUsed.add(item); 234 LostHavenRPG.lstGems.getList().add(new ItemImg(item)); 235 this.inventory.remove(item); 236 LostHavenRPG.lstInventory.getList().remove(new ItemImg(item)); 237 this.gemValue += item.getValue(); 238 addGem((Gem)LostHavenRPG.items.get(item.getName())); 239 if (getSpell() == null) { 240 setSpell(new Weapon("spell", ItemType.Spell, "Dagger.png", new java.awt.image.BufferedImage[8], 10, 250, 0)); 241 } 242 getSpell().update(); 243 return true; 244 } 245 246 public void deactivateGem(Gem item) { 247 this.inventory.add(item); 248 LostHavenRPG.lstInventory.getList().add(new ItemImg(item)); 249 this.gemsUsed.remove(item); 250 LostHavenRPG.lstGems.getList().remove(new ItemImg(item)); 251 this.gemValue -= item.getValue(); 252 removeGem((Gem)LostHavenRPG.items.get(item.getName())); 253 if (this.gemsUsed.size() == 0) { 254 this.spell = null; 255 } else { 256 getSpell().update(); 257 } 258 } 259 260 public LinkedList<Item> getInventory() { 261 return this.inventory; 262 } 263 264 public LinkedList<Item> getGems() { 265 return this.gemsUsed; 266 } 267 268 public void initGems(LinkedList<Gem> lstGems) { 269 Iterator<Gem> iter = lstGems.iterator(); 270 while (iter.hasNext()) 271 this.gems.put(iter.next(), Integer.valueOf(0)); 272 } 273 274 public void addGem(Gem gem) { 275 this.gems.put(gem, Integer.valueOf(((Integer)this.gems.get(gem)).intValue() + 1)); 276 } 277 278 public void removeGem(Gem gem) { 279 this.gems.put(gem, Integer.valueOf(((Integer)this.gems.get(gem)).intValue() - 1)); 280 } 281 282 public int getGemNum(String name) { 283 Iterator<Gem> iter = this.gems.keySet().iterator(); 284 while (iter.hasNext()) { 285 Gem cur = iter.next(); 286 if (cur.getName().equals(name)) { 287 return ((Integer)this.gems.get(cur)).intValue(); 288 } 289 } 290 return 0; 291 } 292 293 public void increaseLevel() { 294 this.skillPoints += 2; 295 setHitpoints(getHitpoints() + getAttribute(Attribute.Constitution)); 296 setMaxHitpoints(getMaxHitpoints() + getAttribute(Attribute.Constitution)); 297 setManapoints(getManapoints() + getAttribute(Attribute.Wisdom)); 298 setMaxManapoints(getMaxManapoints() + getAttribute(Attribute.Wisdom)); 299 setLevel(getLevel() + 1); 300 } 301 302 public void allocateAttribute(Attribute point) { 303 if (this.attributePoints > 0) { 304 setAttribute(point, getAttribute(point) + 1); 305 this.attributePoints--; 306 } 307 } 308 309 public void repickAttribute(Attribute point) { 310 if (getAttribute(point) > 6) { 311 setAttribute(point, getAttribute(point) - 1); 312 this.attributePoints++; 313 } 314 } 315 316 public void allocateSkill(Skill point) { 317 if (this.skillPoints > 0) { 318 setSkill(point, getSkill(point) + 1); 319 this.skillPoints--; 320 this.weapon.update(); 321 } 322 } 323 324 public void repickSkill(Skill point) { 325 if (getSkill(point) > 0) { 326 setSkill(point, getSkill(point) - 1); 327 this.skillPoints++; 328 this.weapon.update(); 329 } 330 } 331 332 private int skillIndex(Skill skill) { 333 switch (skill) { 334 case LightWeapons: 335 return 0; 336 case HeavyWeapons: 337 return 1; 338 case RangedWeapons: 339 return 2; 340 case Evocation: 341 return 3; 342 case Enchantment: 343 return 4; 344 } 345 return -1; 346 } 347 348 public int getSkill(Skill skill) { 349 return this.skills[skillIndex(skill)]; 350 } 351 352 public void setSkill(Skill skill, int num) { 353 this.skills[skillIndex(skill)] = num; 354 } 355 356 public int getGold() { 357 return this.gold; 358 } 359 360 public int getAttributePoints() { 361 return this.attributePoints; 362 } 363 364 public int getSkillPoints() { 365 return this.skillPoints; 366 } 367 368 public int getGemValue() { 369 return this.gemValue; 370 } 371 372 public int getRelicCount() { 373 return this.relicCount; 374 } 375 376 public void setWeapon(Weapon weapon) { 377 this.weapon = new EquippedWeapon(this, weapon); 378 switch (weapon.getType()) { 379 case LightWeapon: 380 case HeavyWeapon: 381 setModel(LostHavenRPG.meleeModel); 382 break; 383 case RangedWeapon: 384 setModel(LostHavenRPG.rangedModel); 385 break; 386 } 387 this.weapon.update(); 388 (this.model.getAnimation(Direction.North, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.North, Action.Attacking)).frames.size()); 389 (this.model.getAnimation(Direction.South, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.South, Action.Attacking)).frames.size()); 390 (this.model.getAnimation(Direction.East, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.East, Action.Attacking)).frames.size()); 391 (this.model.getAnimation(Direction.West, Action.Attacking)).drawInterval = (this.weapon.getAttackSpeed() * 100 / (this.model.getAnimation(Direction.West, Action.Attacking)).frames.size()); 392 } 393 394 public void setGold(int gold) { 395 this.gold = gold; 396 } 397 398 public void setAttributePoints(int attributePoints) { 399 this.attributePoints = attributePoints; 400 } 401 402 public void setAttribute(Attribute attribute, int num) { 403 this.attributes[attributeIndex(attribute)] = num; 404 updateStats(); 405 } 406 407 private void updateStats() { 408 this.hitpoints = 4 * this.attributes[2]; 409 this.maxHitpoints = 4 * this.attributes[2]; 410 this.manapoints = 2 * this.attributes[3]; 411 this.maxManapoints = 2 * this.attributes[3]; 412 } 413 414 public class ItemImg implements Listable { 415 public Item i; 416 public int xCoord; 417 public int yCoord; 418 419 public ItemImg(Item i) { 420 this.i = i; 421 } 422 423 public void draw(int x, int y, Graphics g) { 424 this.xCoord = x; 425 this.yCoord = y; 426 this.i.drawStatic(g, x, y); 427 } 428 429 public Item getItem() { 430 return this.i; 431 } 432 433 public int getHeight() { 434 return this.i.getImg().getHeight(); 435 } 436 437 public int getWidth() { 438 return this.i.getImg().getWidth(); 439 } 440 441 public int getXOffset() { 442 return 0; 443 } 444 445 public int getYOffset() { 446 return 0; 447 } 448 449 public boolean equals(Object o) { 450 return (((ItemImg)o).i == this.i); 451 } 452 } 46 453 } -
main/Point.java
r155577b r8edd04e 2 2 3 3 public class Point { 4 private int x;5 private int xMin;6 private int y;7 private int yMin;8 9 public Point() {10 x = 0;11 y = 0;12 }13 4 14 public Point(int x, int y) { 15 this.x = x; 16 this.xMin = 0; 17 this.y = y; 18 this.yMin = 0; 19 } 20 21 public Point(int x, int xMin, int y, int yMin) { 22 this.x = x; 23 this.xMin = xMin; 24 this.y = y; 25 this.yMin = yMin; 26 } 5 private int x; 6 private int xMin; 7 private int y; 8 private int yMin; 27 9 28 public int getX() { 29 return x; 30 } 31 32 public int getXMin() { 33 return xMin; 34 } 10 public Point() { 11 this.x = 0; 12 this.y = 0; 13 } 35 14 36 public int getY() { 37 return y; 38 } 39 40 public int getYMin() { 41 return yMin; 42 } 15 public Point(int x, int y) { 16 this.x = x; 17 this.xMin = 0; 18 this.y = y; 19 this.yMin = 0; 20 } 43 21 44 public void setX(int x) { 45 this.x = x; 46 } 47 48 public void setXMin(int xMin) { 49 this.xMin = xMin; 50 } 22 public Point(int x, int xMin, int y, int yMin) { 23 this.x = x; 24 this.xMin = xMin; 25 this.y = y; 26 this.yMin = yMin; 27 } 51 28 52 public void setY(int y) { 53 this.y = y; 54 } 55 56 public void setYMin(int yMin) { 57 this.yMin = yMin; 58 } 59 60 public String toString() { 61 return x+","+y; 62 } 63 64 public static int xDif(Point p1, Point p2) { 65 return 100*(p2.x-p1.x)+p2.xMin-p1.xMin; 66 } 67 68 public static int yDif(Point p1, Point p2) { 69 return 100*(p2.y-p1.y)+p2.yMin-p1.yMin; 70 } 71 72 public static double dist(Point p1, Point p2) { 73 return Math.sqrt(Math.pow(p1.x+p1.xMin/100-p2.x-p2.xMin/100, 2)+Math.pow(p1.y+p1.yMin/100-p2.y-p2.yMin/100, 2)); 74 } 29 public Point(Point p) { 30 this.x = p.x; 31 this.xMin = p.xMin; 32 this.y = p.y; 33 this.yMin = p.yMin; 34 } 35 36 public int getX() { 37 return this.x; 38 } 39 40 public int getXMin() { 41 return this.xMin; 42 } 43 44 public int getY() { 45 return this.y; 46 } 47 48 public int getYMin() { 49 return this.yMin; 50 } 51 52 public void setX(int x) { 53 this.x = x; 54 } 55 56 public void setXMin(int xMin) { 57 this.xMin = xMin; 58 } 59 60 public void setY(int y) { 61 this.y = y; 62 } 63 64 public void setYMin(int yMin) { 65 this.yMin = yMin; 66 } 67 68 public boolean equals(Point p) { 69 return (this.x == p.x && this.y == p.y && this.xMin == p.xMin && this.yMin == p.yMin); 70 } 71 72 public String toString() { 73 return String.valueOf(this.x) + "," + this.y; 74 } 75 76 public static int xDif(Point p1, Point p2) { 77 return 100 * (p2.x - p1.x) + p2.xMin - p1.xMin; 78 } 79 80 public static int yDif(Point p1, Point p2) { 81 return 100 * (p2.y - p1.y) + p2.yMin - p1.yMin; 82 } 83 84 public static double dist(Point p1, Point p2) { 85 return Math.sqrt(Math.pow((p1.x + p1.xMin / 100 - p2.x - p2.xMin / 100), 2.0D) + Math.pow((p1.y + p1.yMin / 100 - p2.y - p2.yMin / 100), 2.0D)); 86 } 75 87 } -
main/SpawnPoint.java
r155577b r8edd04e 1 1 package main; 2 2 3 import java.util.Iterator; 4 import java.util.Random; 5 3 6 public class SpawnPoint { 4 Point loc; 5 long lastSpawned; 6 long interval; 7 Creature creature; 8 9 public SpawnPoint(Point loc, long interval, Creature creature) { 10 this.loc = loc; 11 this.interval = interval; 12 this.creature = creature; 13 lastSpawned = 0; 14 } 15 16 //calling class handles the actual spawning of the creature if this method returns true 17 public boolean spawn() { 18 if((System.currentTimeMillis()-lastSpawned) >= interval) { 19 lastSpawned = System.currentTimeMillis(); 20 return true; 21 }else { 22 return false; 23 } 24 } 7 8 static int numSpawnPoints = 0; 9 10 Point loc; 11 long lastSpawned; 12 long interval; 13 Creature creature; 14 int numSpawns; 15 int maxSpawns; 16 int idNum; 17 18 public SpawnPoint(Creature creature, Point loc, long interval, int maxSpawns) { 19 this.creature = creature; 20 this.loc = loc; 21 this.interval = interval; 22 this.maxSpawns = maxSpawns; 23 this.lastSpawned = 0L; 24 this.idNum = ++numSpawnPoints; 25 } 26 27 public Creature spawn() { 28 if (System.currentTimeMillis() - this.lastSpawned >= this.interval && this.numSpawns < this.maxSpawns) { 29 this.lastSpawned = System.currentTimeMillis(); 30 Creature cr = this.creature.copy(); 31 Point newLoc = null; 32 Random gen = new Random(); 33 boolean goodLoc = false, occupied = false; 34 while (!goodLoc) { 35 newLoc = new Point(this.loc.getX() - 400 + gen.nextInt(800), this.loc.getY() - 400 + gen.nextInt(800)); 36 if (newLoc.getX() >= 0 && newLoc.getY() >= 0 && LostHavenRPG.map.getLoc(newLoc.getX() / 100, newLoc.getY() / 100).isPassable() && Point.dist(newLoc, this.loc) <= 400.0D) { 37 occupied = false; 38 int xLow = newLoc.getX() / 100 - 2; 39 int xHigh = xLow + 5; 40 int yLow = newLoc.getY() / 100 - 2; 41 int yHigh = yLow + 5; 42 if (xLow < 0) { 43 xLow = 0; 44 } 45 if (xHigh > LostHavenRPG.map.getLength()) { 46 xHigh = LostHavenRPG.map.getLength(); 47 } 48 if (yLow < 0) { 49 yLow = 0; 50 } 51 if (yHigh > LostHavenRPG.map.getHeight()) { 52 yHigh = LostHavenRPG.map.getHeight(); 53 } 54 for (int x = xLow; x < xHigh; x++) { 55 for (int y = yLow; y < yHigh; y++) { 56 Iterator<Creature> iter = LostHavenRPG.map.getLoc(x, y).getCreatures().iterator(); 57 while (iter.hasNext() && !occupied) { 58 Creature cur = iter.next(); 59 if (Point.dist(cur.getLoc(), newLoc) < 100.0D) { 60 occupied = true; 61 } 62 } 63 } 64 } 65 if (!occupied) { 66 goodLoc = true; 67 } 68 } 69 } 70 cr.setLoc(newLoc); 71 cr.setSpawnPoint(this); 72 this.numSpawns++; 73 return cr; 74 } 75 76 return null; 77 } 78 79 public CreatureType getType() { 80 return this.creature.getType(); 81 } 82 83 public Point getLoc() { 84 return this.loc; 85 } 86 87 public void removeCreature() { 88 this.numSpawns--; 89 } 90 91 public void clear() { 92 this.numSpawns = 0; 93 this.lastSpawned = 0L; 94 } 25 95 } -
main/Structure.java
r155577b r8edd04e 1 1 package main; 2 2 3 import java.awt.image. *;3 import java.awt.image.BufferedImage; 4 4 5 5 public class Structure extends MapElement { 6 private StructureType type; 7 8 public Structure(StructureType type, BufferedImage img, boolean passable) { 9 super(img, passable); 10 11 this.type = type; 12 } 13 14 public Structure(StructureType type, String imgFile, boolean passable) { 15 super(imgFile, passable); 16 17 this.type = type; 18 } 19 20 public StructureType getType() { 21 return type; 22 } 6 7 private StructureType type; 8 private Point loc; 9 10 public Structure(StructureType type, BufferedImage img, boolean passable) { 11 super(img, passable); 12 this.type = type; 13 this.loc = null; 14 } 15 16 public Structure(StructureType type, String imgFile, boolean passable) { 17 super(imgFile, passable); 18 this.type = type; 19 this.loc = null; 20 } 21 22 public Structure(Structure copy, Point loc) { 23 super(copy); 24 this.type = copy.type; 25 this.loc = loc; 26 } 27 28 public StructureType getType() { 29 return this.type; 30 } 31 32 public Point getLoc() { 33 return this.loc; 34 } 23 35 } -
main/StructureType.java
r155577b r8edd04e 2 2 3 3 public enum StructureType { 4 None, 5 Tent, 6 LargeTent, 7 House, 8 Cave, 9 Gravestone, 10 GraveyardFence1, 11 GraveyardFence2, 12 PicketFence1, 13 PicketFence2, 14 Hut, 15 WitchHut, 16 Tree, 17 BlueOrb, 18 RedOrb, 19 LoginPedestal, 20 RejuvenationPedestal, 21 LifePedestal, 22 ManaPedestal 4 None, 5 Tent, 6 LargeTent, 7 House, 8 Cave, 9 Gravestone, 10 GraveyardFence1, 11 GraveyardFence2, 12 PicketFence1, 13 PicketFence2, 14 Hut, 15 WitchHut, 16 Tree, 17 BlueOrb, 18 RedOrb, 19 LoginPedestal, 20 RejuvenationPedestal, 21 LifePedestal, 22 ManaPedestal, 23 RespawnPoint, 24 ArtifactPoint, 25 BossPoint; 23 26 }
Note:
See TracChangeset
for help on using the changeset viewer.