Skip to content

Commit

Permalink
add pause menu
Browse files Browse the repository at this point in the history
  • Loading branch information
KalebHawkins committed Jun 24, 2024
1 parent 3fb2fcb commit fdf5be8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/GameObjects.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ classDiagram
+ playerOne paddle
+ playerTwo paddle
+ ball ball
+ isPaused bool
+ Update() error
+ Draw(*ebiten.Image)
Expand Down
20 changes: 19 additions & 1 deletion pong/pong.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Game struct {
playerOne paddle
playerTwo paddle
ball
isPaused bool
}

// Cfg contains the Game's configuration data.
Expand Down Expand Up @@ -115,7 +116,9 @@ func (g *Game) Update() error {
g.state = gameLoop
}
case gameLoop:

if inpututil.IsKeyJustPressed(ebiten.KeySpace) || inpututil.IsKeyJustPressed(ebiten.KeyEscape) {
g.isPaused = !g.isPaused
}
}

return nil
Expand Down Expand Up @@ -144,6 +147,9 @@ func (g *Game) Draw(screen *ebiten.Image) {
g.drawMainMenu(screen)
case gameLoop:
g.drawGameLoop(screen)
if g.isPaused {
g.drawPauseMenu(screen)
}
}

}
Expand Down Expand Up @@ -202,3 +208,15 @@ func (g *Game) drawGameLoop(screen *ebiten.Image) {
op.GeoM.Translate(float64(g.ball.x), float64(g.ball.y))
screen.DrawImage(g.ball.sprite, op)
}

func (g *Game) drawPauseMenu(screen *ebiten.Image) {
op := &text.DrawOptions{}
op.GeoM.Translate(float64(g.Cfg.ScreenWidth)/2, fontSize)
op.LineSpacing = fontSize
op.PrimaryAlign = text.AlignCenter
op.ColorScale.ScaleWithColor(color.Black)
text.Draw(screen, "GAME PAUSED", &text.GoTextFace{
Source: g.Cfg.faceSource,
Size: fontSize,
}, op)
}
1 change: 0 additions & 1 deletion pong/states.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ type state int
const (
mainMenu state = iota
gameLoop
paused
gameOver
)

0 comments on commit fdf5be8

Please sign in to comment.