Add message display
This commit is contained in:
parent
5b7c8f0294
commit
20981f5ce1
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="302" height="172" tilewidth="16" tileheight="16" infinite="0" nextlayerid="12" nextobjectid="114">
|
||||
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="302" height="172" tilewidth="16" tileheight="16" infinite="0" nextlayerid="12" nextobjectid="115">
|
||||
<tileset firstgid="1" source="../image/robot-tileset/tileset.tsx"/>
|
||||
<objectgroup color="#00ffffff" id="2" name="Room Guides">
|
||||
<object id="2" name="BEDROOM" x="16" y="16" width="960" height="544"/>
|
||||
|
@ -307,7 +307,7 @@
|
|||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,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0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
|
@ -424,8 +424,9 @@
|
|||
<object id="83" name="PLAYERSPAWN" x="496" y="1568" rotation="90"/>
|
||||
<object id="108" name="FAKE ABILITY CONSOLE" x="4544" y="2272" width="16" height="16"/>
|
||||
<object id="109" name="EXTRA LIFE" x="992" y="160" width="16" height="16"/>
|
||||
<object id="111" name="TEMPSPAWN" x="1008" y="1152" rotation="90"/>
|
||||
<object id="111" name="TEMPSPAWN" x="1104" y="1136" rotation="90"/>
|
||||
<object id="112" name="GETMAGNET" gid="396" x="1104" y="1136" width="16" height="16"/>
|
||||
<object id="114" name="GETJUMP" gid="396" x="2432" y="1616" width="16" height="16"/>
|
||||
</objectgroup>
|
||||
<objectgroup id="3" name="PLAYERSPAWN"/>
|
||||
</map>
|
||||
|
|
|
@ -99,6 +99,13 @@ func (g *Game) Update() error {
|
|||
world.ResetGame = false
|
||||
}
|
||||
|
||||
if world.MessageText != "" {
|
||||
if ebiten.IsKeyPressed(ebiten.KeyEnter) {
|
||||
world.MessageText = ""
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
return gohan.Update()
|
||||
}
|
||||
|
||||
|
|
|
@ -165,31 +165,45 @@ func (s *MovementSystem) Update(e gohan.Entity) error {
|
|||
world.CamY += normalize((world.CamTargetY - world.CamY) / targetDiv)
|
||||
}
|
||||
|
||||
// Remove activated trigger.
|
||||
if world.RemoveTrigger != -1 {
|
||||
i := world.RemoveTrigger
|
||||
world.TriggerEntities[i].With(func(s *component.Sprite) {
|
||||
s.Image = world.TileImages[world.TileScreenOff]
|
||||
})
|
||||
world.TriggerRects = append(world.TriggerRects[:i], world.TriggerRects[i+1:]...)
|
||||
world.TriggerActions = append(world.TriggerActions[:i], world.TriggerActions[i+1:]...)
|
||||
world.TriggerEntities = append(world.TriggerEntities[:i], world.TriggerEntities[i+1:]...)
|
||||
world.RemoveTrigger = -1
|
||||
}
|
||||
|
||||
// Check trigger rects.
|
||||
playerRect := world.BBToLevelRect(world.PlayerShape.BB())
|
||||
for i := range world.TriggerRects {
|
||||
if playerRect.Overlaps(world.TriggerRects[i]) {
|
||||
action := world.TriggerActions[i]
|
||||
var message string
|
||||
switch action {
|
||||
case world.TriggerJump:
|
||||
world.CanJump = true
|
||||
message = "<J> TO JUMP."
|
||||
case world.TriggerMagnetize:
|
||||
world.CanMagnetize = true
|
||||
message = "<SPACE> TO MAGNETIZE."
|
||||
case world.TriggerFire:
|
||||
world.CanFire = true
|
||||
message = "<K> TO FIRE."
|
||||
case world.TriggerDoubleJump:
|
||||
world.CanDoubleJump = true
|
||||
message = "<J> TO DOUBLE JUMP."
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown trigger action %d", action))
|
||||
}
|
||||
world.TriggerEntities[i].With(func(s *component.Sprite) {
|
||||
s.Image = world.TileImages[world.TileScreenOff]
|
||||
})
|
||||
// Remove.
|
||||
world.TriggerRects = append(world.TriggerRects[:i], world.TriggerRects[i+1:]...)
|
||||
world.TriggerActions = append(world.TriggerActions[:i], world.TriggerActions[i+1:]...)
|
||||
world.TriggerEntities = append(world.TriggerEntities[:i], world.TriggerEntities[i+1:]...)
|
||||
break
|
||||
// Notify player of new ability.
|
||||
world.SetMessage(fmt.Sprintf("SYSTEM UPGRADED!\n\n%s", message))
|
||||
// Remove trigger during next tick.
|
||||
world.RemoveTrigger = i
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ func (s *RenderSystem) Draw(e gohan.Entity, screen *ebiten.Image) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
if sprite.NumFrames > 0 && time.Since(sprite.LastFrame) > sprite.FrameTime && (sprite.FrameTime != 0 || sprite.Image == nil) {
|
||||
if sprite.NumFrames > 0 && time.Since(sprite.LastFrame) > sprite.FrameTime && (sprite.FrameTime != 0 || sprite.Image == nil) && world.MessageText == "" {
|
||||
sprite.Frame++
|
||||
if sprite.Frame >= sprite.NumFrames {
|
||||
sprite.Frame = 0
|
||||
|
|
|
@ -33,17 +33,27 @@ func (s *RenderMessageSystem) Update(_ gohan.Entity) error {
|
|||
}
|
||||
|
||||
func (s *RenderMessageSystem) Draw(e gohan.Entity, screen *ebiten.Image) error {
|
||||
if !world.GameOver {
|
||||
if world.MessageText == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
message := "GAME OVER :(\n\nPRESS <ENTER> TO RESTART"
|
||||
message := world.MessageText
|
||||
split := strings.Split(message, "\n")
|
||||
lines := len(split)
|
||||
var maxLength int
|
||||
for _, line := range split {
|
||||
l := len(line)
|
||||
if l > maxLength {
|
||||
maxLength = l
|
||||
}
|
||||
}
|
||||
|
||||
w, h := len(message)*6, (strings.Count(message, "\n")+1)*16
|
||||
w, h := maxLength*6, (lines)*16
|
||||
w, h = w+10, h+6
|
||||
|
||||
s.debugImg = ebiten.NewImage(w, h)
|
||||
s.debugImg.Fill(color.RGBA{0, 0, 0, 80})
|
||||
ebitenutil.DebugPrint(s.debugImg, message)
|
||||
s.debugImg.Fill(color.RGBA{80, 80, 80, 255})
|
||||
ebitenutil.DebugPrintAt(s.debugImg, message, 4, 2)
|
||||
|
||||
x, y := world.ScreenWidth/2-float64(w)/2, world.ScreenHeight/2-float64(h)/2
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package world
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
|
||||
"github.com/jakecoffman/cp"
|
||||
|
@ -132,6 +133,11 @@ var (
|
|||
CanMagnetize bool
|
||||
CanFire bool
|
||||
CanDoubleJump bool
|
||||
|
||||
MessageText string
|
||||
MessageUpdated bool
|
||||
|
||||
RemoveTrigger = -1
|
||||
)
|
||||
|
||||
func StartGame() {
|
||||
|
@ -174,3 +180,8 @@ func BBToScreenRect(bb cp.BB) image.Rectangle {
|
|||
func BBToLevelRect(bb cp.BB) image.Rectangle {
|
||||
return image.Rect(int(bb.L), int(bb.T), int(bb.R), int(bb.B))
|
||||
}
|
||||
|
||||
func SetMessage(message string) {
|
||||
MessageText = fmt.Sprintf("%s\n\n<ENTER> TO CONTINUE.", message)
|
||||
MessageUpdated = true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue