Browse Source

Replaced buttons for movement with mouse control

master
Ben Kurtovic 13 years ago
parent
commit
8586c68d90
2 changed files with 89 additions and 151 deletions
  1. +1
    -1
      README
  2. +88
    -150
      lobo.nlogo

+ 1
- 1
README View File

@@ -1,4 +1,4 @@
lobo: Logo Bolo lobo: Logo Bolo
(c) Ben Kurtovic, 2011 (c) Ben Kurtovic, 2011


Logo Bolo is a rewrite of the classic tank game by Stuart Cheshire in NetLogo.
Logo Bolo is a re-envisioning of the classic tank game by Stuart Cheshire in NetLogo.

+ 88
- 150
lobo.nlogo View File

@@ -1,7 +1,7 @@
;; lobo: Logo Bolo ;; lobo: Logo Bolo
;; (c) Ben Kurtovic, 2011 ;; (c) Ben Kurtovic, 2011
;; ;;
;; Logo Bolo is a rewrite of the classic tank game by Stuart Cheshire in NetLogo.
;; Logo Bolo is a re-envisioning of the classic tank game by Stuart Cheshire in NetLogo.
;; ;;


;; ============ ;; ============
@@ -9,17 +9,11 @@
;; ============ ;; ============


globals [ globals [
bullet-speed
bullet-travel-distance
friction
last-tick-time last-tick-time
max-acceleration
max-fps max-fps
max-tank-speed
min-acceleration
mouse-was-down?
player player
speed-up
turn-speed
player-accelerate-for
] ]


breed [bullets bullet] breed [bullets bullet]
@@ -27,11 +21,17 @@ breed [crosshairs crosshair]
breed [tanks tank] breed [tanks tank]


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


tanks-own [ tanks-own [
acceleration acceleration
friction
is-accelerating?
max-speed
max-turn
speed speed
team team
] ]
@@ -54,40 +54,17 @@ to setup
end end


to go to go
do-tank-physics
do-bullet-physics
render
keep-time
end

to player-accelerate
ask player [ ask player [
if acceleration < 0 [
set acceleration 0
]
set acceleration acceleration + speed-up
if acceleration > max-acceleration [
set acceleration max-acceleration
]
do-player-logic
] ]
end

to player-decelerate
ask player [
set acceleration min-acceleration
]
end

to player-turn-left
ask player [
lt turn-speed
ask tanks [
do-tank-logic
] ]
end

to player-turn-right
ask player [
rt turn-speed
ask bullets [
do-bullet-logic
] ]
render
keep-time
end end


to player-fire to player-fire
@@ -101,22 +78,22 @@ end
;; ================ ;; ================


to setup-defaults to setup-defaults
set bullet-speed 2
set bullet-travel-distance 16
set friction 0.01
set max-acceleration 0.5
set-patch-size 30
resize-world -8 8 -8 8
set max-fps 30 set max-fps 30
set max-tank-speed 0.3
set min-acceleration -0.025
set speed-up 0.1
set turn-speed 24
set mouse-was-down? false
set player-accelerate-for 0
end end


to spawn-player to spawn-player
create-ordered-tanks 1 [ create-ordered-tanks 1 [
set player (tank who) set player (tank who)
set color (get-tank-color "player") set color (get-tank-color "player")
set size 2
set acceleration 0.05
set friction 0.01
set is-accelerating? false
set max-speed 0.3
set max-turn 24
set speed 0 set speed 0
set team 0 set team 0
] ]
@@ -126,35 +103,60 @@ to fire
hatch-bullets 1 [ hatch-bullets 1 [
set color white set color white
set size 1 set size 1
set max-travel-distance 8
set speed 2
set travel-distance 0 set travel-distance 0
] ]
end end


to do-tank-physics
ask tanks [
set speed speed + acceleration
if speed > max-tank-speed [
set speed max-tank-speed
to do-player-logic
if mouse-inside? [
if mouse-down? and not mouse-was-down? [
set player-accelerate-for player-accelerate-for + 5
if player-accelerate-for > 30 [
set player-accelerate-for 30
]
] ]
if speed < 0 [
set speed 0
set mouse-was-down? mouse-down?
let old-heading heading
facexy mouse-xcor mouse-ycor

if subtract-headings old-heading heading > max-turn [
set heading old-heading - max-turn
] ]
set acceleration acceleration - friction
if acceleration < min-acceleration [
set acceleration min-acceleration
if subtract-headings old-heading heading < 0 - max-turn [
set heading old-heading + max-turn
] ]
fd speed
]

ifelse player-accelerate-for > 0 [
set player-accelerate-for player-accelerate-for - 1
set is-accelerating? true
] [
set is-accelerating? false
] ]
end end


to do-bullet-physics
ask bullets [
fd bullet-speed
set travel-distance travel-distance + bullet-speed
if travel-distance >= bullet-travel-distance [
die
to do-tank-logic
if is-accelerating? [
set speed speed + acceleration
if speed > max-speed [
set speed max-speed
] ]
] ]
fd speed
set speed speed - friction
if speed < 0 [
set speed 0
]
end

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


to render to render
@@ -192,11 +194,11 @@ end
GRAPHICS-WINDOW GRAPHICS-WINDOW
475 475
10 10
980
536
16
16
15.0
995
551
8
8
30.0
1 1
10 10
1 1
@@ -206,10 +208,10 @@ GRAPHICS-WINDOW
1 1
1 1
1 1
-16
16
-16
16
-8
8
-8
8
0 0
0 0
1 1
@@ -247,70 +249,22 @@ G
NIL NIL
NIL NIL


BUTTON
193
174
289
207
Accelerate
player-accelerate
NIL
1
T
OBSERVER
NIL
W
NIL
NIL

BUTTON
143
236
206
269
Left
player-turn-left
NIL
1
T
OBSERVER
NIL
A
NIL
NIL

BUTTON
250
235
319
268
Right
player-turn-right
NIL
1
T
OBSERVER
NIL
D
NIL
NIL

MONITOR MONITOR
310
297
381 381
410 410
426 426
Player Speed Player Speed
player-speed player-speed
5
8
1 1
11 11


BUTTON BUTTON
81
401
144
434
108
176
285
252
FIRE! FIRE!
player-fire player-fire
NIL NIL
@@ -323,32 +277,16 @@ NIL
NIL NIL


MONITOR MONITOR
281
443
412
488
Player Acceleration
[acceleration] of player
296
433
410
478
Player Accel Time
player-accelerate-for
5 5
1 1
11 11


BUTTON
185
294
295
327
Decelerate
player-decelerate
NIL
1
T
OBSERVER
NIL
S
NIL
NIL

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


Loading…
Cancel
Save