GammelJAN 5 years ago
commit 2bdf196687

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="30" height="40" tilewidth="32" tileheight="32" infinite="0" nextlayerid="10" nextobjectid="44">
<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="30" height="40" tilewidth="32" tileheight="32" infinite="0" nextlayerid="10" nextobjectid="45">
<tileset firstgid="1" source="terrain.tsx"/>
<tileset firstgid="2049" source="bazaar.tsx"/>
<tileset firstgid="2089" source="tileset.tsx"/>
@ -290,7 +290,14 @@
</properties>
</object>
</objectgroup>
<objectgroup id="8" name="InteractionObjects"/>
<objectgroup id="8" name="InteractionObjects">
<object id="44" x="352" y="288" width="32" height="32">
<properties>
<property name="id" type="int" value="0"/>
<property name="texture" value="sign.png"/>
</properties>
</object>
</objectgroup>
<objectgroup id="9" name="NpcRects">
<object id="42" x="416" y="512" width="128" height="96">
<properties>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1022 B

@ -11,7 +11,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion;
*/
public class AnimatedSprite {
private final static int[] ROWLENGTHS = {7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 6, 6, 12, 12, 12, 12, 6};
private int[] rowlengths = {7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 6, 6, 12, 12, 12, 12, 6};
private Sprite sprite;
private TextureRegion[][] texture;
@ -19,13 +19,20 @@ public class AnimatedSprite {
private int row;
private float delta;
public AnimatedSprite(Texture tx, int tileWidth, int tileHeight){
public AnimatedSprite(Texture tx, int tileWidth, int tileHeight, boolean isPlayer){
texture = TextureRegion.split(tx, tileWidth, tileHeight);
sprite = new Sprite();
row = (int) (Math.random()*texture.length);
frame = (int) (Math.random()*texture[row].length);
if(!isPlayer) {
rowlengths = new int[tx.getHeight() / tileHeight];
for(int i = 0; i < rowlengths.length; i++) {
rowlengths[i] = texture[i].length;
}
}
sprite = new Sprite(texture[getRow()][getFrame()]);
}
@ -34,7 +41,7 @@ public class AnimatedSprite {
if(this.delta >= 0.1f) {
this.delta = 0;
if(getFrame() >= ROWLENGTHS[getRow()] - 1){
if(getFrame() >= rowlengths[getRow()] - 1){
setFrame(0);
}
else{

@ -0,0 +1,104 @@
package com.trs.main;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Actor;
public class InteractionObject extends Actor{
Textbox t;
Rectangle collisionRect;
private AnimatedSprite animatedSprite;
boolean currentlyTalking;
DialogueParser parser;
int id;
public InteractionObject(Rectangle collisionRect, float xPos, float yPos, int id, String texture){
setName("interactive");
this.id = id;
Texture t = new Texture(Gdx.files.internal(texture));
currentlyTalking = false;
animatedSprite = new AnimatedSprite(t, 32, 32, false);
animatedSprite.setRow(0);
this.collisionRect = collisionRect;
parser = new DialogueParser("npcs/1/dialogue/test.txt");
Dialogue nextDialogue = parser.firstDialogue();
this.t = new Textbox(nextDialogue.question, nextDialogue.ans, getX()+getWidth()/2, getY()+getHeight()/2);
setBounds(xPos, yPos, animatedSprite.getSprite().getWidth(), animatedSprite.getSprite().getHeight());
}
public void startDialogue(float xPos, float yPos) {
currentlyTalking = true;
getStage().addActor(new Textbox(t, xPos, yPos));
}
@Override
protected void positionChanged() {
animatedSprite.setSpritePosition((int)getX(), (int)getY());
collisionRect = new Rectangle(getX() + 16, getY(), 32, 48);
super.positionChanged();
}
@Override
public void act(float delta) {
if(Main.gamestate == 1 && currentlyTalking) {
if(currentlyTalking) {
for(Actor a : getStage().getActors().toArray(Actor.class)) {
if(a instanceof Textbox) {
if(((Textbox) a).getState() == 2) {
int answer = ((Textbox) a).getSelectedAsw();
Dialogue newDialogue = parser.nextDialogue(answer + 1);
if(newDialogue == null) {
currentlyTalking = false;
parser = new DialogueParser("npcs/1/dialogue/test.txt");
System.out.println("asdfasdf");
}
else {
((Textbox)a).update(newDialogue);
System.out.println("update nicencie");
}
}
}
}
}
}
animatedSprite.updateAnimation(delta);
}
@Override
public void draw(Batch batch, float parentAlpha) {
animatedSprite.draw(batch);
super.draw(batch, parentAlpha); //To change body of generated methods, choose Tools | Templates.
}
public boolean collidingWithMapCollisionObject(){
boolean value = false;
for(Actor a : getStage().getActors()){
if(a.getName().equals("mapobject")){
//Rectangle p = new Rectangle(getX(), getY(), getWidth(), getHeight());
Rectangle o = new Rectangle(a.getX(), a.getY(), a.getWidth(), a.getHeight());
if(Intersector.overlaps(collisionRect, o)){
value = true;
break;
}
}
}
return value;
}
public Textbox getTextbox(){
return t;
}
}

@ -40,13 +40,13 @@ public class MapContainer {
Stage stage;
OrthographicCamera camera;
TmxMapLoader maploader;
TiledMap map;
OrthogonalTiledMapRenderer renderer;
TiledMap map;
OrthogonalTiledMapRenderer renderer;
Door[] doors;
public Door collidingDoor;
final int[] layersBelowPlayer = {0, 1, 2};
final int[] layersAbovePlayer = {3, 4};
final int[] layersBelowPlayer = {0, 1, 2};
final int[] layersAbovePlayer = {3, 4};
// TODO: Value which shows from which door the player is coming?
public MapContainer(float CAMERA_WIDTH, float CAMERA_HEIGHT, Player p, String mapString, int inDoor) {
@ -96,6 +96,18 @@ public class MapContainer {
stage.addActor(new MovingNpc(rect, rect.getX() + (float)(Math.random()*rect.getWidth()), rect.getY()+(float)(Math.random()*rect.getHeight()), id));
}
// adding the InteractionObjects
for(MapObject object : map.getLayers().get(7).getObjects().getByType(RectangleMapObject.class)){
Rectangle rect = ((RectangleMapObject) object).getRectangle();
MapProperties props = object.getProperties();
int id = props.get("id", Integer.class);
String texture = props.get("texture", String.class);
stage.addActor(new InteractionObject(rect, rect.getX(), rect.getY(), id, texture));
stage.addActor(new MapCollisionObject((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height));
}
doors = new Door[tempDoors.size()];
for(int i = 0; i < doors.length; i++) {
doors[i] = tempDoors.get(i);

@ -44,7 +44,7 @@ public class MovingNpc extends Actor{
currentlyTalking = false;
animatedSprite = new AnimatedSprite(t, 64, 64);
animatedSprite = new AnimatedSprite(t, 64, 64, true);
animatedSprite.setRow(0);
collisionRect = new Rectangle(xPos + 16, yPos, 32, 48);
this.area = area;

@ -35,9 +35,9 @@ public class Player extends Actor{
public Player(int xPos, int yPos){
setName("player");
t = new Texture(Gdx.files.internal("player.png"));
playerSprite = new AnimatedSprite(t, 64, 64);
playerSprite = new AnimatedSprite(t, 64, 64, true);
playerSprite.setRow(0);
collisionRect = new Rectangle(xPos + 16, yPos, 32, 48);
collisionRect = new Rectangle(xPos + 16, yPos, 32, 16);
setBounds(xPos, yPos, playerSprite.getSprite().getWidth(), playerSprite.getSprite().getHeight());
}
@ -82,11 +82,20 @@ public class Player extends Actor{
}
if(Gdx.input.isKeyJustPressed(Input.Keys.E)) {
Actor a = collidingActor();
if(a != null && a instanceof MovingNpc){
Main.gamestate = 1;
((MovingNpc)a).startDialogue(getX()+32, getY()+32);
movementX = 0;
movementY = 0;
if(a != null) {
if(a instanceof MovingNpc){
Main.gamestate = 1;
((MovingNpc)a).startDialogue(getX()+32, getY()+32);
movementX = 0;
movementY = 0;
}
else if(a instanceof InteractionObject) {
System.out.println("kfdjfkdjfladjflajdfjadlfj");
Main.gamestate = 1;
((InteractionObject)a).startDialogue(getX()+32, getY()+32);
movementX = 0;
movementY = 0;
}
}
}
}
@ -153,7 +162,7 @@ public class Player extends Actor{
public boolean collidingWithMapCollisionObject(){
boolean value = false;
for(Actor a : getStage().getActors()){
if(a.getName().equals("mapobject")){
if(a instanceof MapCollisionObject){
//Rectangle p = new Rectangle(getX(), getY(), getWidth(), getHeight());
Rectangle o = new Rectangle(a.getX(), a.getY(), a.getWidth(), a.getHeight());
if(Intersector.overlaps(collisionRect, o)){
@ -195,7 +204,7 @@ public class Player extends Actor{
public Actor collidingActor(){
for(Actor a : getStage().getActors()){
if(a.getName().equals("npc")){
if(a instanceof InteractionObject || a instanceof MovingNpc){
Rectangle p = new Rectangle(getX(), getY(), getWidth(), getHeight());
Rectangle npc = new Rectangle(a.getX(), a.getY(), a.getWidth(), a.getHeight());
if(Intersector.overlaps(p, npc)){

Loading…
Cancel
Save