golang-game-framework/main.go

59 lines
1.3 KiB
Go
Raw Permalink Normal View History

2022-06-05 18:54:30 +02:00
package main
import (
"log"
2022-10-24 12:42:58 +02:00
"time"
2022-06-05 18:54:30 +02:00
"github.com/manleydev/golang-game-framework/game"
2022-07-18 02:19:02 +02:00
"github.com/manleydev/golang-game-framework/input"
2022-06-05 18:54:30 +02:00
"github.com/manleydev/golang-game-framework/node"
"github.com/manleydev/golang-game-framework/rendering"
"github.com/manleydev/golang-game-framework/sdl"
)
func main() {
2022-07-18 02:19:02 +02:00
2022-06-05 18:54:30 +02:00
var renderer rendering.Renderer2D = sdl.NewSdlRenderer2D(sdl.SdlRenderer2DInput{
WindowTitle: "Sample Game",
WindowWidth: 1280,
WindowHeight: 720,
})
defer renderer.Destroy()
2022-07-18 02:19:02 +02:00
var input input.InputHandler = sdl.NewSdlInputHandler()
2022-06-05 18:54:30 +02:00
root := node.NewNode()
root.Name = "Root"
2022-07-18 02:19:02 +02:00
game.Run(&root, renderer, input)
2022-06-05 18:54:30 +02:00
running := true
2022-10-24 12:42:58 +02:00
var lastTimestamp int64 = time.Now().UnixMicro()
var delta float64 = 0.0
2022-06-05 18:54:30 +02:00
for running {
2022-07-18 02:19:02 +02:00
2022-10-24 12:42:58 +02:00
if err := root.Update(delta); err != nil {
2022-06-05 18:54:30 +02:00
log.Fatal("Update: ", err)
}
2022-10-24 12:42:58 +02:00
if err := input.Update(delta); err != nil {
2022-07-18 02:19:02 +02:00
log.Fatal("Input Update: ", err)
}
2022-10-24 12:42:58 +02:00
if err := renderer.Update(delta); err != nil {
2022-06-05 18:54:30 +02:00
log.Fatal("Renderer Update: ", err)
}
if err := root.Draw(renderer); err != nil {
log.Fatal("Draw: ", err)
}
if err := renderer.Draw(); err != nil {
log.Fatal("Renderer Draw: ", err)
}
2022-10-24 12:42:58 +02:00
newTimestamp := time.Now().UnixMicro()
delta = float64(lastTimestamp) / float64(newTimestamp)
lastTimestamp = newTimestamp
2022-06-05 18:54:30 +02:00
}
}