minimal.odin 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package karl2d_minimal_example
  2. import k2 "../.."
  3. import "core:mem"
  4. import "core:log"
  5. import "core:fmt"
  6. import "core:math"
  7. import "core:time"
  8. _ :: fmt
  9. _ :: mem
  10. tex: k2.Texture
  11. init :: proc() {
  12. k2.init(1080, 1080, "Karl2D Minimal Program", {.Resizable})
  13. k2.set_window_position(300, 100)
  14. tex = k2.load_texture_from_bytes(#load("sixten.jpg"))
  15. }
  16. t: f32
  17. step :: proc(dt: f32) -> bool {
  18. k2.process_events()
  19. k2.clear(k2.BLUE)
  20. t += dt
  21. pos := math.sin(t*10)*10
  22. rot := t*50
  23. k2.draw_texture_ex(tex, {0, 0, f32(tex.width), f32(tex.height)}, {pos + 400, 450, 900, 500}, {450, 250}, rot)
  24. k2.draw_rect({10, 10, 60, 60}, k2.GREEN)
  25. k2.draw_rect({20, 20, 40, 40}, k2.BLACK)
  26. k2.draw_circle({120, 40}, 30, k2.BLACK)
  27. k2.draw_circle({120, 40}, 20, k2.GREEN)
  28. k2.draw_text("Hellöpe!", {10, 100}, 64, k2.WHITE)
  29. k2.present()
  30. free_all(context.temp_allocator)
  31. res := true
  32. if k2.key_went_down(.Escape) {
  33. res = false
  34. }
  35. return res
  36. }
  37. shutdown :: proc() {
  38. k2.destroy_texture(tex)
  39. k2.shutdown()
  40. }
  41. main :: proc() {
  42. context.logger = log.create_console_logger()
  43. init()
  44. prev_time := time.now()
  45. for !k2.shutdown_wanted() {
  46. now := time.now()
  47. since := time.diff(prev_time, now)
  48. dt := f32(time.duration_seconds(since))
  49. prev_time = now
  50. if !step(dt) {
  51. break
  52. }
  53. }
  54. shutdown()
  55. }