Files
2023-09-05 19:29:11 -04:00

104 lines
2.7 KiB
Go

package main
import (
"cosmos/diego/groovy"
splashmenu "cosmos/diego/groovy/examples/splashmenu/scenes"
"fmt"
"log"
"github.com/hajimehoshi/ebiten/v2"
)
func main() {
//setup manager
manager := groovy.NewManager()
manager.SetDimensions(groovy.Area{Width: 1280, Height: 720})
ebiten.SetWindowSize(manager.Info.Dimensions.Width, manager.Info.Dimensions.Height)
ebiten.SetWindowTitle(manager.Info.Name)
loadScenes(&manager)
//identification
fmt.Println(manager.Info.Name + ": v" + manager.Info.Version)
if err := ebiten.RunGame(&manager); err != nil {
log.Fatal(err)
}
}
// Example loading of two scenes
func loadScenes(m *groovy.Manager) {
//call the loaders for each scene
//loadSplash(m)
//loadBsoft(m)
//loadMenu(m)
//loadNoise(m)
//loadSplashpad(m)
//loadParallax(m)
loadRays(m)
//reset the manager to start scene 1
m.ResetScenes()
}
// creates splash screen, sets completion handler
func loadSplash(m *groovy.Manager) {
//create splash screen and append as first scene in manager
sceneSplash := splashmenu.NewSplash()
m.AddScene(&sceneSplash)
}
// creates menu screen, populates the options, sets key event handler
func loadMenu(m *groovy.Manager) {
//create menu with defined options, append to manager
sceneMenu := splashmenu.NewMenu()
sceneMenu.SetOptions(map[int]splashmenu.MenuOption{
1: {Description: "splash", SelectionEvent: groovy.RESET, Mapping: ebiten.Key1},
2: {Description: "bsoft", SelectionEvent: groovy.COMPLETED, Mapping: ebiten.Key2},
3: {Description: "menu"},
4: {Description: "noise", SelectionEvent: groovy.COMPLETED, Mapping: ebiten.Key4},
5: {Description: "guy", SelectionEvent: groovy.COMPLETED, Mapping: ebiten.Key5},
6: {Description: "parallax", SelectionEvent: groovy.COMPLETED, Mapping: ebiten.Key6},
7: {Description: "exit", SelectionEvent: groovy.ENDGAME, Mapping: ebiten.Key7},
})
m.AddScene(&sceneMenu)
//set up a custom event handler for the menu completion >:]
scene := m.GetScene(m.SceneCount() - 1)
scene.SetEventHandler(groovy.COMPLETED, func() {
//direct manager to update current scene by retrieving menu selection
sceneSelected := sceneMenu.GetMenuSelection() - 1
m.SetCurrentScene(sceneSelected)
})
}
func loadBsoft(m *groovy.Manager) {
sceneBsoft := splashmenu.NewBsoft()
m.AddScene(&sceneBsoft)
}
func loadNoise(m *groovy.Manager) {
sceneNoisy := splashmenu.NewNoisy()
m.AddScene(&sceneNoisy)
}
func loadSplashpad(m *groovy.Manager) {
sceneSplashpad := splashmenu.NewSplashPad()
m.AddScene(&sceneSplashpad)
}
func loadParallax(m *groovy.Manager) {
sceneParallax := splashmenu.NewParallax()
m.AddScene(&sceneParallax)
sceneParallax.InitializeParallax()
}
func loadRays(m *groovy.Manager) {
sceneRays := splashmenu.NewRays()
m.AddScene(&sceneRays)
}