Browse Source

Bullets can hit tanks; crosshairs; ammunition and armor

master
Ben Kurtovic 13 years ago
parent
commit
731930ffb6
3 changed files with 160 additions and 33 deletions
  1. +18
    -13
      bullet.nls
  2. +108
    -20
      lobo.nlogo
  3. +34
    -0
      tank.nls

+ 18
- 13
bullet.nls View File

@@ -5,26 +5,31 @@ breed [bullets bullet]


bullets-own [ bullets-own [
max-travel-distance max-travel-distance
shooter
speed speed
travel-distance travel-distance
] ]


to fire
hatch-bullets 1 [
set max-travel-distance 8
set speed 1
set travel-distance 0

set color white
set shape "bullet"
set size 0.5
]
end

to do-bullet-logic to do-bullet-logic
fd speed fd speed
set travel-distance travel-distance + speed set travel-distance travel-distance + speed
if travel-distance > max-travel-distance [ if travel-distance > max-travel-distance [
die
die
]

let mxcor xcor
let mycor ycor
let is-close-enough false
let target min-one-of (turtles-here with [breed = tanks]) [distancexy mxcor mycor]
if target != nobody [
ask target [
if distancexy mxcor mycor < 0.65 [
set is-close-enough true
shot-at myself
]
]
]
if is-close-enough [
die
] ]
end end

+ 108
- 20
lobo.nlogo View File

@@ -20,6 +20,8 @@ globals [
mouse-was-down? mouse-was-down?
player player
player-accelerate-for player-accelerate-for
player-deaths
player-kills
] ]


;; =========================== ;; ===========================
@@ -34,6 +36,7 @@ to setup
set pcolor (random 3) - 5 + green set pcolor (random 3) - 5 + green
] ]
spawn-player spawn-player
spawn-tank 1
render render
set last-tick-time timer set last-tick-time timer
end end
@@ -48,6 +51,7 @@ to go
ask bullets [ ask bullets [
do-bullet-logic do-bullet-logic
] ]
show-crosshair
render render
keep-time keep-time
end end
@@ -56,12 +60,45 @@ end
;; Other procedures ;; Other procedures
;; ================ ;; ================


to debug [action msg]
output-print (word (round timer) ": " action ": " msg)
end

to setup-defaults to setup-defaults
set-patch-size 30 set-patch-size 30
resize-world -8 8 -8 8 resize-world -8 8 -8 8
set max-fps 30 set max-fps 30
set mouse-was-down? false set mouse-was-down? false
set player-accelerate-for 0 set player-accelerate-for 0
set player-deaths 0
set player-kills 0
end

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
]
]
]
end

to make-square
fd 0.5
pd
rt 90
fd 0.5
repeat 3 [
rt 90
fd 1
]
rt 90
fd 0.5
end end


to render to render
@@ -78,9 +115,9 @@ to keep-time
end end
@#$#@#$#@ @#$#@#$#@
GRAPHICS-WINDOW GRAPHICS-WINDOW
475
452
10 10
995
972
551 551
8 8
8 8
@@ -104,9 +141,9 @@ GRAPHICS-WINDOW
ticks ticks


BUTTON BUTTON
66
43
100 100
161
138
133 133
New Game New Game
setup setup
@@ -120,9 +157,9 @@ NIL
NIL NIL


BUTTON BUTTON
313
290
99 99
407
384
132 132
Play Game Play Game
go go
@@ -136,21 +173,21 @@ NIL
NIL NIL


MONITOR MONITOR
297
382
410
427
269
290
389
339
Player Speed Player Speed
[speed] of player [speed] of player
8 8
1 1
11
12


BUTTON BUTTON
108
176
285
252
148
181
269
233
FIRE! FIRE!
player-fire player-fire
NIL NIL
@@ -163,15 +200,66 @@ NIL
NIL NIL


MONITOR MONITOR
296
433
410
478
270
350
389
399
Player Accel Time Player Accel Time
player-accelerate-for player-accelerate-for
5 5
1 1
11
12

OUTPUT
998
30
1375
521
12

MONITOR
55
290
149
339
Player Deaths
player-deaths
17
1
12

MONITOR
55
350
148
399
Player Kills
player-kills
17
1
12

MONITOR
160
290
261
339
Player Ammo
[ammunition] of player
17
1
12

MONITOR
160
350
260
399
Player Armor
[armor] of player
17
1
12


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


+ 34
- 0
tank.nls View File

@@ -5,6 +5,8 @@ breed [tanks tank]


tanks-own [ tanks-own [
acceleration acceleration
ammunition
armor
friction friction
is-accelerating? is-accelerating?
is-player? is-player?
@@ -14,8 +16,16 @@ tanks-own [
team team
] ]


to spawn-tank [tank-team]
create-tanks 1 [
set-tank-vars tank-team false
]
end

to set-tank-vars [tank-team player-tank?] to set-tank-vars [tank-team player-tank?]
set acceleration 0.03 set acceleration 0.03
set ammunition 20
set armor 8
set friction 0.0075 set friction 0.0075
set is-accelerating? false set is-accelerating? false
set is-player? player-tank? set is-player? player-tank?
@@ -52,6 +62,30 @@ to decelerate [amount]
] ]
end end


to fire
if ammunition > 0 [
set ammunition ammunition - 1
hatch-bullets 1 [
set max-travel-distance 8
set shooter [who] of myself
set speed 1
set travel-distance 0

set color white
set shape "bullet"
set size 0.5
]
]
end

to shot-at [bullet]
debug "SHOT" (word ([shooter] of myself) " -> " who)
set armor armor - 1
if armor = 0 [
die
]
end

to-report get-tank-color to-report get-tank-color
if is-player? [ report black ] if is-player? [ report black ]
if team = 0 [ report green ] if team = 0 [ report green ]


Loading…
Cancel
Save