mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
Fixed enemy spawning in structures
reduced segmented WaveFunctionCollapse calculation for better performance added flying to enemies
This commit is contained in:
@@ -56,8 +56,14 @@ public class CharacterSprite extends MapActor {
|
||||
anim = atlas.createSprites(stand.toString());
|
||||
else
|
||||
anim = atlas.createSprites(stand.toString() + dir.toString());
|
||||
|
||||
if (anim.size != 0) {
|
||||
dirs.put(dir, new Animation<>(0.2f, anim));
|
||||
if(getWidth()==0.0)//init size onload
|
||||
{
|
||||
setWidth(anim.first().getWidth());
|
||||
setHeight(anim.first().getHeight());
|
||||
}
|
||||
}
|
||||
}
|
||||
animations.put(stand, dirs);
|
||||
|
||||
@@ -55,9 +55,8 @@ public class MapActor extends Actor {
|
||||
}
|
||||
@Override
|
||||
protected void positionChanged() {
|
||||
|
||||
updateBoundingRect();
|
||||
super.positionChanged();
|
||||
updateBoundingRect();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,6 +15,7 @@ public class EnemyData {
|
||||
public boolean copyPlayerDeck = false;
|
||||
public String ai;
|
||||
public boolean boss = false;
|
||||
public boolean flying = false;
|
||||
public float spawnRate;
|
||||
public float difficulty;
|
||||
public float speed;
|
||||
@@ -30,6 +31,7 @@ public class EnemyData {
|
||||
deck = enemyData.deck;
|
||||
ai = enemyData.ai;
|
||||
boss = enemyData.boss;
|
||||
flying = enemyData.flying;
|
||||
spawnRate = enemyData.spawnRate;
|
||||
copyPlayerDeck = enemyData.copyPlayerDeck;
|
||||
difficulty = enemyData.difficulty;
|
||||
|
||||
@@ -225,7 +225,16 @@ public class NewGameScene extends UIScene {
|
||||
|
||||
if(Forge.createNewAdventureMap)
|
||||
{
|
||||
start();
|
||||
FModel.getPreferences().setPref(ForgePreferences.FPref.UI_ENABLE_MUSIC, false);
|
||||
WorldSave.generateNewWorld(selectedName.getText(),
|
||||
gender.getCurrentIndex() == 0,
|
||||
race.getCurrentIndex(),
|
||||
avatarIndex,
|
||||
deck.getCurrentIndex(),
|
||||
Config.instance().getConfigData().difficulties[difficulty.getCurrentIndex()],
|
||||
fantasyMode, easyMode, deck.getText(), 0);
|
||||
GamePlayerUtil.getGuiPlayer().setName(selectedName.getText());
|
||||
Forge.switchScene(SceneType.GameScene.instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ public class WorldStage extends GameStage implements SaveFileContent {
|
||||
enemyMoveVector.setLength(mob.speed()*delta);
|
||||
tempBoundingRect.set(mob.getX()+ enemyMoveVector.x,mob.getY()+ enemyMoveVector.y,mob.getWidth(),mob.getHeight()*mob.getCollisionHeight());
|
||||
|
||||
if(WorldSave.getCurrentSave().getWorld().collidingTile(tempBoundingRect))//if direct path is not possible
|
||||
if(!mob.getData().flying && WorldSave.getCurrentSave().getWorld().collidingTile(tempBoundingRect))//if direct path is not possible
|
||||
{
|
||||
tempBoundingRect.set(mob.getX()+ enemyMoveVector.x,mob.getY(),mob.getWidth(),mob.getHeight());
|
||||
if(WorldSave.getCurrentSave().getWorld().collidingTile(tempBoundingRect))//if only x path is not possible
|
||||
@@ -238,7 +238,7 @@ public class WorldStage extends GameStage implements SaveFileContent {
|
||||
boolean enemyYIsBigger=sprite.getY()>player.getY();
|
||||
sprite.setX(player.getX() + spawnPos.x+(i*sprite.getWidth()*(enemyXIsBigger?1:-1)));//maybe find a better way to get spawn points
|
||||
sprite.setY(player.getY() + spawnPos.y+(i*sprite.getHeight()*(enemyYIsBigger?1:-1)));
|
||||
if(!WorldSave.getCurrentSave().getWorld().collidingTile(sprite.boundingRect()))
|
||||
if(sprite.getData().flying || !WorldSave.getCurrentSave().getWorld().collidingTile(sprite.boundingRect()))
|
||||
{
|
||||
enemies.add(Pair.of(globalTimer,sprite));
|
||||
foregroundSprites.addActor(sprite);
|
||||
|
||||
@@ -18,6 +18,7 @@ public class BiomeStructure {
|
||||
boolean init=false;
|
||||
private TextureAtlas structureAtlas;
|
||||
public ColorMap image;
|
||||
private final static int MAXIMUM_WAVEFUNCTIONSIZE=50;
|
||||
|
||||
public BiomeStructure(BiomeStructureData data,long seed,int width,int height)
|
||||
{
|
||||
@@ -59,50 +60,62 @@ public class BiomeStructure {
|
||||
long currentTime = System.currentTimeMillis();
|
||||
|
||||
init=true;
|
||||
OverlappingModel model= new OverlappingModel(sourceImage,data.N, (int) (data.width* biomeWidth), (int) (data.height*biomeHeight),data.periodicInput,data.periodicOutput,data.symmetry,data.ground);
|
||||
int targetWidth=(int) (data.width* biomeWidth);
|
||||
int targetHeight=(int) (data.width* biomeWidth);
|
||||
dataMap=new int[targetWidth][ targetHeight];
|
||||
collisionMap=new boolean[targetWidth][ targetHeight];
|
||||
ColorMap finalImage=new ColorMap(targetWidth, targetHeight);
|
||||
HashMap<Integer,Integer> colorIdMap=new HashMap<>();
|
||||
for(int i=0;i<data.mappingInfo.length;i++)
|
||||
{
|
||||
colorIdMap.put(Integer.parseInt(data.mappingInfo[i].color,16),i);
|
||||
}
|
||||
boolean suc=false;
|
||||
for(int i=0;i<10&&!suc;i++)
|
||||
suc=model.run((int) seed+(i*5355),0);
|
||||
currentTime= System.currentTimeMillis();
|
||||
if(!suc)
|
||||
for(int mx=0;mx<targetWidth;mx+=Math.min(targetWidth-mx,MAXIMUM_WAVEFUNCTIONSIZE))
|
||||
{
|
||||
dataMap=new int[(int) (data.width* biomeWidth)][ (int) (data.height*biomeHeight)];
|
||||
collisionMap=new boolean[(int) (data.width* biomeWidth)][ (int) (data.height*biomeHeight)];
|
||||
for(int x=0;x<dataMap.length;x++)
|
||||
for(int y=0;y<dataMap[x].length;y++)
|
||||
dataMap[x][y]=-1;
|
||||
return;
|
||||
}
|
||||
image=model.graphics();
|
||||
dataMap=new int[image.getWidth()][image.getHeight()];
|
||||
collisionMap=new boolean[image.getWidth()][image.getHeight()];
|
||||
for(int x=0;x<image.getWidth();x++)
|
||||
{
|
||||
|
||||
for(int y=0;y<image.getHeight();y++)
|
||||
for(int my=0;my<targetWidth;my+=Math.min(targetHeight-my,MAXIMUM_WAVEFUNCTIONSIZE))
|
||||
{
|
||||
boolean isWhitePixel=maskImage!=null&&(maskImage.getColor((int) (x*maskImage.getWidth()/(float)image.getWidth()),(int)(y*(maskImage.getHeight()/(float)image.getHeight())) )).equals(Color.WHITE);
|
||||
OverlappingModel model= new OverlappingModel(sourceImage,data.N,Math.min(targetWidth-mx,MAXIMUM_WAVEFUNCTIONSIZE), Math.min(targetHeight-my,MAXIMUM_WAVEFUNCTIONSIZE),data.periodicInput,data.periodicOutput,data.symmetry,data.ground);
|
||||
|
||||
if(isWhitePixel)
|
||||
image.setColor(x,y, Color.WHITE);
|
||||
int rgb=Color.rgb888(image.getColor(x,y)) ;
|
||||
if(isWhitePixel||!colorIdMap.containsKey(rgb))
|
||||
boolean suc=false;
|
||||
for(int i=0;i<10&&!suc;i++)
|
||||
suc=model.run((int) seed+(i*5355)+mx*my,0);
|
||||
if(!suc)
|
||||
{
|
||||
dataMap[x][y]=-1;
|
||||
for(int x=0;x<dataMap.length;x++)
|
||||
for(int y=0;y<dataMap[x].length;y++)
|
||||
dataMap[mx+x][my+y]=-1;
|
||||
return;
|
||||
}
|
||||
else
|
||||
image=model.graphics();
|
||||
for(int x=0;x<image.getWidth();x++)
|
||||
{
|
||||
dataMap[x][y]=colorIdMap.get(rgb);
|
||||
collisionMap[x][y]=data.mappingInfo[colorIdMap.get(rgb)].collision;
|
||||
|
||||
for(int y=0;y<image.getHeight();y++)
|
||||
{
|
||||
boolean isWhitePixel=maskImage!=null&&(maskImage.getColor((int) ((mx+x)*maskImage.getWidth()/(float)targetWidth),(int)((my+y)*(maskImage.getHeight()/(float)targetHeight)) )).equals(Color.WHITE);
|
||||
|
||||
if(isWhitePixel)
|
||||
finalImage.setColor(mx+x,my+y, Color.WHITE);
|
||||
else
|
||||
finalImage.setColor(mx+x,my+y, image.getColor(x,y));
|
||||
int rgb=Color.rgb888(image.getColor(x,y)) ;
|
||||
if(isWhitePixel||!colorIdMap.containsKey(rgb))
|
||||
{
|
||||
dataMap[mx+x][my+y]=-1;
|
||||
}
|
||||
else
|
||||
{
|
||||
dataMap[mx+x][my+y]=colorIdMap.get(rgb);
|
||||
collisionMap[mx+x][my+y]=data.mappingInfo[colorIdMap.get(rgb)].collision;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
image=finalImage;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public void initialize() {
|
||||
initialize(sourceImage(),maskImage());
|
||||
|
||||
Reference in New Issue
Block a user