Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- to setup
- page1
- ; sorry but you will have to listen for this
- launch [rocketman_sound]
- cg
- st
- ; add background
- ask [t1] [
- setsize 40
- setshape 9
- stamp
- setshape 0
- ]
- ; draw the death zone of a level
- ask [t1] [ pu setpos [-375 -180] ]
- ask [t1] [
- pd
- setcolor 'red'
- setheading 90
- forward 800
- home
- st
- setheading 180
- fd 1
- fill
- pu
- ]
- ; draw a starting place
- ask [t1] [
- setpos [-375 -180]
- setheading 0
- setcolor 'black'
- pd
- repeat 4 [fd 20 rt 90]
- rt 45
- fd 1
- fill
- pu
- make_outline
- ;create globals
- make 'gravity' 0
- make 'speed' 0
- make 'acceleration' 1
- ; please do not ask why we have 3 variable for a fuel
- make 'fuel_tank' 100
- make 'fuel_tank_starting' 100
- make 'fuel_used' 0
- ]
- ; create ending zone
- ask [t1] [
- setpos [336 -180]
- setheading 0
- setcolor 'green'
- pd
- fd 20 rt 90
- fd 40 rt 90
- fd 20 rt 90
- fd 40 rt 90
- rt 45
- fd 1
- fill
- pu
- ]
- ask [t2] [
- setpos [-360 0]
- setheading 0
- SET 't1' 'visible?' 'false'
- ; setsh 0
- setsize 10
- setsh [1 2]
- ; some technical globals to bound fuel to the player turtle
- MAKE 'ycor_of_t2' ycor
- MAKE 'xcor_of_t2' xcor
- MAKE 'heading_of_t2' 2160
- MAKE 'ycor_old_of_t2' (THING 'ycor_of_t2')
- ; global for a level
- MAKE 'level' 'base'
- rt 720
- lt 720
- ]
- ; if we leave it black, that might trigger some bags
- ask [t_fuel_tank] [
- setcolor 'yellow'
- setsize 10
- setshape 8
- ]
- go
- end
- ; go similar to NetLogo style game procedure
- ; that is a game engine
- to go
- ; since each page should have it's own turtles, we have no choice but to write the same
- ; turtles moving code but for a turles on each page with different names, that are playing the same role
- forever [
- use_key
- ; some reasonable wait time that is basically the game speed
- wait 0.1
- if (THING 'level') = 'base' [
- ; the roket moves based on a current gravity and players inputs
- ask [t2] [ move_rocket ]
- ; the fual tank follows the player on a distance of 25
- ask [t_fuel_tank] [move_fuel_tank 25]
- ]
- if (THING 'level') = 'moon_1'[
- ask [t_rocket_moon_1] [move_rocket]
- ask [t_fuel_tank_moon_1] [move_fuel_tank 25]
- ask [t_friend_1_moon_1] [ move_fuel_tank 50]
- ; asteroid moves with some speed
- ask [t_bad_moon] [move_asteroid 0.5]
- ]
- if (THING 'level') = 'moon_2'[
- ask [t_rocket_moon_2] [move_rocket]
- ask [t_fuel_tank_moon_2] [move_fuel_tank 25]
- ask [t_bad_moon_2] [move_asteroid_2 -2]
- ask [t_bad_moon_3] [move_asteroid_2 2]
- ask [t_bad_moon_4] [move_asteroid_2 -2]
- ask [t_bad_moon_5] [move_asteroid_2 2]
- ask [t_friend_1_moon_2] [move_fuel_tank 50 ]
- ask [t_friend_2_moon_2] [move_fuel_tank 75 ]
- ]
- if (THING 'level') = 'maze_1'[
- ask [t_rocket_maze_1] [move_rocket]
- ask [t_fuel_tank_maze_1] [move_fuel_tank 25]
- ask [t_friend_1_maze_1] [move_fuel_tank 50 ]
- ask [t_friend_2_maze_1] [move_fuel_tank 75 ]
- ask [t_friend_3_maze_1] [move_fuel_tank 100]
- ]
- if (THING 'level') = 'maze_2'[
- ask [t_rocket_maze_2] [move_rocket]
- ask [t_fuel_tank_maze_2] [move_fuel_tank 25]
- ask [t_friend_1_maze_2] [move_fuel_tank 50 ]
- ask [t_friend_2_maze_2] [move_fuel_tank 75 ]
- ask [t_friend_3_maze_2] [move_fuel_tank 100]
- ask [t_friend_4_maze_2] [move_fuel_tank 125]
- ]
- ]
- end
- to move_rocket
- setheading (THING 'heading_of_t2')
- ; turtle moves forward, base on a current speed
- fd (THING 'speed')
- ; the gravity pulls turtle down
- SETY ycor - (THING 'gravity')
- set 'fuel' 'text' word 'fuel: 'THING 'fuel_tank'
- IFELSE (THING 'speed') > 0 [
- ; air resistance (or gravity, idk) eats some of a speed
- ; but it could be negative
- MAKE 'speed' (THING 'speed') - 0.01
- ] [MAKE 'speed' 0]
- MAKE 'ycor_of_t2' ycor
- MAKE 'xcor_of_t2' xcor
- end
- ; place friend or fuel turtale on some distance from player
- to move_fuel_tank :distance
- ifelse (THING 'ycor_of_t2') > (THING 'ycor_old_of_t2')
- [ SETY (THING 'ycor_of_t2') - 5] [
- ifelse (THING 'ycor_of_t2') = (THING 'ycor_old_of_t2') [
- SETY (THING 'ycor_of_t2')
- ]
- [ SETY (THING 'ycor_of_t2') + 5]
- ]
- SETX (THING 'xcor_of_t2') - :distance
- setsize 12
- if :distance = 25 [
- ; animation for fuel left
- display_fuel_change [40 30 20 10 0]
- ]
- if :distance = 50 [
- if (THING 'choice_1') = 'friend' [setsh 17]
- if (THING 'choice_1') = 'fuel canister' [
- display_fuel_change muliply_list [40 30 20 10 0] 40
- ]
- ]
- if :distance = 75 [
- if (THING 'choice_2') = 'friend' [setsh 18]
- if (THING 'choice_2') = 'fuel canister' [
- display_fuel_change muliply_list [40 30 20 10 0] 60
- ]
- ]
- if :distance = 100 [
- if (THING 'choice_3') = 'friend' [setsh 19]
- if (THING 'choice_3') = 'fuel canister' [
- display_fuel_change muliply_list [40 30 20 10 0] 80
- ]
- ]
- if :distance = 125 [
- if (THING 'choice_4') = 'friend' [setsh 20]
- if (THING 'choice_4') = 'fuel canister' [
- display_fuel_change muliply_list [40 30 20 10 0] 100
- ]
- ]
- MAKE 'ycor_old_of_t2' (THING 'ycor_of_t2')
- end
- ; technical function to change fuel tank image based on a vector of values
- to display_fuel_change :list_of_values
- ifelse (THING 'fuel_tank') > ITEM 1 :list_of_values [setsh 8] [
- ifelse (THING 'fuel_tank') > ITEM 2 :list_of_values [setsh 7] [
- ifelse (THING 'fuel_tank') > ITEM 3 :list_of_values [setsh 6] [
- ifelse (THING 'fuel_tank') > ITEM 4 :list_of_values [setsh 5] [
- ifelse (THING 'fuel_tank') > ITEM 5 :list_of_values [setsh 4] [
- setsh 3]
- ] ] ] ]
- end
- ; we do not want to hardcode stuff, so we had to add X to all
- ; elements in the list
- ; firtsly we thought that we need to multiply something
- ; hence the name
- to muliply_list :list_of_values :mult
- make 'm_list' []
- dolist [i :list_of_values] [
- make 'm_list' LPUT (:i + :mult) THING 'm_list'
- ]
- OUTPUT THING 'm_list'
- end
- ; move asteroid by x cor
- to move_asteroid :speed
- setx xcor + :speed
- rt 90
- end
- ; move asteroid by y cor
- to move_asteroid_2 :speed
- sety ycor + :speed
- rt 90
- end
- ; all interactions are based on a pure colors:
- ; black == stop moving
- ; green == next level
- ; red reset t the beggining
- ; all other colors -- usual behaviour
- to t2_oncolour :prevColour :newColour
- IFELSE :NEWCOLOUR = 'black' [
- MAKE 'gravity' 0 MAKE 'speed' 0] [
- IFELSE :NEWCOLOUR = 'red' [MAKE 'fuel_used' 100 - (THING 'fuel_tank') + (THING 'fuel_used') setup] [
- IFELSE :NEWCOLOUR = 'green' [
- ; ANNOUNCE "finished"
- MAKE 'fuel_used' (thing 'fuel_tank_starting') - (THING 'fuel_tank') + (THING 'fuel_used')
- ; page_moon_1
- ; ht
- ; setup_moon
- page_choice_1
- stop
- ] [
- MAKE 'gravity' 1 ]
- ]
- ]
- end
- ; noting will happend without user input
- ; and without fuel
- ; w increases your speed by acceleration
- ; s decreases
- ; a is left turn
- ; d is the right one
- ; user inputs consume 2 fuel on each click
- to use_key
- if not KEY? [stop]
- if (THING 'fuel_tank') = 0 [stop]
- if peekchar = 'w' [make 'speed' (THING 'speed') + (THING 'acceleration')]
- if peekchar = 's' [
- make 'speed' (THING 'speed') - (THING 'acceleration')]
- if peekchar = 'a' [
- MAKE 'heading_of_t2' (THING 'heading_of_t2') - 45
- ]
- if peekchar = 'd' [
- MAKE 'heading_of_t2' (THING 'heading_of_t2') + 45
- ]
- MAKE 'fuel_tank' (THING 'fuel_tank') - 2
- skipchar
- end
- ; originnaly was used for a debugging, but
- ; could help to return to the wery beggining
- to reset
- page1
- t1,
- t2,
- setup
- end
- ; if you crash into asteroid
- ; you will hear some sound
- ; yes, even in the space
- to t2_click
- t2_click
- end
- to t_bad_moon_2_touch :touchedturtle
- t_bad_moon_touch_2
- end
- to t_bad_moon_3_touch :touchedturtle
- t_bad_moon_touch_2
- end
- to t_bad_moon_4_touch :touchedturtle
- t_bad_moon_touch_2
- end
- to t_bad_moon_5_touch :touchedturtle
- t_bad_moon_touch_2
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement