Browse Source

Add intro message

main v1.0.0
Trevor Slocum 2 months ago
parent
commit
10d9b1f0ed
  1. 3
      entity/player.go
  2. 6
      main.go
  3. 12
      system/rendermessage.go
  4. 9
      world/world.go

3
entity/player.go

@ -20,7 +20,8 @@ func NewPlayer() gohan.Entity {
player.AddComponent(weapon)
player.AddComponent(&component.Sprite{
Image: asset.FishImage(int(level.FishParrot)),
Image: asset.FishImage(int(level.FishParrot)),
HorizontalFlip: true,
})
player.AddComponent(&component.Rail{})

6
main.go

@ -39,7 +39,11 @@ func main() {
g.Exit()
}()
world.StartGame()
if world.World.Debug == 0 {
world.SetMessage("POLLUTION... DESTRUCTION...\nTHE FISH HAVE HAD ENOUGH!\nIT'S PAYBACK TIME!\nPRESS <ENTER> TO GET REVENGE!", 144)
} else {
world.StartGame()
}
err = ebiten.RunGame(g)
if err != nil {

12
system/rendermessage.go

@ -47,7 +47,7 @@ func (s *RenderMessageSystem) Update(_ gohan.Entity) error {
}
func (s *RenderMessageSystem) Draw(_ gohan.Entity, screen *ebiten.Image) error {
if !world.World.GameStarted || !world.World.MessageVisible {
if !world.World.MessageVisible {
return nil
}
@ -68,23 +68,23 @@ func (s *RenderMessageSystem) drawMessage() {
split := strings.Split(world.World.MessageText, "\n")
width := 0
for _, line := range split {
lineSize := len(line) * 12
lineSize := len(line) * 6
if lineSize > width {
width = lineSize
}
}
height := len(split) * 32
height := len(split) * 16
const padding = 8
const padding = 4
width, height = width+padding*2, height+padding*2
s.msgImg = ebiten.NewImage(width, height)
s.msgImg.Fill(color.RGBA{17, 17, 17, 255})
s.msgImg.Fill(color.RGBA{0, 0, 0, 255})
s.tmpImg.Clear()
s.tmpImg = ebiten.NewImage(width*2, height*2)
s.op.GeoM.Reset()
s.op.GeoM.Scale(2, 2)
s.op.GeoM.Scale(1, 1)
s.op.GeoM.Translate(float64(padding), float64(padding))
ebitenutil.DebugPrint(s.tmpImg, world.World.MessageText)
s.msgImg.DrawImage(s.tmpImg, s.op)

9
world/world.go

@ -97,7 +97,9 @@ func Reset() {
e.Remove()
}
World.MessageVisible = false
if World.GameStarted {
World.MessageVisible = false
}
World.FirstSectionB = false
World.Player = 0
World.Score = 0
@ -156,6 +158,9 @@ func StartGame() {
if !World.StartMuted {
asset.SoundMusic.Play()
}
World.MessageVisible = false
World.MessageUpdated = false
}
func SetMessage(message string, duration int) {
@ -193,7 +198,6 @@ func MaxCreeps() int {
level := World.Tick / (144 * levelUpSeconds)
maxCreeps := minCreeps + math.Pow(2, float64(level)/4)
log.Println("level", level, maxCreeps)
return int(maxCreeps)
}
@ -202,7 +206,6 @@ func NeededKills() int {
level := int(World.Fish)
maxCreeps := minCreeps + level*7
log.Println("need creep", level, maxCreeps)
return int(maxCreeps)
}

Loading…
Cancel
Save