Child of Space Invaders

No preview image

1 collaborator

Default-person Ryken White (Author)

Tags

(This model has yet to be categorized with any tags)
Child of model Space Invaders preview imageSpace Invaders
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.4.0 • Viewed 71 times • Downloaded 13 times • Run 0 times
Download the 'Child of Space Invaders' modelDownload this modelEmbed this model

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


Comments and Questions

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

Click to Run Model

extensions [ sound ]


;;;;;;;;;;;;;
;;Variables;;
;;;;;;;;;;;;;

breed [ players player]
breed [ grunt grunts ]
breed [ beefys beefy ]
breed [ shooters shooter ]
breed [ bullets bullet ]
breed [ ebullets ebullet ]
bullets-own [ num enemy ]
ebullets-own [ enemy ]
players-own [ enemy ]
grunt-own [ enemy ]
beefys-own [ enemy ]
shooters-own [ enemy eshoot ]
globals [ cycle xpos ypos score eypos canShoot bypos nume cooldown pxpos lives pscore death level ]

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

to setup ;; Sets up the program
  clear-all ;; Clears the screen
  reset-ticks ;; Resets the tick counter
  var-setup ;; Sets up inital globals
  home-setup ;; Sets up the baracades
  player-setup ;; Sets up player and bullets
  enemy-setup ;; Sets up enemies
end 

to reset
  clear-turtles
  reset-ticks
  home-setup
  player-setup
  enemy-setup
  var-setup
  level-counter
  set pscore score
  set score 0
end 

to var-setup ;; Procedure for setting up variables
  set canshoot 1 ;; Sets canshoot to true
  set cycle 0 ;; Sets the inital cycle to 0
  set cooldown 0 ;; No cooldown for the first shot
  set nume 55 ;; Sets the number of enemies counter to 55
end 

to home-setup ;; Procedure for setting up baracades
   ;; Just asks patches to change their color to green
  ask patch 4 -11 [
   set pcolor green
  ]
  ask patch 5 -11 [
   set pcolor green
  ]
  ask patch 4 -10 [
   set pcolor green
  ]
  ask patch 5 -10 [
   set pcolor green
  ]
end 

to enemy-setup
  ;; Sets up Grunts
  set-default-shape grunt "grunt" ;; Sets Grunts shape
  create-grunt 11 [ ;; Creates 11 grunts on this line
    set heading 0 ;; Makes them all point the same direction
    set size 2 ;; sets their size to two
    set color green ;; sets their color to green
    set xcor who + who / 2 ;; fancy equation for spacing them out
  ]
  create-grunt 11 [
    set heading 0
    set size 2
    set color green
    set xcor ( who - 11 ) + ( who - 11 ) / 2
    set ycor 1
  ]
  ;;Sets up Beefys
  set-default-shape beefys "octopus"
  create-beefys 11 [
    set heading 0
    set size 2
    set color green
    set xcor ( who - 22 ) + ( who - 22 ) / 2
    set ycor -1
  ]
  create-beefys 11 [
    set heading 0
    set size 2
    set color green
    set xcor ( who - 33 ) + ( who - 33 ) / 2
    set ycor -2
  ]
  ;; Sets up shooters
  set-default-shape shooters "squid"
  create-shooters 11 [
    set heading 0
    set size 2
    set color green
    set xcor ( who - 44 ) + ( who - 44 ) / 2
    set ycor 2
  ]
  ;; Sets all enemies to say that they're enemies
  ask grunt [ set enemy 1 ]
  ask beefys [ set enemy 1 ]
  ask shooters [ set enemy 1 ]
  ask ebullets [ set enemy 1 ]
end 

to player-setup
  set-default-shape bullets "dot" ;; Sets up bullets shape

  create-players 1 [
    set shape "default" ;; Sets players shape to a triangle
    set heading 0
    set size 2
    set color green
    set xcor 10
    set ycor -15.5
  ]
  ask players [ set enemy 0 ]
  ask bullets [ set enemy 0 ]
end 

to level-counter
  ifelse level = 1
  [
  ]
  [
  ifelse level = 5
  [
      set Difficulty Difficulty + 1
  ]
  [
  ifelse level = 10
  [
      set Difficulty Difficulty + 1
  ]
  [
  ifelse level = 15
  [
      set Difficulty Difficulty + 1
  ]
  [
  ]
  ]
  ]
  ]
end 

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

