Pac-Man Level Editor

Pac-Man Level Editor preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

game 

Tagged by Reuven M. Lerner almost 11 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 8217 times • Downloaded 253 times • Run 4 times
Download the 'Pac-Man Level Editor' modelDownload this modelEmbed this model

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


WHAT IS IT?

This is a level editor for the Pac-Man model. It can be used to edit the included levels and to create new levels that can be played in the Pac-Man model. Familiarity with the Pac-Man model will be very helpful before attempting to create or edit levels.

HOW IT WORKS

Use the various tools to construct a level for the Pac-Man model.

HOW TO USE IT

The following are for setup, loading, and saving:

NEW LEVEL - Clears the level and sets it up to start making a new level from scratch. LOAD LEVEL - Prompts for a level number to load for editing. The file opened will be the file "pacmap#.csv" (where # is the input level number), and the file must be in the Games folder in the Sample Models section of the Models Library. (Files will not be visible in the Models Library Browser.) -- With both NEW LEVEL and LOAD LEVEL, any unsaved changes to a level will be lost (you will be reminded of this and prompted to continue when using these buttons). SAVE LEVEL - Prompts to save the current level to a file usable by the Pac-Man model. The file will be saved in the Games folder in the Sample Models section of the Models Library with the Pac-Man model with the file name "pacmap#.csv" (where # is the currently set level number). Saving a level with the same level number as a previously created level will overwrite the old level (it is not be possible to recover overwritten levels). SET LEVEL - Sets the current value of 'level' which determines the filename of the level when it is saved with SAVE LEVEL. LEVEL - This monitor shows the current value of level.

The following are the tools for actually editing levels:

USE TOOL - Allows you to use the current tool on a patch by clicking on it with the mouse. CURRENT TOOL - Shows what the currently selected tool is. WHICH-GHOST - This slider determines which Ghost will be moved by the PLACE GHOST tool.

-- The following buttons set the current tool to do different actions. ERASER - This tool allows you to clear a patch of walls, gates, and pellets. DRAW WALL - This tool allows you to draw a wall (blue) on the current patch. DRAW GATE - This tool allows you to draw a gate (gray) on the current patch. PLACE PELLET - This tool allows you to place a pellet on the grid. TOGGLE POWER PELLET - This tool allows you to change a Pellet into a Power Pellet and vice versa. PLACE PAC-MAN - This tool allows you to change Pac-Man's starting position. PLACE GHOST - This tool allows you to change the starting position of the Ghost chosen by WHICH-GHOST.

THINGS TO NOTICE

If Pac-Man goes off the edge of the maze he will wrap around to the other side.

Identifying Things in the Maze: -- Yellow Circle with a mouth: This is Pac-Man - The protagonist. -- Small White Circles: These are Pellets - Pac-Man will have to collect all of these (including the Power-Pellets) to move on to the next level.

-- Large White Circles: These are Power-Pellets - They allow Pac-Man to eat the Ghosts for a limited amount of time.

-- Blue Squares: These are the walls of the maze - Neither Pac-Man nor the Ghosts can move through the walls.

-- Gray Squares: These are the Ghost Gates - Only Ghosts can move through them, and if they do so after having been eaten they will be healed.

-- Colorful Ghost with Eyes: These are the Ghosts - The antagonists.

THINGS TO TRY

Make a maze by strategically placing gates that has corridors that only Ghosts can travel down, but Pac-Man has to circum-navigate.

EXTENDING THE MODEL

The Pac-Man model suggests adding new features. Add tools to this model to allow you to construct these new features in a level.

Add the ability to have a variable number of ghosts in a level (including more than four).

NETLOGO FEATURES

This model makes use of breeds, create-, user-message, user-input, user-yes-or-no?, read-from-string, as well as the mouse primitives and import-world and export-world for loading and saving levels.

RELATED MODELS

Pac-Man

HOW TO CITE

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 AND LICENSE

Copyright 2003 Uri Wilensky.

CC BY-NC-SA 3.0

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ 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 uri@northwestern.edu.

This model was created as part of the projects: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT. The project gratefully acknowledges the support of the National Science Foundation (REPP & ROLE programs) -- grant numbers REC #9814682 and REC-0126227.

Comments and Questions

Click to Run Model

breed       [ pacmans pacman ]
breed       [ ghosts ghost ]
breed       [ pellets pellet ]
breed       [ bonuses bonus ]
turtles-own [ home-pos ]
ghosts-own  [ eaten? ]
pellets-own [ powerup? ]
bonuses-own [ value countdown ]

patches-own [ pellet-grid? ]

globals [
  difficulty    ;; Slider in Pac-Man.nlogo
  level         ;; Current Level
  score         ;; Your Score
  lives         ;; Remaining Lives
  extra-lives   ;; Total Number of Extra Lives you've won
  scared        ;; Time until Ghosts aren't scared (0 means not scared)
  level-over?   ;; True when a level is complete
  dead?         ;; True when pacman is loses a life
  next-bonus-in ;; Time until next bonus is created
  tool          ;; The currently selected tool
]


;;;;;;;;;;;;;;;;;;;;;;
;; Setup Procedures ;;
;;;;;;;;;;;;;;;;;;;;;;

;; Setup a new level

to new
  if user-yes-or-no? "Do you really want to clear the level?"
  [
    ca
    set difficulty 0
    set level 0
    set score 0
    set lives 3
    set extra-lives 0
    set scared 0
    set level-over? false
    set dead? false
    set next-bonus-in 0
    set tool "Eraser"

    create-pacmans 1
    [
      set color yellow
      set shape "pacman"
      setxy 10 10
    ]

    create-ghosts 4
    [
      set shape "ghost"
      setxy 0 3
      set heading 0
      set eaten? false
    ]

    ; set ghost colors and initial position
    ask turtle 1 [ set color 15  setxy 10 9 ]
    ask turtle 2 [ set color 26  setxy 10 8 ]
    ask turtle 3 [ set color 127 setxy 10 7 ]
    ask turtle 4 [ set color 85  setxy 10 6 ]

    ask turtles
    [ set home-pos list xcor ycor ]

    ask patches
    [ set pellet-grid? false ]
  ]
end 


;;;;;;;;;;;;;;;;;;;;;;;;
;; Runtime Procedures ;;
;;;;;;;;;;;;;;;;;;;;;;;;

;; If the mouse is down, use the Current Tool on the patch the mouse is over

to draw
  if mouse-down?
  [
    ;; Eraser Tool - Clears Walls/Gates, Removes Pellets
    if tool = "Eraser"
    [ erase ]
    ;; Wall Tool - Draws a Wall - Neither Pac-Man nor Ghosts can move through walls
    if tool = "Draw Wall"
    [ draw-boundary blue ]
    ;; Gate Tool - Draws a Gate - Only Ghosts can move through Gates
    ;;             Gates also heal ghosts which have been eaten.
    if tool = "Draw Ghost Gate"
    [ draw-boundary gray ]
    ;; Pellet Tool - Places a pellet on the grid
    if tool = "Place Pellet"
    [ place-pellet ]
    ;; Power Pellet Toggle Tool - Changes a Pellet into a Power Pellet and vice versa.
    if tool = "Toggle Power Pellet"
    [ toggle-power-pellet ]
    ;; Pac-Man Tool - Changes Pac-Man's starting position
    if tool = "Place Pac-Man"
    [ place-pacman ]
    ;; Ghost Tool - Changes the starting position of the Ghost chosen by the WHICH-GHOST slider
    if tool = "Place Ghost"
    [ place-ghost ]
  ]
end 

;;;;;;;;;;;;;;;;;;;;;
;; Tool Procedures ;;
;;;;;;;;;;;;;;;;;;;;;

;; Clears Walls/Gates, Removes Pellets from the patch the mouse is over

to erase
  ask patch (round mouse-xcor) (round mouse-ycor)
  [
    set pcolor black
    set pellet-grid? false
    ask pellets-here
    [ die ]
  ]
end 

;; Draws a Wall or a Gate if there are not any pellets, or Ghosts, or Pac-Man on the patch the mouse is over

to draw-boundary [ boundary-color ]
  ask patch (round mouse-xcor) (round mouse-ycor)
  [
    ifelse not any? turtles-here
    [ set pcolor boundary-color ]
    [
      ifelse boundary-color = gray
      [
        ifelse any? pacmans-here or any? pellets-here
        [ user-message "You cannot place a gate on top of pacman or a pellet." ]
        [ set pcolor boundary-color ]
      ]
      [ user-message "You cannot place a wall on top of pacman, a ghost, or a pellet." ]
    ]
  ]
end 

;; Place a pellet on a patch if the patch is not already a Wall or a Gate

to place-pellet
  ask patch (round mouse-xcor) (round mouse-ycor)
  [
    ifelse pcolor != black
    [ user-message "You cannot place a pellet on top of a wall or a gate." ]
    [
      if not any? turtles-here
      [
        sprout-pellets 1
        [
          set color white
          set powerup? false
          set shape "pellet"
        ]
        set pellet-grid? true
        set pcolor black
      ]
    ]
  ]
end 

;; Changes a Pellet into a Power Pellet and vice versa.

to toggle-power-pellet
  if any? pellets-on patch mouse-xcor mouse-ycor
  [
    ask one-of pellets-on patch mouse-xcor mouse-ycor
    [
      set powerup? not powerup?
      ifelse powerup?
      [ set shape "circle" ]
      [ set shape "pellet" ]
      wait 0.1
    ]
  ]
end 

;; Changes Pac-Man's starting position

to place-pacman
  ifelse [pcolor] of patch round mouse-xcor mouse-ycor != black
  [ user-message "You must place pacman on a corridor space, not a wall or a gate." ]
  [
    ask pacmans
    [ setxy (round mouse-xcor) (round mouse-ycor) ]
  ]
end 

;; Changes the starting position of the Ghost chosen by the WHICH-GHOST slider

to place-ghost
  ifelse [pcolor] of patch mouse-xcor mouse-ycor = blue
  [ user-message "You must place a ghost on a corridor space or a gate, not a wall." ]
  [
    ask turtle which-ghost
    [ setxy (round mouse-xcor) (round mouse-ycor) ]
  ]
end 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Saving and Loading Procedures ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Change the Level

to set-level
  if level > 0
  [
    if not user-yes-or-no? "Are you sure you want to change the level number of this map?"
    [ stop ]
  ]
  let temp 0
  while[ temp <= 0 ]
  [
    set temp read-from-string user-input "Input New Level Number:"
    if temp <= 0
    [ user-message "The level must be a positive number." ]
  ]
  set level temp
end 

;; If there are pellets and the level has been set, save the file

to save-level
  if not any? pellets
  [
    user-message "You must have at least 1 pellet in a level."
    stop
  ]
  if level <= 0
  [
    user-message "You must choose a positive level number before saving."
    set-level
  ]
  let filepath (word "../pacmap" level ".csv")
  ifelse user-yes-or-no? (word "File will be saved at: " filepath
     "\nIf this file already exists, it will be overwritten.\nAre you sure you want to save?")
  [
    export-world filepath
    user-message "File Saved."
  ]
  [ user-message "Save Canceled. File not saved." ]
end 

;; Load a level

to load-level
  let choice 0
  while[ choice <= 0 ]
  [
    set choice read-from-string user-input "Load What Level? (1 or greater)"
    if choice <= 0
    [ user-message "You must choose a positive level number to load." ]
  ]
  let filepath (word "../pacmap" choice ".csv")
  ifelse user-yes-or-no? (word "Load File: " filepath
         "\nThis will clear your current level and replace it with the level loaded."
         "\nAre you sure you want to Load?")
  [
    import-world filepath
    set tool "Eraser"
    user-message "File Loaded."
  ]
  [ user-message "Load Canceled. File not loaded." ]
end 


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

There are 10 versions of this model.

Uploaded by When Description Download
Uri Wilensky almost 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky over 11 years ago Updated version tag Download this version
Uri Wilensky over 11 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky about 12 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 13 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 13 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 13 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 13 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky almost 14 years ago Pac-Man Level Editor Download this version

Attached files

File Type Description Last updated
Pac-Man Level Editor.png preview Preview for 'Pac-Man Level Editor' almost 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.