package main import ( _ "embed" "fmt" "git.danitheskunk.com/squishy/blooblib/color" . "git.danitheskunk.com/squishy/blooblib/src" "github.com/veandco/go-sdl2/sdl" "time" ) const Width = 640 const Height = 360 //test func main() { _ = sdl.Init(sdl.INIT_EVERYTHING) defer sdl.Quit() scale := 3 window, _ := sdl.CreateWindow( "test", sdl.WINDOWPOS_CENTERED, sdl.WINDOWPOS_CENTERED, int32(Width*scale), int32(Height*scale), sdl.WINDOW_SHOWN, ) surface, _ := window.GetSurface() //data := unsafe.Slice((*uint32)(surface.Data()), Width*Height) windowImage := NewImageFromPointer(surface.Data(), Vec2i{X: Width * scale, Y: Height * scale}) screen := NewImage(Vec2i{X: Width, Y: Height}) screen.Alpha = false //sprite := NewImage(Vec2i{X: 32, Y: 32}) //sprite.Clear(0xabcdef) fmt.Printf("%d\n", surface.Format.BitsPerPixel) println("\n"[0]) tiles := LoadImage("go.png").MakeTileset(Vec2i{X: 16, Y: 16}) tilemap := NewTilemap(Vec2i{X: 40, Y: 23}, tiles) tilemap.Clear(16) for y := 0; y < 19; y += 1 { for x := 0; x < 19; x += 1 { tilemap.Set(Vec2i{X: 10 + x, Y: 1 + y}, 3) } //tilemap.Set(Vec2i{X: 9, Y: 1 + y}, 17) tilemap.Set(Vec2i{X: 10, Y: 1 + y}, 11) tilemap.Set(Vec2i{X: 28, Y: 1 + y}, 12) } for x := 0; x < 19; x += 1 { //tilemap.Set(Vec2i{X: 10 + x, Y: 0}, 18) tilemap.Set(Vec2i{X: 10 + x, Y: 1}, 9) tilemap.Set(Vec2i{X: 10 + x, Y: 19}, 10) tilemap.Set(Vec2i{X: 10 + x, Y: 20}, 17) tilemap.Set(Vec2i{X: 10 + x, Y: 21}, 18) } for y := 0; y < 21; y += 1 { tilemap.Set(Vec2i{X: 29, Y: 1 + y}, 19) } tilemap.Set(Vec2i{X: 10, Y: 21}, 20) tilemap.Set(Vec2i{X: 29, Y: 1}, 21) tilemap.Set(Vec2i{X: 10, Y: 1}, 5) tilemap.Set(Vec2i{X: 28, Y: 1}, 6) tilemap.Set(Vec2i{X: 10, Y: 19}, 7) tilemap.Set(Vec2i{X: 28, Y: 19}, 8) tilemap.Set(Vec2i{X: 13, Y: 4}, 4) tilemap.Set(Vec2i{X: 25, Y: 4}, 4) tilemap.Set(Vec2i{X: 13, Y: 16}, 4) tilemap.Set(Vec2i{X: 25, Y: 16}, 4) tilemap.Set(Vec2i{X: 13, Y: 10}, 4) tilemap.Set(Vec2i{X: 13, Y: 16}, 4) tilemap.Set(Vec2i{X: 25, Y: 10}, 4) tilemap.Set(Vec2i{X: 25, Y: 16}, 4) tilemap.Set(Vec2i{X: 19, Y: 4}, 4) tilemap.Set(Vec2i{X: 19, Y: 10}, 4) tilemap.Set(Vec2i{X: 19, Y: 16}, 4) _ = window.UpdateSurface() lastSecond := time.Now() framesSinceLastSecond := 0 targetFPS := 60 frameDuration := time.Second / time.Duration(targetFPS) lastFrame := lastSecond running := true tick := 0 for running { for event := sdl.PollEvent(); event != nil; event = sdl.PollEvent() { switch event.(type) { case *sdl.QuitEvent: running = false break } } now := time.Now() delta := now.Sub(lastSecond) //println(delta.Seconds()) //println(now.Second()) if delta.Seconds() >= 1.0 { fmt.Printf("FPS: %5d | mspf: %f\n", framesSinceLastSecond, 1000.0/float32(framesSinceLastSecond)) framesSinceLastSecond = 0 lastSecond = lastSecond.Add(time.Second) } delta2 := now.Sub(lastFrame) if delta2 >= frameDuration { //t := (float64(tick)) / 1000 screen.Clear(0x123456) screen.DrawTextOutline( // "Hello World, this is a test,\nand now for another line :)", // "Hello World, this is a test", // "Vigilance, deathtouch, haste\n\nQuesting Beast can't be blocked by creatures\nwith power 2 or less.\n\nCombat damage that would be dealt by\ncreatures you control can't be prevented.\n\nWhenever Questing Beast deals combat damage\nto an opponent, it deals that much damage to\ntarget planeswalker that player controls.", "Lorem ipsum dolor sit amet,\n"+ "consectetur adipiscing elit,\n"+ "sed do eiusmod tempor incididunt\n"+ "ut labore et dolore magna aliqua.\n"+ "Ut enim ad minim veniam, quis\n"+ "nostrud exercitation ullamco\n"+ "laboris nisi ut aliquip ex ea\n"+ "commodo consequat. Duis aute\n"+ "irure dolor in reprehenderit in\n"+ "voluptate velit esse cillum dolore\n"+ "eu fugiat nulla pariatur.\n"+ "Excepteur sint occaecat cupidatat\n"+ "non proident, sunt in culpa qui\n"+ "officia deserunt mollit anim id\n"+ "est laborum.", DefaultFont, Vec2i{X: 10, Y: 10}, 0xffdddd, color.Black, // 50, // 3.0, // float64(tick) / 60.0, ) screen.DrawTilemap(tilemap, Vec2i{}) screen.Draw(tilemap.Tileset[2], Vec2i{X: 16 * 25, Y: 16 * 4}) screen.Draw(tilemap.Tileset[1], Vec2i{X: 16 * 13, Y: 16 * 16}) windowImage.DrawUpscale(screen) //windowImage.Draw(screen, Vec2i{}) tick += 1 framesSinceLastSecond += 1 lastFrame = lastFrame.Add(frameDuration) } _ = window.UpdateSurface() } }