Raytracing funktioniert

master
Jonathan Hager 6 years ago
parent 991c60944f
commit db811c2de6

@ -143,6 +143,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor{
if(tileX == 0 || tileX == roomX || tileY == 0 || tileY == roomY){
updateRoom();
}
// Render methode zum rendern der einzelnen Sprites wird aufgerufen

@ -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;
}
}

@ -12,9 +12,11 @@ import com.badlogic.gdx.maps.tiled.TiledMap;
import com.badlogic.gdx.maps.tiled.TiledMapRenderer;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.utils.Timer;
import com.dungeoncrawler.model.Dungeon;
import com.dungeoncrawler.model.Entity;
import com.dungeoncrawler.model.entities.*;
import java.util.ArrayList;
public class GameScreen {
//CONTROLS
@ -44,6 +46,9 @@ public class GameScreen {
TiledMapRenderer tmr;
TiledMap tm;
OrthographicCamera camera;
ArrayList<AnimatedObject> objects;
Timer animations;
// Sound
public Music music;
@ -94,6 +99,18 @@ public class GameScreen {
music = Gdx.audio.newMusic(Gdx.files.internal("music/gamemusic.mp3"));
music.setVolume(volume);
music.play();
animations = new Timer();
animations.scheduleTask(new Timer.Task() {
@Override
public void run() {
if(objects != null){
for(AnimatedObject object : objects){
object.updateTexture();
}
}
}
},0, 0.1f);
}
@ -107,6 +124,7 @@ public class GameScreen {
player.setY(p.getyPos());
tm = getM().getMaps()[level][roomPosX][roomPosY].getMap();
objects = getM().getMaps()[level][roomPosX][roomPosY].getObjects();
if(tm == null){
System.out.println("Dein scheiß geht net");
@ -161,6 +179,10 @@ public class GameScreen {
//BATCH
batch.begin();
for(AnimatedObject object : objects){
object.getSprite().draw(batch);
}
player.draw(batch);
//controls.draw(batch);
//DRAW'T JEDES ENTITY - prueft vorher ob vorhanden
@ -227,6 +249,7 @@ public class GameScreen {
arrowSprites[i].draw(batch);
}
}
batch.end();
}

@ -5,9 +5,8 @@
*/
package com.dungeoncrawler.view;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.maps.tiled.TiledMap;
import java.util.ArrayList;
/**
*
@ -15,13 +14,11 @@ import com.badlogic.gdx.maps.tiled.TiledMap;
*/
public class MapContainer {
private TiledMap map;
private Sprite[] animatedObjects;
private TextureRegion[][][] textures;
private ArrayList<AnimatedObject> objects;
public MapContainer(TiledMap map, int objectAmount){
public MapContainer(TiledMap map){
this.map = map;
this.animatedObjects = new Sprite[objectAmount];
this.textures = new TextureRegion[objectAmount][][];
this.objects = new ArrayList<>();
}
/**
@ -39,40 +36,17 @@ public class MapContainer {
}
/**
* @return the animatedObjects
* @return the objects
*/
public Sprite[] getAnimatedObjects() {
return animatedObjects;
public ArrayList<AnimatedObject> getObjects() {
return objects;
}
/**
* @param animatedObjects the animatedObjects to set
* @param objects the objects to set
*/
public void setAnimatedObjects(Sprite[] animatedObjects) {
this.animatedObjects = animatedObjects;
public void setObjects(ArrayList<AnimatedObject> objects) {
this.objects = objects;
}
public void setAnimatedObjects(Sprite animatedObject, int i) {
this.animatedObjects[i] = animatedObject;
}
/**
* @return the textures
*/
public TextureRegion[][][] getTextures() {
return textures;
}
/**
* @param textures the textures to set
*/
public void setTextures(TextureRegion[][][] textures) {
this.textures = textures;
}
public void setTextures(TextureRegion[][] textures, int i) {
this.textures[i] = textures;
}
}

@ -26,13 +26,12 @@ public class MapGenerator {
Texture tiles;
TextureRegion[][] splitTiles;
Texture torchT;
TextureRegion[][] torch;
public MapGenerator(Texture tiles){
this.tiles = tiles;
splitTiles = TextureRegion.split(this.tiles, 48, 48);
torchT = new Texture("sprites/torch.png");
torch = TextureRegion.split(torchT, 48, 48);
//torch = TextureRegion.split(torchT, 48, 48);
}
public Map generateMap(Dungeon d){
@ -121,9 +120,13 @@ public class MapGenerator {
// X: Gesamtlänge, Y: Exakte Mitte der Gesamtlänge
staticLayer.getCell(tempX + 1, (tempY / 2) + 0).setTile(new StaticTiledMapTile(splitTiles[4][4])); //rechts-1
staticLayer.getCell(tempX + 1, (tempY / 2) + 1).setTile(new StaticTiledMapTile(splitTiles[0][0])); //rechts1
staticLayer.getCell(tempX + 1, (tempY / 2) + 2).setTile(new StaticTiledMapTile(splitTiles[3][1])); //rechts2
staticLayer.getCell(tempX + 1, (tempY / 2) + 3).setTile(new StaticTiledMapTile(splitTiles[2][1])); //rechts3
staticLayer.getCell(tempX + 1, (tempY / 2) + 2).setTile(new StaticTiledMapTile(splitTiles[1][1])); //rechts2
staticLayer.getCell(tempX + 1, (tempY / 2) + 3).setTile(new StaticTiledMapTile(splitTiles[0][1])); //rechts3
staticLayer.getCell(tempX + 1, (tempY / 2) + 4).setTile(new StaticTiledMapTile(splitTiles[2][5])); //rechts4
AnimatedObject tempObject = new AnimatedObject(torchT, 48, 48);
tempObject.getSprite().setPosition((tempX + 1) * 48, ((tempY / 2) + 2) * 48);
temp.getObjects().add(tempObject);
}
collisionLayer.getObjects().remove(right);
@ -167,9 +170,13 @@ public class MapGenerator {
// X: 0, Y: Exakte Mitte der Gesamtlänge
staticLayer.getCell(0, (tempY / 2) + 0).setTile(new StaticTiledMapTile(splitTiles[4][5])); //links-1
staticLayer.getCell(0, (tempY / 2) + 1).setTile(new StaticTiledMapTile(splitTiles[0][0])); //links1
staticLayer.getCell(0, (tempY / 2) + 2).setTile(new StaticTiledMapTile(splitTiles[3][1])); //links2
staticLayer.getCell(0, (tempY / 2) + 3).setTile(new StaticTiledMapTile(splitTiles[2][1])); //links3
staticLayer.getCell(0, (tempY / 2) + 2).setTile(new StaticTiledMapTile(splitTiles[1][1])); //links2
staticLayer.getCell(0, (tempY / 2) + 3).setTile(new StaticTiledMapTile(splitTiles[0][1])); //links3
staticLayer.getCell(0, (tempY / 2) + 4).setTile(new StaticTiledMapTile(splitTiles[3][5])); //links4
AnimatedObject tempObject = new AnimatedObject(torchT, 48, 48);
tempObject.getSprite().setPosition(0, ((tempY / 2) + 2) * 48);
temp.getObjects().add(tempObject);
}
collisionLayer.getObjects().remove(left);
@ -192,6 +199,8 @@ public class MapGenerator {
}
private MapContainer generateRoom(Room r, int roomDimensionX, int roomDimensionY, int lvl){
TiledMap tempRoom = new TiledMap();
MapContainer temp = new MapContainer(tempRoom);
int bodenX;
int bodenY;
@ -205,9 +214,6 @@ public class MapGenerator {
bodenY = lvl - 4;
}
MapContainer temp;
TiledMap tempRoom = new TiledMap();
// roomDimension bezieht sich auf die Größe des Raumes, da aber noch die Wände fehlen,
// muss auf die Größe jeweils 2 addiert werden.
int mapDimensionX = roomDimensionX + 2;
@ -258,20 +264,17 @@ public class MapGenerator {
// oben1
else if(y == mapDimensionY - 1){
if(x == roomDimensionX / 2 - 1 || x == roomDimensionX / 2 + 3){
cell.setTile(new StaticTiledMapTile(splitTiles[3][1]));
}
else{
cell.setTile(new StaticTiledMapTile(splitTiles[1][1]));
AnimatedObject tempObject = new AnimatedObject(torchT, 48, 48);
tempObject.getSprite().setPosition(x * 48, y * 48);
temp.getObjects().add(tempObject);
}
cell.setTile(new StaticTiledMapTile(splitTiles[1][1]));
}
// oben2
else if(y == mapDimensionY){
if(x == roomDimensionX / 2 - 1 || x == roomDimensionX / 2 + 3){
cell.setTile(new StaticTiledMapTile(splitTiles[2][1]));
}
else{
cell.setTile(new StaticTiledMapTile(splitTiles[0][1]));
}
cell.setTile(new StaticTiledMapTile(splitTiles[0][1]));
}
// oben3
else if(y == mapDimensionY + 1){
@ -308,7 +311,6 @@ public class MapGenerator {
layers.add(dynamicLayer);
layers.add(staticLayer);
temp = new MapContainer(tempRoom, 0);
return temp;
}

Loading…
Cancel
Save