From 049006fab0b8b58c24248c3a9baff7fd08d0f15c Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Sat, 22 Jan 2022 18:53:41 -0800 Subject: [PATCH] Add nuclear power plant --- asset/asset.go | 1 + asset/image/help.png | Bin 0 -> 1065 bytes asset/map/power_nuclear.tmx | 40 ++++++++++++++ game/game.go | 30 ++++++----- system/input_move.go | 9 +++- system/renderhud.go | 11 ++-- world/structure.go | 5 +- world/world.go | 105 +++++++++++++----------------------- 8 files changed, 113 insertions(+), 88 deletions(-) create mode 100644 asset/image/help.png create mode 100644 asset/map/power_nuclear.tmx diff --git a/asset/asset.go b/asset/asset.go index d988082..a60fdba 100644 --- a/asset/asset.go +++ b/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") ) diff --git a/asset/image/help.png b/asset/image/help.png new file mode 100644 index 0000000000000000000000000000000000000000..3409c1652295ec9c06ff22eb6e6ed97d329a06d8 GIT binary patch literal 1065 zcmV+^1lIeBP)EX>4Tx04R}tkvmAkP!xv$rivmJ2a8H^$WWauh>AFB6^c+H)C#RSnB4RQO&XFE z7e~Rh;NWAi>fqw6tAnc`2tGg@otzY1q{MTRLW>v=9PY<|&wn`gTtKLonPzp21DbA| zsYG1NWLL$mR|GIfIe>`FEMrcRlJJeMd#a?ki}7Cmb$>>$nzI-X5Q%4*VcNtS#M7I$ z!FiuJ%!;x~d`>)O(tyN|Tvt4P<6LlA;61};IyFxmCKd~Ath6yJni}yGaa7fG>MvwG zRyl8R*2-1ZoRhyWl+#z1xlTEZ1QxLb2_h6!Q9>CuVsz@HSV+-*+{Yhr{Svtpa+Scy zv49FR$gUs!4}R~~%1=&sokDS-^TlyKMu4tepiy(2?_s_02y>eSad^gZEa<4bO1wgWnpw> zWFU8GbZ8()Nlj2!fese{00IF?L_t(|+U=LUYZXBhN6)-GR8+*ELi}i~f~1f%R%rw~ z!6Hb?h#**7_#fD%66~!l#7=qGr17H=0!macL=X!NA|ymbbnnk55fNtIipyko-aRnQ zo88$t_sz_`1CHZ3j^j9v<2a5pa)jI;lsE}Y1BZd}t)JI{&%iS9Is~esqAW3`id!;1 z%FvMZMaDge3ld{p7av!}?Hbatwj^<;tMaF0y#EjR?e>kw1vVi1Pw$a9*yM!! z4F|x0L8Nc+594ek`np{l)!ItNtH>7Elp0^Ptvg4~CC-rtrOO}RstsakaJFRm$z%#O z9!mLdues#sWUMFTUrHP*QG8#G+u{?6BPGh8knubzUvYC-<=9pE2^lL1`8A32rSA8h zjKzffV~L|BpZ1p$^7o5e@_$u%OA+~1iT$M)I>!=4&effmQ|`KYD$%#N69MRF{@y17 zmlHQh$H`3A%Z0==a5~ccC + + + + +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 + + + + +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 + + + + +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 + + + + +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 + + + diff --git a/game/game.go b/game/game.go index 6910ee0..487a9dc 100644 --- a/game/game.go +++ b/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, }, } diff --git a/system/input_move.go b/system/input_move.go index 53374b6..f86b0db 100644 --- a/system/input_move.go +++ b/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 { diff --git a/system/renderhud.go b/system/renderhud.go index 00c4b90..ca1c117 100644 --- a/system/renderhud.go +++ b/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 + } } } diff --git a/world/structure.go b/world/structure.go index 26150c5..8ac14d6 100644 --- a/world/structure.go +++ b/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 { diff --git a/world/world.go b/world/world.go index 2770c90..aa730ac 100644 --- a/world/world.go +++ b/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 {