Advertisement
vvseva

base logo

Jan 23rd, 2023
832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. to setup
  2. page1
  3. ; sorry but you will have to listen for this
  4. launch [rocketman_sound]
  5.  
  6. cg
  7. st
  8.  
  9. ; add background
  10. ask [t1] [
  11.   setsize 40
  12.   setshape 9
  13.   stamp
  14.   setshape 0
  15.   ]
  16.  
  17. ; draw the death zone of a level
  18. ask [t1] [ pu setpos [-375 -180] ]
  19.  
  20. ask [t1] [
  21.   pd
  22. setcolor 'red'
  23. setheading 90
  24. forward 800
  25.   home
  26.   st
  27. setheading 180
  28. fd 1
  29. fill
  30. pu
  31. ]
  32.  
  33. ; draw a starting place
  34. ask [t1] [
  35.   setpos [-375 -180]
  36.   setheading 0
  37.   setcolor 'black'
  38.   pd
  39.   repeat 4 [fd 20  rt 90]
  40.   rt 45
  41.   fd 1
  42.   fill
  43.   pu
  44.   make_outline
  45.   ;create globals
  46.   make 'gravity' 0
  47.   make 'speed' 0
  48.   make 'acceleration' 1
  49.   ; please do not ask why we have 3 variable for a fuel
  50.   make 'fuel_tank' 100
  51.   make 'fuel_tank_starting' 100
  52.   make 'fuel_used' 0
  53.   ]
  54.  
  55. ; create ending zone
  56. ask [t1] [
  57.   setpos [336 -180]
  58.   setheading 0
  59.   setcolor 'green'
  60.   pd
  61.   fd 20  rt 90
  62.   fd 40  rt 90
  63.   fd 20  rt 90
  64.   fd 40  rt 90
  65.   rt 45
  66.   fd 1
  67.   fill
  68.   pu
  69.   ]
  70.  
  71.   ask [t2] [
  72.    
  73.     setpos [-360 0]
  74.     setheading 0
  75.     SET 't1' 'visible?' 'false'
  76.     ; setsh 0
  77.     setsize 10
  78.     setsh [1 2]
  79.    
  80.     ; some technical globals to bound fuel to the player turtle
  81.     MAKE 'ycor_of_t2' ycor
  82.     MAKE 'xcor_of_t2' xcor
  83.    
  84.     MAKE 'heading_of_t2' 2160
  85.    
  86.     MAKE 'ycor_old_of_t2' (THING 'ycor_of_t2')
  87.    
  88.     ; global for a level
  89.     MAKE 'level' 'base'
  90.    
  91.    
  92.     rt 720
  93.     lt 720
  94.     ]
  95.    
  96.     ; if we leave it black, that might trigger some bags
  97.   ask [t_fuel_tank]  [
  98.     setcolor 'yellow'
  99.     setsize 10
  100.     setshape 8
  101.     ]
  102. go    
  103.  
  104. end
  105.  
  106. ; go similar to NetLogo style game procedure
  107. ; that is a game engine
  108. to go
  109. ; since each page should have it's own turtles, we have no choice but to write the same
  110. ; turtles moving code but for a turles on each page with different names, that are playing the same role
  111. forever [
  112.   use_key
  113.   ; some reasonable wait time that is basically the game speed
  114.   wait 0.1
  115.  
  116.  
  117.   if (THING 'level') = 'base' [
  118.   ; the roket moves based on a current gravity and players inputs
  119.   ask [t2] [ move_rocket ]
  120.   ; the fual tank follows the player on a distance of 25
  121.   ask [t_fuel_tank] [move_fuel_tank 25]
  122. ]
  123.  
  124.   if (THING 'level') = 'moon_1'[
  125.     ask [t_rocket_moon_1] [move_rocket]
  126.     ask [t_fuel_tank_moon_1] [move_fuel_tank 25]
  127.     ask [t_friend_1_moon_1] [ move_fuel_tank 50]
  128.     ; asteroid moves with some speed
  129.     ask [t_bad_moon] [move_asteroid 0.5]
  130.     ]
  131.     if (THING 'level') = 'moon_2'[
  132.     ask [t_rocket_moon_2] [move_rocket]
  133.     ask [t_fuel_tank_moon_2] [move_fuel_tank 25]
  134.     ask [t_bad_moon_2] [move_asteroid_2 -2]
  135.     ask [t_bad_moon_3] [move_asteroid_2 2]
  136.     ask [t_bad_moon_4] [move_asteroid_2 -2]
  137.     ask [t_bad_moon_5] [move_asteroid_2 2]
  138.     ask [t_friend_1_moon_2] [move_fuel_tank 50 ]
  139.     ask [t_friend_2_moon_2] [move_fuel_tank 75 ]
  140.  
  141.     ]
  142.   if (THING 'level') = 'maze_1'[
  143.     ask [t_rocket_maze_1] [move_rocket]
  144.     ask [t_fuel_tank_maze_1] [move_fuel_tank 25]
  145.     ask [t_friend_1_maze_1] [move_fuel_tank 50 ]
  146.     ask [t_friend_2_maze_1] [move_fuel_tank 75 ]
  147.     ask [t_friend_3_maze_1] [move_fuel_tank 100]
  148.  
  149.     ]
  150.   if (THING 'level') = 'maze_2'[
  151.     ask [t_rocket_maze_2] [move_rocket]
  152.     ask [t_fuel_tank_maze_2] [move_fuel_tank 25]
  153.     ask [t_friend_1_maze_2] [move_fuel_tank 50 ]
  154.     ask [t_friend_2_maze_2] [move_fuel_tank 75 ]
  155.     ask [t_friend_3_maze_2] [move_fuel_tank 100]
  156.     ask [t_friend_4_maze_2] [move_fuel_tank 125]
  157.  
  158.     ]
  159.   ]
  160. end
  161.  
  162. to move_rocket
  163.  
  164.     setheading (THING 'heading_of_t2')
  165.    
  166.     ; turtle moves forward, base on a current speed
  167.     fd (THING 'speed')
  168.     ; the gravity pulls turtle down
  169.     SETY ycor - (THING 'gravity')
  170.     set 'fuel' 'text' word 'fuel: 'THING 'fuel_tank'
  171.    
  172.     IFELSE (THING 'speed') > 0 [
  173.     ; air resistance (or gravity, idk) eats some of a speed
  174.     ; but it could be negative
  175.       MAKE 'speed' (THING 'speed') - 0.01
  176.     ] [MAKE 'speed' 0]
  177.    
  178.     MAKE 'ycor_of_t2' ycor
  179.     MAKE 'xcor_of_t2' xcor
  180.    
  181.  
  182. end
  183.  
  184. ; place friend or fuel turtale on some distance from player
  185. to move_fuel_tank :distance
  186.  
  187.   ifelse (THING 'ycor_of_t2') > (THING 'ycor_old_of_t2')
  188.   [ SETY (THING 'ycor_of_t2') - 5] [
  189.     ifelse  (THING 'ycor_of_t2') = (THING 'ycor_old_of_t2') [
  190.       SETY (THING 'ycor_of_t2')
  191.       ]
  192.    
  193.   [ SETY (THING 'ycor_of_t2') + 5]
  194. ]
  195.   SETX (THING 'xcor_of_t2') - :distance
  196.   setsize 12
  197.   if :distance = 25 [
  198.   ; animation for fuel left
  199.   display_fuel_change [40 30 20 10 0]
  200.  
  201.   ]
  202.  
  203.   if :distance = 50 [
  204.   if (THING 'choice_1') = 'friend' [setsh 17]
  205.   if (THING 'choice_1') = 'fuel canister' [
  206.      display_fuel_change muliply_list [40 30 20 10 0] 40
  207.   ]
  208.   ]
  209.  
  210.     if :distance = 75 [
  211.   if (THING 'choice_2') = 'friend' [setsh 18]
  212.   if (THING 'choice_2') = 'fuel canister' [
  213.      display_fuel_change muliply_list [40 30 20 10 0] 60
  214.   ]
  215.   ]
  216.  
  217.       if :distance = 100 [
  218.   if (THING 'choice_3') = 'friend' [setsh 19]
  219.   if (THING 'choice_3') = 'fuel canister' [
  220.      display_fuel_change muliply_list [40 30 20 10 0] 80
  221.   ]
  222.   ]
  223.  
  224.     if :distance = 125 [
  225.   if (THING 'choice_4') = 'friend' [setsh 20]
  226.   if (THING 'choice_4') = 'fuel canister' [
  227.      display_fuel_change muliply_list [40 30 20 10 0] 100
  228.   ]
  229.   ]
  230.  
  231. MAKE 'ycor_old_of_t2' (THING 'ycor_of_t2')
  232.  
  233. end
  234.  
  235. ; technical function to change fuel tank image based on a vector of values
  236. to display_fuel_change :list_of_values
  237.   ifelse (THING 'fuel_tank') > ITEM 1 :list_of_values [setsh 8] [
  238.   ifelse (THING 'fuel_tank') > ITEM 2 :list_of_values [setsh 7] [
  239.   ifelse (THING 'fuel_tank') > ITEM 3 :list_of_values [setsh 6] [
  240.   ifelse (THING 'fuel_tank') > ITEM 4 :list_of_values [setsh 5] [
  241.   ifelse (THING 'fuel_tank') > ITEM 5 :list_of_values [setsh 4] [
  242.      setsh 3]
  243.   ] ] ] ]  
  244. end
  245.  
  246. ; we do not want to hardcode stuff, so we had to add X to all
  247. ; elements in the list
  248. ; firtsly we thought that we need to multiply something
  249. ; hence the name
  250. to muliply_list :list_of_values :mult
  251. make 'm_list' []
  252. dolist [i :list_of_values] [
  253.   make 'm_list' LPUT (:i + :mult) THING 'm_list'
  254.   ]
  255.  OUTPUT THING 'm_list'
  256. end
  257.  
  258. ; move asteroid by x cor
  259. to move_asteroid :speed
  260.   setx xcor + :speed
  261.   rt 90
  262. end
  263.  
  264. ; move asteroid by y cor
  265. to move_asteroid_2 :speed
  266.   sety ycor + :speed
  267.   rt 90
  268. end
  269.  
  270. ; all interactions are based on a pure colors:
  271. ; black == stop moving
  272. ; green == next level
  273. ; red reset t the beggining
  274. ; all other colors -- usual behaviour
  275. to t2_oncolour :prevColour :newColour
  276. IFELSE :NEWCOLOUR = 'black' [
  277. MAKE 'gravity' 0 MAKE 'speed' 0] [
  278.   IFELSE :NEWCOLOUR = 'red' [MAKE 'fuel_used' 100 - (THING 'fuel_tank') + (THING 'fuel_used') setup] [
  279.     IFELSE :NEWCOLOUR = 'green' [
  280.   ; ANNOUNCE "finished"
  281.   MAKE 'fuel_used' (thing 'fuel_tank_starting') - (THING 'fuel_tank') + (THING 'fuel_used')
  282.   ; page_moon_1
  283.   ; ht
  284.   ; setup_moon
  285.   page_choice_1
  286.   stop
  287. ] [
  288. MAKE 'gravity' 1 ]
  289.     ]
  290.   ]
  291.  
  292. end
  293.  
  294. ; noting will happend without user input
  295. ; and without fuel
  296. ; w increases your speed by acceleration
  297. ; s decreases
  298. ; a is left turn
  299. ; d is the right one
  300. ; user inputs consume 2 fuel on each click
  301. to use_key
  302. if not KEY? [stop]
  303. if (THING 'fuel_tank') = 0 [stop]
  304. if peekchar = 'w' [make 'speed' (THING 'speed') + (THING 'acceleration')]
  305. if peekchar = 's' [
  306.   make 'speed' (THING 'speed') - (THING 'acceleration')]
  307. if peekchar = 'a' [
  308.   MAKE 'heading_of_t2' (THING 'heading_of_t2') - 45
  309.   ]
  310. if peekchar = 'd' [
  311.   MAKE 'heading_of_t2' (THING 'heading_of_t2') + 45
  312.   ]
  313. MAKE 'fuel_tank' (THING 'fuel_tank') - 2
  314. skipchar
  315. end
  316.  
  317. ; originnaly was used for a debugging, but
  318. ; could help to return to the wery beggining
  319. to reset
  320. page1
  321. t1,
  322. t2,
  323. setup
  324. end
  325.  
  326.  
  327. ; if you crash into asteroid
  328. ; you will hear some sound
  329. ; yes, even in the space
  330. to t2_click
  331. t2_click
  332. end
  333.  
  334. to t_bad_moon_2_touch :touchedturtle
  335. t_bad_moon_touch_2
  336. end
  337.  
  338. to t_bad_moon_3_touch :touchedturtle
  339. t_bad_moon_touch_2
  340. end
  341.  
  342. to t_bad_moon_4_touch :touchedturtle
  343. t_bad_moon_touch_2
  344. end
  345.  
  346. to t_bad_moon_5_touch :touchedturtle
  347. t_bad_moon_touch_2
  348. end
  349.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement