瀏覽代碼

Player has a "target" instead of simply moving towards the mouse.

master
Ben Kurtovic 13 年之前
父節點
當前提交
06a1b0eccc
共有 4 個檔案被更改,包括 73 行新增54 行删除
  1. +2
    -1
      bullet.nls
  2. +43
    -22
      lobo.nlogo
  3. +15
    -31
      player.nls
  4. +13
    -0
      tank.nls

+ 2
- 1
bullet.nls 查看文件

@@ -21,7 +21,8 @@ to fire-bullet
set shape "bullet"
set size 0.5

lt random 10 ; Bullets shouldn't travel perfectly straight
; Bullets shouldn't travel perfectly straight:
lt random 10
rt random 10
]
end


+ 43
- 22
lobo.nlogo 查看文件

@@ -20,9 +20,11 @@ globals [
max-fps
mouse-was-down?
player
player-accelerate-for
player-deaths
player-has-target?
player-kills
player-target-xcor
player-target-ycor
sounds
]

@@ -38,8 +40,8 @@ to setup
set pcolor (random 3) - 5 + green
]
spawn-player
spawn-tank 0 ask tank 1 [ setxy -10 0 ]
spawn-tank 1 ask tank 2 [ setxy 10 0 ]
spawn-tank 0 ask tank 1 [ setxy -6 0 ]
spawn-tank 1 ask tank 2 [ setxy 6 0 ]
render
set last-tick-time timer
end
@@ -74,9 +76,11 @@ to setup-defaults
resize-world -8 8 -8 8
set max-fps 30
set mouse-was-down? false
set player-accelerate-for 0
set player-deaths 0
set player-has-target? false
set player-kills 0
set player-target-xcor 0
set player-target-ycor 0
make-sounds-table
end

@@ -95,27 +99,33 @@ to show-crosshair
clear-drawing
if mouse-inside? [
ask patch mouse-xcor mouse-ycor [
sprout 1 [
set color white
set heading 0
make-square
die
]
draw-border white 1
]
]
if player-has-target? [
ask patch player-target-xcor player-target-ycor [
draw-border white 2
]
]
end

to make-square
fd 0.5
pd
rt 90
fd 0.5
repeat 3 [
to draw-border [b-color b-thickness]
sprout 1 [
set color b-color
set pen-size b-thickness
set heading 0
fd 0.5
pd
rt 90
fd 1
fd 0.5
repeat 3 [
rt 90
fd 1
]
rt 90
fd 0.5
die
]
rt 90
fd 0.5
end

to render
@@ -165,7 +175,7 @@ GRAPHICS-WINDOW
0
0
1
ticks
frames

BUTTON
43
@@ -231,8 +241,8 @@ MONITOR
350
389
399
Player Accel Time
player-accelerate-for
Player Has Target?
player-has-target?
5
1
12
@@ -299,6 +309,17 @@ enable-sound?
1
-1000

MONITOR
272
411
390
460
Player Target
word \"(\" player-target-xcor \", \" player-target-ycor \")\"
10
1
12

@#$#@#$#@
WHAT IS IT?
-----------


+ 15
- 31
player.nls 查看文件

@@ -17,41 +17,25 @@ end
to do-player-logic
if mouse-inside? [
if mouse-down? and not mouse-was-down? [
set player-accelerate-for player-accelerate-for + 10
if player-accelerate-for > 60 [
set player-accelerate-for 60
]
set is-accelerating? true
set player-has-target? true
set player-target-xcor (round mouse-xcor)
set player-target-ycor (round mouse-ycor)
]
set mouse-was-down? mouse-down?
let old-heading heading

; Slow down the tank a bit more than usual if we're
; very close to the mouse:
let mouse-dist distancexy mouse-xcor mouse-ycor
if mouse-dist < 3 [
decelerate friction
]
if mouse-dist < 1.5 [
decelerate friction * 6.5
]
if mouse-dist < 0.35 [
set speed 0
set player-accelerate-for 0
]

facexy mouse-xcor mouse-ycor
if subtract-headings old-heading heading > max-turn [
set heading old-heading - max-turn
]
ifelse player-has-target? [
tank-facexy player-target-xcor player-target-ycor
let dist distancexy player-target-xcor player-target-ycor
if dist < 2 and speed > 0.075 [
decelerate friction * 5
]
if subtract-headings old-heading heading < 0 - max-turn [
set heading old-heading + max-turn
if dist < 0.1 [
set is-accelerating? false
set player-has-target? false
]
]

ifelse player-accelerate-for > 0 [
set player-accelerate-for player-accelerate-for - 1
set is-accelerating? true
] [
set is-accelerating? false
tank-facexy mouse-xcor mouse-ycor
]
end

+ 13
- 0
tank.nls 查看文件

@@ -69,6 +69,19 @@ to decelerate [amount]
]
end

to tank-facexy [txcor tycor]
;; Face a target at (txcor, tycor) like facexy, but don't
;; turn more than our max turn rate (max-turn¡):
let old-heading heading
facexy txcor tycor
if subtract-headings old-heading heading > max-turn [
set heading old-heading - max-turn
]
if subtract-headings old-heading heading < 0 - max-turn [
set heading old-heading + max-turn
]
end

to fire
if ammunition > 0 and fire-cool-down = 0 [
debug "FIRE" (word who " (" ammunition " left)")


Loading…
取消
儲存