breeds [ pacman ghosts pellets bonuses ] turtles-own [ home-pos ] ghosts-own [ eaten? ] pellets-own [ powerup? ] bonuses-own [ bonus 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-custom-pacman 1 [ set color yellow set shape "pacman" setxy 10 10 ] create-custom-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? pacman-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 1 [ set breed pellets 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-at (round mouse-xcor) (round mouse-ycor) [ ask one-of pellets-at (round mouse-xcor) (round 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-at (round mouse-xcor) (round mouse-ycor) != black [ user-message "You must place pacman on a corridor space, not a wall or a gate." ] [ ask pacman [ 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-at (round mouse-xcor) (round 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 locals [ temp ] if level > 0 [ if not user-yes-or-no? "Are you sure you want to change the level number of this map?" [ stop ] ] 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 locals [filepath] 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 ] set filepath "../pacmap" + level + ".csv" ifelse user-yes-or-no? ("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 locals [filepath load-level] while[ load-level <= 0 ] [ set load-level read-from-string user-input "Load What Level? (1 or greater)" if load-level <= 0 [ user-message "You must choose a positive level number to load." ] ] set filepath "../pacmap" + load-level + ".csv" ifelse user-yes-or-no? ("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 ; *** NetLogo Model Copyright Notice *** ; ; This model was created as part of the project: ; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN ; CLASSROOMS. The project gratefully acknowledges the support of the ; National Science Foundation (REPP program) -- grant number REC #9814682. ; ; Copyright 2003 by Uri Wilensky. Updated 2003. All rights reserved. ; ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from Uri Wilensky. ; Contact Uri Wilensky for appropriate licenses for redistribution for ; profit. ; ; To refer to this model in academic publications, please use: ; Wilensky, U. (2003). NetLogo Pac-Man Level Editor model. ; http://ccl.northwestern.edu/netlogo/models/Pac-ManLevelEditor. ; Center for Connected Learning and Computer-Based Modeling, ; Northwestern University, Evanston, IL. ; ; In other publications, please use: ; Copyright 1998 by Uri Wilensky. All rights reserved. See ; http://ccl.northwestern.edu/netlogo/models/Pac-ManLevelEditor ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 285 10 736 482 10 10 21.0 1 10 1 1 1 CC-WINDOW 9 371 269 461 Command Center MONITOR 139 136 274 185 Current Tool tool 0 1 BUTTON 139 261 274 294 Draw Wall set tool "Draw Wall" NIL 1 T OBSERVER T SLIDER 139 327 274 360 which-ghost which-ghost 1 4 1 1 1 NIL BUTTON 139 294 274 327 Draw Gate set tool "Draw Ghost Gate" NIL 1 T OBSERVER T BUTTON 9 228 139 261 Place Pellet set tool "Place Pellet" NIL 1 T OBSERVER T BUTTON 9 261 139 294 Toggle Power Pellet set tool "Toggle Power Pellet" NIL 1 T OBSERVER T BUTTON 9 294 139 327 Place Pac-Man set tool "Place Pac-Man" NIL 1 T OBSERVER T BUTTON 9 327 139 360 Place Ghost: set tool "Place Ghost" NIL 1 T OBSERVER T BUTTON 9 136 139 185 Use Tool draw T 1 T OBSERVER NIL BUTTON 9 41 139 74 New Level new NIL 1 T OBSERVER T BUTTON 139 228 274 261 Eraser set tool "Eraser" NIL 1 T OBSERVER T MONITOR 216 74 274 123 NIL level 0 1 TEXTBOX 12 202 102 220 Choose Tool: BUTTON 9 74 139 107 Save Level save-level NIL 1 T OBSERVER T BUTTON 139 41 274 74 Load Level load-level NIL 1 T OBSERVER T BUTTON 139 74 216 123 Set Level set-level NIL 1 T OBSERVER T @#$#@#$#@ 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 ------------- 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. LEVEL EDITING TOOLS ------------------- 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-custom-, 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 CREDITS AND REFERENCES ---------------------- To refer to this model in academic publications, please use: Wilensky, U. (2003). NetLogo Pac-Man Level Editor model. http://ccl.northwestern.edu/netlogo/models/Pac-ManLevelEditor. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. In other publications, please use: Copyright 2003 by Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/Pac-ManLevelEditor for terms of use. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 circle false 0 Circle -7566196 true true 34 34 230 eyes false 0 Circle -1 true false 62 75 57 Circle -1 true false 182 75 57 Circle -16777216 true false 79 93 20 Circle -16777216 true false 196 93 21 ghost false 0 Circle -7566196 true true 61 30 179 Rectangle -7566196 true true 60 120 240 232 Polygon -7566196 true true 60 229 60 284 105 239 149 284 195 240 239 285 239 228 60 229 60 229 60 229 Circle -1 true false 81 78 56 Circle -16777216 true false 98 96 21 Circle -1 true false 165 81 51 Circle -16777216 true false 181 97 17 Rectangle -16777216 true false 69 46 97 73 pacman true 0 Circle -7566196 true true 35 35 230 Polygon -16777216 true false 120 30 148 149 180 30 pacman-open true 0 Circle -7566196 true true 35 35 230 Polygon -16777216 true false 225 30 149 152 75 30 pellet true 0 Circle -7566196 true true 91 90 120 scared false 0 Circle -16776961 true false 61 30 179 Rectangle -16776961 true false 60 120 240 232 Polygon -16776961 true false 60 229 60 284 105 239 149 284 195 240 239 285 239 228 60 229 60 229 60 229 Circle -16777216 true false 81 78 56 Circle -16777216 true false 165 81 51 Rectangle -16777216 true false 144 179 165 199 Rectangle -16777216 true false 119 156 140 175 Rectangle -16777216 true false 95 177 113 199 Rectangle -16777216 true false 166 159 185 177 Rectangle -16777216 true false 188 178 208 198 Rectangle -16777216 true false 66 41 99 73 star true 0 Polygon -7566196 true true 74 254 149 16 224 254 29 104 270 104 @#$#@#$#@ NetLogo 2.0beta5 @#$#@#$#@ import-world "../pacmap4.csv" @#$#@#$#@ @#$#@#$#@