Skip to content

Commit

Permalink
start working on bases
Browse files Browse the repository at this point in the history
  • Loading branch information
Mesabloo committed Jun 6, 2022
1 parent e228e19 commit 183ec2b
Show file tree
Hide file tree
Showing 13 changed files with 254 additions and 101 deletions.
15 changes: 14 additions & 1 deletion core/assets/data/upgrades.json
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
{"BASE_CANNON":[{"cost":600,"attack":0},{"cost":1200,"attack":0},{"cost":2400,"attack":0},{"cost":4800,"attack":0},{"cost":9600,"attack":0},{"cost":19200,"attack":0},{"cost":0,"attack":0}],"BASE_DEFENSE":[{"cost":600,"defense":10000},{"cost":1200,"defense":15000},{"cost":2400,"defense":20000},{"cost":4800,"defense":30000},{"cost":9600,"defense":50000},{"cost":19200,"defense":70000},{"cost":0,"defense":100000}],"BUILD_TIME":[{"cost":700,"multiplier":1},{"cost":1400,"multiplier":0.96},{"cost":2800,"multiplier":0.92},{"cost":5600,"multiplier":0.88},{"cost":11200,"multiplier":0.84},{"cost":22400,"multiplier":0.8},{"cost":44800,"multiplier":0.76},{"cost":89600,"multiplier":0.72},{"cost":179200,"multiplier":0.68},{"cost":0,"multiplier":0.64}],"CR_RESEARCH":[{"cost":500,"multiplier":1},{"cost":1000,"multiplier":1.2},{"cost":2000,"multiplier":1.4},{"cost":4000,"multiplier":1.6},{"cost":8000,"multiplier":1.8},{"cost":16000,"multiplier":2},{"cost":32000,"multiplier":2.2},{"cost":64000,"multiplier":2.4},{"cost":128000,"multiplier":2.7},{"cost":0,"multiplier":3}],"CELL_RESEARCH":[{"cost":800,"multiplier":1},{"cost":1600,"multiplier":1.1},{"cost":3200,"multiplier":1.2},{"cost":6400,"multiplier":1.3},{"cost":12800,"multiplier":1.4},{"cost":25600,"multiplier":1.5},{"cost":51200,"multiplier":1.6},{"cost":102400,"multiplier":1.8},{"cost":204800,"multiplier":2},{"cost":0,"multiplier":2.2}],"CELL_STORAGE":[{"cost":700,"storage":500},{"cost":1400,"storage":700},{"cost":2800,"storage":1000},{"cost":5600,"storage":1400},{"cost":11200,"storage":1800},{"cost":22400,"storage":2300},{"cost":44800,"storage":2900},{"cost":89600,"storage":3400},{"cost":179200,"storage":4000},{"cost":0,"storage":4700}]}
{"BASE_CANNON":[
{"cost":600,"attack":0,
"reload": 2.5,"shell_count": 10, "shot_delay": 0.16, "bullet_speed": 1, "spread": 1.0
},
{"cost":1200,"attack":0,"reload": 2.4,"shell_count": 12, "shot_delay": 0.15, "bullet_speed": 1, "spread": 0.95},
{"cost":2400,"attack":0,"reload": 2.3,"shell_count": 14, "shot_delay": 0.14, "bullet_speed": 1, "spread": 0.90},
{"cost":4800,"attack":0,"reload": 2.2,"shell_count": 16, "shot_delay": 0.13, "bullet_speed": 1, "spread": 0.85},
{"cost":9600,"attack":0,"reload": 2.1,"shell_count": 18, "shot_delay": 0.12, "bullet_speed": 1, "spread": 0.80},
{"cost":19200,"attack":0,"reload": 2.0,"shell_count": 20, "shot_delay": 0.11, "bullet_speed": 1, "spread": 0.75},
{"cost":0,"attack":0,"reload": 1.9,"shell_count": 24, "shot_delay": 0.10, "bullet_speed": 1, "spread": 0.70}
],


"BASE_DEFENSE":[{"cost":600,"defense":10000},{"cost":1200,"defense":15000},{"cost":2400,"defense":20000},{"cost":4800,"defense":30000},{"cost":9600,"defense":50000},{"cost":19200,"defense":70000},{"cost":0,"defense":100000}],"BUILD_TIME":[{"cost":700,"multiplier":1},{"cost":1400,"multiplier":0.96},{"cost":2800,"multiplier":0.92},{"cost":5600,"multiplier":0.88},{"cost":11200,"multiplier":0.84},{"cost":22400,"multiplier":0.8},{"cost":44800,"multiplier":0.76},{"cost":89600,"multiplier":0.72},{"cost":179200,"multiplier":0.68},{"cost":0,"multiplier":0.64}],"CR_RESEARCH":[{"cost":500,"multiplier":1},{"cost":1000,"multiplier":1.2},{"cost":2000,"multiplier":1.4},{"cost":4000,"multiplier":1.6},{"cost":8000,"multiplier":1.8},{"cost":16000,"multiplier":2},{"cost":32000,"multiplier":2.2},{"cost":64000,"multiplier":2.4},{"cost":128000,"multiplier":2.7},{"cost":0,"multiplier":3}],"CELL_RESEARCH":[{"cost":800,"multiplier":1},{"cost":1600,"multiplier":1.1},{"cost":3200,"multiplier":1.2},{"cost":6400,"multiplier":1.3},{"cost":12800,"multiplier":1.4},{"cost":25600,"multiplier":1.5},{"cost":51200,"multiplier":1.6},{"cost":102400,"multiplier":1.8},{"cost":204800,"multiplier":2},{"cost":0,"multiplier":2.2}],"CELL_STORAGE":[{"cost":700,"storage":500},{"cost":1400,"storage":700},{"cost":2800,"storage":1000},{"cost":5600,"storage":1400},{"cost":11200,"storage":1800},{"cost":22400,"storage":2300},{"cost":44800,"storage":2900},{"cost":89600,"storage":3400},{"cost":179200,"storage":4000},{"cost":0,"storage":4700}]}
70 changes: 35 additions & 35 deletions core/assets/gfx/models/base/ally-base.atlas
Original file line number Diff line number Diff line change
Expand Up @@ -6,147 +6,147 @@ filter: Nearest, Nearest
repeat: none
base-01
rotate: false
xy: 132, 111
size: 128, 256
orig: 128, 256
xy: 2, 113
size: 256, 128
orig: 256, 128
offset: 0, 0
index: -1
base-02
rotate: false
xy: 2, 111
size: 128, 256
orig: 128, 256
xy: 2, 503
size: 256, 128
orig: 256, 128
offset: 0, 0
index: -1
base-03
rotate: false
xy: 2, 369
size: 128, 256
orig: 128, 256
xy: 2, 763
size: 256, 128
orig: 256, 128
offset: 0, 0
index: -1
base-04
rotate: false
xy: 262, 627
size: 128, 256
orig: 128, 256
xy: 2, 243
size: 256, 128
orig: 256, 128
offset: 0, 0
index: -1
base-05
rotate: false
xy: 132, 627
size: 128, 256
orig: 128, 256
xy: 2, 633
size: 256, 128
orig: 256, 128
offset: 0, 0
index: -1
base-06
rotate: false
xy: 2, 627
size: 128, 256
orig: 128, 256
xy: 2, 893
size: 256, 128
orig: 256, 128
offset: 0, 0
index: -1
base-07
rotate: false
xy: 132, 369
size: 128, 256
orig: 128, 256
xy: 2, 373
size: 256, 128
orig: 256, 128
offset: 0, 0
index: -1
radar-01
rotate: false
xy: 460, 843
xy: 72, 71
size: 37, 14
orig: 37, 14
offset: 0, 0
index: -1
radar-02
rotate: false
xy: 75, 72
xy: 2, 2
size: 37, 12
orig: 37, 12
offset: 0, 0
index: -1
radar-03
rotate: false
xy: 128, 86
xy: 260, 879
size: 45, 23
orig: 45, 23
offset: 0, 0
index: -1
radar-04
rotate: false
xy: 2, 2
xy: 124, 88
size: 45, 23
orig: 45, 23
offset: 0, 0
index: -1
radar-05
rotate: false
xy: 262, 555
xy: 260, 904
size: 46, 23
orig: 46, 23
offset: 0, 0
index: -1
radar-06
rotate: false
xy: 392, 813
xy: 2, 16
size: 46, 23
orig: 46, 23
offset: 0, 0
index: -1
radar-07
rotate: false
xy: 332, 602
xy: 400, 998
size: 46, 23
orig: 46, 23
offset: 0, 0
index: -1
weapon-01
rotate: false
xy: 262, 531
xy: 448, 999
size: 45, 22
orig: 45, 22
offset: 0, 0
index: -1
weapon-02
rotate: false
xy: 460, 859
xy: 72, 87
size: 50, 24
orig: 50, 24
offset: 0, 0
index: -1
weapon-03
rotate: false
xy: 75, 86
xy: 2, 41
size: 51, 23
orig: 51, 23
offset: 0, 0
index: -1
weapon-04
rotate: false
xy: 2, 27
xy: 333, 986
size: 65, 35
orig: 65, 35
offset: 0, 0
index: -1
weapon-05
rotate: false
xy: 2, 64
xy: 260, 976
size: 71, 45
orig: 71, 45
offset: 0, 0
index: -1
weapon-06
rotate: false
xy: 392, 838
xy: 260, 929
size: 66, 45
orig: 66, 45
offset: 0, 0
index: -1
weapon-07
rotate: false
xy: 262, 580
xy: 2, 66
size: 68, 45
orig: 68, 45
offset: 0, 0
Expand Down
Binary file modified core/assets/gfx/models/base/ally-base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 4 additions & 37 deletions core/src/kotlin/fr/mesabloo/heavymachdefense/data/GameSave.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ data class GameSave(
Pair(UpgradeKind.CR_RESEARCH, 1),
Pair(UpgradeKind.CELL_RESEARCH, 1),
Pair(UpgradeKind.CELL_STORAGE, 1)
),
var buildSlots: MutableList<Slot> = mutableListOf(
MachineSlot(MachineKind.RIFLE)
)
) {
companion object {
Expand All @@ -57,40 +60,4 @@ object DateTimestampSerializer : KSerializer<Date> {
override fun deserialize(decoder: Decoder): Date = Date(decoder.decodeLong())

override fun serialize(encoder: Encoder, value: Date) = encoder.encodeLong(value.time)
}

//object GameSaveJsonSerializer : Json.Serializer<GameSave> {
// override fun read(json: Json, data: JsonValue, type: Class<*>): GameSave? {
// val save = GameSave()
//
// try {
// save.creationDate = json.readValue<Long?>(data, "creationDate")?.let { Date(it) } ?: Date()
// save.lastAccessedDate = json.readValue<Long?>(data, "lastAccessedDate")?.let { Date(it) } ?: Date()
// save.lastStageCompleted = json.readValue(data, "lastStageCompleted") ?: 0
// save.credits = json.readValue(data, "credits") ?: 0
// save.name = json.readValue(data, "name") ?: ""
// // TODO: if name empty -> default one (e.g. "Username")
//
// json.readValue<HashMap<MachineKind, Int>?>(data, "machineUpgrades")?.also { save.machineUpgrades = it }
// json.readValue<HashMap<TurretKind, Int>?>(data, "turretUpgrades")?.also { save.turretUpgrades = it }
// json.readValue<HashMap<UpgradeKind, Int>?>(data, "mainUpgrades")?.also { save.mainUpgrades = it }
// } catch (ex: GdxRuntimeException) {
// return null
// }
//
// return save
// }
//
// override fun write(json: Json, `object`: GameSave, knownType: Class<*>) {
// json.writeObjectStart()
// json.writeValue("creationDate", `object`.creationDate.time)
// json.writeValue("lastAccessedDate", `object`.lastAccessedDate.time)
// json.writeValue("lastStageCompleted", `object`.lastStageCompleted)
// json.writeValue("credits", `object`.credits)
// json.writeValue("name", `object`.name)
// json.writeValue("machineUpgrades", `object`.machineUpgrades)
// json.writeValue("turretUpgrades", `object`.turretUpgrades)
// json.writeValue("mainUpgrades", `object`.mainUpgrades)
// json.writeObjectEnd()
// }
//}
}
12 changes: 12 additions & 0 deletions core/src/kotlin/fr/mesabloo/heavymachdefense/data/Slot.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package fr.mesabloo.heavymachdefense.data

import kotlinx.serialization.Serializable

@Serializable
abstract class Slot

@Serializable
data class MachineSlot(val kind: MachineKind) : Slot()

@Serializable
data class TurretSlot(val kind: TurretKind) : Slot()
36 changes: 36 additions & 0 deletions core/src/kotlin/fr/mesabloo/heavymachdefense/entities/Bases.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package fr.mesabloo.heavymachdefense.entities

import com.badlogic.gdx.physics.box2d.BodyDef
import fr.mesabloo.heavymachdefense.PPM
import fr.mesabloo.heavymachdefense.data.GameSave
import fr.mesabloo.heavymachdefense.data.UpgradeKind
import fr.mesabloo.heavymachdefense.data.Upgrades
import fr.mesabloo.heavymachdefense.ui.stage.game.AllyBase
import fr.mesabloo.heavymachdefense.ui.stage.game.EnemyBase
import fr.mesabloo.heavymachdefense.world.GameWorld
import ktx.box2d.body
import ktx.box2d.box
import kotlin.reflect.KProperty0

fun createBases(world: GameWorld, upgrades: Upgrades, save: KProperty0<GameSave>) {
world.world.body {
type = BodyDef.BodyType.StaticBody
box(width = 256f / PPM, height = 128f / PPM) {
density = 10000000f
isSensor = true
}
userData = AllyBase(save.get().mainUpgrades[UpgradeKind.BASE_DEFENSE]?.minus(1) ?: 0)

position.set(512f / 2f / PPM, (128f / 2f + 16f) / PPM)
}
world.world.body {
type = BodyDef.BodyType.StaticBody
box(width = 256f / PPM, height = 128f / PPM) {
density = 10000000f
isSensor = true
}
userData = EnemyBase()

position.set(512f / 2f / PPM, (2048f - 128f / 2f + 8f) / PPM)
}
}
24 changes: 24 additions & 0 deletions core/src/kotlin/fr/mesabloo/heavymachdefense/entities/Terrain.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package fr.mesabloo.heavymachdefense.entities

import com.badlogic.gdx.physics.box2d.BodyDef
import fr.mesabloo.heavymachdefense.BG_BORDER
import fr.mesabloo.heavymachdefense.PPM
import fr.mesabloo.heavymachdefense.world.GameWorld
import ktx.box2d.body
import ktx.box2d.box
import ktx.math.vec2

fun createTerrainBody(world: GameWorld) {
val width = 512f / PPM
val height = 2048f / PPM

world.world.body {
type = BodyDef.BodyType.StaticBody
box(width, height, position = vec2(width / 2f, height / 2f)) {
isSensor = false
userData = BG_BORDER
}

//position.set(-512f / PPM, -2048f / PPM)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ class StageAssetsManager : Disposable {

fun get(path: String): TextureRegion = TextureRegion(assetManager.get<Texture>(path))

fun unsafeRegion(path: String, regionName: String): TextureRegion =
assetManager.get<TextureAtlas>(path).findRegion(regionName)

override fun dispose() {
if (this.stageLevel != null) {
val (bg1, bg2) = backgrounds(this.stageLevel!!)
Expand Down
Loading

0 comments on commit 183ec2b

Please sign in to comment.