map has doorlayere with id - npc class added

master
GammelJAN 5 years ago
parent 9deb603a79
commit 62d7318cda

@ -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="10" height="10" tilewidth="32" tileheight="32" infinite="0" nextlayerid="4" nextobjectid="9">
<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="10" height="10" tilewidth="32" tileheight="32" infinite="0" nextlayerid="5" nextobjectid="10">
<tileset firstgid="1" source="nice2.tsx"/>
<layer id="1" name="Kachelebene 1" width="10" height="10">
<data encoding="csv">
@ -18,11 +18,11 @@
<layer id="2" name="Kachelebene 2" width="10" height="10">
<data encoding="csv">
137,221,221,221,221,221,221,222,260,261,
201,0,236,237,233,0,0,0,281,178,
201,0,236,233,232,232,0,0,0,199,
201,0,233,178,179,180,0,0,0,199,
201,0,234,199,200,201,0,0,0,199,
201,0,0,220,221,222,236,234,0,199,
201,257,258,237,233,0,0,0,281,178,
201,278,279,233,232,232,0,0,0,199,
201,0,233,0,0,0,0,0,0,199,
201,0,0,0,0,0,0,0,0,199,
201,0,0,0,0,0,236,234,0,199,
201,0,0,0,233,235,235,235,0,199,
201,0,0,0,0,237,232,235,0,199,
158,179,179,179,179,179,179,179,179,159,
@ -35,6 +35,12 @@
<object id="3" x="32" y="288" width="288" height="32"/>
<object id="4" x="288" y="64" width="32" height="224"/>
<object id="5" x="256" y="0" width="64" height="64"/>
<object id="6" x="96" y="128" width="96" height="64"/>
</objectgroup>
<objectgroup id="4" name="tuerebene">
<object id="9" x="32" y="32" width="64" height="64">
<properties>
<property name="id" type="int" value="0"/>
</properties>
</object>
</objectgroup>
</map>

@ -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="100" height="100" tilewidth="32" tileheight="32" infinite="0" nextlayerid="4" nextobjectid="38">
<map version="1.4" tiledversion="1.4.3" orientation="orthogonal" renderorder="right-down" width="100" height="100" tilewidth="32" tileheight="32" infinite="0" nextlayerid="5" nextobjectid="41">
<tileset firstgid="1" source="nice2.tsx"/>
<layer id="1" name="Kachelebene 1" width="100" height="100">
<data encoding="csv">
@ -88,8 +88,8 @@
237,237,235,233,232,236,237,234,232,235,237,232,234,234,234,235,236,237,234,236,233,236,236,232,234,233,234,232,235,232,235,232,233,236,235,236,236,234,232,232,232,237,235,236,237,233,235,232,233,236,234,234,235,233,232,235,232,233,232,235,235,236,232,233,232,236,237,235,237,237,237,232,232,234,232,234,236,232,235,232,234,237,235,237,235,234,235,233,236,234,236,232,233,234,235,236,237,235,235,235,
235,235,234,233,235,235,236,234,233,233,232,235,236,237,233,237,232,235,236,237,237,235,232,235,235,233,234,233,234,237,235,232,235,234,234,235,235,235,233,235,232,234,235,235,235,233,236,236,236,232,234,235,233,233,236,234,237,233,232,236,234,234,233,234,235,233,237,236,235,234,232,233,235,233,236,237,233,233,232,232,237,234,235,235,233,237,235,235,236,237,236,235,236,233,237,232,235,237,236,236,
236,237,235,235,232,234,237,233,232,235,232,233,237,237,235,232,236,232,236,236,235,233,235,233,232,235,232,237,236,236,237,232,233,235,232,237,234,237,236,234,235,237,237,234,236,236,232,237,233,233,237,237,233,233,236,233,232,235,232,232,232,232,233,235,233,236,234,233,233,237,237,232,236,234,233,234,233,237,237,232,232,236,237,236,234,237,233,232,237,236,232,235,233,232,237,233,234,233,232,234,
233,232,232,236,237,233,234,237,236,236,236,232,237,235,236,234,233,237,237,232,232,235,232,237,237,235,236,233,236,236,235,234,233,234,232,233,237,237,232,233,233,232,234,232,233,233,232,233,235,235,236,233,237,232,236,234,232,233,233,236,236,236,232,237,233,234,234,235,234,236,237,232,236,236,236,232,235,236,233,232,235,232,233,232,233,233,232,237,234,234,233,232,235,232,236,233,235,233,237,237,
232,233,236,237,237,234,237,234,236,235,234,237,234,232,232,233,236,236,232,234,233,234,237,237,233,237,233,233,235,233,232,234,234,233,234,232,235,234,235,234,234,236,236,237,233,234,232,233,232,235,236,234,237,234,237,232,232,237,233,235,237,235,233,235,236,232,232,235,236,234,232,232,235,237,234,232,233,232,235,233,232,232,236,235,235,232,237,235,232,236,232,234,235,234,236,232,235,236,234,234,
233,232,232,236,237,233,257,258,236,236,236,232,237,235,236,234,233,237,237,232,232,235,232,237,237,235,236,233,236,236,235,234,233,234,232,233,237,237,232,233,233,232,234,232,233,233,232,233,235,235,236,233,237,232,236,234,232,233,233,236,236,236,232,237,233,234,234,235,234,236,237,232,236,236,236,232,235,236,233,232,235,232,233,232,233,233,232,237,234,234,233,232,235,232,236,233,235,233,237,237,
232,233,236,237,237,234,278,279,236,235,234,237,234,232,232,233,236,236,232,234,233,234,237,237,233,237,233,233,235,233,232,234,234,233,234,232,235,234,235,234,234,236,236,237,233,234,232,233,232,235,236,234,237,234,237,232,232,237,233,235,237,235,233,235,236,232,232,235,236,234,232,232,235,237,234,232,233,232,235,233,232,232,236,235,235,232,237,235,232,236,232,234,235,234,236,232,235,236,234,234,
232,235,235,237,233,235,237,234,237,235,234,235,237,233,234,237,232,237,233,233,232,237,233,232,232,237,235,233,233,235,233,237,235,232,237,236,237,233,233,232,234,232,236,235,236,235,237,236,235,236,232,237,234,235,235,237,234,237,236,234,233,232,233,234,234,233,236,237,235,235,234,236,236,235,237,232,234,232,234,236,237,235,232,235,235,234,232,233,232,232,235,237,234,233,232,235,233,233,233,232,
236,236,234,236,237,234,233,237,233,235,235,233,235,234,234,237,232,235,233,235,232,236,234,236,234,233,232,237,235,234,237,232,234,234,237,237,234,232,235,234,236,237,234,233,236,232,235,235,234,236,236,232,235,236,232,237,235,234,236,236,235,234,234,234,236,234,232,234,233,232,234,236,237,235,232,234,236,236,236,237,234,233,233,237,236,236,232,235,235,232,235,234,237,237,233,232,236,234,233,233,
236,235,237,237,234,234,234,236,235,235,233,235,234,237,235,236,232,237,232,236,236,233,234,232,234,234,232,235,237,237,232,233,234,233,236,234,233,234,236,236,232,233,237,236,233,234,234,232,236,237,235,232,236,233,233,233,235,234,237,233,237,235,237,232,236,235,235,237,234,237,232,233,232,232,233,237,235,234,232,236,236,233,234,234,234,235,234,237,234,237,232,232,232,237,235,236,232,236,235,236,
@ -238,4 +238,11 @@
<object id="35" x="0" y="0" width="3200" height="64"/>
<object id="37" x="3136" y="0" width="64" height="3200"/>
</objectgroup>
<objectgroup id="4" name="tuerebene">
<object id="40" x="192" y="2720" width="64" height="64">
<properties>
<property name="id" type="int" value="0"/>
</properties>
</object>
</objectgroup>
</map>

