Browse Source

Add nuclear power plant

main
Trevor Slocum 7 months ago
parent
commit
049006fab0
  1. 1
      asset/asset.go
  2. BIN
      asset/image/help.png
  3. 40
      asset/map/power_nuclear.tmx
  4. 30
      game/game.go
  5. 9
      system/input_move.go
  6. 11
      system/renderhud.go
  7. 5
      world/structure.go
  8. 105
      world/world.go

1
asset/asset.go

@ -23,6 +23,7 @@ var (
ImgBlank = ebiten.NewImage(1, 1)
ImgWhiteSquare = ebiten.NewImage(64, 64)
ImgBlackSquare = ebiten.NewImage(64, 64)
ImgHelp = LoadImage("image/help.png")
ImgPower = LoadImage("image/power.png")
)

BIN
asset/image/help.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

40
asset/map/power_nuclear.tmx

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.7.2" orientation="isometric" renderorder="right-down" width="5" height="5" tilewidth="64" tileheight="32" infinite="0" nextlayerid="6" nextobjectid="1">
<tileset firstgid="1" source="../image/tileset/MRMO_BRIK.tsx"/>
<layer id="1" name="1" width="5" height="5">
<data encoding="csv">
3,3,3,3,3,
3,3,3,3,3,
3,3,3,3,3,
3,3,3,3,3,
3,3,3,3,527
</data>
</layer>
<layer id="2" name="2" width="5" height="5" offsetx="0" offsety="-40">
<data encoding="csv">
3,3,3,3,3,
3,632,3,632,3,
3,3,3,3,3,
3,3,3,3,3,
3,3,3,3,3
</data>
</layer>
<layer id="4" name="3" width="5" height="5" offsetx="0" offsety="-80">
<data encoding="csv">
7,21,21,21,14,
7,632,7,632,7,
0,0,0,0,0,
571,0,11,11,14,
571,0,10,11,10
</data>
</layer>
<layer id="5" name="4" width="5" height="5" offsetx="0" offsety="-120">
<data encoding="csv">
0,0,0,0,0,
0,635,0,635,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0
</data>
</layer>
</map>

30
game/game.go

