diff --git a/src/core/assets/area/demo.txt b/src/core/assets/area/demo.txt index d2fb9a7..c02a5e4 100644 --- a/src/core/assets/area/demo.txt +++ b/src/core/assets/area/demo.txt @@ -34,5 +34,6 @@ 5 8 2 5 7 2 5 6 2 -0 +1 +8 8 2 8 7 100 10 1 diff --git a/src/core/assets/img/entities.txt b/src/core/assets/img/entities.txt index ea0a9d1..5c16d60 100644 --- a/src/core/assets/img/entities.txt +++ b/src/core/assets/img/entities.txt @@ -1,2 +1,3 @@ -1 +2 1 img/player.png +2 img/player.png diff --git a/src/core/src/cs383/team1/Main.java b/src/core/src/cs383/team1/Main.java index 7010d0f..f69d92c 100644 --- a/src/core/src/cs383/team1/Main.java +++ b/src/core/src/cs383/team1/Main.java @@ -5,6 +5,7 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.InputProcessor; +import cs383.team1.input.DialogueBox; import cs383.team1.input.InputManager; import cs383.team1.model.GameManager; import cs383.team1.render.DemoDisplay; @@ -13,6 +14,7 @@ public class Main implements ApplicationListener, InputProcessor { public InputManager inputManager; public GameManager gm; public DemoDisplay screen; + public DialogueBox textBox; @Override public void create () { @@ -21,13 +23,15 @@ public void create () { Gdx.input.setInputProcessor(this); inputManager = new InputManager(); + textBox = new DialogueBox(); Gdx.app.debug("Main:create", "instantiating GameManager"); gm = GameManager.instance; Gdx.app.debug("Main:create", "instantiating DemoDisplay"); - screen = new DemoDisplay(); - } + //screen = new DemoDisplay(textBox); + screen = new DemoDisplay(); + } @Override public void dispose() { @@ -39,7 +43,7 @@ public void dispose() { public void render() { if(inputManager.consumable()) { Gdx.app.debug("Main:render", "Updating GameManager"); - gm.update(inputManager); + gm.update(inputManager, textBox); } screen.render(); @@ -71,6 +75,7 @@ public boolean keyUp (int key) { @Override public boolean keyTyped (char ch) { + return false; } diff --git a/src/core/src/cs383/team1/input/DialogueBox.java b/src/core/src/cs383/team1/input/DialogueBox.java new file mode 100644 index 0000000..a6c79aa --- /dev/null +++ b/src/core/src/cs383/team1/input/DialogueBox.java @@ -0,0 +1,55 @@ +/* DialogueBox.java + Creates TextArea based on user input + + */ +package cs383.team1.input; + +import com.badlogic.gdx.scenes.scene2d.ui.Skin; +import com.badlogic.gdx.scenes.scene2d.ui.TextArea; +import com.badlogic.gdx.scenes.scene2d.ui.TextButton; +import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; +import com.badlogic.gdx.scenes.scene2d.InputEvent; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.scenes.scene2d.ui.Label; +import java.lang.String; +import java.util.ArrayList; + +/** + * + * @author Casey + */ +public class DialogueBox { + Skin skin = new Skin(); + TextArea textBox; + public TextButton button; + String text; + public ArrayList messages; + Label textDisplay; + + public void DialogueBox(){ + textBox = new TextArea("", skin); + textBox = new TextArea("", skin); + button = new TextButton("Send", skin); + button.addListener(new ClickListener()); + messages = new ArrayList(); + text = new String(); + } + + public void clicked(InputEvent event, float x, float y){ + + if(textBox.getText().length() > 0){ + text = textBox.getText(); + } + messages.add(text); + textDisplay = new Label(messages.get(0), skin); + } + + public void removeMessage(){ + messages.remove(text); + } + + public boolean consumable(){ + return !messages.isEmpty(); + } + +} diff --git a/src/core/src/cs383/team1/model/GameManager.java b/src/core/src/cs383/team1/model/GameManager.java index 8a5321e..5a8d0fa 100644 --- a/src/core/src/cs383/team1/model/GameManager.java +++ b/src/core/src/cs383/team1/model/GameManager.java @@ -3,10 +3,12 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.Input.Keys; +import cs383.team1.input.DialogueBox; import cs383.team1.input.InputManager; import cs383.team1.model.State; import cs383.team1.model.StateManager; import cs383.team1.model.overworld.AreaManager; +import cs383.team1.model.overworld.NPC; import cs383.team1.model.overworld.Player; import cs383.team1.model.overworld.Position; import cs383.team1.model.overworld.Tile; @@ -49,13 +51,18 @@ public void load() { areas.current = index != -1 ? areas.areas.get(index) : null; } - public void update(InputManager in) { + public void update(InputManager in, DialogueBox textBox) { Player player; Position next; Tile target; - + NPC npc; player = areas.current.player; - + npc = (NPC) areas.current.entities.get(0); + npc.ai(areas.current); + + //while(textBox.consumable()){ + + //} while(in.consumable()) { switch(in.keys.remove(0)) { case Keys.LEFT: @@ -70,7 +77,7 @@ public void update(InputManager in) { case Keys.DOWN: next = new Position(player.pos.x, player.pos.y - 1); break; - default: + default: continue; } @@ -91,6 +98,8 @@ public void update(InputManager in) { player.pos = next; } } + + /* TODO: move the keyhandling code to the StateManager */ /* diff --git a/src/core/src/cs383/team1/model/overworld/Area.java b/src/core/src/cs383/team1/model/overworld/Area.java index 8e64e23..779e3ff 100644 --- a/src/core/src/cs383/team1/model/overworld/Area.java +++ b/src/core/src/cs383/team1/model/overworld/Area.java @@ -10,6 +10,7 @@ public class Area { public List tiles; public List entities; public Player player; + public Area() { this(new ArrayList(), new ArrayList(), new Player()); @@ -20,5 +21,6 @@ public Area(List tileList, List entityList, Player p) { tiles = tileList; entities = entityList; player = p; + } } diff --git a/src/core/src/cs383/team1/model/overworld/AreaManager.java b/src/core/src/cs383/team1/model/overworld/AreaManager.java index 831f80d..71943fd 100644 --- a/src/core/src/cs383/team1/model/overworld/AreaManager.java +++ b/src/core/src/cs383/team1/model/overworld/AreaManager.java @@ -99,12 +99,16 @@ public Area loadArea(String fname) { type = Integer.parseInt(vals[i + 2]); pos = new Position(x, y); - + switch(type) { case DemoEntity.TYPE: Gdx.app.debug("AreaManager:loadArea", "Loading DemoEntity"); entities.add(new DemoEntity(pos)); break; + case NPC.TYPE: + Gdx.app.debug("AreaManager:loadArea", "Loading NPC"); + entities.add(new NPC(pos)); + break; default: Gdx.app.error("AreaManager:loadArea", "invalid entity type " + vals[i + 2]); diff --git a/src/core/src/cs383/team1/model/overworld/NPC.java b/src/core/src/cs383/team1/model/overworld/NPC.java new file mode 100644 index 0000000..f0d97d0 --- /dev/null +++ b/src/core/src/cs383/team1/model/overworld/NPC.java @@ -0,0 +1,86 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package cs383.team1.model.overworld; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input; +import cs383.team1.model.overworld.Entity; +import cs383.team1.model.overworld.Position; +import cs383.team1.model.overworld.Tile; +import java.util.Random; + +public final class NPC implements Entity { + public static final int TYPE = 2; + public Position pos; + Position next; + Tile target; + + public int hp; + public int mp; + public int ap; + + + public NPC() { + //this(new Position(0, 0), 0, 0, 0); + this(new Position(0, 0)); + } + + + public NPC(Position p) { + Gdx.app.debug("Player:Player", "instantiating class"); + pos = p; + } + + public int type() { + return TYPE; + } + + public Position pos() { + return pos; + } + + public void ai(Area area) { + Random randomDirection = new Random(); + int randomint = randomDirection.nextInt(4); + System.out.println("Printing random direction: " + randomint); + switch(randomint) { + case 0: + //Move Left + next = new Position(pos.x - 1, pos.y); + break; + case 1: + //Move right + next = new Position(pos.x + 1, pos.y); + break; + case 2: + //Move up + next = new Position(pos.x, pos.y + 1); + break; + case 3: + //Move down + next = new Position(pos.x, pos.y - 1); + break; + + } + + target = null; + for(Tile t : area.tiles) { + if(t.pos().x == next.x && t.pos().y == next.y) { + target = t; + break; + } + } + + if(target == null) { + Gdx.app.error("GameManager:update", "invalid move"); + + } + + if(target.passable()) { + pos = next; + } + } +} \ No newline at end of file diff --git a/src/core/src/cs383/team1/render/DemoDisplay.java b/src/core/src/cs383/team1/render/DemoDisplay.java index 3f7d32f..f21b16f 100644 --- a/src/core/src/cs383/team1/render/DemoDisplay.java +++ b/src/core/src/cs383/team1/render/DemoDisplay.java @@ -6,14 +6,19 @@ import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.scenes.scene2d.ui.Label; +import com.badlogic.gdx.scenes.scene2d.ui.Skin; +import com.badlogic.gdx.scenes.scene2d.ui.Table; import cs383.team1.model.GameManager; import cs383.team1.model.overworld.Entity; import cs383.team1.model.overworld.Tile; import cs383.team1.model.overworld.DemoEntity; import cs383.team1.model.overworld.Player; import cs383.team1.render.Display; +import cs383.team1.input.DialogueBox; public class DemoDisplay extends Display { private static final String FNAME = "img/demo.png"; @@ -24,7 +29,11 @@ public class DemoDisplay extends Display { private Map tileTextures; private Map entitySprites; private Map entityTextures; - + private Table table; + Skin skin; + Label dialogue; + DialogueBox chatBox; + private Texture getTileTexture(int i) { String fname; @@ -133,6 +142,11 @@ public DemoDisplay() { tileTextures = new HashMap(); entitySprites = new HashMap(); entityTextures = new HashMap(); + table = new Table(); + skin = new Skin(); + //dialogue = new Label(textBox.messages.get(0), skin); + //chatBox = textBox; + loadSpriteMaps(); } @@ -178,7 +192,12 @@ public void render() { sprite.setPosition(player.pos().x * Tile.WIDTH, (player.pos().y * Tile.HEIGHT) + (int) (0.33 * Tile.HEIGHT)); sprite.draw(batch); + + //Draw dialogue text on to screen + //table.add(dialogue).padBottom(40).row(); + //table.add(chatBox.button).size(150,60).padBottom(20).row(); + batch.end(); } }