@ -0,0 +1,124 @@
/*
* 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 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.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import static com.trs.main.Player.SQRT2;
/**
*
* @author Jan
*/
public class MovingNpc extends Actor{
public static final float SQRT2 = 1.414f;
Textbox t;
Rectangle area;
Rectangle collisionRect;
float speed;
private AnimatedSprite animatedSprite;
int facing;
float movementX;
float movementY;
Vector2 POI;
public MovingNpc(Rectangle area, float xPos, float yPos){
setName("npc");
Texture t = new Texture(Gdx.files.internal("player.png"));
animatedSprite = new AnimatedSprite(t, 64, 64);
animatedSprite.setRow(0);
collisionRect = new Rectangle(xPos + 16, yPos, 32, 48);
this.area = area;
speed = 2.5f;
setBounds(xPos, yPos, animatedSprite.getSprite().getWidth(), animatedSprite.getSprite().getHeight());
}
@Override
protected void positionChanged() {
animatedSprite.setSpritePosition((int)getX(), (int)getY());
collisionRect = new Rectangle(getX() + 16, getY(), 32, 48);
super.positionChanged(); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void act(float delta) {
if(POI == null || Math.random() < 0.05f){
POI = new Vector2(area.getX()+(float)Math.random() * (float)area.getWidth(), area.getY()+(float)Math.random()*(float)area.getHeight());
}
Vector2 movement = new Vector2(speed,0);
movement.setAngleRad((float)Math.atan((double)(POI.y-getY())/(double)(POI.x-getX())));
System.out.println(movement.angleDeg());
System.out.println(POI.x + " " + POI.y);
System.out.println();
movementX = movement.x;
movementY = movement.y;
if(movementX == 0 && movementY == 0){
}
else if(movementX == 0 && movementY != 0){
setY(getY()+movementY);
if(collidingWithMapCollisionObject()){
setY(getY()-movementY);
}
}
else if(movementY == 0 && movementX != 0){
setX(getX()+movementX);
if(collidingWithMapCollisionObject()){
setX(getX()-movementX);
}
}
else if(movementX != 0 && movementY != 0){
setX(getX()+ (movementX));
if(collidingWithMapCollisionObject()){
setX(getX() - (movementX));
}
setY(getY() + (movementY));
if(collidingWithMapCollisionObject()){
setY(getY()- (movementY));
}
}
int animationRow = 0;
if(movementX != 0 || movementY != 0) {
animationRow = 8;
}
animatedSprite.setRow(animationRow + facing);
animatedSprite.updateAnimation(delta);
movementX = 0;
movementY = 0;
}
@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;
}
}

@ -22,6 +22,7 @@ import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.trs.main.Main;
import com.trs.main.MapCollisionObject;
import com.trs.main.MovingNpc;
import com.trs.main.Player;
import com.trs.main.Textbox;
import java.util.ArrayList;
@ -42,6 +43,7 @@ public class GameScreen extends AbstractScreen{
public GameScreen(Game game, float CAMERA_WIDTH, float CAMERA_HEIGHT) {
super(game, CAMERA_WIDTH, CAMERA_HEIGHT);
stage.addActor(new Player(250,50));
stage.addActor(new MovingNpc(new Rectangle(20,20,400,400), 80, 80));
//setTextbox(new Textbox("How are you doing my friend How are you doing my friend How are you doing my friend How are you doing my friend", "good", "bad"));
maploader = new TmxMapLoader();

Loading…
Cancel
Save