CodingLand/pkg/main.go

63 lines
1.3 KiB
Go
Raw Normal View History

package main
import (
"git.solsynth.dev/highland/codingland/pkg/internal/entities"
2024-07-18 05:59:06 +00:00
"git.solsynth.dev/highland/codingland/pkg/internal/land"
"log"
"runtime"
2024-07-18 06:47:41 +00:00
"time"
"github.com/veandco/go-sdl2/sdl"
)
const (
2024-07-18 06:47:41 +00:00
windowWidth = 720
windowHeight = 480
)
func init() {
runtime.LockOSThread()
}
func main() {
if err := sdl.Init(sdl.INIT_EVERYTHING); err != nil {
log.Fatalf("Failed to initialize SDL: %s", err)
}
defer sdl.Quit()
window, err := sdl.CreateWindow("CodingLand", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, windowWidth, windowHeight, sdl.WINDOW_SHOWN)
if err != nil {
log.Fatalf("Failed to create window: %s", err)
}
defer window.Destroy()
renderer, err := sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED|sdl.RENDERER_PRESENTVSYNC)
if err != nil {
log.Fatalf("Failed to create renderer: %s", err)
}
defer renderer.Destroy()
2024-07-18 06:47:41 +00:00
root := land.NewRootObject()
2024-07-18 05:59:06 +00:00
root.AddChild(&entities.Player{
2024-07-18 06:47:41 +00:00
Position: land.Vector2D{X: windowWidth/2 - 25, Y: windowHeight/2 - 25},
Size: land.Vector2D{X: 50, Y: 50},
2024-07-18 05:59:06 +00:00
})
2024-07-18 06:47:41 +00:00
// 10ms delay use be 100tps average
go root.RunEventLoop(10 * time.Millisecond)
running := true
for running {
for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
switch event.(type) {
case *sdl.QuitEvent:
running = false
}
}
2024-07-18 05:59:06 +00:00
root.Draw(renderer)
renderer.Present()
}
}