@@ -0,0 +1,136 @@ | |||
;; lobo: Logo Bolo | |||
;; (c) Ben Kurtovic, 2011 | |||
globals [ | |||
base-max-ammo | |||
base-max-armor | |||
] | |||
breed [bases base] | |||
bases-own [ | |||
ammunition | |||
armor | |||
last-ammo-regen | |||
last-armor-regen | |||
last-refuel | |||
team | |||
] | |||
;; ========== | |||
;; Procedures | |||
;; ========== | |||
to spawn-base [base-xcor base-ycor] | |||
create-bases 1 [ | |||
set-base-vars base-max-ammo base-max-armor -1 base-xcor base-ycor | |||
] | |||
end | |||
to set-base-vars [b-ammo b-armor b-team b-xcor b-ycor] | |||
set ammunition b-ammo | |||
set armor b-armor | |||
set team b-team | |||
set last-ammo-regen timer | |||
set last-armor-regen timer | |||
set last-refuel timer | |||
set color get-base-color | |||
set shape "base" | |||
set size 1.15 | |||
setxy b-xcor b-ycor | |||
end | |||
to do-base-logic | |||
ifelse team = -1 [ | |||
if any? tanks-here [ | |||
claim-base one-of tanks-here | |||
] | |||
] [ | |||
let allies-here tanks-here with [team = ([team] of myself)] | |||
let enemies-here tanks-here with [team != ([team] of myself)] | |||
if any? allies-here [ | |||
refuel-tank one-of allies-here | |||
] | |||
if any? enemies-here and armor = 0 [ | |||
claim-base one-of enemies-here | |||
set armor 1 | |||
] | |||
] | |||
regenerate | |||
set label armor | |||
end | |||
to claim-base [claimer] | |||
set team [team] of claimer | |||
set color get-base-color | |||
end | |||
to refuel-tank [tank-to-refuel] | |||
let did-armor-refuel? false | |||
let did-ammo-refuel? false | |||
let time-since-last-refuel timer - last-refuel | |||
ask tank-to-refuel [ | |||
if armor < tank-max-armor and ([armor] of myself) > 1 and time-since-last-refuel > 25 / max-fps [ ; 25 frames | |||
set armor armor + 1 | |||
set did-armor-refuel? true | |||
] | |||
if ammunition < tank-max-ammo and ([ammunition] of myself) > 1 and time-since-last-refuel > 10 / max-fps [ ; 10 frames | |||
set ammunition ammunition + 1 | |||
set did-ammo-refuel? true | |||
] | |||
] | |||
if did-armor-refuel? or did-ammo-refuel? [ | |||
set last-refuel timer | |||
ifelse did-armor-refuel? [ | |||
set armor armor - 1 | |||
] [ | |||
set ammunition ammunition - 1 | |||
] | |||
] | |||
end | |||
to regenerate | |||
let time-since-last-ammo-regen timer - last-ammo-regen | |||
let time-since-last-armor-regen timer - last-armor-regen | |||
if ammunition < base-max-ammo and time-since-last-ammo-regen > 10 [ | |||
set ammunition ammunition + 1 | |||
set last-ammo-regen timer | |||
] | |||
if armor < base-max-armor and time-since-last-armor-regen > 25 [ | |||
set armor armor + 1 | |||
set last-armor-regen timer | |||
] | |||
end | |||
to base-shot-at | |||
debug "BASE-SHOT" (word who " by " ([shooter] of myself)) | |||
set armor armor - 1 | |||
ifelse armor > 0 [ | |||
explode "decay" | |||
play-sound "shot" | |||
] [ | |||
explode "shot" | |||
play-sound "kill" | |||
] | |||
end | |||
;; ========= | |||
;; Reporters | |||
;; ========= | |||
to-report get-base-afiliation | |||
if team = -1 [ report "neutral" ] | |||
if team = 0 [ report "ally" ] | |||
report "enemy" | |||
end | |||
to-report get-base-color | |||
let affiliation get-base-afiliation | |||
if affiliation = "neutral" [ report gray ] | |||
if affiliation = "ally" [ report green ] | |||
if affiliation = "enemy" [ report red ] | |||
end |
@@ -26,8 +26,8 @@ to fire-bullet | |||
set size 0.5 | |||
; Bullets shouldn't travel perfectly straight: | |||
lt random 10 | |||
rt random 10 | |||
lt random 5 | |||
rt random 5 | |||
] | |||
end | |||
@@ -42,12 +42,18 @@ to do-bullet-logic | |||
let mxcor xcor | |||
let mycor ycor | |||
let is-close-enough false | |||
let target min-one-of tanks-here [distancexy mxcor mycor] | |||
let shootable-bases-here bases-here with [armor > 0 and team != -1 and team != [team] of tank [shooter] of myself] | |||
let targets (turtle-set tanks-here shootable-bases-here) | |||
let target min-one-of targets [distancexy mxcor mycor] | |||
if target != nobody [ | |||
ask target [ | |||
if distancexy mxcor mycor < 0.65 [ | |||
set is-close-enough true | |||
shot-at | |||
ifelse breed = tanks [ | |||
tank-shot-at | |||
] [ | |||
base-shot-at | |||
] | |||
] | |||
] | |||
] | |||
@@ -25,15 +25,17 @@ to make-explosions-table | |||
table:put explodes "kill" [["explosion-kill" 3 20 0.5] ["explosion-shot" 1.25 15 1] | |||
["explosion-shot" 1.25 15 1 ] ["explosion-shot" 1.25 10 1] | |||
["explosion-shot" 1.25 10 1 ] ["explosion-decay" 0.65 10 2] | |||
["explosion-decay" 0.65 10 2 ] ["explosion-decay" 0.65 7.5 2] | |||
["explosion-decay" 0.65 7.5 2 ] ["explosion-decay" 0.65 5 3] | |||
["explosion-decay" 0.65 10 2 ] ["explosion-decay" 0.65 8 2] | |||
["explosion-decay" 0.65 7 2 ] ["explosion-decay" 0.65 5 3] | |||
["explosion-decay" 0.65 5 3 ]] | |||
end | |||
to explode [name] | |||
debug "EXPLODE" name | |||
let data table:get explodes name | |||
foreach data [create-explosion ?] | |||
foreach data [ | |||
create-explosion ? | |||
] | |||
end | |||
to create-explosion [info] | |||
@@ -42,6 +44,7 @@ to create-explosion [info] | |||
let lifespan (item 2 info) | |||
let deviation (item 3 info) | |||
hatch-explosions 1 [ | |||
set label "" | |||
set shape sprite | |||
set size maxsize / 2 | |||
set midlife lifespan / 2 | |||
@@ -5,6 +5,7 @@ | |||
;; | |||
__includes [ | |||
"base.nls" | |||
"bullet.nls" | |||
"explosion.nls" | |||
"player.nls" | |||
@@ -34,9 +35,12 @@ to setup | |||
make-sounds-table | |||
make-explosions-table | |||
load-map | |||
spawn-player | |||
spawn-tank 0 ask tank 1 [ setxy -6 0 ] | |||
spawn-tank 1 ask tank 2 [ setxy 6 0 ] | |||
spawn-player 0 0 0 | |||
spawn-tank 0 -6 0 90 | |||
spawn-tank 1 6 0 270 | |||
;spawn-base -3 -7 | |||
spawn-base 0 -7 | |||
;spawn-base 3 -7 | |||
render | |||
set last-tick-time timer | |||
end | |||
@@ -48,6 +52,9 @@ to go | |||
ask tanks [ | |||
do-tank-logic | |||
] | |||
ask bases [ | |||
do-base-logic | |||
] | |||
ask bullets [ | |||
do-bullet-logic | |||
] | |||
@@ -91,6 +98,10 @@ to setup-defaults | |||
set player-kills 0 | |||
set player-target-xcor 0 | |||
set player-target-ycor 0 | |||
set tank-max-ammo 24 | |||
set tank-max-armor 8 | |||
set base-max-ammo 50 | |||
set base-max-armor 20 | |||
end | |||
to make-sounds-table | |||
@@ -260,10 +271,10 @@ player-has-target? | |||
12 | |||
OUTPUT | |||
998 | |||
30 | |||
1375 | |||
521 | |||
1012 | |||
10 | |||
1500 | |||
557 | |||
12 | |||
MONITOR | |||
@@ -398,6 +409,39 @@ true | |||
0 | |||
Polygon -7500403 true true 150 5 40 250 150 205 260 250 | |||
base | |||
false | |||
0 | |||
Rectangle -1184463 true false 60 240 120 255 | |||
Rectangle -1184463 true false 120 225 180 240 | |||
Rectangle -1184463 true false 180 240 240 255 | |||
Polygon -1184463 true false 45 240 30 240 30 270 60 270 60 255 45 255 | |||
Polygon -7500403 true true 195 210 195 225 225 225 225 195 210 195 210 210 | |||
Polygon -1184463 true false 60 45 60 30 30 30 30 60 45 60 45 45 | |||
Polygon -1184463 true false 240 255 240 270 270 270 270 240 255 240 255 255 | |||
Rectangle -1184463 true false 45 60 60 120 | |||
Rectangle -1184463 true false 180 45 240 60 | |||
Rectangle -1184463 true false 240 180 255 240 | |||
Rectangle -1184463 true false 60 120 75 180 | |||
Rectangle -1184463 true false 120 60 180 75 | |||
Rectangle -1184463 true false 225 120 240 180 | |||
Rectangle -1184463 true false 45 180 60 240 | |||
Rectangle -1184463 true false 60 45 120 60 | |||
Rectangle -1184463 true false 240 60 255 120 | |||
Rectangle -1184463 true false 135 135 165 165 | |||
Rectangle -1184463 true false 165 120 180 135 | |||
Rectangle -1184463 true false 120 120 135 135 | |||
Rectangle -1184463 true false 120 165 135 180 | |||
Rectangle -1184463 true false 165 165 180 180 | |||
Rectangle -7500403 true true 195 105 210 195 | |||
Polygon -1184463 true false 255 60 270 60 270 30 240 30 240 45 255 45 | |||
Rectangle -7500403 true true 105 90 195 105 | |||
Rectangle -7500403 true true 90 105 105 195 | |||
Rectangle -7500403 true true 105 195 195 210 | |||
Polygon -7500403 true true 210 105 225 105 225 75 195 75 195 90 210 90 | |||
Polygon -7500403 true true 105 90 105 75 75 75 75 105 90 105 90 90 | |||
Polygon -7500403 true true 90 195 75 195 75 225 105 225 105 210 90 210 | |||
bullet | |||
true | |||
5 | |||
@@ -14,10 +14,10 @@ globals [ | |||
;; Procedures | |||
;; ========== | |||
to spawn-player | |||
to spawn-player [tank-xcor tank-ycor tank-heading] | |||
create-tanks 1 [ | |||
set player tank who | |||
set-tank-vars 0 true | |||
set-tank-vars true 0 tank-xcor tank-ycor tank-heading | |||
] | |||
end | |||
@@ -1,6 +1,11 @@ | |||
;; lobo: Logo Bolo | |||
;; (c) Ben Kurtovic, 2011 | |||
globals [ | |||
tank-max-ammo | |||
tank-max-armor | |||
] | |||
breed [tanks tank] | |||
tanks-own [ | |||
@@ -22,30 +27,31 @@ tanks-own [ | |||
;; Procedures | |||
;; ========== | |||
to spawn-tank [tank-team] | |||
to spawn-tank [tank-team tank-xcor tank-ycor tank-heading] | |||
create-tanks 1 [ | |||
set-tank-vars tank-team false | |||
set-tank-vars false tank-team tank-xcor tank-ycor tank-heading | |||
] | |||
end | |||
to set-tank-vars [tank-team player-tank?] | |||
to set-tank-vars [player? tteam txcor tycor theading] | |||
set acceleration 0.03 | |||
set ammunition 24 | |||
set armor 8 | |||
set ammunition tank-max-ammo | |||
set armor tank-max-armor | |||
set fire-cool-down 0 | |||
set friction 0.0075 | |||
set is-accelerating? false | |||
set is-player? player-tank? | |||
set is-player? player? | |||
set max-fire-rate 7 | |||
set max-speed 0.25 | |||
set max-turn 24 | |||
set speed 0 | |||
set team tank-team | |||
set team tteam | |||
set color get-tank-color | |||
set heading 0 | |||
set heading theading | |||
set shape "tank" | |||
set size 1.5 | |||
setxy txcor tycor | |||
end | |||
to do-tank-logic | |||
@@ -100,7 +106,7 @@ to fire | |||
] | |||
end | |||
to shot-at | |||
to tank-shot-at | |||
debug "SHOT" (word who " by " ([shooter] of myself)) | |||
set armor armor - 1 | |||
ifelse armor = 0 [ | |||