Browse Source

Clean up player logic such that the player respawns with throwing exceptions

master
Ben Kurtovic 12 years ago
parent
commit
ea0704a358
3 changed files with 35 additions and 22 deletions
  1. +2
    -17
      lobo.nlogo
  2. +32
    -5
      player.nls
  3. +1
    -0
      tank.nls

+ 2
- 17
lobo.nlogo View File

@@ -48,11 +48,7 @@ to setup
end end


to go to go
if player != nobody [
ask player [
do-player-logic
]
]
do-player-logic
ask tanks [ ask tanks [
do-tank-logic do-tank-logic
] ]
@@ -75,18 +71,6 @@ to go
keep-time keep-time
end end


to player-fire
ask player [
fire
]
end

to player-cancel-order
ask player [
cancel-order
]
end

;; ================ ;; ================
;; Other procedures ;; Other procedures
;; ================ ;; ================
@@ -105,6 +89,7 @@ to setup-defaults
set max-fps 30 set max-fps 30
set mouse-was-down? false set mouse-was-down? false
set sound-stopped? true set sound-stopped? true
set player-death-time timer
set player-deaths 0 set player-deaths 0
set player-has-target? false set player-has-target? false
set player-kills 0 set player-kills 0


+ 32
- 5
player.nls View File

@@ -3,6 +3,7 @@


globals [ globals [
player player
player-death-time
player-deaths player-deaths
player-has-target? player-has-target?
player-kills player-kills
@@ -22,6 +23,18 @@ to spawn-player [tank-xcor tank-ycor tank-heading]
end end


to do-player-logic to do-player-logic
ifelse player = nobody [
if timer - player-death-time > 1.5 [
spawn-player 0 0 0
]
] [
ask player [
do-player-movement
]
]
end

to do-player-movement
if mouse-inside? [ if mouse-inside? [
if mouse-down? and not mouse-was-down? [ if mouse-down? and not mouse-was-down? [
let txcor round mouse-xcor let txcor round mouse-xcor
@@ -54,15 +67,29 @@ to do-player-logic
] ]
end end


to player-fire
if player != nobody [
ask player [
fire
]
]
end

to player-place-pill to player-place-pill
ask player [
place-pill
if player != nobody [
ask player [
place-pill
]
] ]
end end


to cancel-order
if player-has-target? [
cancel-target
to player-cancel-order
if player != nobody [
ask player [
if player-has-target? [
cancel-target
]
]
] ]
end end




+ 1
- 0
tank.nls View File

@@ -123,6 +123,7 @@ end


to kill-tank to kill-tank
if is-player? [ if is-player? [
set player-death-time timer
set player-deaths player-deaths + 1 set player-deaths player-deaths + 1
] ]
if [is-shooter-player?] of myself [ if [is-shooter-player?] of myself [


Loading…
Cancel
Save