From d5b631536b670942e017d6654d7de1e3ef9c64a0 Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Sun, 31 Oct 2021 11:30:42 -0700 Subject: [PATCH] Adjust difficulty --- creep.go | 2 +- flags.go | 1 + game.go | 35 +++++++++++++++++------------------ level.go | 3 +++ main.go | 30 ++++++++++++++++++++++-------- 5 files changed, 44 insertions(+), 27 deletions(-) diff --git a/creep.go b/creep.go index bd66c4f..7dda6a6 100644 --- a/creep.go +++ b/creep.go @@ -140,7 +140,7 @@ func (c *gameCreep) moveSpeed() float64 { if c.creepType == TypeSoul { return 0.5 / 4 } - return 0.4 + return 0.1 + (float64(c.level.num) * 0.1) } func (c *gameCreep) seekPlayer() { diff --git a/flags.go b/flags.go index 47c0838..93bfda4 100644 --- a/flags.go +++ b/flags.go @@ -13,5 +13,6 @@ func parseFlags(g *game) { flag.BoolVar(&g.fullBrightMode, "fullbright", false, "Enable fullbright mode") flag.BoolVar(&g.debugMode, "debug", false, "Enable debug mode") flag.BoolVar(&g.muteAudio, "mute", false, "Mute audio") + flag.IntVar(&g.levelNum, "level", 0, "Warp to level") flag.Parse() } diff --git a/game.go b/game.go index 13f3c23..6c4d663 100644 --- a/game.go +++ b/game.go @@ -142,7 +142,6 @@ func NewGame() (*game, error) { activeGamepad: -1, minLevelColorScale: -1, minPlayerColorScale: -1, - levelNum: 1, op: &ebiten.DrawImageOptions{}, } @@ -461,6 +460,7 @@ func (g *game) Update() error { if dx <= biteThreshold && dy <= biteThreshold { if c.creepType == TypeSoul { g.player.soulsRescued++ + g.player.score += 13 err := g.hurtCreep(c, -1) if err != nil { // TODO @@ -753,7 +753,7 @@ UPDATEPROJECTILES: } // Spawn ghosts. - if g.tick%1872 == 0 { + if false && g.tick%1872 == 0 { // Auto-spawn disabled. spawnAmount := g.tick / 1872 if spawnAmount < 1 { spawnAmount = 1 @@ -907,14 +907,17 @@ func (g *game) Draw(screen *ebiten.Image) { var drawn int if g.gameOverTime.IsZero() || g.gameWon { if g.gameWon { + g.drawProjectiles(screen) + g.op.GeoM.Reset() g.op.ColorM.Reset() - g.op.ColorM.Scale(g.winScreenColorScale, g.winScreenColorScale, g.winScreenColorScale, 1) + g.op.ColorM.Scale(1, 1, 1, g.winScreenColorScale) screen.DrawImage(g.winScreenBackground, g.op) + g.op.GeoM.Reset() g.op.GeoM.Translate(float64(g.w)*0.75, g.winScreenSunY) g.op.ColorM.Reset() - g.op.ColorM.Scale(g.winScreenColorScale, g.winScreenColorScale, g.winScreenColorScale, 1) + g.op.ColorM.Scale(g.winScreenColorScale, g.winScreenColorScale, g.winScreenColorScale, g.winScreenColorScale) screen.DrawImage(g.winScreenSun, g.op) g.op.ColorM.Reset() } @@ -1194,10 +1197,6 @@ func (g *game) renderLevel(screen *ebiten.Image) int { } } - if g.gameWon { - drawn += g.drawProjectiles(screen) - } - var t *Tile for y := 0; y < g.level.h; y++ { for x := 0; x < g.level.w; x++ { @@ -1556,15 +1555,13 @@ func (g *game) showWinScreen() { var removedExistingStars bool - var addedStars bool - - for i := 0; i < 144*20; i++ { + for i := 0; i < 144*25; i++ { if p.health > 0 { // Game has restarted. return } - if i > int(144*3.5) { + if i > int(144*7) { if !removedExistingStars { // Remove existing stars. stars = nil @@ -1575,13 +1572,14 @@ func (g *game) showWinScreen() { } if i > int(144*12) { - p.angle += 0.0025 * (float64((144*5)-i) / (144 * 5)) + p.angle -= 0.0025 * (float64(i-(144*12)) / (144 * 3)) addStar() addStar() addStar() addStar() - _ = addedStars + addStar() + addStar() } p.x += 0.05 @@ -1589,13 +1587,14 @@ func (g *game) showWinScreen() { if i > 144*11 { for _, star := range stars { - pct := float64((144*7)-i) / 144 * 7 + pct := float64((144*15)-i) / 144 * 7 - star.x -= 0.05 * pct / 50 + star.x -= 0.1 * pct / 50 // Apply warp effect. + div := 100.0 dx, dy := deltaXY(g.player.x, g.player.y, star.x, star.y) - star.x, star.y = star.x+(dx/100)*pct/1000, star.y+(dy/100)*pct/1000 + star.x, star.y = star.x-(dx/100)*pct/div-0.025, star.y+(dy/100)*pct/div-0.01 } } @@ -1649,7 +1648,7 @@ func (g *game) showWinScreen() { } g.Unlock() - time.Sleep(6 * time.Second) + time.Sleep(7 * time.Second) // Fade in game over screen. diff --git a/level.go b/level.go index 528df67..2388c77 100644 --- a/level.go +++ b/level.go @@ -13,6 +13,8 @@ const dungeonScale = 4 // Level represents a game level. type Level struct { + num int + w, h int tiles [][]*Tile // (Y,X) array of tiles @@ -101,6 +103,7 @@ func NewLevel(levelNum int, p *gamePlayer) (*Level, error) { multiplier = 2 } l := &Level{ + num: levelNum, w: 336 * multiplier, h: 336 * multiplier, tileSize: 32, diff --git a/main.go b/main.go index 6859384..e87b918 100644 --- a/main.go +++ b/main.go @@ -28,15 +28,7 @@ func main() { log.Fatal(err) } - err = g.reset() - if err != nil { - panic(err) - } - parseFlags(g) - if !g.debugMode { - g.gameStartTime = time.Time{} - } sigc := make(chan os.Signal, 1) signal.Notify(sigc, @@ -48,6 +40,28 @@ func main() { g.exit() }() + // Handle warp. + if g.levelNum > 0 { + warpTo := g.levelNum + go func() { + time.Sleep(2 * time.Second) + g.Lock() + defer g.Unlock() + + g.reset() + g.levelNum = warpTo - 1 + g.nextLevel() + }() + } + + err = g.reset() + if err != nil { + panic(err) + } + if !g.debugMode { + g.gameStartTime = time.Time{} + } + err = ebiten.RunGame(g) if err != nil { log.Fatal(err)