Journey of the Prarie King

Journey of the Prarie King preview image

1 collaborator

Default-person Don Osipov (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 6.1.0 • Viewed 55 times • Downloaded 6 times • Run 0 times
Download the 'Journey of the Prarie King' modelDownload this modelEmbed this model

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


Info tab cannot be displayed because of an encoding error

Comments and Questions

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

Click to Run Model

;DollieandDilan
;Don Osipov, Willie Chen, Dilan Apterman
;IntroCS1 pd9
;Final Project
;2019-01-20

globals [
  going?            ;if the game is running this is true
  time-left         ;duration left in the game until win
  fired?            ;used to implement firerate
  kills             ;used for powerup spawning
  killlocker        ;used to prevent a bug with poewrup spawning
  lives             ;amount of lives before death
  firerate          ;changed by firerate powerup
  fireratetime      ;duration of powerup
  deadorc           ;used to prevent a bug
  dead?             ;used to prevent a bug
  hardmode?         ;changes various values if true (to make game harder)
]

patches-own [spawnpoint?]

players-own [
  speed                ;changed by speed powerup
  speedtime            ;duration of powerup
  octashot             ;changed by octashot powerup
  octashottime         ;duration of powerup
  shotgun              ;changed by shotgun powerup
  shotguntime          ;duration of powerup
]

breed [players player]              ;player
breed [bullets bullet]              ;bullets
breed [orcs orc]                    ;enemy
breed [speedups speedup]            ;powerup
breed [octashotups octashotup]      ;powerup
breed [nukes nuke]                  ;powerup
breed [liveups liveup]              ;powerup
breed [shotgunups shotgunup]        ;powerup
breed [firerateups firerateup]      ;powerup

to setup
  ca
  import-pcolors "Journey of the Prarie King.png"
  create-players 1
  set hardmode? false

  ask player 0 [
    set shape "idle"
    set size 25
    set speed 7
    set fired? 0
    set shotgun false]

ask patch 8 122 [set spawnpoint? true];north side      ;used to set spawnpoints on enemies...
ask patch -8 122 [set spawnpoint? true]
ask patch 24 122 [set spawnpoint? true]

ask patch 8 -122 [set spawnpoint? true];south side
ask patch -8 122 [set spawnpoint? true]
ask patch 24 -122 [set spawnpoint? true]

ask patch -122 8 [set spawnpoint? true];west side
ask patch -122 -8 [set spawnpoint? true]
ask patch -122 -24 [set spawnpoint? true]

ask patch 122 8 [set spawnpoint? true];east side
ask patch 122 -8 [set spawnpoint? true]
ask patch 122 -24 [set spawnpoint? true]

set time-left 60              ;60 seconds until game finishes
set fired? false
set killlocker true
set kills 0
set lives 2                   ;start with 2 lives
set firerate .5
reset-timer
end 

to hardmode-setup
  ca
  import-pcolors "JOPK_Level_1_1.png"
  create-players 1
  set hardmode? true

  ask player 0 [
    set shape "idle"
    set size 25
    set speed 6
    set fired? 0
    set shotgun false ]

  ask patch 8 122 [set spawnpoint? true];north side
  ask patch -8 122 [set spawnpoint? true]
  ask patch 24 122 [set spawnpoint? true]

  ask patch 8 -122 [set spawnpoint? true];south side
  ask patch -8 122 [set spawnpoint? true]
  ask patch 24 -122 [set spawnpoint? true]

  ask patch -122 8 [set spawnpoint? true];west side
  ask patch -122 -8 [set spawnpoint? true]
  ask patch -122 -24 [set spawnpoint? true]

  ask patch 122 8 [set spawnpoint? true];east side
  ask patch 122 -8 [set spawnpoint? true]
  ask patch 122 -24 [set spawnpoint? true]

  set time-left 60
  set fired? false
  set killlocker true
  set kills 0
  set lives 1                   ;start with 1 life
  set firerate .6
reset-timer
end 

to go
  if dead? != true [       ;if player is not dead...
    set going? true
    cycle

    every .1
    [
      bullet-travel
      die?
      spawn
      move
      speedtimer
      speeduppower
      powerupspawn
      octashotpower
      octashottimer
      nukepower
      fireratepower
      fireratetimer
      shotgunpower
      shotguntimer
      liveuppower]

    every 1 [
      set time-left (time-left - 1)       ;counts down timer until win
    ]

    if time-left = 0 [
      ask orcs [die]
      user-message "You have won!"      ;win message
      stop
      set going? false]
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;PLAYER DEATH

to die?
  ask orcs [
    ask players in-radius 15 [
      set lives lives - 1
      set going? false
      set deadorc true] ;deadorc used to prevent bug
    if deadorc = true [
      set deadorc false
      die]]
  if lives <= 0 [
    set lives 0
    user-message "Game Over"           ;death message
    set dead? true
    stop]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;POWERUP TIMERS

to speedtimer                         ;duration of powerup
  ifelse hardmode? = true [
    if count players > 0 [            ;if count players > 0 used to prevent death bug
    ask player 0 [
      if speed = 10 [
        every .1 [
          if count players != 0 [
            ask player 0 [set speedtime speedtime + .1]
            ask player 0 [if speedtime >= 5 [set speed 6]]
  ]]]]]]

  [
    if count players > 0 [             ;if count players > 0 used to prevent death bug
      ask player 0 [
        if speed = 13 [
          every .1 [
            if count players != 0 [
              ask player 0 [set speedtime speedtime + .1]
              ask player 0 [if speedtime >= 7 [set speed 7]]
  ]]]]]]
end 

to octashottimer                    ;duration of powerup
  if count players > 0 [            ;if count players > 0 used to prevent death bug
    ask player 0 [
      if octashot = 1 [
        every .1 [
          if count players != 0 [
            ask player 0 [
              set octashottime octashottime + .1
              ifelse hardmode? = true [
                if octashottime >= 5 [set octashot 0 set octashottime 0]] [
                if octashottime >= 7 [set octashot 0 set octashottime 0]]
  ]]]]]]
end 

to fireratetimer                   ;duration of powerup
  ifelse hardmode? = true [
    if firerate = .3 [
      every .1 [
        if count players != 0 [
          set fireratetime fireratetime + .1
          if fireratetime >= 5 [set firerate .6 set fireratetime 0]
  ]]]]
  [
    if firerate = .2 [
      every .1 [
        if count players != 0 [
          set fireratetime fireratetime + .1
          if fireratetime >= 7 [set firerate .5 set fireratetime 0]
  ]]]]
end 

to shotguntimer                   ;duration of powerup
  if count players > 0 [          ;if count lpayers > 0 used to prevent death bug
    ask player 0 [
      if shotgun = true [
        every .1 [
          if count players != 0 [
            ask player 0 [
              set shotguntime shotguntime + .1
              ifelse hardmode? = true [
                if shotguntime >= 5 [set shotgun false set shotguntime 0]] [
                if shotguntime >= 7 [set shotgun false set shotguntime 0]]
  ]]]]]]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;POWERUP EFFECTS

to speeduppower                       ;effect of powerup
  ifelse hardmode? = true [
    ask speedups [
    ask players in-radius 15 [
      set speedtime 0
      set speed 10]
    if count players in-radius 15 > 0 [
        die]]]

  [
    ask speedups [
      ask players in-radius 15 [
        set speedtime 0
        set speed 13]
      if count players in-radius 15 > 0 [
        die]]]
end 

to octashotpower                   ;effect of powerup
  ask octashotups [
    ask players in-radius 15 [
      set octashot 1]
    if count players in-radius 15 > 0 [
      die]]
end 

to nukepower                       ;effect of powerup
  ask nukes [
    if count players in-radius 15 != 0 [
      ask orcs [die]
      die]]
end 

to fireratepower                  ;effect of powerup
  ifelse hardmode? = true [
    ask firerateups [
      if count players in-radius 15 != 0 [
        set firerate .3
        die]]]
  [
    ask firerateups [
      if count players in-radius 15 != 0 [
        set firerate .2
        die]]]
end 

to shotgunpower                   ;effect of powerup
  ask shotgunups [
    if count players in-radius 15 != 0 [
      ask player 0 [
        set shotgun true]
      die]]
end 

to liveuppower                   ;effect of powerup
  ask liveups [
    if count players in-radius 15 != 0 [
      set lives lives + 1
      die]]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;POWERUP SPAWN

to powerupspawn
  ifelse hardmode? = true [

    if kills mod 14 = 1 [
      set killlocker false]

    if kills mod 14 = 0 and kills != 0 [
      if killlocker = false [
        let randomizer random 6                  ;so that uses same random value for each powerup
        if randomizer = 0 [
          create-speedups 1 [setxy random (96 - -96 + 1) + -96 random (96 - -96 + 1) + -96 set size 20 set shape "coffee"]]           ;custom turtles created for look
        if randomizer = 1 [
          create-octashotups 1 [setxy random (96 - -96 + 1) + -96 random (96 - -96 + 1) + -96 set size 20 set shape "wheel"]]
        if randomizer = 2 [
          create-nukes 1 [setxy random (96 - -96 + 1) + -96 random (96 - -96 + 1) + -96 set size 20 set shape "nuke"]]
        if randomizer = 3 [
          create-firerateups 1 [setxy random (96 - -96 + 1) + -96 random (96 - -96 + 1) + -96 set size 20 set shape "machinegun"]]
        if randomizer = 4 [
          create-shotgunups 1 [setxy random (96 - -96 + 1) + -96 random (96 - -96 + 1) + -96 set size 20 set shape "shotgun"]]
        if randomizer = 5 [
          create-liveups 1 [setxy random (96 - -96 + 1) + -96 random (96 - -96 + 1) + -96 set size 20 set shape "extralife"]]
        set killlocker true]]]

  [
    if kills mod 10 = 1 [
      set killlocker false]

    if kills mod 10 = 0 and kills != 0 [
      if killlocker = false [
        let randomizer random 6
        if randomizer = 0 [
          create-speedups 1 [setxy random (96 - -96 + 1) + -96 random (96 - -96 + 1) + -96 set size 20 set shape "coffee"]]
        if randomizer = 1 [
          create-octashotups 1 [setxy random (96 - -96 + 1) + -96 random (96 - -96 + 1) + -96 set size 20 set shape "wheel"]]
        if randomizer = 2 [
          create-nukes 1 [setxy random (96 - -96 + 1) + -96 random (96 - -96 + 1) + -96 set size 20 set shape "nuke"]]
        if randomizer = 3 [
          create-firerateups 1 [setxy random (96 - -96 + 1) + -96 random (96 - -96 + 1) + -96 set size 20 set shape "machinegun"]]
        if randomizer = 4 [
          create-shotgunups 1 [setxy random (96 - -96 + 1) + -96 random (96 - -96 + 1) + -96 set size 20 set shape "shotgun"]]
        if randomizer = 5 [
          create-liveups 1 [setxy random (96 - -96 + 1) + -96 random (96 - -96 + 1) + -96 set size 20 set shape "extralife"]]
        set killlocker true]]]
end 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ORCS

to spawn
  ask patches with [spawnpoint? = true] [         ;spawns at spawnpoints
    if random 125 = 0 [
      sprout-orcs 1 [
        set shape "orcwalk_1"
        set size 25]
    ]
  ]
end 

to move
  ifelse hardmode? = true [
    ask orcs [
      if going? = true [
        ifelse count bullets in-radius 15 > 0

        [
          set kills kills + 1
          ask bullets in-radius 15 [die]
          die]

        [
          set shape "orcwalk_1"
          if count players > 0 [         ;if count lpayers > 0 used to prevent death bug
            set heading towards player 0
            every 10 / 100 [
              fd 6]
            set shape "orcwalk_2"]]
  ]]]
  [
    ask orcs [
      if going? = true [
        ifelse count bullets in-radius 15 > 0

        [
          set kills kills + 1
          ask bullets in-radius 15 [die]
          die]

        [
          set shape "orcwalk_1"
          if count players > 0 [          ;if count lpayers > 0 used to prevent death bug
            set heading towards player 0
            every 10 / 100 [
              fd 5]
            set shape "orcwalk_2"]]
  ]]]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;PLAYER MOVEMENT

to walk-right
  if going? = true [
    ask player 0 [

      set heading 90
      set shape "rightwalk_1"
      every 10 / 100 [
        fd speed]
      set shape "rightwalk_2"
    ]
  ]
end 

to walk-left
  if going? = true [
    ask player 0 [
      set heading 270
      set shape "leftwalk_1"
      every 10 / 100 [
        fd speed]
      set shape "leftwalk_2"
    ]
  ]
end 

to walk-up
  if going? = true [
    ask player 0 [
      set heading 360
      set shape "upwalk_1"
      every 10 / 100
      [fd speed]
      set shape "upwalk_2"
    ]
  ]
end 

to walk-down
  if going? = true [
    ask player 0 [
      set heading 180
      set shape "walkdown_1"
      every 10 / 100
      [fd speed]
      set shape "walkdown_2"
    ]
  ]
end 

                             ;if wanted for future implementation
;to walk-upright
;  if going? = true
;  [ask player 0
;   [set heading 45
;      set shape "upwalk_1"
;        fd 3
;       set shape "upwalk_2"]
;  ]
;end

;to walk-downright
;  if going? = true
;  [ask player 0
;   [set heading 135
;      set shape "walkdown_1"
;        fd 3
;        set shape "walkdown_2"]
;  ]
;end

;to walk-upleft
;  if going? = true
;  [ask player 0
;    [set heading 315
;     set shape "upwalk_1"
;        fd 3
;        set shape "upwalk_2"]
;  ]
;end

;to walk-downleft
;  if going? = true
;  [ask player 0
;    [set heading 225
;      set shape "walkdown_1"
;        fd 3
;        set shape "walkdown_2"]
;  ]
;end



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SHOOTING

to cycle ;needed for firerate
  every firerate
  [if fired? = true
    [set fired? false]]
end 

to bullet-travel ;bullet speed and causes them to die if they step outside the map
  ask turtles [
    if breed = bullets [
      ifelse abs xcor = 128 or abs ycor = 128 [
        die]
      [fd 8
      ]
  ]]
end 

to shoot-up
  ask player 0 [
    if octashot = 1 [
      octashotyay
    ]
    if shotgun = true [
      shotgun-upwards
    ]
    if octashot = 0 and shotgun = false [
      if fired? = false [
        set shape "upwalk_1"
        hatch-bullets 1 [
          set shape "bullet"
          set heading 360
          fd 3]
        set fired? true]]]
end 

to shoot-down
  ask player 0 [
    if octashot = 1 [
      octashotyay
    ]
    if shotgun = true [
      shotgun-downwards
    ]
    if octashot = 0 and shotgun = false [
      if fired? = false [
        set shape "walkdown_1"
        hatch-bullets 1 [
          set shape "bullet"
          set heading 180
          fd 3]
        set fired? true]]]
end 

to shoot-left
  ask player 0 [
    if octashot = 1 [
      octashotyay
    ]
    if shotgun = true [
      shotgun-leftwards
    ]
    if octashot = 0 and shotgun = false [
      if fired? = false [
        set shape "leftwalk_1"
        hatch-bullets 1 [
          set shape "bullet"
          set heading 270
          fd 3]
        set fired? true]]]
end 

to shoot-right
  ask player 0 [
    if octashot = 1 [
      octashotyay
    ]
    if shotgun = true [
      shotgun-rightwards
    ]
    if octashot = 0 and shotgun = false [
      if fired? = false [
        set shape "rightwalk_1"
        hatch-bullets 1 [
          set shape "bullet"
          set heading 90
          fd 3]
        set fired? true]]]
end 

to shoot-upright
  ask player 0 [
    ifelse octashot = 1 [
      octashotyay
    ]
    [
      if fired? = false [
        set shape "rightwalk_1"
        hatch-bullets 1 [
          set shape "bullet"
          set heading 45
          fd 3]
        set fired? true]]]
end 

to shoot-downright
  ask player 0 [
    ifelse octashot = 1 [
      octashotyay
    ]
    [
      if fired? = false [
        set shape "rightwalk_1"
        hatch-bullets 1 [
          set shape "bullet"
          set heading 135
          fd 3]
        set fired? true]]]
end 

to shoot-upleft
  ask player 0 [
    ifelse octashot = 1 [
      octashotyay
    ]
    [
      if fired? = false [
        set shape "rightwalk_1"
        hatch-bullets 1 [
          set shape "bullet"
          set heading 315
          fd 3]
        set fired? true]]]
end 

to shoot-downleft
  ask player 0 [
    ifelse octashot = 1 [
      octashotyay
    ]
    [
      if fired? = false [
        set shape "rightwalk_1"
        hatch-bullets 1 [
          set shape "bullet"
          set heading 225
          fd 3]
        set fired? true]]]
end 

to octashotyay ;is called on instead of shooting in a specific direction if the octashot powerup is active - shoots in 8 directions simultaneously
  ask player 0 [
    if fired? = false [
      hatch-bullets 1 [
        set shape "bullet"
        set heading 360
        fd 3]
      hatch-bullets 1 [
        set shape "bullet"
        set heading 180
        fd 3]
      hatch-bullets 1 [
        set shape "bullet"
        set heading 270
        fd 3]
      hatch-bullets 1 [
        set shape "bullet"
        set heading 90
        fd 3]
      hatch-bullets 1 [
        set shape "bullet"
        set heading 45
        fd 3]
      hatch-bullets 1 [
        set shape "bullet"
        set heading 135
        fd 3]
      hatch-bullets 1 [
        set shape "bullet"
        set heading 315
        fd 3]
      hatch-bullets 1 [
        set shape "bullet"
        set heading 225
        fd 3]
      set fired? true]]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Shotgun shots - replace regular shots if shotgun powerup is active

to shotgun-upwards
  ask player 0 [
    if fired? = false [
      hatch-bullets 1 [
        set shape "bullet"
        set heading 360
        fd 3]
      hatch-bullets 1 [
        set shape "bullet"
        set heading 20
        fd 3]
      hatch-bullets 1 [
        set shape "bullet"
        set heading 340
        fd 3]
      set fired? true]]
end 

to shotgun-leftwards
  ask player 0 [
    if fired? = false [
      hatch-bullets 1 [
        set shape "bullet"
        set heading 270
        fd 3]
      hatch-bullets 1 [
        set shape "bullet"
        set heading 290
        fd 3]
      hatch-bullets 1 [
        set shape "bullet"
        set heading 250
        fd 3]
      set fired? true]]
end 

to shotgun-rightwards
  ask player 0 [
    if fired? = false [
      hatch-bullets 1 [
        set shape "bullet"
        set heading 90
        fd 3]
      hatch-bullets 1 [
        set shape "bullet"
        set heading 110
        fd 3]
      hatch-bullets 1 [
        set shape "bullet"
        set heading 70
        fd 3]
      set fired? true]]
end 

to shotgun-downwards
ask player 0 [
    if fired? = false [
      hatch-bullets 1 [
        set shape "bullet"
        set heading 180
        fd 3]
      hatch-bullets 1 [
        set shape "bullet"
        set heading 200
        fd 3]
      hatch-bullets 1 [
        set shape "bullet"
        set heading 160
        fd 3]
      set fired? true]]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MONITORS

to-report timeuntilWIN
  report time-left
end 

to-report killcounter
  report kills
end 

to-report lives-left
  report lives
end 

There is only one version of this model, created almost 4 years ago by Don Osipov.

Attached files

File Type Description Last updated
Journey of the Prarie King.png preview Preview for 'Journey of the Prarie King' almost 4 years ago, by Don Osipov Download

This model does not have any ancestors.

This model does not have any descendants.