Advertisement
Guest User

pico 8 adventure game animation error

a guest
Dec 27th, 2024
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.33 KB | Source Code | 0 0
  1. function _init()
  2. map_setup()
  3. text_setup()
  4. make_player()
  5. end
  6.  
  7. function _update()
  8. if (not active_text) then
  9. update_map()
  10. walk()
  11. end
  12. end
  13.  
  14. function _draw()
  15. cls()
  16. draw_map()
  17. draw_player()
  18. draw_text()
  19. end
  20. --map
  21.  
  22. function map_setup()
  23. --timers
  24. timer=0
  25. anim_time=30
  26.  
  27. --flags
  28. wall=0
  29. anim1=1 --frame 1
  30. anim2=2 --frame 2
  31. text=5
  32. end
  33.  
  34. function update_map()
  35. if (timer<0) then
  36. toggle_tiles()
  37. timer=anim_time
  38. end
  39. timer-=1
  40. end
  41.  
  42. function draw_map()
  43. mapx=flr(player.x/16)*16
  44. mapy=flr(player.y/16)*16
  45. camera(mapx*8,mapy*8)
  46.  
  47. map(0,0,0,0,128,64)
  48. end
  49.  
  50. function is_tile(tile_type,x,y)
  51. tile=mget(x,y)
  52. has_flag=fget(tile,tyle_type)
  53. return has_flag
  54. end
  55.  
  56. function can_move(x,y)
  57. return not is_tile(wall,x,y)
  58. end
  59.  
  60. function interact(x,y)
  61. if (is_tile(text,x,y)) then
  62. active_text=get_text(x,y)
  63. end
  64. end
  65.  
  66. function swap_tile(x,y)
  67. tile=mget(x,y)
  68. mset(x,y,tile+1)
  69. end
  70.  
  71. function unswap_tile(x,y)
  72. tile=mget(x,y)
  73. mset(x,y,tile-1)
  74. end
  75. --player things
  76. function make_player()
  77. player={}
  78. player.sprite=1
  79. player.x=8
  80. player.y=5
  81. player.flip=false
  82. player.up=false
  83. end
  84.  
  85. function draw_player()
  86. spr(player.sprite,player.x*8,player.y*8,1,1,player.flip)
  87. if player.up==true then
  88. spr(2,player.x*8,player.y*8)
  89. end
  90. end
  91.  
  92. function walk()
  93. newx=player.x
  94. newy=player.y
  95.  
  96. if btnp(⬆️) then newy-=1
  97. player.up=true
  98. elseif btnp(⬇️) then newy+=1
  99. player.up=false
  100. elseif btnp(⬅️) then newx-=1
  101. player.flip=true
  102. player.up=false
  103. elseif btnp(➡️) then newx+=1
  104. player.flip=false
  105. player.up=false
  106. end
  107.  
  108. interact(newx,newy)
  109.  
  110. if (can_move(newx,newy)) then
  111. player.x=mid(0,newx,127)
  112. player.y=mid(0,newy,63)
  113. else
  114. sfx(0)
  115. end
  116. end
  117. --text
  118.  
  119. function text_setup()
  120. texts={}
  121. add_text(8,3,"the creature lives here.")
  122. add_text(21,7,"welcom e to\nmushroom villag")
  123. end
  124.  
  125. function add_text(x,y,message)
  126. texts[x+y*128]=message
  127. end
  128.  
  129. function get_text(x,y)
  130. return texts[x+y*128]
  131. end
  132.  
  133. function draw_text()
  134. if (active_text) then
  135. textx=mapx*8+4
  136. texty=mapy*8+48
  137.  
  138. rectfill(textx,texty,textx+119,texty+31,7)
  139. print(active_text,textx+4,texty+4,5)
  140. print("❎ to ok",textx+4,texty+23,6)
  141. end
  142.  
  143. if btnp() then active_text=nil end
  144. end
  145. --anim code
  146.  
  147. function toggle_tiles()
  148. for x=mapx,mapx+15 do
  149. for y=mapy,mapy+15 do
  150. if (is_tile(anim1,x,y)) then
  151. swap_tile(x,y)
  152. elseif (is_tile(anim1,x,y)) then
  153. unswap_tile(x,y)
  154. end
  155. end
  156. end
  157. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement