3 changed files with 53 additions and 45 deletions
-
1lib/event.go
-
46lib/game.go
-
51lib/scene.go
@ -0,0 +1 @@ |
|||
package lib |
|||
@ -0,0 +1,51 @@ |
|||
package lib |
|||
|
|||
import ( |
|||
"github.com/hajimehoshi/ebiten/v2" |
|||
"github.com/hajimehoshi/ebiten/v2/ebitenutil" |
|||
) |
|||
|
|||
// Scenes: Main Menu
|
|||
// Game Mode
|
|||
|
|||
type GameEvent struct { |
|||
Type int |
|||
} |
|||
|
|||
type HandleResult int |
|||
|
|||
const ( |
|||
EventNoOp int = iota |
|||
EventKeyRelease |
|||
) |
|||
|
|||
const ( |
|||
DoNothing HandleResult = iota |
|||
EndProgram |
|||
) |
|||
|
|||
// Scene is the highest level organization unit of a Game. It handles events.
|
|||
// A game has a currently active scene, and can transition
|
|||
type Scene interface { |
|||
// Handles a game event and returns a result.
|
|||
HandleEvent(*GameEvent) HandleResult |
|||
Draw(screen *ebiten.Image) |
|||
} |
|||
|
|||
type MainMenuScene struct { |
|||
selections [1]string |
|||
currentSelectionIndex int |
|||
} |
|||
|
|||
func (menu *MainMenuScene) HandleEvent(e *GameEvent) HandleResult { |
|||
if e.Type == 1 { |
|||
if menu.selections[menu.currentSelectionIndex] == "Quit" { |
|||
return EndProgram |
|||
} |
|||
} |
|||
return DoNothing |
|||
} |
|||
|
|||
func (menu *MainMenuScene) Draw(screen *ebiten.Image) { |
|||
ebitenutil.DebugPrint(screen, menu.selections[menu.currentSelectionIndex]) |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue