2024-07-18 04:23:16 +00:00
|
|
|
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"
|
2024-07-18 04:23:16 +00:00
|
|
|
"log"
|
|
|
|
"runtime"
|
|
|
|
|
|
|
|
"github.com/veandco/go-sdl2/sdl"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
windowWidth = 640
|
|
|
|
windowHeight = 480
|
|
|
|
playerSize = 50
|
|
|
|
)
|
|
|
|
|
|
|
|
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 05:59:06 +00:00
|
|
|
root := &land.RootObject{}
|
|
|
|
root.AddChild(&entities.Player{
|
|
|
|
Position: land.Vector2D{X: windowWidth / 2, Y: windowHeight / 2},
|
|
|
|
Size: land.Vector2D{X: playerSize, Y: playerSize},
|
|
|
|
})
|
2024-07-18 04:23:16 +00:00
|
|
|
|
|
|
|
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.Update()
|
2024-07-18 04:23:16 +00:00
|
|
|
|
|
|
|
renderer.SetDrawColor(0, 0, 0, 255)
|
|
|
|
renderer.Clear()
|
|
|
|
|
2024-07-18 05:59:06 +00:00
|
|
|
root.Draw(renderer)
|
2024-07-18 04:23:16 +00:00
|
|
|
|
|
|
|
renderer.Present()
|
|
|
|
}
|
|
|
|
}
|