parent
9c21970b79
commit
7cb1714247
After Width: | Height: | Size: 543 B |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 711 B |
After Width: | Height: | Size: 727 B |
After Width: | Height: | Size: 170 B |
After Width: | Height: | Size: 741 B |
@ -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(); |
||||||
|
} |
||||||
|
} |
@ -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()); |
||||||
|
} |
||||||
|
} |
@ -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; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,12 @@ |
|||||||
|
package sig.megamon.creature; |
||||||
|
|
||||||
|
import java.lang.reflect.Field; |
||||||
|
|
||||||
|
public enum ExperienceRate { |
||||||
|
ERRATIC, |
||||||
|
FAST, |
||||||
|
MEDIUM_FAST, |
||||||
|
MEDIUM_SLOW, |
||||||
|
SLOW, |
||||||
|
FLUCTUATING; |
||||||
|
} |
@ -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; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,13 @@ |
|||||||
|
package sig.megamon.creature; |
||||||
|
|
||||||
|
import java.lang.reflect.Field; |
||||||
|
|
||||||
|
public enum VolatileStatus { |
||||||
|
BIND, |
||||||
|
NO_ESCAPE, |
||||||
|
CONFUSED, |
||||||
|
CURSE, |
||||||
|
FLINCH, |
||||||
|
LEECHED, |
||||||
|
; |
||||||
|
} |
@ -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); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,7 @@ |
|||||||
|
package sig.megamon.utils; |
||||||
|
|
||||||
|
public class TrainerUtils { |
||||||
|
public static int getRandomTrainerID() { |
||||||
|
return (int)(Math.random()*1000000); |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue