Implemented Megamon stats, Start menu. Consolidated Player functions
into Player class.
This commit is contained in:
parent
9c21970b79
commit
7cb1714247
BIN
Megamon-core/assets/Megamon/test_mini_sprite.png
Normal file
BIN
Megamon-core/assets/Megamon/test_mini_sprite.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 543 B |
BIN
Megamon-core/assets/Megamon/test_sprite.png
Normal file
BIN
Megamon-core/assets/Megamon/test_sprite.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
BIN
Megamon-core/assets/startmenu_box.png
Normal file
BIN
Megamon-core/assets/startmenu_box.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 711 B |
BIN
Megamon-core/assets/startmenu_box_bottom.png
Normal file
BIN
Megamon-core/assets/startmenu_box_bottom.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 727 B |
BIN
Megamon-core/assets/startmenu_box_middle.png
Normal file
BIN
Megamon-core/assets/startmenu_box_middle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 170 B |
BIN
Megamon-core/assets/startmenu_highlight.png
Normal file
BIN
Megamon-core/assets/startmenu_highlight.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 741 B |
@ -4,6 +4,7 @@ import java.awt.Point;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
@ -30,6 +31,11 @@ import com.badlogic.gdx.maps.tiled.TiledMap;
|
||||
import com.badlogic.gdx.maps.tiled.TmxMapLoader;
|
||||
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
|
||||
|
||||
import sig.megamon.creature.CreatureMove;
|
||||
import sig.megamon.creature.CreatureType;
|
||||
import sig.megamon.creature.ExperienceRate;
|
||||
import sig.megamon.menu.DialogBox;
|
||||
import sig.megamon.menu.StartMenuBox;
|
||||
import sig.megamon.ref.Ref;
|
||||
import sig.megamon.ref.RoomRef;
|
||||
import sig.megamon.ref.SignRef;
|
||||
@ -42,17 +48,16 @@ public class Megamon extends ApplicationAdapter implements ApplicationListener{
|
||||
Texture img;
|
||||
public static BitmapFont font;
|
||||
public static DialogBox messagebox;
|
||||
public static StartMenuBox startmenubox;
|
||||
//AssetManager assets;
|
||||
//TiledMap map;
|
||||
OrthographicCamera camera;
|
||||
static OrthographicCamera camera;
|
||||
final public static int TILESIZE=16;
|
||||
final public static int WINDOW_WIDTH=640;
|
||||
final public static int WINDOW_HEIGHT=480;
|
||||
final public static double CHAR_SPD=0.1;
|
||||
Point2D.Double direction = new Point2D.Double(0,0);
|
||||
Point2D.Double lastdirection = new Point2D.Double(0,1);
|
||||
final public static Point2D.Double position=new Point2D.Double(1,1);
|
||||
Calendar lastCheck = Calendar.getInstance();
|
||||
public static Player mainP;
|
||||
int framesPassed=0;
|
||||
final public static String HIDDENLAYERNAME = "Tile Layer 2";
|
||||
final public static int ACTIONKEY = Keys.Z;
|
||||
@ -61,6 +66,7 @@ public class Megamon extends ApplicationAdapter implements ApplicationListener{
|
||||
final public static int MOVERIGHTKEY = Keys.RIGHT;
|
||||
final public static int MOVEUPKEY = Keys.UP;
|
||||
final public static int MOVEDOWNKEY = Keys.DOWN;
|
||||
final public static int MENUKEY = Keys.ENTER;
|
||||
//public static List<Object> objects = new ArrayList<Object>();
|
||||
public static Room currentLevel;
|
||||
public static HashMap<String,RoomRef> doorDatabase = new HashMap<String,RoomRef>();
|
||||
@ -69,9 +75,8 @@ public class Megamon extends ApplicationAdapter implements ApplicationListener{
|
||||
@Override
|
||||
public void create() {
|
||||
batch = new SpriteBatch();
|
||||
img = new Texture("megamon_icon64.png");
|
||||
font = new BitmapFont(Gdx.files.internal("fonts/AgencyFB.fnt"));
|
||||
|
||||
mainP = new Player(new Point2D.Double(1,1),"megamon_icon64.png");
|
||||
//assets = new AssetManager();
|
||||
|
||||
/*assets.setLoader(TiledMap.class, new TmxMapLoader(new InternalFileHandleResolver()));
|
||||
@ -86,8 +91,16 @@ public class Megamon extends ApplicationAdapter implements ApplicationListener{
|
||||
objects.add(new Object("megamonlogowip.png",new Point2D.Double(3, 7)));*/
|
||||
Database.SetupDoorDatabase();
|
||||
Database.SetupInfoDatabase();
|
||||
currentLevel = new Room(position,"Test Map");
|
||||
currentLevel = new Room(mainP.position,"Test Map");
|
||||
|
||||
/*MegamonPet testPet = new MegamonPet("Test",
|
||||
new MegamonCreature("test_mini_sprite.png","test_sprite.png","test_sprite.png",
|
||||
"Test Creature", "This is for testing purposes only.", 14, 60, CreatureType.NORMAL,
|
||||
40,60,30,30,50,55,30,ExperienceRate.MEDIUM_FAST,new CreatureMove[]{}),
|
||||
100);
|
||||
System.out.println(testPet);*/
|
||||
//messagebox = new DialogBox("This is a test message.This is a test message.This is a test message.This is a test message.This is a test message.This is a test message.This is a test message.This is a test message.This is a test message.This is a test message.This is a test message.This is a test message.This is a test message.This is a test message.This is a test message.This is a test message.");
|
||||
//startmenubox = new StartMenuBox(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -102,45 +115,26 @@ public class Megamon extends ApplicationAdapter implements ApplicationListener{
|
||||
if (messagebox!=null) {
|
||||
messagebox.run();
|
||||
}
|
||||
else
|
||||
if (startmenubox!=null){
|
||||
startmenubox.run();
|
||||
}
|
||||
else {
|
||||
for (Object o : currentLevel.getObjects()) {
|
||||
o.run();
|
||||
}
|
||||
if (PlayerUtils.isSnappedToGrid(position)) {
|
||||
direction=new Point2D.Double(0, 0);
|
||||
if (Gdx.input.isKeyPressed(MOVELEFTKEY)) {
|
||||
direction=lastdirection=new Point2D.Double(-CHAR_SPD,0);
|
||||
} else
|
||||
if (Gdx.input.isKeyPressed(MOVEUPKEY)) {
|
||||
direction=lastdirection=new Point2D.Double(0,CHAR_SPD);
|
||||
} else
|
||||
if (Gdx.input.isKeyPressed(MOVERIGHTKEY)) {
|
||||
direction=lastdirection=new Point2D.Double(CHAR_SPD,0);
|
||||
} else
|
||||
if (Gdx.input.isKeyPressed(MOVEDOWNKEY)) {
|
||||
direction=lastdirection=new Point2D.Double(0,-CHAR_SPD);
|
||||
}
|
||||
Point2D.Double destinationposition = new Point2D.Double(position.x+Math.signum(lastdirection.x),position.y+Math.signum(lastdirection.y));
|
||||
if (Gdx.input.isKeyJustPressed(ACTIONKEY)) {
|
||||
CheckForInfo(destinationposition);
|
||||
}
|
||||
if (direction.x!=0 || direction.y!=0) {
|
||||
//System.out.println("("+position.x+","+Math.signum(direction.x)+","+position.y+","+Math.signum(direction.y)+")");
|
||||
//Point2D.Double destinationposition = new Point2D.Double(position.x+Math.signum(direction.x),position.y+Math.signum(direction.y));
|
||||
if (PlayerUtils.isLocationPassable(currentLevel.getMap(),destinationposition)) {
|
||||
position.setLocation(position.x+direction.x, position.y+direction.y);
|
||||
} else {
|
||||
//We hit a wall.
|
||||
}
|
||||
System.out.println(infoDatabase.keySet());
|
||||
CheckForDoor(destinationposition);
|
||||
}
|
||||
} else {
|
||||
position.setLocation(position.x+direction.x, position.y+direction.y);
|
||||
//System.out.println(position);
|
||||
if (Gdx.input.isKeyJustPressed(Megamon.MENUKEY)) {
|
||||
Megamon.startmenubox = new StartMenuBox(0);
|
||||
}
|
||||
if (PlayerUtils.isSnappedToGrid(mainP.position)) {
|
||||
mainP.run();
|
||||
}
|
||||
}
|
||||
camera.position.set((float)position.x+0.5f, (float)position.y+0.5f, camera.position.z);
|
||||
if (!PlayerUtils.isSnappedToGrid(mainP.position)) {
|
||||
mainP.position.setLocation(mainP.position.x+mainP.direction.x, mainP.position.y+mainP.direction.y);
|
||||
//System.out.println(position);
|
||||
}
|
||||
camera.position.set((float)mainP.position.x+0.5f, (float)mainP.position.y+0.5f, camera.position.z);
|
||||
//System.out.println("Camera position: "+camera.position);
|
||||
camera.update();
|
||||
//System.out.println(Megamon.WINDOW_WIDTH+","+Megamon.WINDOW_HEIGHT+";"+camera.viewportWidth+","+camera.viewportHeight);
|
||||
@ -154,10 +148,13 @@ public class Megamon extends ApplicationAdapter implements ApplicationListener{
|
||||
(float)GraphicUtils.getRelativePixelPositionFromPlayer(camera, o.position).y);
|
||||
o.draw();
|
||||
}
|
||||
batch.draw(img, (int)GraphicUtils.getPlayerPixelPosition(camera).getX(), (int)GraphicUtils.getPlayerPixelPosition(camera).getY(), (int)GraphicUtils.getTileSize(camera).getX(), (int)GraphicUtils.getTileSize(camera).getY());
|
||||
mainP.draw(batch);
|
||||
if (messagebox!=null) {
|
||||
messagebox.draw(batch);
|
||||
}
|
||||
if (startmenubox!=null) {
|
||||
startmenubox.draw(batch);
|
||||
}
|
||||
GlyphLayout size = font.draw(batch, "Test Text", 0, 32);
|
||||
//font.draw(batch, "Test Text", Megamon.WINDOW_WIDTH-size.width, 128-size.height);
|
||||
batch.end();
|
||||
@ -169,31 +166,34 @@ public class Megamon extends ApplicationAdapter implements ApplicationListener{
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckForDoor(Point2D.Double destinationposition) {
|
||||
if (doorDatabase.containsKey(PlayerUtils.getDoorPositionHash(destinationposition))) {
|
||||
//System.out.println("This is a door!");
|
||||
RoomRef door = doorDatabase.get(PlayerUtils.getDoorPositionHash(destinationposition));
|
||||
if (!door.destinationRoom.equalsIgnoreCase(currentLevel.mapName)) {
|
||||
currentLevel.destroy();
|
||||
currentLevel = new Room(door.doorDestination,door.destinationRoom);
|
||||
} else {
|
||||
position.setLocation(door.doorDestination);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckForInfo(Point2D.Double destinationposition) {
|
||||
if (infoDatabase.containsKey(PlayerUtils.getDoorPositionHash(destinationposition))) {
|
||||
//System.out.println("This is a door!");
|
||||
SignRef info = infoDatabase.get(PlayerUtils.getDoorPositionHash(destinationposition));
|
||||
//TODO Do interface stuff here.
|
||||
messagebox = new DialogBox(info.getMessages());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose () {
|
||||
batch.dispose();
|
||||
img.dispose();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(this.getClass().getSimpleName()+"(");
|
||||
boolean first=true;
|
||||
for (Field f : this.getClass().getDeclaredFields()) {
|
||||
try {
|
||||
if (!first) {
|
||||
sb.append(",");
|
||||
} else {
|
||||
first=false;
|
||||
}
|
||||
sb.append(f.getName()+"="+this.getClass().getDeclaredField(f.getName()).get(this));
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +1,51 @@
|
||||
package sig.megamon;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import sig.megamon.creature.CreatureLore;
|
||||
import sig.megamon.creature.CreatureMove;
|
||||
import sig.megamon.creature.CreatureType;
|
||||
import sig.megamon.creature.ExperienceRate;
|
||||
import sig.megamon.creature.SpriteCollection;
|
||||
|
||||
public class MegamonCreature {
|
||||
SpriteCollection sprites;
|
||||
String name;
|
||||
String bio;
|
||||
CreatureType type1;
|
||||
CreatureType type2;
|
||||
int hp;
|
||||
int atk;
|
||||
int def;
|
||||
int spd;
|
||||
int spc;
|
||||
List<CreatureMove> moveset;
|
||||
final SpriteCollection sprites;
|
||||
final String name;
|
||||
final CreatureLore bio;
|
||||
final CreatureType type1;
|
||||
final CreatureType type2;
|
||||
final int hp;
|
||||
final int atk;
|
||||
final int def;
|
||||
final int spd;
|
||||
final int spc;
|
||||
final int catch_rate;
|
||||
final int base_exp;
|
||||
final ExperienceRate exp_rate;
|
||||
final List<CreatureMove> moveset;
|
||||
boolean seenByPlayer=false;
|
||||
|
||||
public MegamonCreature(String mini_icon, String sprite, String back_sprite,
|
||||
String name, String bio, CreatureType type1, int base_hp, int base_atk, int base_def, int base_spd, int base_spc,
|
||||
String name, String bio, int size, float weight, CreatureType type1,
|
||||
int base_hp, int base_atk, int base_def, int base_spd, int base_spc,
|
||||
int catch_rate, int base_exp, ExperienceRate exp_rate,
|
||||
CreatureMove...moveset) {
|
||||
this(mini_icon,sprite,back_sprite,name,bio,type1,CreatureType.NONE,base_hp,base_atk,base_def,base_spd,base_spc,moveset);
|
||||
this(mini_icon,sprite,back_sprite,name,bio,size, weight,type1,CreatureType.NONE,base_hp,base_atk,base_def,base_spd,base_spc,catch_rate,base_exp,exp_rate,moveset);
|
||||
}
|
||||
|
||||
public MegamonCreature(String mini_icon, String sprite, String back_sprite,
|
||||
String name, String bio, CreatureType type1, CreatureType type2, int base_hp, int base_atk, int base_def, int base_spd, int base_spc,
|
||||
String name, String bio, int size, float weight, CreatureType type1,
|
||||
CreatureType type2,
|
||||
int base_hp, int base_atk, int base_def, int base_spd, int base_spc,
|
||||
int catch_rate, int base_exp, ExperienceRate exp_rate,
|
||||
CreatureMove...moveset) {
|
||||
this.sprites = new SpriteCollection(mini_icon,sprite,back_sprite);
|
||||
this.name = name;
|
||||
this.bio = bio;
|
||||
this.bio = new CreatureLore(bio,size,weight);
|
||||
this.type1 = type1;
|
||||
this.type2 = type2;
|
||||
this.hp = base_hp;
|
||||
@ -41,6 +53,38 @@ public class MegamonCreature {
|
||||
this.def = base_def;
|
||||
this.spd = base_spd;
|
||||
this.spc = base_spc;
|
||||
this.catch_rate=catch_rate;
|
||||
this.base_exp=base_exp;
|
||||
this.exp_rate = exp_rate;
|
||||
this.moveset = new LinkedList(Arrays.asList(moveset));
|
||||
}
|
||||
|
||||
public void setSeen(boolean seenByPlayer) {
|
||||
this.seenByPlayer=seenByPlayer;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(this.getClass().getSimpleName()+"(");
|
||||
boolean first=true;
|
||||
for (Field f : this.getClass().getDeclaredFields()) {
|
||||
try {
|
||||
if (!first) {
|
||||
sb.append(",");
|
||||
} else {
|
||||
first=false;
|
||||
}
|
||||
sb.append(f.getName()+"="+this.getClass().getDeclaredField(f.getName()).get(this));
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
146
Megamon-core/src/sig/megamon/MegamonPet.java
Normal file
146
Megamon-core/src/sig/megamon/MegamonPet.java
Normal file
@ -0,0 +1,146 @@
|
||||
package sig.megamon;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import sig.megamon.creature.NonVolatileStatus;
|
||||
import sig.megamon.creature.VolatileStatus;
|
||||
|
||||
public class MegamonPet {
|
||||
MegamonCreature creature;
|
||||
NonVolatileStatus status;
|
||||
VolatileStatus battlestatus;
|
||||
Integer atk_modifier;
|
||||
Integer def_modifier;
|
||||
Integer spd_modifier;
|
||||
Integer spc_modifier;
|
||||
Integer eva_modifier;
|
||||
Integer acc_modifier;
|
||||
Integer atk_iv;
|
||||
Integer def_iv;
|
||||
Integer spd_iv;
|
||||
Integer spc_iv;
|
||||
Integer atk_ev;
|
||||
Integer def_ev;
|
||||
Integer spd_ev;
|
||||
Integer spc_ev;
|
||||
Integer hp_ev;
|
||||
Integer hp;
|
||||
Integer maxhp;
|
||||
Integer atk;
|
||||
Integer def;
|
||||
Integer spd;
|
||||
Integer spc;
|
||||
String nickname;
|
||||
Integer original_trainer;
|
||||
String original_trainer_name;
|
||||
Integer level;
|
||||
Integer hp_iv;
|
||||
|
||||
public MegamonPet(String nickname, MegamonCreature creature_type, Integer level) {
|
||||
this(nickname,creature_type,level,Megamon.mainP.trainer_id,Megamon.mainP.name);
|
||||
}
|
||||
|
||||
public MegamonPet(String nickname, MegamonCreature creature_type, Integer level,
|
||||
Integer original_trainer, String original_trainer_name) {
|
||||
this(nickname,creature_type,level,original_trainer,original_trainer_name,
|
||||
new Integer[]{}, new Integer[]{});
|
||||
}
|
||||
|
||||
public MegamonPet(String nickname, MegamonCreature creature_type, Integer level,
|
||||
Integer original_trainer, String original_trainer_name, Integer[] stats_collection,
|
||||
Integer...IV_EV_Collection) {
|
||||
this.creature = creature_type;
|
||||
if (nickname.length()>0) {
|
||||
this.nickname = nickname;
|
||||
} else {
|
||||
this.nickname = creature_type.name;
|
||||
}
|
||||
this.level = level;
|
||||
this.original_trainer = original_trainer;
|
||||
this.original_trainer_name = original_trainer_name;
|
||||
InitializeStats(stats_collection,IV_EV_Collection);
|
||||
}
|
||||
|
||||
private void InitializeStats(Integer[] stats_collection, Integer[] IV_EV_Collection) {
|
||||
/*if (stats_collection.length<6) {
|
||||
//System.out.println("WARNING! Malformed stats array! Will fill in with defaults.");
|
||||
}
|
||||
if (IV_EV_Collection.length<9) {
|
||||
//System.out.println("WARNING! Malformed IV_EV array! Will fill in with defaults.");
|
||||
}*/
|
||||
|
||||
int i=0;
|
||||
atk_iv = UseStatOrDefault(IV_EV_Collection,i++,(int)(Math.random()*16));
|
||||
def_iv = UseStatOrDefault(IV_EV_Collection,i++,(int)(Math.random()*16));
|
||||
spd_iv = UseStatOrDefault(IV_EV_Collection,i++,(int)(Math.random()*16));
|
||||
spc_iv = UseStatOrDefault(IV_EV_Collection,i++,(int)(Math.random()*16));
|
||||
hp_iv = CalculateHPIV();
|
||||
atk_ev = UseStatOrDefault(IV_EV_Collection,i++,0);
|
||||
def_ev = UseStatOrDefault(IV_EV_Collection,i++,0);
|
||||
spd_ev = UseStatOrDefault(IV_EV_Collection,i++,0);
|
||||
spc_ev = UseStatOrDefault(IV_EV_Collection,i++,0);
|
||||
hp_ev = UseStatOrDefault(IV_EV_Collection,i++,0);
|
||||
i=0;
|
||||
hp = UseStatOrDefault(stats_collection,i++,CalculateHealth(level));
|
||||
maxhp = UseStatOrDefault(stats_collection,i++,CalculateHealth(level));
|
||||
atk = UseStatOrDefault(stats_collection,i++,CalculateStat(level,creature.atk,atk_iv,atk_ev));
|
||||
def = UseStatOrDefault(stats_collection,i++,CalculateStat(level,creature.def,def_iv,def_ev));
|
||||
spd = UseStatOrDefault(stats_collection,i++,CalculateStat(level,creature.spd,spd_iv,spd_ev));
|
||||
spc = UseStatOrDefault(stats_collection,i++,CalculateStat(level,creature.spc,spc_iv,spc_ev));
|
||||
}
|
||||
|
||||
private boolean isOdd(Integer val) {
|
||||
return val % 2 == 0;
|
||||
}
|
||||
|
||||
private Integer CalculateHPIV() {
|
||||
int lsb_total = ((isOdd(atk_iv))?8:0)+
|
||||
((isOdd(def_iv))?4:0)+
|
||||
((isOdd(spd_iv))?2:0)+
|
||||
((isOdd(spc_iv))?1:0);
|
||||
return lsb_total;
|
||||
}
|
||||
|
||||
private Integer UseStatOrDefault(Integer[] stat_array, int index, int default_value) {
|
||||
if (stat_array.length>index) {
|
||||
return stat_array[index];
|
||||
} else {
|
||||
return default_value;
|
||||
}
|
||||
}
|
||||
|
||||
private int CalculateHealth(Integer lv) {
|
||||
return (int)(((((creature.hp+hp_iv)*2)+(Math.sqrt(hp_ev)/4))*lv)/100)+lv+10;
|
||||
}
|
||||
|
||||
private int CalculateStat(Integer lv, int base, Integer iv, Integer ev) {
|
||||
return (int)(((((base+iv)*2)+(Math.sqrt(ev)/4))*lv)/100)+5;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(this.getClass().getSimpleName()+"(");
|
||||
boolean first=true;
|
||||
for (Field f : this.getClass().getDeclaredFields()) {
|
||||
try {
|
||||
if (!first) {
|
||||
sb.append(",");
|
||||
} else {
|
||||
first=false;
|
||||
}
|
||||
sb.append(f.getName()+"="+this.getClass().getDeclaredField(f.getName()).get(this));
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
92
Megamon-core/src/sig/megamon/Player.java
Normal file
92
Megamon-core/src/sig/megamon/Player.java
Normal file
@ -0,0 +1,92 @@
|
||||
package sig.megamon;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Point2D.Double;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
|
||||
import sig.megamon.menu.DialogBox;
|
||||
import sig.megamon.ref.RoomRef;
|
||||
import sig.megamon.ref.SignRef;
|
||||
import sig.megamon.utils.GraphicUtils;
|
||||
import sig.megamon.utils.PlayerUtils;
|
||||
import sig.megamon.utils.TrainerUtils;
|
||||
|
||||
public class Player {
|
||||
|
||||
public Point2D.Double position = new Point2D.Double(1,1);
|
||||
Point2D.Double direction = new Point2D.Double(0,0);
|
||||
Point2D.Double lastdirection = new Point2D.Double(0,1);
|
||||
Texture sprite;
|
||||
List<MegamonPet> megamon_party = new ArrayList<MegamonPet>();
|
||||
int trainer_id;
|
||||
String name;
|
||||
|
||||
public Player(Point2D.Double position, String sprite) {
|
||||
this.position=position;
|
||||
this.sprite=new Texture(sprite);
|
||||
this.trainer_id = TrainerUtils.getRandomTrainerID();
|
||||
this.name = "Rob";
|
||||
}
|
||||
|
||||
public void run() {
|
||||
direction=new Point2D.Double(0, 0);
|
||||
if (Gdx.input.isKeyPressed(Megamon.MOVELEFTKEY)) {
|
||||
direction=lastdirection=new Point2D.Double(-Megamon.CHAR_SPD,0);
|
||||
} else
|
||||
if (Gdx.input.isKeyPressed(Megamon.MOVEUPKEY)) {
|
||||
direction=lastdirection=new Point2D.Double(0,Megamon.CHAR_SPD);
|
||||
} else
|
||||
if (Gdx.input.isKeyPressed(Megamon.MOVERIGHTKEY)) {
|
||||
direction=lastdirection=new Point2D.Double(Megamon.CHAR_SPD,0);
|
||||
} else
|
||||
if (Gdx.input.isKeyPressed(Megamon.MOVEDOWNKEY)) {
|
||||
direction=lastdirection=new Point2D.Double(0,-Megamon.CHAR_SPD);
|
||||
}
|
||||
Point2D.Double destinationposition = new Point2D.Double(position.x+Math.signum(lastdirection.x),position.y+Math.signum(lastdirection.y));
|
||||
if (Gdx.input.isKeyJustPressed(Megamon.ACTIONKEY)) {
|
||||
CheckForInfo(destinationposition);
|
||||
}
|
||||
if (direction.x!=0 || direction.y!=0) {
|
||||
//System.out.println("("+position.x+","+Math.signum(direction.x)+","+position.y+","+Math.signum(direction.y)+")");
|
||||
//Point2D.Double destinationposition = new Point2D.Double(position.x+Math.signum(direction.x),position.y+Math.signum(direction.y));
|
||||
if (PlayerUtils.isLocationPassable(Megamon.currentLevel.getMap(),destinationposition)) {
|
||||
position.setLocation(position.x+direction.x, position.y+direction.y);
|
||||
} else {
|
||||
//We hit a wall.
|
||||
}
|
||||
//System.out.println(Megamon.infoDatabase.keySet());
|
||||
CheckForDoor(destinationposition);
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckForDoor(Point2D.Double destinationposition) {
|
||||
if (Megamon.doorDatabase.containsKey(PlayerUtils.getDoorPositionHash(destinationposition))) {
|
||||
//System.out.println("This is a door!");
|
||||
RoomRef door = Megamon.doorDatabase.get(PlayerUtils.getDoorPositionHash(destinationposition));
|
||||
if (!door.destinationRoom.equalsIgnoreCase(Megamon.currentLevel.mapName)) {
|
||||
Megamon.currentLevel.destroy();
|
||||
Megamon.currentLevel = new Room(door.doorDestination,door.destinationRoom);
|
||||
} else {
|
||||
position.setLocation(door.doorDestination);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckForInfo(Point2D.Double destinationposition) {
|
||||
if (Megamon.infoDatabase.containsKey(PlayerUtils.getDoorPositionHash(destinationposition))) {
|
||||
//System.out.println("This is a door!");
|
||||
SignRef info = Megamon.infoDatabase.get(PlayerUtils.getDoorPositionHash(destinationposition));
|
||||
//TODO Do interface stuff here.
|
||||
Megamon.messagebox = new DialogBox(info.getMessages());
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(SpriteBatch batch) {
|
||||
batch.draw(sprite, (int)GraphicUtils.getPlayerPixelPosition(Megamon.camera).getX(), (int)GraphicUtils.getPlayerPixelPosition(Megamon.camera).getY(), (int)GraphicUtils.getTileSize(Megamon.camera).getX(), (int)GraphicUtils.getTileSize(Megamon.camera).getY());
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@ public class Room {
|
||||
*/
|
||||
public Room(Point2D.Double startingLoc, String mapFileRef) {
|
||||
this.startingLocation=startingLoc;
|
||||
Megamon.position.setLocation(startingLoc);
|
||||
Megamon.mainP.position.setLocation(startingLoc);
|
||||
this.map = new TmxMapLoader().load(MAPFOLDER+mapFileRef+".tmx");
|
||||
this.map.getLayers().get(Megamon.HIDDENLAYERNAME).setVisible(false);
|
||||
renderer = new OrthogonalTiledMapRenderer(this.map,1/(float)Megamon.TILESIZE);
|
||||
|
15
Megamon-core/src/sig/megamon/creature/CreatureLore.java
Normal file
15
Megamon-core/src/sig/megamon/creature/CreatureLore.java
Normal file
@ -0,0 +1,15 @@
|
||||
package sig.megamon.creature;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class CreatureLore {
|
||||
final String bio;
|
||||
final int size; //In inches.
|
||||
final float weight; //In lbs.
|
||||
|
||||
public CreatureLore(String bio, int size, float weight) {
|
||||
this.bio = bio;
|
||||
this.size = size;
|
||||
this.weight = weight;
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package sig.megamon.creature;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class CreatureMove {
|
||||
int lvLearned=0;
|
||||
String name="";
|
||||
@ -14,4 +16,29 @@ public class CreatureMove {
|
||||
this.type=type;
|
||||
this.cat=category;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(this.getClass().getSimpleName()+"(");
|
||||
boolean first=true;
|
||||
for (Field f : this.getClass().getDeclaredFields()) {
|
||||
try {
|
||||
if (!first) {
|
||||
sb.append(",");
|
||||
} else {
|
||||
first=false;
|
||||
}
|
||||
sb.append(f.getName()+"="+this.getClass().getDeclaredField(f.getName()).get(this));
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package sig.megamon.creature;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public enum CreatureType {
|
||||
NORMAL,
|
||||
FIRE,
|
||||
|
12
Megamon-core/src/sig/megamon/creature/ExperienceRate.java
Normal file
12
Megamon-core/src/sig/megamon/creature/ExperienceRate.java
Normal file
@ -0,0 +1,12 @@
|
||||
package sig.megamon.creature;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public enum ExperienceRate {
|
||||
ERRATIC,
|
||||
FAST,
|
||||
MEDIUM_FAST,
|
||||
MEDIUM_SLOW,
|
||||
SLOW,
|
||||
FLUCTUATING;
|
||||
}
|
18
Megamon-core/src/sig/megamon/creature/NonVolatileStatus.java
Normal file
18
Megamon-core/src/sig/megamon/creature/NonVolatileStatus.java
Normal file
@ -0,0 +1,18 @@
|
||||
package sig.megamon.creature;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public enum NonVolatileStatus {
|
||||
BURN("BRN"),
|
||||
FREEZE("FRZ"),
|
||||
PARALYSIS("BRN"),
|
||||
POISON("PSN"),
|
||||
BAD_POISON("PSN"),
|
||||
SLEEP("SLP");
|
||||
|
||||
String abbreviation;
|
||||
|
||||
NonVolatileStatus(String abbreviation) {
|
||||
this.abbreviation=abbreviation;
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package sig.megamon.creature;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
|
||||
/**
|
||||
@ -32,4 +34,29 @@ public class SpriteCollection {
|
||||
public Texture getBackSprite() {
|
||||
return back_sprite;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(this.getClass().getSimpleName()+"(");
|
||||
boolean first=true;
|
||||
for (Field f : this.getClass().getDeclaredFields()) {
|
||||
try {
|
||||
if (!first) {
|
||||
sb.append(",");
|
||||
} else {
|
||||
first=false;
|
||||
}
|
||||
sb.append(f.getName()+"="+this.getClass().getDeclaredField(f.getName()).get(this));
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
13
Megamon-core/src/sig/megamon/creature/VolatileStatus.java
Normal file
13
Megamon-core/src/sig/megamon/creature/VolatileStatus.java
Normal file
@ -0,0 +1,13 @@
|
||||
package sig.megamon.creature;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public enum VolatileStatus {
|
||||
BIND,
|
||||
NO_ESCAPE,
|
||||
CONFUSED,
|
||||
CURSE,
|
||||
FLINCH,
|
||||
LEECHED,
|
||||
;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package sig.megamon;
|
||||
package sig.megamon.menu;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -13,6 +13,7 @@ import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
|
||||
import sig.megamon.Megamon;
|
||||
import sig.megamon.utils.DrawUtils;
|
||||
|
||||
public class DialogBox {
|
||||
@ -34,7 +35,7 @@ public class DialogBox {
|
||||
public void run() {
|
||||
//TODO accept keyboard inputs for the dialog box.
|
||||
if (Gdx.input.isKeyJustPressed(Megamon.ACTIONKEY)) {
|
||||
System.out.println("Cursor is at position "+cursor+"/"+displayedMessage.length());
|
||||
//System.out.println("Cursor is at position "+cursor+"/"+displayedMessage.length());
|
||||
if (cursor==displayedMessage.length()) {
|
||||
if (cursor!=messageBody.length()) {
|
||||
displayedMessage="";
|
||||
@ -88,9 +89,9 @@ public class DialogBox {
|
||||
String subString=messageBody.substring(cursor, messageBody.length());
|
||||
//System.out.println("Substring is "+subString);
|
||||
for (int i=0;i<subString.length();i++) {
|
||||
System.out.println("Character at "+i+" is "+subString.charAt(i));
|
||||
//System.out.println("Character at "+i+" is "+subString.charAt(i));
|
||||
if (subString.charAt(i)==' ') {
|
||||
System.out.println("Found a space at position "+i);
|
||||
//System.out.println("Found a space at position "+i);
|
||||
return i;
|
||||
}
|
||||
}
|
59
Megamon-core/src/sig/megamon/menu/StartMenuBox.java
Normal file
59
Megamon-core/src/sig/megamon/menu/StartMenuBox.java
Normal file
@ -0,0 +1,59 @@
|
||||
package sig.megamon.menu;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
|
||||
import sig.megamon.Megamon;
|
||||
|
||||
public class StartMenuBox {
|
||||
static Texture startmenu_background = new Texture("startmenu_box_middle.png");
|
||||
static Texture startmenu_background_bottom = new Texture("startmenu_box_bottom.png");
|
||||
static Texture startmenu_background_top = new Texture("startmenu_box.png");
|
||||
static Texture startmenu_highlight = new Texture("startmenu_highlight.png");
|
||||
int selection=0;
|
||||
String[] menuitems = new String[]
|
||||
{"Megadex",
|
||||
"Megamon",
|
||||
"Bag",
|
||||
"<Trainer>",
|
||||
"Save",
|
||||
"Options",
|
||||
"Exit"};
|
||||
int menuitem_spacing = 28;
|
||||
|
||||
public StartMenuBox(int cursorStartingPosition) {
|
||||
this.selection=cursorStartingPosition;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
if (Gdx.input.isKeyJustPressed(Megamon.MOVEUPKEY)) {
|
||||
selection = Math.floorMod(selection-1, menuitems.length);
|
||||
}
|
||||
if (Gdx.input.isKeyJustPressed(Megamon.MOVEDOWNKEY)) {
|
||||
selection = Math.floorMod(selection+1, menuitems.length);
|
||||
}
|
||||
if (Gdx.input.isKeyJustPressed(Megamon.MENUKEY)) {
|
||||
Megamon.startmenubox=null;
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(SpriteBatch batch) {
|
||||
int windowx = Megamon.WINDOW_WIDTH-startmenu_background_top.getWidth();
|
||||
int windowy = Megamon.WINDOW_HEIGHT-startmenu_background_top.getHeight();
|
||||
int spacingpixels = menuitem_spacing*menuitems.length-startmenu_background_bottom.getHeight();
|
||||
int menubot = windowy-spacingpixels;
|
||||
batch.draw(startmenu_background_top, windowx,windowy);
|
||||
batch.draw(startmenu_background, windowx, windowy-spacingpixels, 0,0,startmenu_background.getWidth(),
|
||||
spacingpixels);
|
||||
batch.draw(startmenu_background_bottom, windowx,menubot-startmenu_background_bottom.getHeight());
|
||||
int i=0;
|
||||
for (String s : menuitems) {
|
||||
if (i==selection) {
|
||||
batch.draw(startmenu_highlight, windowx-4, windowy-((i+1)*menuitem_spacing)+8);
|
||||
}
|
||||
DialogBox.messageboxfont.draw(batch, s, windowx+28, windowy-(i++*menuitem_spacing));
|
||||
}
|
||||
Megamon.font.draw(batch, ">", windowx+8, windowy-(selection*menuitem_spacing)+8);
|
||||
}
|
||||
}
|
@ -12,11 +12,11 @@ public class ColorUtils {
|
||||
String r = hex.substring(1, 3);
|
||||
String g = hex.substring(3, 5);
|
||||
String b = hex.substring(5, 7);
|
||||
System.out.println("Colors: "+r+","+g+","+b);
|
||||
//System.out.println("Colors: "+r+","+g+","+b);
|
||||
float r_col = ConvertHexStringToDecimal(r);
|
||||
float g_col = ConvertHexStringToDecimal(g);
|
||||
float b_col = ConvertHexStringToDecimal(b);
|
||||
System.out.println("Colors: "+r_col+","+g_col+","+b_col);
|
||||
//System.out.println("Colors: "+r_col+","+g_col+","+b_col);
|
||||
return new Color(r_col/255,g_col/255,b_col/255,1);
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Camera;
|
||||
|
||||
import sig.megamon.Megamon;
|
||||
import sig.megamon.Player;
|
||||
|
||||
public class GraphicUtils {
|
||||
public static double getAspectRatio() {
|
||||
@ -24,7 +25,7 @@ public class GraphicUtils {
|
||||
}
|
||||
public static Point2D.Double getRelativePixelPositionFromPlayer(Camera camera,Point2D.Double position) {
|
||||
Point2D.Double pixelpos = getTileToPixel(camera,position);
|
||||
Point2D.Double playerpos = getTileToPixel(camera,Megamon.position);
|
||||
Point2D.Double playerpos = getTileToPixel(camera,Megamon.mainP.position);
|
||||
Point2D.Double playerpixelpos = getPlayerPixelPosition(camera);
|
||||
return new Point2D.Double(playerpixelpos.x+(pixelpos.x-playerpos.x), playerpixelpos.y+(pixelpos.y-playerpos.y));
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class PlayerUtils {
|
||||
public static String getDoorPositionHash(Point2D.Double position) {
|
||||
//position = getRoundedPosition(position);
|
||||
String hash = Megamon.currentLevel.getMapName()+"_"+(int)Math.round(position.getX())+","+(int)Math.round(position.getY());
|
||||
System.out.println("Getting hash "+hash);
|
||||
//System.out.println("Getting hash "+hash);
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
7
Megamon-core/src/sig/megamon/utils/TrainerUtils.java
Normal file
7
Megamon-core/src/sig/megamon/utils/TrainerUtils.java
Normal file
@ -0,0 +1,7 @@
|
||||
package sig.megamon.utils;
|
||||
|
||||
public class TrainerUtils {
|
||||
public static int getRandomTrainerID() {
|
||||
return (int)(Math.random()*1000000);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user