Name change
This commit is contained in:
@@ -6,26 +6,32 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/v2/vector"
|
||||
|
||||
"github.com/atridad/BigFeelings/internal/hero"
|
||||
"github.com/atridad/BigFeelings/internal/save"
|
||||
"github.com/atridad/BigFeelings/internal/status"
|
||||
"github.com/atridad/BigFeelings/internal/ui/hud"
|
||||
"github.com/atridad/LilGuy/internal/hero"
|
||||
"github.com/atridad/LilGuy/internal/projectile"
|
||||
"github.com/atridad/LilGuy/internal/save"
|
||||
"github.com/atridad/LilGuy/internal/status"
|
||||
"github.com/atridad/LilGuy/internal/ui/hud"
|
||||
"github.com/atridad/LilGuy/internal/world"
|
||||
)
|
||||
|
||||
var (
|
||||
backgroundColor = color.NRGBA{R: 0, G: 0, B: 0, A: 255}
|
||||
backgroundColor = color.NRGBA{R: 135, G: 206, B: 235, A: 255}
|
||||
saveNotificationColor = color.NRGBA{R: 50, G: 200, B: 50, A: 255}
|
||||
)
|
||||
|
||||
// Hero settings.
|
||||
const (
|
||||
heroStartX = 960 / 2 // ScreenWidth / 2
|
||||
heroStartY = 540 / 2 // ScreenHeight / 2
|
||||
heroStartX = 960 / 2
|
||||
heroStartY = 540 / 2
|
||||
heroRadius = 28.0
|
||||
heroSpeed = 180.0
|
||||
heroMaxStamina = 100.0
|
||||
heroStaminaDrain = 50.0
|
||||
heroStaminaRegen = 30.0
|
||||
|
||||
saveNotificationDuration = 2 * time.Second
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -59,9 +65,9 @@ const (
|
||||
type GameplayInput struct {
|
||||
Left bool
|
||||
Right bool
|
||||
Up bool
|
||||
Down bool
|
||||
Jump bool
|
||||
Sprint bool
|
||||
Shoot bool
|
||||
}
|
||||
|
||||
// Manages the main gameplay state including the hero, HUD, and game world.
|
||||
@@ -69,6 +75,8 @@ type GameplayInput struct {
|
||||
type GameplayScreen struct {
|
||||
hero *hero.Hero
|
||||
hud hud.Overlay
|
||||
world *world.World
|
||||
projectiles *projectile.Manager
|
||||
bounds hero.Bounds
|
||||
lastTick time.Time
|
||||
gameStartTime time.Time
|
||||
@@ -77,10 +85,25 @@ type GameplayScreen struct {
|
||||
fpsFrames int
|
||||
fpsAccumulator time.Duration
|
||||
fpsValue float64
|
||||
|
||||
saveNotificationTimer time.Duration
|
||||
showSaveNotification bool
|
||||
}
|
||||
|
||||
// Creates a new gameplay screen instance.
|
||||
func NewGameplayScreen(screenWidth, screenHeight int, fpsEnabled *bool) *GameplayScreen {
|
||||
w := world.NewWorld()
|
||||
|
||||
groundHeight := 16.0
|
||||
w.AddSurface(&world.Surface{
|
||||
X: 0,
|
||||
Y: float64(screenHeight) - groundHeight,
|
||||
Width: float64(screenWidth),
|
||||
Height: groundHeight,
|
||||
Tag: world.TagGround,
|
||||
Color: color.NRGBA{R: 34, G: 139, B: 34, A: 255},
|
||||
})
|
||||
|
||||
return &GameplayScreen{
|
||||
hero: hero.New(hero.Config{
|
||||
StartX: heroStartX,
|
||||
@@ -97,9 +120,12 @@ func NewGameplayScreen(screenWidth, screenHeight int, fpsEnabled *bool) *Gamepla
|
||||
Y: hudY,
|
||||
Color: color.White,
|
||||
},
|
||||
world: w,
|
||||
projectiles: projectile.NewManager(),
|
||||
bounds: hero.Bounds{
|
||||
Width: float64(screenWidth),
|
||||
Height: float64(screenHeight),
|
||||
Ground: float64(screenHeight) - groundHeight,
|
||||
},
|
||||
lastTick: time.Now(),
|
||||
gameStartTime: time.Now(),
|
||||
@@ -114,15 +140,30 @@ func (g *GameplayScreen) Update(input GameplayInput, delta time.Duration) {
|
||||
g.hero.Update(hero.Input{
|
||||
Left: input.Left,
|
||||
Right: input.Right,
|
||||
Up: input.Up,
|
||||
Down: input.Down,
|
||||
Jump: input.Jump,
|
||||
Sprint: input.Sprint,
|
||||
}, dt, g.bounds)
|
||||
|
||||
// Track total play time
|
||||
if input.Shoot {
|
||||
direction := 1.0
|
||||
if g.hero.GetDirection() == hero.DirLeft {
|
||||
direction = -1.0
|
||||
}
|
||||
g.projectiles.Shoot(g.hero.X, g.hero.Y-20, direction, g.hero.ProjectileConfig)
|
||||
}
|
||||
|
||||
g.projectiles.Update(dt, g.bounds.Width, g.bounds.Height)
|
||||
|
||||
g.totalPlayTime += delta
|
||||
|
||||
g.trackFPS(delta)
|
||||
|
||||
if g.showSaveNotification {
|
||||
g.saveNotificationTimer -= delta
|
||||
if g.saveNotificationTimer <= 0 {
|
||||
g.showSaveNotification = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calculates the current FPS if FPS monitoring is enabled.
|
||||
@@ -144,6 +185,9 @@ func (g *GameplayScreen) trackFPS(delta time.Duration) {
|
||||
// Renders the gameplay screen.
|
||||
func (g *GameplayScreen) Draw(screen *ebiten.Image) {
|
||||
screen.Fill(backgroundColor)
|
||||
|
||||
g.world.Draw(screen)
|
||||
g.projectiles.Draw(screen)
|
||||
g.hero.Draw(screen)
|
||||
|
||||
staminaColor := staminaNormalColor
|
||||
@@ -181,10 +225,63 @@ func (g *GameplayScreen) Draw(screen *ebiten.Image) {
|
||||
}
|
||||
|
||||
g.hud.Draw(screen, meters)
|
||||
|
||||
if g.showSaveNotification {
|
||||
g.drawSaveNotification(screen)
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GameplayScreen) drawSaveNotification(screen *ebiten.Image) {
|
||||
centerX := float32(g.bounds.Width / 2)
|
||||
centerY := float32(30)
|
||||
|
||||
boxWidth := float32(140)
|
||||
boxHeight := float32(40)
|
||||
|
||||
vector.DrawFilledRect(screen,
|
||||
centerX-boxWidth/2,
|
||||
centerY-boxHeight/2,
|
||||
boxWidth,
|
||||
boxHeight,
|
||||
color.NRGBA{R: 0, G: 0, B: 0, A: 180},
|
||||
false)
|
||||
|
||||
vector.StrokeRect(screen,
|
||||
centerX-boxWidth/2,
|
||||
centerY-boxHeight/2,
|
||||
boxWidth,
|
||||
boxHeight,
|
||||
2,
|
||||
saveNotificationColor,
|
||||
false)
|
||||
|
||||
msg := "Game Saved!"
|
||||
textX := centerX - 45
|
||||
textY := centerY - 5
|
||||
ebitenutil.DebugPrintAt(screen, msg, int(textX), int(textY))
|
||||
}
|
||||
|
||||
func (g *GameplayScreen) ShowSaveNotification() {
|
||||
g.showSaveNotification = true
|
||||
g.saveNotificationTimer = saveNotificationDuration
|
||||
}
|
||||
|
||||
// Resets the gameplay screen to its initial state.
|
||||
func (g *GameplayScreen) Reset() {
|
||||
screenWidth := int(g.bounds.Width)
|
||||
screenHeight := int(g.bounds.Height)
|
||||
groundHeight := 16.0
|
||||
|
||||
w := world.NewWorld()
|
||||
w.AddSurface(&world.Surface{
|
||||
X: 0,
|
||||
Y: float64(screenHeight) - groundHeight,
|
||||
Width: float64(screenWidth),
|
||||
Height: groundHeight,
|
||||
Tag: world.TagGround,
|
||||
Color: color.NRGBA{R: 34, G: 139, B: 34, A: 255},
|
||||
})
|
||||
|
||||
g.hero = hero.New(hero.Config{
|
||||
StartX: heroStartX,
|
||||
StartY: heroStartY,
|
||||
@@ -195,6 +292,13 @@ func (g *GameplayScreen) Reset() {
|
||||
StaminaDrain: heroStaminaDrain,
|
||||
StaminaRegen: heroStaminaRegen,
|
||||
})
|
||||
g.world = w
|
||||
g.projectiles = projectile.NewManager()
|
||||
g.bounds = hero.Bounds{
|
||||
Width: float64(screenWidth),
|
||||
Height: float64(screenHeight),
|
||||
Ground: float64(screenHeight) - groundHeight,
|
||||
}
|
||||
g.lastTick = time.Now()
|
||||
g.gameStartTime = time.Now()
|
||||
g.totalPlayTime = 0
|
||||
@@ -215,6 +319,20 @@ func (g *GameplayScreen) SaveState() *save.GameState {
|
||||
|
||||
// LoadState restores gameplay state from saved data.
|
||||
func (g *GameplayScreen) LoadState(state *save.GameState) {
|
||||
screenWidth := int(g.bounds.Width)
|
||||
screenHeight := int(g.bounds.Height)
|
||||
groundHeight := 16.0
|
||||
|
||||
w := world.NewWorld()
|
||||
w.AddSurface(&world.Surface{
|
||||
X: 0,
|
||||
Y: float64(screenHeight) - groundHeight,
|
||||
Width: float64(screenWidth),
|
||||
Height: groundHeight,
|
||||
Tag: world.TagGround,
|
||||
Color: color.NRGBA{R: 34, G: 139, B: 34, A: 255},
|
||||
})
|
||||
|
||||
g.hero = hero.New(hero.Config{
|
||||
StartX: state.HeroX,
|
||||
StartY: state.HeroY,
|
||||
@@ -226,6 +344,13 @@ func (g *GameplayScreen) LoadState(state *save.GameState) {
|
||||
StaminaRegen: heroStaminaRegen,
|
||||
})
|
||||
g.hero.Stamina = state.HeroStamina
|
||||
g.world = w
|
||||
g.projectiles = projectile.NewManager()
|
||||
g.bounds = hero.Bounds{
|
||||
Width: float64(screenWidth),
|
||||
Height: float64(screenHeight),
|
||||
Ground: float64(screenHeight) - groundHeight,
|
||||
}
|
||||
g.totalPlayTime = time.Duration(state.PlayTimeMS) * time.Millisecond
|
||||
g.lastTick = time.Now()
|
||||
g.gameStartTime = time.Now()
|
||||
|
||||
Reference in New Issue
Block a user