Почему мой игрок проваливается на плиточной карте? - PullRequest
0 голосов
/ 14 января 2020

Я задыхаюсь. У меня есть эта игра очень скоро. Я сделал свой плеер таким образом, чтобы он не проваливался или не проходил сквозь плитки Tiled, у которых свойство «заблокировано». Я не знаю почему, но это не работает. Это продолжает проваливаться. Пожалуйста, помогите мне. Я остро нуждаюсь. Ты моя единственная надежда.

Вот код моего игрока. Обнаружение столкновения на этом. пакет net .hasanbilal.prisonrevelations.entities;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell;
import com.badlogic.gdx.math.Vector2;

public class Player extends Sprite implements InputProcessor {

    /** 
     * x and y velocity
     */
    private Vector2 velocity = new Vector2();

    //Speed is gravity times 2, meaning that the characters reach terminal velocity at 2 seconds
    private float speed = 19.6f;
    private float gravity = 9.8f;

    private boolean canJump;

    private TiledMapTileLayer cLayer;
    private String blockedKey = "blocked";

    public Player(Sprite s, TiledMapTileLayer cLayer) {
        super(s);
        this.cLayer = cLayer;
    }

    public void draw(SpriteBatch sb) {
        update(Gdx.graphics.getDeltaTime());
        super.draw(sb);

    }
    public void update(float delta) {
        velocity.y -= gravity * delta; //gravity to player


        //Terminal Velocity and Falling

        if(velocity.y > speed)
            velocity.y = speed;
        else if(velocity.y < speed)
            velocity.y = -speed;

        //saves old position for collision detection
        float preX = getX();
        float preY = getY();
        boolean collideX = false;
        boolean collideY = false;
        float tWidth = cLayer.getTileWidth();
        float tHeight = cLayer.getTileHeight();

        setX(getX() + velocity.x * delta);

        if (velocity.x < 0) {

            collideX = collidesLeft();

        } else if (velocity.x > 0) {

            collideX = collidesRight();

        }

        if (collideX) {
            setX(preX);
            velocity.x = 0;
        }




        setY(getY() + velocity.y * delta);



        if (velocity.y < 0) {

            canJump = collideY = collidesBottom();

        } else if (velocity.y > 0) {

            collideY = collidesTop();

        }

        if (collideY) {
            setY(preY);
            velocity.y = 0;
        }
    }



    public Vector2 getVelocity() {
        return velocity;
    }

    public void setVelocity(Vector2 velocity) {
        this.velocity = velocity;
    }

    public float getSpeed() {
        return speed;
    }

    public void setSpeed(float speed) {
        this.speed = speed;
    }

    public float getGravity() {
        return gravity;
    }

    public void setGravity(float gravity) {
        this.gravity = gravity;
    }

    public TiledMapTileLayer getcLayer() {
        return cLayer;
    }

    public void setcLayer(TiledMapTileLayer cLayer) {
        this.cLayer = cLayer;
    }

    private boolean isCellBlocked(float x, float y) {
        Cell cell = cLayer.getCell((int) (x / cLayer.getTileWidth()), (int) (y / cLayer.getTileHeight()));
        return cell != null && cell.getTile() != null && cell.getTile().getProperties().containsKey(blockedKey);
    }

    public boolean collidesRight() {
        for(float step = 0; step < getHeight(); step += cLayer.getTileHeight() / 2)
            if(isCellBlocked(getX() + getWidth(), getY() + step))
                return true;
        return false;
    }

    public boolean collidesLeft() {
        for(float step = 0; step < getHeight(); step += cLayer.getTileHeight() / 2)
            if(isCellBlocked(getX(), getY() + step))
                return true;
        return false;
    }

    public boolean collidesTop() {
        for(float step = 0; step < getWidth(); step += cLayer.getTileWidth() / 2)
            if(isCellBlocked(getX() + step, getY() + getHeight()))
                return true;
        return false;

    }

