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 [
max-travel-distance
shooter
speed
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
fd speed
set travel-distance travel-distance + speed
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

+ 108
- 20
lobo.nlogo View File

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

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

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

to setup-defaults
set-patch-size 30
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-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

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

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

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

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

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

MONITOR
296
433
410
478
270
350
389
399
Player Accel Time
player-accelerate-for
5
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?


+ 34
- 0
tank.nls View File

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

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

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

to set-tank-vars [tank-team player-tank?]
set acceleration 0.03
set ammunition 20
set armor 8
set friction 0.0075
set is-accelerating? false
set is-player? player-tank?
@@ -52,6 +62,30 @@ to decelerate [amount]
]
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
if is-player? [ report black ]
if team = 0 [ report green ]


Loading…
Cancel
Save