bunnymark.odin 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // This is a port of https://www.raylib.com/examples/textures/loader.html?name=textures_bunnymark
  2. package karl2d_bunnymark
  3. import k2 "../../.."
  4. import "core:math/rand"
  5. import "core:log"
  6. MAX_BUNNIES :: 50000
  7. Bunny :: struct {
  8. position: k2.Vec2,
  9. speed: k2.Vec2,
  10. color: k2.Color,
  11. }
  12. main :: proc() {
  13. context.logger = log.create_console_logger()
  14. SCREEN_WIDTH :: 800
  15. SCREEN_HEIGHT :: 450
  16. k2.init(SCREEN_WIDTH, SCREEN_HEIGHT, "bunnymark (raylib port)")
  17. tex_bunny := k2.load_texture_from_file("wabbit_alpha.png")
  18. bunnies: [dynamic]Bunny
  19. for !k2.shutdown_wanted() {
  20. if k2.mouse_button_is_held(.Left) {
  21. for _ in 0..<100 {
  22. append(&bunnies, Bunny {
  23. position = k2.get_mouse_position(),
  24. speed = {
  25. rand.float32_range(-250, 250)/60,
  26. rand.float32_range(-250, 250)/60,
  27. },
  28. color = {
  29. u8(rand.int_max(190) + 50),
  30. u8(rand.int_max(160) + 80),
  31. u8(rand.int_max(140) + 100),
  32. 255,
  33. },
  34. })
  35. }
  36. }
  37. for &b in bunnies {
  38. b.position += b.speed
  39. if (b.position.x + f32(tex_bunny.width/2) > f32(k2.get_screen_width())) || ((b.position.x + f32(tex_bunny.width/2)) < 0) {
  40. b.speed.x *= -1
  41. }
  42. if (b.position.y + f32(tex_bunny.height/2) > f32(k2.get_screen_height())) || ((b.position.y + f32(tex_bunny.height/2)) < 0) {
  43. b.speed.y *= -1
  44. }
  45. }
  46. k2.process_events()
  47. k2.clear(k2.RL_RAYWHITE)
  48. for &b in bunnies {
  49. k2.draw_texture(tex_bunny, b.position, b.color)
  50. }
  51. k2.present()
  52. }
  53. delete(bunnies)
  54. k2.destroy_texture(tex_bunny)
  55. k2.shutdown()
  56. }