minimal.odin 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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")
  13. tex = k2.load_texture_from_bytes(#load("sixten.jpg"))
  14. }
  15. t: f32
  16. step :: proc(dt: f32) -> bool {
  17. k2.process_events()
  18. k2.clear(k2.BLUE)
  19. t += dt
  20. pos := math.sin(t*10)*10
  21. rot := t*50
  22. k2.draw_texture_ex(tex, {0, 0, f32(tex.width), f32(tex.height)}, {pos + 400, 450, 900, 500}, {450, 250}, rot)
  23. k2.draw_rect({10, 10, 60, 60}, k2.GREEN)
  24. k2.draw_rect({20, 20, 40, 40}, k2.BLACK)
  25. k2.draw_circle({120, 40}, 30, k2.BLACK)
  26. k2.draw_circle({120, 40}, 20, k2.GREEN)
  27. k2.draw_text("Hellöpe!", {10, 100}, 64, k2.WHITE)
  28. if k2.key_went_down(.R) {
  29. k2.set_window_flags({.Resizable})
  30. }
  31. if k2.key_went_down(.N) {
  32. k2.set_window_flags({})
  33. }
  34. k2.present()
  35. free_all(context.temp_allocator)
  36. res := true
  37. if k2.key_went_down(.Escape) {
  38. res = false
  39. }
  40. return res
  41. }
  42. shutdown :: proc() {
  43. k2.destroy_texture(tex)
  44. k2.shutdown()
  45. }
  46. main :: proc() {
  47. context.logger = log.create_console_logger()
  48. init()
  49. prev_time := time.now()
  50. for !k2.shutdown_wanted() {
  51. now := time.now()
  52. since := time.diff(prev_time, now)
  53. dt := f32(time.duration_seconds(since))
  54. prev_time = now
  55. if !step(dt) {
  56. break
  57. }
  58. }
  59. shutdown()
  60. }