Big map update 3

Changed map pickups:
Now it's a new Actor type and takes its reward values from what the map designer decides using some simple embedded JSON.
Defining rewards as enemies is unnecessary now.
This commit is contained in:
Magpie
2022-04-13 05:00:44 +02:00
parent 6a668f1871
commit 75f58f580c
18 changed files with 202 additions and 117 deletions

View File

@@ -0,0 +1,66 @@
package forge.adventure.character;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Json;
import com.badlogic.gdx.utils.SerializationException;
import forge.adventure.data.RewardData;
import forge.adventure.util.Reward;
/**
* RewardSprite
* Character sprite that represents reward pickups.
*/
public class RewardSprite extends CharacterSprite {
private final String default_reward = "[\n" +
"\t\t{\n" +
"\t\t\t\"type\": \"gold\",\n" +
"\t\t\t\"count\": 10,\n" +
"\t\t\t\"addMaxCount\": 100,\n" +
"\t\t}\n" +
"\t]";
private int id;
private RewardData[] rewards = null;
public RewardSprite(String data, String _sprite){
super(_sprite);
Json json = new Json();
if (data != null) {
try { rewards = json.fromJson(RewardData[].class, data); }
catch(SerializationException E){
//JSON parsing could fail. Since this an user written part, assume failure is possible (it happens).
System.err.printf("[%s] while loading JSON file for reward actor. JSON:\n%s\nUsing a default reward.", E.getMessage(), data);
rewards = json.fromJson(RewardData[].class, default_reward);
}
} else { //Shouldn't happen, but make sure it doesn't fly by.
System.err.printf("Reward data is null. Using a default reward.");
rewards = json.fromJson(RewardData[].class, default_reward);
}
}
public RewardSprite(int _id, String data, String _sprite){
this(data, _sprite);
this.id = _id; //The ID is for remembering removals.
}
@Override
void updateBoundingRect() { //We want rewards to take a full tile.
boundingRect = new Rectangle(getX(), getY(), getWidth(), getHeight());
}
public Array<Reward> getRewards() { //Get list of rewards.
Array<Reward> ret = new Array<Reward>();
if(rewards == null) return ret;
for(RewardData rdata:rewards) {
ret.addAll(rdata.generate(false));
}
return ret;
}
public int getId() {
return id;
}
}

View File

@@ -253,6 +253,10 @@ public class MapStage extends GameStage {
EntryActor entry = new EntryActor(this, sourceMap, id, prop.get("teleport").toString(), x, y, w, h, prop.get("direction").toString());
addMapActor(obj, entry);
break;
case "reward":
RewardSprite R = new RewardSprite(id, prop.get("reward").toString(), prop.get("sprite").toString());
addMapActor(obj, R);
break;
case "enemy":
EnemySprite mob = new EnemySprite(id, WorldData.getEnemy(prop.get("enemy").toString()));
addMapActor(obj, mob);
@@ -429,6 +433,20 @@ public class MapStage extends GameStage {
});
break;
}
} else if (actor instanceof RewardSprite) {
Gdx.input.vibrate(50);
startPause(0.1f, new Runnable() {
@Override
public void run() { //Switch to item pickup scene.
RewardSprite RS = (RewardSprite) actor;
((RewardScene) SceneType.RewardScene.instance).loadRewards(RS.getRewards(), RewardScene.Type.Loot, null);
RS.remove();
actors.removeValue(RS, true);
changes.deleteObject(RS.getId());
Forge.switchScene(SceneType.RewardScene.instance);
}
});
break;
}
}
}

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.7.1" orientation="orthogonal" renderorder="right-down" width="30" height="30" tilewidth="16" tileheight="16" infinite="0" nextlayerid="6" nextobjectid="52">
<map version="1.8" tiledversion="1.8.4" orientation="orthogonal" renderorder="right-down" width="30" height="30" tilewidth="16" tileheight="16" infinite="0" nextlayerid="6" nextobjectid="53">
<editorsettings>
<export target="wastetown..tmx" format="tmx"/>
</editorsettings>
@@ -30,11 +30,6 @@
</layer>
<objectgroup id="4" name="Objects">
<object id="47" template="../../obj/gold.tx" x="323" y="219"/>
<object id="48" template="../../obj/treasure.tx" x="207" y="67">
<properties>
<property name="enemy" value="2Life"/>
</properties>
</object>
<object id="49" template="../../obj/gold.tx" x="106" y="216"/>
<object id="50" template="../../obj/enemy.tx" x="198" y="153" width="32" height="32">
<properties>
@@ -46,5 +41,17 @@
<property name="teleport" value=""/>
</properties>
</object>
<object id="52" template="../../obj/treasure.tx" x="208" y="80">
<properties>
<property name="reward">[
{
&quot;type&quot;: &quot;life&quot;,
&quot;count&quot;: 2
}
]
</property>
<property name="sprite" value="sprites/2life.atlas"/>
</properties>
</object>
</objectgroup>
</map>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.7.1" orientation="orthogonal" renderorder="right-down" width="30" height="30" tilewidth="16" tileheight="16" infinite="0" nextlayerid="6" nextobjectid="52">
<map version="1.8" tiledversion="1.8.4" orientation="orthogonal" renderorder="right-down" width="30" height="30" tilewidth="16" tileheight="16" infinite="0" nextlayerid="6" nextobjectid="52">
<editorsettings>
<export target="wastetown..tmx" format="tmx"/>
</editorsettings>
@@ -30,9 +30,16 @@
</layer>
<objectgroup id="4" name="Objects">
<object id="47" template="../../obj/gold.tx" x="323" y="219"/>
<object id="48" template="../../obj/treasure.tx" x="207" y="67">
<object id="48" template="../../obj/treasure.tx" x="208" y="80">
<properties>
<property name="enemy" value="2Life"/>
<property name="reward">[
{
&quot;type&quot;: &quot;life&quot;,
&quot;count&quot;: 2
}
]
</property>
<property name="sprite" value="sprites/2life.atlas"/>
</properties>
</object>
<object id="49" template="../../obj/gold.tx" x="106" y="216"/>

