This repository has been archived on 2024-03-23. You can view files and clone it, but cannot push or open issues or pull requests.
ambition-legacy/frontend/main.go

78 lines
1.5 KiB
Go
Raw Normal View History

2023-07-21 19:54:39 +01:00
package main
import (
// Misc.
"log"
2023-07-22 23:40:06 +01:00
"math/rand"
// Ambition
p "github.com/devraza/ambition/frontend/player"
u "github.com/devraza/ambition/frontend/ui"
2023-07-21 19:54:39 +01:00
2023-07-22 23:40:06 +01:00
// Ebitengine
2023-07-21 19:54:39 +01:00
"github.com/hajimehoshi/ebiten/v2"
2023-07-23 15:27:31 +01:00
// "github.com/hajimehoshi/ebiten/v2/ebitenutil"
2023-07-21 19:54:39 +01:00
)
// Initialise the test player
var testPlayer = p.GetPlayer()
// Create the `Game` struct
2023-07-22 23:40:06 +01:00
type Game struct {
ui u.UI
activePlayer p.Player
2023-07-22 20:26:25 +01:00
}
2023-07-23 15:27:31 +01:00
// Define the window width/height
const (
2023-07-23 15:27:31 +01:00
window_width = 1440
window_height = 960
)
2023-07-21 19:54:39 +01:00
// Update implements Game
2023-07-21 19:54:39 +01:00
func (g *Game) Update() error {
g.ui.Base.Update()
g.activePlayer.Update()
2023-07-21 19:54:39 +01:00
return nil
}
// Draw implements Game
2023-07-21 19:54:39 +01:00
func (g *Game) Draw(screen *ebiten.Image) {
2023-07-23 00:36:55 +01:00
// Draw the UI onto the screen
g.ui.Base.Draw(screen)
2023-07-21 19:54:39 +01:00
}
// Layout implements Game
2023-07-21 19:54:39 +01:00
func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
return outsideWidth, outsideHeight
2023-07-21 19:54:39 +01:00
}
2023-07-23 00:36:55 +01:00
// Main function
2023-07-21 19:54:39 +01:00
func main() {
2023-07-23 00:36:55 +01:00
// Randomize window titles!
2023-07-22 23:40:06 +01:00
window_titles := []string{
"coding into the online cyberframe",
"seriously prideful",
"[REDACTED]",
"just another day of shooting down bevies",
"mud is delicious",
}
window_title := "Ambition: " + window_titles[rand.Intn(len(window_titles))]
2023-07-23 00:36:55 +01:00
// Engine setup
ebiten.SetWindowSize(window_width, window_height)
2023-07-22 23:40:06 +01:00
ebiten.SetWindowTitle(window_title)
2023-07-23 00:36:55 +01:00
// Initialise the game
2023-07-22 20:26:25 +01:00
game := Game{
2023-07-23 00:36:55 +01:00
// Initialise the UI
activePlayer: testPlayer,
ui: u.UiInit(window_width, window_height),
2023-07-22 20:26:25 +01:00
}
2023-07-23 00:36:55 +01:00
// Log and exit on error
2023-07-22 20:26:25 +01:00
if err := ebiten.RunGame(&game); err != nil {
2023-07-21 19:54:39 +01:00
log.Fatal(err)
}
}