1
0

mario.l 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. (
  2. (def rgb888->565 (fn orig (do
  3. (let sz 0)
  4. (let i 0)
  5. (let j 0)
  6. (let r 0)
  7. (let g 0)
  8. (let b 0)
  9. (let rgb 0)
  10. (let sz (size orig))
  11. (let out (alloc (/ sz 2)))
  12. (while (lt i sz) (do
  13. (let r (shl (shr (get orig (+ i 2)) 3) 11))
  14. (let g (shl (shr (get orig (+ i 1)) 2) 5))
  15. (let b (shr (get orig (+ i 0)) 3))
  16. (let rgb (bitor (bitor g b) r))
  17. (put out (+ j 1) (shr (bitand rgb 0xff00) 8))
  18. (put out (+ j 0) (bitand rgb 0xff))
  19. (let i (+ i 4))
  20. (let j (+ j 2))
  21. ))
  22. out
  23. )))
  24. (blit-str "loading tiles..." 500 800)
  25. (def f (open "/sd/smb3.888"))
  26. (def mariotiles (rgb888->565 (recv f)))
  27. (blit-str "loading sprites..." 500 800)
  28. (def sprites (rgb888->565 (load "/sd/mario.888")))
  29. (def mario-palm (fn x y (do
  30. (let rs rune-spacing)
  31. (blit-str [c5c6c7] (* x rs) (* y rs))
  32. (blit-char 0x100 (* (+ 1 x) rs) (* (+ 1 y) rs))
  33. )))
  34. (def set-mario-font (fn (do
  35. (def font mariotiles)
  36. (def font-pitch 986)
  37. (def rune-w 17)
  38. (def rune-h 17)
  39. (def rune-spacing 16)
  40. (def rune-mod 58)
  41. )))
  42. (def set-sprite-font (fn (do
  43. (def font sprites)
  44. (def font-pitch 400)
  45. (def rune-w 20)
  46. (def rune-h 30)
  47. (def rune-spacing 20)
  48. (def rune-mod 100)
  49. )))
  50. (def mario (fn (do
  51. (set-mario-font)
  52. (let rs rune-spacing)
  53. ;(blit-str [0102030405060708090a0b0c0d0e] 0 0)
  54. ;(blit-str [0f101112131415161718191a1b1c] 0 17)
  55. (let i 0)
  56. (while (lt i 20) (do
  57. (blit-str [84848484848484848484848484848484848484848484848484848484848484] 0 (* i rs))
  58. (let i (+ i 1))
  59. ))
  60. (mario-palm 5 5)
  61. (mario-palm 7 6)
  62. (mario-palm 10 5)
  63. (mario-palm 9 8)
  64. (blit-char 0x42b (* 16 20) (* 16 8))
  65. (blit-char 0x42c (* 16 21) (* 16 8))
  66. (blit-char 0x465 (* 16 20) (* 16 9))
  67. (blit-char 0x466 (* 16 21) (* 16 9))
  68. (let x 200)
  69. (let y 150)
  70. (let tick 0)
  71. (let runs 1)
  72. (let mario-rune 5)
  73. (while runs (do
  74. ;(set-mario-font)
  75. ;(if tick
  76. ; (blit-str "vvvv" (* 16 20) (* 16 10))
  77. ; (blit-str "wwww" (* 16 20) (* 16 10))
  78. ;)
  79. (set-sprite-font)
  80. ;(let x (+ x 1))
  81. (let str (recv keyboard))
  82. (let c (get str 0))
  83. (if (eq c 17) (do ; walk up
  84. (let y (- y 2))
  85. (let tick (- 1 tick))
  86. ) 0)
  87. (if (eq c 18) (do ; walk down
  88. (let y (+ y 2))
  89. (let tick (- 1 tick))
  90. ) 0)
  91. (if (eq c 19) (do ; walk left
  92. (let x (- x 2))
  93. (let mario-rune 3)
  94. (let tick (- 1 tick))
  95. ) 0)
  96. (if (eq c 20) (do ; walk right
  97. (let x (+ x 2))
  98. (let mario-rune 5)
  99. (let tick (- 1 tick))
  100. ) 0)
  101. (if (eq c 32) (do
  102. (let runs 0)
  103. ) 0)
  104. (blit-char (+ mario-rune tick) x y)
  105. (send scr 0)
  106. ;(gc)
  107. ))
  108. (set-unifont)
  109. )))
  110. (def mario2 (fn (do
  111. (mario)
  112. (print (gc))
  113. 0
  114. )))
  115. (mario2)
  116. (main)
  117. )