Lunar Lander Knob and Button

No preview image

1 collaborator

Default-person Bryan Guo (Author)


(This model has yet to be categorized with any tags)
Child of model Lunar Lander preview imageLunar Lander
Model group LS426_2013 | Visible to everyone | Changeable by group members (LS426_2013)
Model was written in NetLogo 5.0.3 • Viewed 268 times • Downloaded 22 times • Run 0 times
Download the 'Lunar Lander Knob and Button' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


This model is based on the arcade game, Lunar Lander. The object of the game is to land the red lunar module on the blue landing pad on the surface of the moon without crashing or breaking the module.

The lunar module is fragile, so you have to be moving extremely slowly to prevent damage when you touch down. You have one thruster that exerts a force depending on the tilt of the module. You have the ability to tilt right and left.


Buttons: SETUP starts the game over by creating a new surface for you to navigate and poising your module above that surface, ready for descent. GO starts the game. Be ready; the module will start descending fairly quickly. LEFT and RIGHT tilt the module back and forth THRUST fires your rockets according to your current tilt.

Sliders: PLATFORM-WIDTH controls the width of the blue landing pad created at setup, a wider landing pad makes an easier target. TERRAIN-BUMPINESS controls the variation in the elevation of the lunar surface. More bumpiness may mean you will have large obstacles to maneuver around. THRUST-AMOUNT controls the magnitude of the force of your rockets.


When terrain-bumpiness is very high some of the randomly generated surfaces are not navigable.


Try to land the module with the fewest adjustments.

Increase the THRUST-AMOUNT to make the game harder.


Add one or more plots to the model. For example, you might plot the position, velocity, and/or acceleration of the module, in the plane or just on the Y axis.

Currently, collisions with the edges of the module are not detected, so you can graze the side of a peak with the edge of the module without crashing. It would be more realistic if these crashes were detected.

Add levels to the game by continually making the terrain bumpier, the platform smaller, or by some other method of making the game more difficult, perhaps alien spaceships.

Try to write a robot pilot that will automatically land the module safely.


This model uses the random-poisson reporter to create the terrain. See its entry in the NetLogo Dictionary, and also

The frame rate setting is used to control the speed of the game.


  • Projectile Attack
  • Gravitation


If you mention this model in a publication, we ask that you include these citations for the model itself and for the NetLogo software:


Copyright 2005 Uri Wilensky.


This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

extensions [gogo]

globals [
  platform     ;; the x coordinate of the center of the platform

turtles-own [
  xvel yvel    ;; x and y components of the lander's velocity

to connect
  set serial-port user-one-of "Select a port" gogo:ports
  gogo:open serial-port

to setup
  crt 1 [
    set shape "lander"
    set color red
    set size 10
    setxy (platform + max-pxcor)
          (max-pycor - size / 2)
    set heading 0

to setup-terrain
  let terrain-color gray
  set platform platform-width
               + random (world-width - 2 * platform-width)
               + min-pxcor
  ;; first use a turtle to draw the surface of the moon
  ;; including the landing platform
  crt 1 [
    set color gray
    setxy min-pxcor
          floor (min-pycor / 2)
    set heading 90
    repeat world-width [
      set pcolor color
      fd 1
      ;; draw the platform in blue
      if pxcor = platform - (platform-width / 2) [
        set heading 90
        set color blue
      ;; everything else is moon surface and should be gray
      if pxcor = platform + (platform-width / 2) [
        set color gray
      ;; and if it isn't the platform it should also be
      ;; jagged so vary ycor by the terrain-bumpiness
      if color != blue [
        ;; random-poisson usually gives small variations, occasionally
        ;; larger ones
        let y ( ycor + one-of [1 -1] * random-poisson ( terrain-bumpiness ) )
        ;; prevent the drawing turtle from wrapping vertically
        ;; while contouring the terrain
          if patch-at 0 (y - ycor) != nobody
          [ set ycor y ]

  ;; then use more turtles to make solid gray below the gray line
  ask patches with [pcolor != black] [
    sprout 1 [
      set heading 180
      ;; if the drawing turtle is already at the bottom it should not continue
      if not can-move? 1 [ die ]
      fd 1
      set pcolor gray
      fd 1
      while [ can-move? 1 ]
        set pcolor gray
        fd 1
      set pcolor gray

to go
  set vol gogo:sensor 2
    set button gogo:sensor 3
  if (not any? turtles) or ([color] of one-of turtles != red)
    [ stop ]
  ask turtles [
    ;; if the module is about to wrap vertically
    ;; stop its ascent
    ifelse ycor + yvel > max-pycor
    [ set xcor (xcor + xvel)
      set yvel 0 ]
    [ setxy (xcor + xvel) (ycor + yvel) ]
    ;; exert the force of gravity
    set yvel yvel - 0.001
    ;; detect crashes and insufficiently soft landings
    if [pcolor] of patch-at 0 -2 != black [
      ifelse (abs yvel > 0.08) or
             (abs xvel > 0.04) or
             (heading != 0) or
             ((pxcor - platform) >= platform-width / 2)
      [ game-over ]
      [ set color green - 1 ]
    ;; switch back to the shape without the thrusters on
    if shape = "lander2" and timer > 0.3
      [ set shape "lander" ]
  print vol
  if vol > 50 [ask turtles [set heading -50]]
  if vol > 100 [ask turtles [set heading -25]]
  if vol > 150 [ask turtles [set heading 0]]
  if vol > 200 [ask turtles [set heading 25]]
  if vol > 230 [ask turtles [set heading 50]]
  if button < 500 [ask turtles [thrust]]

to game-over  ;; turtle procedure
  set shape "skull"
  set color white
  set heading 0

to rotate-left  ;; turtle procedure
  if shape = "lander" [
    lt 5

to rotate-right  ;; turtle procedure
  if shape = "lander" [
    rt 5

to thrust  ;; turtle procedure
  if shape = "lander" [
    set xvel xvel + thrust-amount * dx
    set yvel yvel + thrust-amount * dy
    ;; lander2 has a visual indication that the thrusters are on
    set shape "lander2"

; Copyright 2005 Uri Wilensky.
; See Info tab for full copyright and license.

There is only one version of this model, created over 10 years ago by Bryan Guo.

Attached files

No files

Parent: Lunar Lander

This model does not have any descendants.

Graph of models related to 'Lunar Lander Knob and Button'