Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function _init()
- map_setup()
- text_setup()
- make_player()
- end
- function _update()
- if (not active_text) then
- update_map()
- walk()
- end
- end
- function _draw()
- cls()
- draw_map()
- draw_player()
- draw_text()
- end
- --map
- function map_setup()
- --timers
- timer=0
- anim_time=30
- --flags
- wall=0
- anim1=1 --frame 1
- anim2=2 --frame 2
- text=5
- end
- function update_map()
- if (timer<0) then
- toggle_tiles()
- timer=anim_time
- end
- timer-=1
- end
- function draw_map()
- mapx=flr(player.x/16)*16
- mapy=flr(player.y/16)*16
- camera(mapx*8,mapy*8)
- map(0,0,0,0,128,64)
- end
- function is_tile(tile_type,x,y)
- tile=mget(x,y)
- has_flag=fget(tile,tyle_type)
- return has_flag
- end
- function can_move(x,y)
- return not is_tile(wall,x,y)
- end
- function interact(x,y)
- if (is_tile(text,x,y)) then
- active_text=get_text(x,y)
- end
- end
- function swap_tile(x,y)
- tile=mget(x,y)
- mset(x,y,tile+1)
- end
- function unswap_tile(x,y)
- tile=mget(x,y)
- mset(x,y,tile-1)
- end
- --player things
- function make_player()
- player={}
- player.sprite=1
- player.x=8
- player.y=5
- player.flip=false
- player.up=false
- end
- function draw_player()
- spr(player.sprite,player.x*8,player.y*8,1,1,player.flip)
- if player.up==true then
- spr(2,player.x*8,player.y*8)
- end
- end
- function walk()
- newx=player.x
- newy=player.y
- if btnp(⬆️) then newy-=1
- player.up=true
- elseif btnp(⬇️) then newy+=1
- player.up=false
- elseif btnp(⬅️) then newx-=1
- player.flip=true
- player.up=false
- elseif btnp(➡️) then newx+=1
- player.flip=false
- player.up=false
- end
- interact(newx,newy)
- if (can_move(newx,newy)) then
- player.x=mid(0,newx,127)
- player.y=mid(0,newy,63)
- else
- sfx(0)
- end
- end
- --text
- function text_setup()
- texts={}
- add_text(8,3,"the creature lives here.")
- add_text(21,7,"welcom e to\nmushroom villag")
- end
- function add_text(x,y,message)
- texts[x+y*128]=message
- end
- function get_text(x,y)
- return texts[x+y*128]
- end
- function draw_text()
- if (active_text) then
- textx=mapx*8+4
- texty=mapy*8+48
- rectfill(textx,texty,textx+119,texty+31,7)
- print(active_text,textx+4,texty+4,5)
- print("❎ to ok",textx+4,texty+23,6)
- end
- if btnp(❎) then active_text=nil end
- end
- --anim code
- function toggle_tiles()
- for x=mapx,mapx+15 do
- for y=mapy,mapy+15 do
- if (is_tile(anim1,x,y)) then
- swap_tile(x,y)
- elseif (is_tile(anim1,x,y)) then
- unswap_tile(x,y)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement