Guest User

Untitled

a guest
Nov 16th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. frogX=0
  2. frogY=0
  3. died=0
  4. camX=frogX
  5. camY=frogY
  6.  
  7. ::_::
  8. flip()
  9. cls(1)
  10.  
  11. // weird arrow key input
  12. z=btnp()
  13.  
  14. // add +/- 5 to x for right/left arrows
  15. frogX+=(flr(z/2)%2-z%2)*5
  16.  
  17. // add +/- 1 to y for up/down arrows
  18. frogY-=flr(z/8)%2-flr(z/4)%2
  19.  
  20. // camera eases toward frog position
  21. camX+=(frogX-camX)/3
  22. camY+=(frogY-camY)/3
  23.  
  24. // draw road lanes
  25. for laneY=frogY+25,frogY-2,-1 do
  26. // each lane has its own randomized properties
  27. srand(laneY)
  28.  
  29. // car animation properties
  30. cycleOffset=rnd()
  31. carSpeed=8+rnd(16)
  32.  
  33. // perspective distortion strength
  34. // (persp=0 means "infinitely far away")
  35. persp=(laneY-camY+2.3)/12
  36.  
  37. // draw the road
  38. // (but draw it offscreen if persp<0)
  39. rectfill(-1,64+9/persp,sgn(persp)*127,127,6-laneY%2)
  40.  
  41. // draw a frog in every lane...
  42. // but offset it off the screen if the
  43. // frog isn't actually in this lane
  44. print("🐱",61+(frogX-camX)/persp+(laneY-frogY)*99,62+7.5/persp,3)
  45.  
  46. // each lane has a different # of cars
  47. // (early/negative lanes have no cars)
  48. for i=1,sgn(laneY-2)*rnd(8) do
  49. // a car has two halves, parallel to the lane
  50. // (near-half and far-half)
  51. for k=0,1 do
  52. // each car has five sub-circles for the body
  53. for j=-2,2 do
  54. // x-position of this sub-circle
  55. worldX=(i*carSpeed*4+j+t()*carSpeed+cycleOffset-camX)%198-99
  56.  
  57. // collision detection for the frog
  58. if laneY==frogY and abs(worldX-frogX+camX)<2 then
  59. died=1
  60. end
  61.  
  62. // far-half of car uses a different persp value
  63. persp2=persp-k/60
  64.  
  65. // get screen position of this sub-circle
  66. screenX=worldX/persp2+64
  67. screenY=5/persp2+64
  68.  
  69. // draw this sub-circle
  70. circfill(screenX,screenY,2/persp2,laneY%5)
  71.  
  72. // draw a wheel, but only if j equals +/- 2
  73. circfill(screenX,screenY+2/persp2,(abs(j)-1)/persp2,0)
  74. end
  75. end
  76. end
  77. end
  78.  
  79. // self-explanatory death check
  80. if (died>0) then
  81. goto dead
  82. end
  83.  
  84. // if you're not dead, continue the game loop
  85. goto _
  86.  
  87. ::dead::
  88. // you done goofed
  89.  
  90. // random red/orange noise
  91. pset(rnd(128),rnd(128),8+rnd(2))
  92.  
  93. // death UI
  94. print("❎ reset",46,62,7)
  95.  
  96. // your score is your distance, literally
  97. print("score: "..frogY,3,3)
  98.  
  99. // restart command
  100. if btn(5) then
  101. run()
  102. end
  103.  
  104. // haven't reset yet. resume death
  105. goto dead
Advertisement
Add Comment
Please, Sign In to add comment