View File

@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.7.1" orientation="orthogonal" renderorder="right-down" width="30" height="30" tilewidth="16" tileheight="16" infinite="0" nextlayerid="6" nextobjectid="53">
<map version="1.8" tiledversion="1.8.4" orientation="orthogonal" renderorder="right-down" width="30" height="30" tilewidth="16" tileheight="16" infinite="0" nextlayerid="6" nextobjectid="65">
<editorsettings>
<export target="wastetown..tmx" format="tmx"/>
</editorsettings>
<tileset firstgid="1" source="../../tileset/main.tsx"/>
<tileset firstgid="4425" source="../../tileset/buildings.tsx"/>
<tileset firstgid="6321" source="../../tileset/buildings.tsx"/>
<layer id="1" name="Background" width="30" height="30">
<data encoding="base64" compression="zlib">
eJztwzEJAAAMA7C+8w/VWyFLIL2kqqqqvjuO1S8b
@@ -30,11 +30,6 @@
</layer>
<objectgroup id="4" name="Objects">
<object id="47" template="../../obj/gold.tx" x="323" y="219"/>
<object id="48" template="../../obj/treasure.tx" x="207" y="67">
<properties>
<property name="enemy" value="3Life"/>
</properties>
</object>
<object id="49" template="../../obj/gold.tx" x="106" y="216"/>
<object id="50" template="../../obj/enemy.tx" x="186" y="218" width="64" height="64">
<properties>
@@ -51,5 +46,17 @@
<property name="dialog" value="dialogs/colorless_door.json"/>
</properties>
</object>
<object id="54" template="../../obj/treasure.tx" x="208" y="80">
<properties>
<property name="reward">[
{
&quot;type&quot;: &quot;life&quot;,
&quot;count&quot;: 3
}
]
</property>
<property name="sprite" value="sprites/3life.atlas"/>
</properties>
</object>
</objectgroup>
</map>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.7.1" orientation="orthogonal" renderorder="right-down" width="30" height="114" tilewidth="16" tileheight="16" infinite="0" nextlayerid="6" nextobjectid="61">
<map version="1.8" tiledversion="1.8.4" orientation="orthogonal" renderorder="right-down" width="30" height="114" tilewidth="16" tileheight="16" infinite="0" nextlayerid="6" nextobjectid="63">
<editorsettings>
<export target="wastetown..tmx" format="tmx"/>
</editorsettings>
@@ -35,11 +35,6 @@
</properties>
</object>
<object id="47" template="../../obj/gold.tx" x="323" y="219"/>
<object id="48" template="../../obj/treasure.tx" x="207" y="67">
<properties>
<property name="enemy" value="3Life"/>
</properties>
</object>
<object id="49" template="../../obj/gold.tx" x="106" y="216"/>
<object id="50" template="../../obj/enemy.tx" x="185" y="213" width="64" height="64">
<properties>
@@ -96,5 +91,17 @@
<property name="dialog" value="dialogs/black_door.json"/>
</properties>
</object>
<object id="62" template="../../obj/treasure.tx" x="208" y="80">
<properties>
<property name="reward">[
{
&quot;type&quot;: &quot;life&quot;,
&quot;count&quot;: 3
}
]
</property>
<property name="sprite" value="sprites/3life.atlas"/>
</properties>
</object>
</objectgroup>
</map>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.8" tiledversion="1.8.4" orientation="orthogonal" renderorder="right-down" width="30" height="30" tilewidth="16" tileheight="16" infinite="0" nextlayerid="6" nextobjectid="53">
<map version="1.8" tiledversion="1.8.4" orientation="orthogonal" renderorder="right-down" width="30" height="30" tilewidth="16" tileheight="16" infinite="0" nextlayerid="6" nextobjectid="54">
<editorsettings>
<export target="wastetown..tmx" format="tmx"/>
</editorsettings>
@@ -30,11 +30,6 @@
</layer>
<objectgroup id="4" name="Objects">
<object id="47" template="../../obj/gold.tx" x="323" y="219"/>
<object id="48" template="../../obj/treasure.tx" x="207" y="67">
<properties>
<property name="enemy" value="2Life"/>
</properties>
</object>
<object id="49" template="../../obj/gold.tx" x="106" y="216"/>
<object id="51" template="../../obj/entry_up.tx" x="209" y="480">
<properties>
@@ -46,5 +41,17 @@
<property name="enemy" value="Ghalta"/>
</properties>
</object>
<object id="53" template="../../obj/treasure.tx" x="208" y="80">
<properties>
<property name="reward">[
{
&quot;type&quot;: &quot;life&quot;,
&quot;count&quot;: 2
}
]
</property>
<property name="sprite" value="sprites/2life.atlas"/>
</properties>
</object>
</objectgroup>
</map>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.7.1" orientation="orthogonal" renderorder="right-down" width="30" height="30" tilewidth="16" tileheight="16" infinite="0" nextlayerid="6" nextobjectid="53">
<map version="1.8" tiledversion="1.8.4" orientation="orthogonal" renderorder="right-down" width="30" height="30" tilewidth="16" tileheight="16" infinite="0" nextlayerid="6" nextobjectid="54">
<editorsettings>
<export target="wastetown..tmx" format="tmx"/>
</editorsettings>
@@ -30,11 +30,6 @@
</layer>
<objectgroup id="4" name="Objects">
<object id="47" template="../../obj/gold.tx" x="323" y="219"/>
<object id="48" template="../../obj/treasure.tx" x="207" y="67">
<properties>
<property name="enemy" value="2Life"/>
</properties>
</object>
<object id="49" template="../../obj/gold.tx" x="106" y="216"/>
<object id="51" template="../../obj/entry_up.tx" x="209" y="480">
<properties>
@@ -46,5 +41,17 @@
<property name="enemy" value="Lathliss"/>
</properties>
</object>
<object id="53" template="../../obj/treasure.tx" x="208" y="80">
<properties>
<property name="reward">[
{
&quot;type&quot;: &quot;life&quot;,
&quot;count&quot;: 2
}
]
</property>
<property name="sprite" value="sprites/2life.atlas"/>
</properties>
</object>
</objectgroup>
</map>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.7.1" orientation="orthogonal" renderorder="right-down" width="30" height="30" tilewidth="16" tileheight="16" infinite="0" nextlayerid="6" nextobjectid="52">
<map version="1.8" tiledversion="1.8.4" orientation="orthogonal" renderorder="right-down" width="30" height="30" tilewidth="16" tileheight="16" infinite="0" nextlayerid="6" nextobjectid="53">
<editorsettings>
<export target="wastetown..tmx" format="tmx"/>
</editorsettings>
@@ -30,11 +30,6 @@
</layer>
<objectgroup id="4" name="Objects">
<object id="47" template="../../obj/gold.tx" x="323" y="219"/>
<object id="48" template="../../obj/treasure.tx" x="207" y="67">
<properties>
<property name="enemy" value="2Life"/>
</properties>
</object>
<object id="49" template="../../obj/gold.tx" x="106" y="216"/>
<object id="50" template="../../obj/enemy.tx" x="200" y="151" width="32" height="32">
<properties>
@@ -46,5 +41,17 @@
<property name="teleport" value=""/>
</properties>
</object>
<object id="52" template="../../obj/treasure.tx" x="208" y="80">
<properties>
<property name="reward">[
{
&quot;type&quot;: &quot;life&quot;,
&quot;count&quot;: 2
}
]
</property>
<property name="sprite" value="sprites/2life.atlas"/>
</properties>
</object>
</objectgroup>
</map>

View File

@@ -1,12 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<template>
<tileset firstgid="1" source="../tileset/buildings.tsx"/>
<object name="Gold" type="enemy" gid="501" width="16" height="16">
<object name="Gold" type="reward" gid="501" width="16" height="16">
<properties>
<property name="enemy" value="Gold"/>
<property name="override_gold_max" type="int" value="0"/>
<property name="override_gold_min" type="int" value="0"/>
<property name="override_reward" type="bool" value="false"/>
<property name="reward">[
{
&quot;type&quot;: &quot;gold&quot;,
&quot;count&quot;: 999,
&quot;addMaxCount&quot;: 0
}
]</property>
<property name="sprite" value="sprites/gold.atlas"/>
</properties>
</object>
</template>

View File

@@ -1,9 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<template>
<tileset firstgid="1" source="../tileset/buildings.tsx"/>
<object name="Treasure" type="enemy" gid="504" width="16" height="16">
<object name="Treasure" type="reward" gid="504" width="16" height="16">
<properties>
<property name="enemy" value="Treasure"/>
<property name="reward">[
{
&quot;type&quot;: &quot;randomCard&quot;,
&quot;count&quot;: 2,
&quot;addMaxCount&quot;: 8
}
]
</property>
<property name="sprite" value="sprites/treasure.atlas"/>
</properties>
</object>
</template>

View File

@@ -1,5 +1,5 @@
treasure.png
size: 64,96
size: 64,112
format: RGBA8888
filter: Nearest,Nearest
repeat: none
@@ -14,4 +14,4 @@ Idle
size: 16, 16
Idle
xy: 48, 48
size: 16, 16
size: 16, 16

View File

@@ -1,5 +1,5 @@
treasure.png
size: 64,96
size: 64,112
format: RGBA8888
filter: Nearest,Nearest
repeat: none
@@ -14,4 +14,4 @@ Idle
size: 16, 16
Idle
xy: 48, 64
size: 16, 16
size: 16, 16

View File

@@ -1,5 +1,5 @@
treasure.png
size: 64,96
size: 64,112
format: RGBA8888
filter: Nearest,Nearest
repeat: none
@@ -14,4 +14,4 @@ Idle
size: 16, 16
Idle
xy: 48, 80
size: 16, 16
size: 16, 16

View File

@@ -1,5 +1,5 @@
treasure.png
size: 64,96
size: 64,112
format: RGBA8888
filter: Nearest,Nearest
repeat: none
@@ -14,4 +14,4 @@ Idle
size: 16, 16
Idle
xy: 48, 32
size: 16, 16
size: 16, 16

View File

@@ -1,5 +1,5 @@
treasure.png
size: 64,96
size: 64,112
format: RGBA8888
filter: Nearest,Nearest
repeat: none
@@ -26,4 +26,4 @@ Death
size: 16, 16
Death
xy: 48, 16
size: 16, 16
size: 16, 16

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -1,31 +1,4 @@
[
{
"name": "Gold",
"sprite": "sprites/gold.atlas",
"rewards": [
{
"type": "gold",
"count": 10,
"addMaxCount": 100,
"cardName": "",
"itemName": "",
"manaCosts": [],
"cardText": ""
}
]
},
{
"name": "Treasure",
"sprite": "sprites/treasure.atlas",
"deck": "",
"rewards": [
{
"type": "randomCard",
"count": 2,
"addMaxCount": 8
}
]
},
{
"name": "Adventurer",
"sprite": "sprites/swordsman_3.atlas",
@@ -3280,38 +3253,5 @@
"equipment": [
"Mox Ruby"
]
},
{
"name": "1Life",
"sprite": "sprites/1life.atlas",
"deck": "",
"rewards": [
{
"type": "life",
"count": 3
}
]
},
{
"name": "2Life",
"sprite": "sprites/2life.atlas",
"deck": "",
"rewards": [
{
"type": "life",
"count": 2
}
]
},
{
"name": "3Life",
"sprite": "sprites/3life.atlas",
"deck": "",
"rewards": [
{
"type": "life",
"count": 3
}
]
}
]