to go ;; Runs the Program

  ecounter ;; Runs the Enemy Counter Procedure

  collide ;; Runs collide procedure

  cool-down ;; Runs cooldown procedure

  if nume = 0
  [
    set pscore score
    wait 1
    set level level + 1
    reset
  ]

  ask shooters [ set eypos ycor ]
  ask grunt [ set eypos ycor ]
  ask beefys [ set eypos ycor ]

  if eypos < -15 or lives = 0 [
   set lives lives - 1
   ask bullets [ die ]
   ask ebullets [ die ]

    ifelse lives > 0 [
      reset
    ]
    [
   set score "gameover"
      ask bullets [ die ]
      ask ebullets [ die ]
   stop
    ]
  ]

  enemy-move

  enemy-shoot

  cycle-counter

  bullet-move



  set score pscore + ( 220 - ( count beefys * 10 ) ) + ( 440 - ( count grunt * 20 ) ) + ( 330 - ( count shooters * 30 ) )
  tick
end 

to down
   ask beefys [
    set ycor ycor - 1
  ]
  ask grunt [
    set ycor ycor - 1
  ]
  ask shooters [
    set ycor ycor - 1
  ]
end 

to r
  ask beefys [
    set xcor xcor + 1
  ]
  ask grunt [
    set xcor xcor + 1
  ]
  ask shooters [
    set xcor xcor + 1
  ]
end 

to l
  ask beefys [
    set xcor xcor - 1
  ]
  ask grunt [
    set xcor xcor - 1
  ]
  ask shooters [
    set xcor xcor - 1
  ]
end 

to shoot
  ask players [ set xpos xcor set ypos ycor ]
  ifelse score != "gameover" [ ;; if the game is still going you can still shoot
  create-bullets 1 [ ;; creates one bullet
    set color white
    set heading 0
    set xcor xpos
    set ycor ypos + .75 ;; Makes the bullet shoot from the top of the player
  ]
    go ;; returns back to the main program
  ]
  [
    ask bullets [die] ;; if the game is over ask bullets to die...
    stop ;; ...and stop the game
  ]
end 

to collide
 ask bullets [
    set bypos ycor
    set num nume
    ask turtles-here with [ enemy = 1 and bypos >= eypos ] [
      die
    ]
  ecounter
  if num > nume [ ;; Checks to see if the number of enemies has went down
    die ;; asks the bullets and the enemy it hit to die
    ]
  ]

  ask ebullets [
    if ycor < -15.5 and xcor = pxpos [
      ask players [
        set lives lives - 1
        set death 1
        Die
      ]
    ]
  ]
  if death = 1 [
    set death 0
    reset
  ]
end 

to ecounter ;; Enemy Counter Procedure
  set nume count beefys + count shooters + count grunt ;; Sets the number of enemies to the sum of all enemies
end 

to cool-down
  ifelse cooldown = 0 [
    set canshoot 1
    set cooldown Difficulty * 5
  ]
  [
    set cooldown  cooldown - 1
  ]
end 

to enemy-move
  ifelse cycle =  0 or cycle = 59  [
    down
  ][

  ifelse cycle = 19 or cycle = 39 [
    r
  ][
  ifelse cycle = 79 or cycle = 99 [
    l
      ][
      ]
  ]
  ]
end 

to cycle-counter
   ifelse cycle > 119 [
    set cycle 0
  ][

  set cycle cycle + 1
  ]
end 

to bullet-move
  ask bullets [ fd 1
    if ycor > 15 [ die ]
  ]
  ask ebullets [ fd .1
    if ycor < -16 [ die ]
  ]
end 

to enemy-shoot
  ask shooters [
    if random-float 100 < .5 [
      set eshoot 1
    ]

  if eshoot = 1 [
      hatch-ebullets random count shooters / 4 [
        set shape "dot"
        set size 1
        set heading 180
        set color white
      ]
    set eshoot 0
  ]
  ]
end 

There are 3 versions of this model.

Uploaded by When Description Download
Ryken White 3 months ago This a more complete version. It includes enemy bullets, lives, levels, score, difficulty, and scaling difficulty. Hope you enjoy Download this version
Ryken White 3 months ago This is a more complete dev version Download this version
Ryken White 3 months ago Fixes Sound Big Download this version

Attached files

No files

Parent: Space Invaders

This model does not have any descendants.

Graph of models related to 'Child of Space Invaders'