Advertisement
SteelGolem

[pico-8] fixed platform example

Mar 19th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.88 KB | None | 0 0
  1. game_w=128
  2. game_h=128
  3.  
  4. function _init()
  5.  plat={}
  6.  plat.w=game_w
  7.  plat.h=game_h
  8.  plat.x=0
  9.  plat.y=game_h/2
  10.  
  11.  player={}
  12.  player.w=8
  13.  player.h=8
  14.  player.x=game_w/2
  15.  player.y=plat.y-player.h
  16.  player.spr=1
  17.  player.spd=2
  18.  player.vy=0
  19.  player.start_vy=-5
  20.  player.in_air=false
  21.  
  22.  grav=.5
  23. end
  24.  
  25. function _update()
  26.  if btn(➡️) then
  27.   if player.x+player.w<game_w then
  28.    player.x+=player.spd
  29.   end
  30.  end
  31.  if btn(⬅️) then
  32.   if player.x>0 then
  33.    player.x-=player.spd
  34.   end
  35.  end
  36.  if btnp() then
  37.   if player.vy==0 then
  38.    player.vy=player.start_vy
  39.    player.in_air=true
  40.   end
  41.  end
  42.  if player.in_air then
  43.   player.y+=player.vy
  44.   player.vy+=grav
  45.  end
  46.  if player.y+player.h>=plat.y then
  47.   player.vy=0
  48.   player.in_air=false
  49.  end
  50. end
  51.  
  52. function _draw()
  53.  cls()
  54.  rectfill(plat.x,plat.y,plat.x+plat.w-1,plat.y+plat.h-1,7)
  55.  spr(player.spr,player.x,player.y)
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement