commit
f28cf8858c
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* 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.dungeoncrawler.view;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jonathan
|
||||||
|
*/
|
||||||
|
public class AnimatedObject {
|
||||||
|
private Sprite sprite;
|
||||||
|
private TextureRegion[][] texture;
|
||||||
|
private int frame;
|
||||||
|
private int row;
|
||||||
|
|
||||||
|
public AnimatedObject(Texture tx, int tileWidth, int tileHeight){
|
||||||
|
texture = TextureRegion.split(tx, tileWidth, tileHeight);
|
||||||
|
|
||||||
|
frame = (int) (Math.random()*texture[0].length);
|
||||||
|
row = (int) (Math.random()*texture.length);
|
||||||
|
|
||||||
|
sprite = new Sprite(texture[row][frame]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateTexture(){
|
||||||
|
if(frame >= texture[0].length - 1){
|
||||||
|
frame = 0;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
frame++;
|
||||||
|
}
|
||||||
|
|
||||||
|
sprite.setRegion(texture[row][frame]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the sprite
|
||||||
|
*/
|
||||||
|
public Sprite getSprite() {
|
||||||
|
return sprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param sprite the sprite to set
|
||||||
|
*/
|
||||||
|
public void setSprite(Sprite sprite) {
|
||||||
|
this.sprite = sprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the texture
|
||||||
|
*/
|
||||||
|
public TextureRegion[][] getTexture() {
|
||||||
|
return texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param texture the texture to set
|
||||||
|
*/
|
||||||
|
public void setTexture(TextureRegion[][] texture) {
|
||||||
|
this.texture = texture;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* 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.dungeoncrawler.view;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.maps.tiled.TiledMap;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jonathan
|
||||||
|
*/
|
||||||
|
public class MapContainer {
|
||||||
|
private TiledMap map;
|
||||||
|
private ArrayList<AnimatedObject> objects;
|
||||||
|
|
||||||
|
public MapContainer(TiledMap map){
|
||||||
|
this.map = map;
|
||||||
|
this.objects = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the map
|
||||||
|
*/
|
||||||
|
public TiledMap getMap() {
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param map the map to set
|
||||||
|
*/
|
||||||
|
public void setMap(TiledMap map) {
|
||||||
|
this.map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the objects
|
||||||
|
*/
|
||||||
|
public ArrayList<AnimatedObject> getObjects() {
|
||||||
|
return objects;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param objects the objects to set
|
||||||
|
*/
|
||||||
|
public void setObjects(ArrayList<AnimatedObject> objects) {
|
||||||
|
this.objects = objects;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in new issue