    public boolean collidesBottom() {
        for(float step = 0; step < getWidth(); step += cLayer.getTileWidth() / 2)
            if(isCellBlocked(getX() + step, getY()))
                return true;
        return false;
    }

    @Override
    public boolean keyDown(int arg0) {
        // TODO Auto-generated method stub
        return true;
    }

    @Override
    public boolean keyTyped(char arg0) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean keyUp(int arg0) {
        // TODO Auto-generated method stub
        return true;
    }

    @Override
    public boolean mouseMoved(int arg0, int arg1) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean scrolled(int arg0) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean touchDown(int arg0, int arg1, int arg2, int arg3) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean touchDragged(int arg0, int arg1, int arg2) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean touchUp(int arg0, int arg1, int arg2, int arg3) {
        // TODO Auto-generated method stub
        return false;
    }


}

Вот код для мозаичной карты. Это были все значения и свойства плитки.

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.2" tiledversion="1.3.1" orientation="orthogonal" renderorder="right-down" compressionlevel="0" width="62" height="37" tilewidth="16" tileheight="16" infinite="0" nextlayerid="3" nextobjectid="1">
 <tileset firstgid="1" name="newTileSet" tilewidth="16" tileheight="16" tilecount="5" columns="10">
  <image source="newTileSet.png" width="160" height="16"/>
  <tile id="0">
   <properties>
    <property name="blocked" value=""/>
   </properties>
  </tile>
  <tile id="1">
   <properties>
    <property name="blocked" value=""/>
   </properties>
  </tile>
  <tile id="5">
   <properties>
    <property name="blocked" value=""/>
   </properties>
  </tile>
  <tile id="7">
   <properties>
    <property name="blocked" value=""/>
   </properties>
  </tile>
  <tile id="8">
   <properties>
    <property name="blocked" value=""/>
   </properties>
  </tile>
 </tileset>
 <layer id="2" name="Tile Layer 2" width="62" height="37">
  <data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0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7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
6,6,7,7,7,7,7,7,7,7,7,7,7,7,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,6,8,8,8,8,8,8,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
6,6,7,7,7,7,7,7,7,7,7,7,7,7,6,6,6,7,9,9,7,7,7,7,7,7,7,7,7,7,7,6,6,7,7,7,7,7,7,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
6,6,7,7,7,7,7,7,7,7,6,6,7,7,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,6,6,2,2,2,2,2,2,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
6,6,6,6,6,7,7,7,7,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,4,4,6,6,6,6,6,6,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
 </layer>
</map>

Вот код для набора плиток. Даже не уверен, что мне это нужно, потому что .tmx говорит, что он использует png, а не tsx.

<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.2" tiledversion="1.3.1" name="newTileSet" tilewidth="16" tileheight="16" tilecount="10" columns="10">
 <image source="newTileSet.png" width="160" height="16"/>
 <tile id="0">
  <properties>
   <property name="blocked" value=""/>
  </properties>
 </tile>
 <tile id="1">
  <properties>
   <property name="blocked" value=""/>
  </properties>
 </tile>
 <tile id="5">
  <properties>
   <property name="blocked" value=""/>
  </properties>
 </tile>
 <tile id="7">
  <properties>
   <property name="blocked" value=""/>
  </properties>
 </tile>
 <tile id="8">
  <properties>
   <property name="blocked" value=""/>
  </properties>
 </tile>
</tileset>

Пожалуйста, помогите мне. Я сделаю что угодно.

1 Ответ

0 голосов
/ 14 января 2020

Вероятно, это не должно помочь в проблеме коллизий, но у вас есть проблема здесь:

  if(velocity.y > speed)
        velocity.y = speed;
    else if(velocity.y < speed) // should be -speed
        velocity.y = -speed

Каждая итерация velocity.y < speed истинна, потому что velocity.y < 0 и speed > 0

...