Commit
…logue box
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,5 +34,6 @@ | |
5 8 2 | ||
5 7 2 | ||
5 6 2 | ||
0 | ||
1 | ||
8 8 2 | ||
8 7 100 10 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
1 | ||
2 | ||
1 img/player.png | ||
2 img/player.png |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> 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){ | ||
This comment has been minimized.
Sorry, something went wrong.
fabe0940
Member
|
||
|
||
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(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
This comment has been minimized.
Sorry, something went wrong.
fabe0940
Member
|
||
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 */ | ||
/* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
pos = p; | ||
} | ||
|
||
public int type() { | ||
return TYPE; | ||
} | ||
|
||
public Position pos() { | ||
return pos; | ||
} | ||
|
||
public void ai(Area area) { | ||
This comment has been minimized.
Sorry, something went wrong.
fabe0940
Member
|
||
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; | ||
} | ||
} | ||
} |
Maybe this should belong to a
Display
subclass? We're trying to keepMain
as thin as possible, and let the rest of the classes do most (all) of the heavy lifting. It's just a thought, but aDialogueBox
does not seem like a top level class nor does it seem like an independent one.