@ -92,15 +92,12 @@ func (g *game) Update() error {
}
// Fill below ground layer.
grassTile := uint32(11*32 + (0))
treeTileA := uint32(5*32 + (24))
treeTileB := uint32(5*32 + (25))
var img uint32
for x := range world.World.Level.Tiles[0] {
for y := range world.World.Level.Tiles[0][x] {
img = world.DirtTile
if rand.Intn(150) == 0 {
img = grassTile
img = world.GrassTile
world.World.Level.Tiles[0][x][y].EnvironmentSprite = world.World.TileImages[img+world.World.TileImagesFirstGID]
for offsetX := -2 - rand.Intn(7); offsetX < 2+rand.Intn(7); offsetX++ {
for offsetY := -2 - rand.Intn(7); offsetY < 2+rand.Intn(7); offsetY++ {
@ -108,9 +105,9 @@ func (g *game) Update() error {
world.World.Level.Tiles[0][x+offsetX][y+offsetY].EnvironmentSprite = world.World.TileImages[img+world.World.TileImagesFirstGID]
if rand.Intn(4) == 0 {
if rand.Intn(3) == 0 {
world.World.Level.Tiles[1][x+offsetX][y+offsetY].EnvironmentSprite = world.World.TileImages[treeTileA+world.World.TileImagesFirstGID]
world.World.Level.Tiles[1][x+offsetX][y+offsetY].EnvironmentSprite = world.World.TileImages[world.TreeTileA+world.World.TileImagesFirstGID]
} else {
world.World.Level.Tiles[1][x+offsetX][y+offsetY].EnvironmentSprite = world.World.TileImages[treeTileB+world.World.TileImagesFirstGID]
world.World.Level.Tiles[1][x+offsetX][y+offsetY].EnvironmentSprite = world.World.TileImages[world.TreeTileB+world.World.TileImagesFirstGID]
}
}
}
@ -143,7 +140,9 @@ func (g *game) Update() error {
Sprite: world.DrawMap(world.StructureRoad),
SpriteOffsetX: -12,
SpriteOffsetY: -28,
}, {
},
nil,
{
StructureType: world.StructureResidentialZone,
Sprite: world.DrawMap(world.StructureResidentialLow),
SpriteOffsetX: -12,
@ -169,10 +168,10 @@ func (g *game) Update() error {
SpriteOffsetY: 2,
Sprite: world.DrawMap(world.StructurePowerPlantSolar),
}, {
StructureType: world.StructurePoliceStation,
SpriteOffsetX: -19,
SpriteOffsetY: -4,
Sprite: world.DrawMap(world.StructurePoliceStation),
StructureType: world.StructurePowerPlantNuclear,
SpriteOffsetX: -20,
SpriteOffsetY: 2,
Sprite: world.DrawMap(world.StructurePowerPlantNuclear),
},
nil,
nil,
@ -194,12 +193,17 @@ func (g *game) Update() error {
nil,
nil,
nil,
nil,
{
StructureType: world.StructureToggleHelp,
Sprite: asset.ImgHelp,
SpriteOffsetX: 0,
SpriteOffsetY: -1,
},
{
StructureType: world.StructureToggleTransparentStructures,
Sprite: transparentImg,
SpriteOffsetX: -12,
SpriteOffsetY: 0,
SpriteOffsetY: -0,
},
}

9
system/input_move.go

@ -263,7 +263,13 @@ func (s *playerMoveSystem) Update(ctx *gohan.Context) error {
button := world.HUDButtonAt(x, y)
if button != nil {
if button.StructureType != 0 {
if button.StructureType == world.StructureToggleTransparentStructures {
if button.StructureType == world.StructureToggleHelp {
if world.World.HelpPage != -1 {
world.SetHelpPage(-1)
} else {
world.SetHelpPage(0)
}
} else if button.StructureType == world.StructureToggleTransparentStructures {
world.World.TransparentStructures = !world.World.TransparentStructures
world.World.HUDUpdated = true
@ -343,7 +349,6 @@ func (s *playerMoveSystem) Update(ctx *gohan.Context) error {
tileX, tileY := world.ScreenToCartesian(x, y)
if tileX >= 0 && tileY >= 0 && tileX < 256 && tileY < 256 {
multiUseStructure := world.World.HoverStructure == world.StructureBulldozer || world.World.HoverStructure == world.StructureRoad || world.IsZone(world.World.HoverStructure)
dragStarted := world.World.BuildDragX != -1 || world.World.BuildDragY != -1
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) || (multiUseStructure && ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft)) || dragStarted {

11
system/renderhud.go

@ -104,7 +104,9 @@ func (s *RenderHudSystem) drawSidebar() {
if button != nil {
selected := world.World.HoverStructure == button.StructureType
if button.StructureType == world.StructureToggleTransparentStructures {
if button.StructureType == world.StructureToggleHelp {
selected = world.World.HelpPage != -1
} else if button.StructureType == world.StructureToggleTransparentStructures {
selected = world.World.TransparentStructures
}
@ -120,8 +122,11 @@ func (s *RenderHudSystem) drawSidebar() {
}
world.World.HUDButtonRects[i] = r
if button != nil && button.StructureType != world.StructureToggleTransparentStructures {
lastButtonY = y
if button != nil {
nonHUDButton := button.StructureType == world.StructureToggleHelp || button.StructureType == world.StructureToggleTransparentStructures
if !nonHUDButton {
lastButtonY = y
}
}
}

5
world/structure.go

@ -3,7 +3,8 @@ package world
import "code.rocketnine.space/tslocum/gohan"
const (
StructureToggleTransparentStructures = iota + 1
StructureToggleHelp = iota + 1
StructureToggleTransparentStructures
StructureBulldozer
StructureRoad
StructureResidentialZone
@ -21,6 +22,7 @@ const (
StructurePoliceStation
StructurePowerPlantCoal
StructurePowerPlantSolar
StructurePowerPlantNuclear
)
var StructureFilePaths = map[int]string{
@ -41,6 +43,7 @@ var StructureFilePaths = map[int]string{
StructurePoliceStation: "map/policestation.tmx",
StructurePowerPlantCoal: "map/power_coal.tmx",
StructurePowerPlantSolar: "map/power_solar.tmx",
StructurePowerPlantNuclear: "map/power_nuclear.tmx",
}
type Structure struct {

105
world/world.go

@ -13,6 +13,8 @@ import (
"sync"
"time"
"github.com/hajimehoshi/ebiten/v2/audio"
"golang.org/x/text/language"
"golang.org/x/text/message"
@ -43,6 +45,12 @@ const startingZoom = 1.0
const SidebarWidth = 199
var (
GrassTile = uint32(11*32 + (0))
TreeTileA = uint32(5*32 + (24))
TreeTileB = uint32(5*32 + (25))
)
type HUDButton struct {
Sprite *ebiten.Image
SpriteOffsetX, SpriteOffsetY float64
@ -187,11 +195,6 @@ type GameWorld struct {
var ErrNothingToBulldoze = errors.New("nothing to bulldoze")
func TileToGameCoords(x, y int) (float64, float64) {
//return float64(x) * 32, float64(g.currentMap.Height*32) - float64(y)*32 - 32
return float64(x) * TileSize, float64(y) * TileSize
}
func Reset() {
for _, e := range ECS.Entities() {
ECS.RemoveEntity(e)
@ -323,37 +326,6 @@ func ShowBuildCost(structureType int, cost int) {
}
func BuildStructure(structureType int, hover bool, placeX int, placeY int) (*Structure, error) {
// For previewing buildings
/*v := rand.Intn(3)
if structureType == StructureResidentialZone {
switch v {
case 0:
structureType = StructureResidentialLow
case 1:
structureType = StructureResidentialMedium
case 2:
structureType = StructureResidentialHigh
}
} else if structureType == StructureCommercialZone {
switch v {
case 0:
structureType = StructureCommercialLow
case 1:
structureType = StructureCommercialMedium
case 2:
structureType = StructureCommercialHigh
}
} else if structureType == StructureIndustrialZone {
switch v {
case 0:
structureType = StructureIndustrialLow
case 1:
structureType = StructureIndustrialMedium
case 2:
structureType = StructureIndustrialHigh
}
}*/
m, err := LoadMap(structureType)
if err != nil {
return nil, err
@ -395,6 +367,18 @@ func BuildStructure(structureType int, hover bool, placeX int, placeY int) (*Str
img = World.TileImages[DirtTile+World.TileImagesFirstGID]
}
if World.Level.Tiles[i][placeX][placeY].EnvironmentSprite != img {
bulldozeTree := World.Level.Tiles[i][placeX][placeY].EnvironmentSprite == World.TileImages[TreeTileA+World.TileImagesFirstGID] || World.Level.Tiles[i][placeX][placeY].EnvironmentSprite == World.TileImages[TreeTileB+World.TileImagesFirstGID]
if bulldozeTree {
sounds := []*audio.Player{
asset.SoundPop1,
asset.SoundPop4,
asset.SoundPop5,
}
sound := sounds[rand.Intn(len(sounds))]
sound.Rewind()
sound.Play()
}
World.Level.Tiles[i][placeX][placeY].EnvironmentSprite = img
bulldozed = true
}
@ -545,28 +529,6 @@ func (w *GameWorld) SetGameOver(vx, vy float64) {
}
w.GameOver = true
// TODO
}
// TODO move
func NewActor(creepType int, creepID int64, x float64, y float64) gohan.Entity {
actor := ECS.NewEntity()
ECS.AddComponent(actor, &component.PositionComponent{
X: x,
Y: y,
})
ECS.AddComponent(actor, &component.ActorComponent{
Type: creepType,
Health: 64,
FireAmount: 8,
FireRate: 144 / 4,
Rand: rand.New(rand.NewSource(creepID)),
})
return actor
}
func StartGame() {
@ -681,26 +643,29 @@ func Demand() (r, c, i float64) {
}
var StructureTooltips = map[int]string{
StructureToggleHelp: "Help",
StructureToggleTransparentStructures: "Transparent buildings",
StructureBulldozer: "Bulldozer",
StructureRoad: "Road",
StructurePoliceStation: "Police station",
StructurePowerPlantCoal: "Coal power plant",
StructurePowerPlantSolar: "Solar power plant",
StructurePowerPlantNuclear: "Nuclear plant",
StructureResidentialZone: "Residential zone",
StructureCommercialZone: "Commercial zone",
StructureIndustrialZone: "Industrial zone",
}
var StructureCosts = map[int]int{
StructureBulldozer: 5,
StructureRoad: 25,
StructurePoliceStation: 1000,
StructurePowerPlantCoal: 4000,
StructurePowerPlantSolar: 10000,
StructureResidentialZone: 100,
StructureCommercialZone: 200,
StructureIndustrialZone: 100,
StructureBulldozer: 5,
StructureRoad: 25,
StructurePoliceStation: 1000,
StructurePowerPlantCoal: 4000,
StructurePowerPlantSolar: 10000,
StructurePowerPlantNuclear: 25000,
StructureResidentialZone: 100,
StructureCommercialZone: 200,
StructureIndustrialZone: 100,
}
func Tooltip() string {
@ -784,8 +749,9 @@ func ValidXY(x, y int) bool {
}
var PowerPlantCapacities = map[int]int{
StructurePowerPlantCoal: 60,
StructurePowerPlantSolar: 40,
StructurePowerPlantCoal: 60,
StructurePowerPlantSolar: 40,
StructurePowerPlantNuclear: 200,
}
var ZonePowerRequirement = map[int]int{
@ -797,10 +763,11 @@ var ZonePowerRequirement = map[int]int{
func SetHelpPage(page int) {
World.HelpPage = page
World.HelpUpdated = true
World.HUDUpdated = true
}
func IsPowerPlant(structureType int) bool {
return structureType == StructurePowerPlantCoal || structureType == StructurePowerPlantSolar
return structureType == StructurePowerPlantCoal || structureType == StructurePowerPlantSolar || structureType == StructurePowerPlantNuclear
}
func IsZone(structureType int) bool {

Loading…
Cancel
Save