Artillery version 6
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
This model is based on the classic game Tank Wars. Players must adjust angle and power of fire to hit a target with a projectile. Several factors, including gravity and wind must be taken into account.
HOW IT WORKS
The warhead is fired and moves ballistically towards its target.
HOW TO USE IT
The SETUP button creates a new randomly-positioned target and obstacle wall.
The GO button causes the game logic to be active and must be pressed anytime the game is in play.
The FIRE button launches the projectile with the currently specified parameters.
The WIND slider adjusts the direction and magnitude of the wind.
Properties of the obstacle wall can be configured including its height (WALL-HEIGHT slider), it's location (WALL-POSITION slider), and what effect it has on wind (WALL-BLOCKS-WIND? switch)
THINGS TO TRY
Try to hit the target!
NETLOGO FEATURES
This model uses the TIE command for links, to conveniently make it so that changing the heading of the tank causes its gun to swivel and the "aiming arrow" to also swivel.
This model also fakes having no ceiling to the world, by having the shell (projectile) wrap around to the bottom of the view, but it is hidden until it comes back down again.
RELATED MODELS
Lunar Lander
CREDITS AND REFERENCES
Thanks to James Newell for his work on this model.
HOW TO CITE
If you mention this model in an academic publication, we ask that you include these citations for the model itself and for the NetLogo software:
- Wilensky, U. (2008). NetLogo Projectile Attack model. http://ccl.northwestern.edu/netlogo/models/ProjectileAttack. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.
- Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.
In other publications, please use:
- Copyright 2008 Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/ProjectileAttack for terms of use.
COPYRIGHT NOTICE
Copyright 2008 Uri Wilensky. All rights reserved.
Permission to use, modify or redistribute this model is hereby granted, provided that both of the following requirements are followed: a) this copyright notice is included. b) this model will not be redistributed for profit without permission from Uri Wilensky. Contact Uri Wilensky for appropriate licenses for redistribution for profit.
Comments and Questions
breed [ clouds cloud ] breed [ targets target ] breed [ left_tanks left_tank ] breed [ right_tanks right_tank ] breed [ left_guns left_gun ] breed [ right_guns right_gun ] breed [ shells shell ] globals [ x-vel y-vel velocity previous-wall-height previous-wall-pos] to setup ;; (for this model to work with NetLogo's new plotting features, ;; __clear-all-and-reset-ticks should be replaced with clear-all at ;; the beginning of your setup procedure and reset-ticks at the end ;; of the procedure.) clear-all set-default-shape right_tanks "tank" set-default-shape left_tanks "tank" set-default-shape right_guns "gun" set-default-shape left_guns "gun" set-default-shape clouds "cloud" set-default-shape shells "ball" reset-ticks ask patches [ set pcolor 97 ] ask patches with [ pycor < -20 ] [ set pcolor black ] ; next we create the tank, it's gun, and the aiming arrow create-left_tanks 1 [ set heading angle_right setxy (-35 + random 25) -19.2 set color green - 2 set size 3 hatch-left_guns 1 ; the tank's gun/nozzle [ set size 1 set color green - 3 ; this confusing line of code creates a directed "tie" link ; between the tank and its gun ask myself [ create-link-to myself [ tie hide-link ]] hatch 1 ; the "aiming arrow" [ set breed turtles fd 3 set color red - 1 ; and now we create a directed "tie" link between ; the gun and its aiming arrow ask myself [ create-link-to myself [ tie hide-link ]] ] ] ] create-right_tanks 1 [ set heading angle_right setxy (35 - random 25) -19.2 set color green - 2 set size 3 hatch-right_guns 1 ; the tank's gun/nozzle [ set size 1 set color green - 3 ; this confusing line of code creates a directed "tie" link ; between the tank and its gun ask myself [ create-link-to myself [ tie hide-link ]] hatch 1 ; the "aiming arrow" [ set breed turtles fd 3 set color red - 1 ; and now we create a directed "tie" link between ; the gun and its aiming arrow ask myself [ create-link-to myself [ tie hide-link ]] ] ] ] create-clouds 1 [ set shape "cloud" setxy 0 15 set color 8 set size 3.5 set heading 90 ] create-targets 1 [ set color green set shape "tree pine" setxy (26 - random 15) -18.5 set size 4 ] create-targets 1 [ set color green set shape "tree pine" setxy (-26 + random 15) -18.5 set size 4 ] ; create the wall ask patches with [ pycor > -21 ] [ ifelse (pycor < wall-height - 21 and pxcor = wall-position ) [ set pcolor gray ] [ set pcolor 97 ] ] set previous-wall-height wall-height set previous-wall-pos wall-position end to go if not any? targets [ stop ] ask right_tanks [ set heading angle_right ] ask left_tanks [ set heading angle_left ] if ( previous-wall-height != wall-height or previous-wall-pos != wall-position ) [ ask patches with [ pycor > -21 ] [ ifelse (pycor < wall-height - 21 and pxcor = wall-position ) [ set pcolor gray ] [ set pcolor 97 ] ] set previous-wall-height wall-height set previous-wall-pos wall-position ] every .05 [ ask shells [ setxy (xcor + x-vel) (ycor + y-vel) set y-vel (y-vel - .01) ; NOTE: this is *NOT* modeling a realistic wind effect on a projectile. ; Instead, we just treat wind like gravitational acceleration along x-axis if (wall-block-wind? = false or (wall-block-wind? = true and (ycor > wall-height - 15) or ((xcor - wall-position) * wind < 0))) [ set x-vel (x-vel + (wind / 10000)) ] set velocity sqrt (( x-vel ^ 2 ) + (y-vel ^ 2)) if (velocity > 1) [ set x-vel x-vel / velocity set y-vel y-vel / velocity set velocity 1 ] check-shell ] ask clouds [ setxy (xcor + wind / 100) (ycor) ] ] display end to fire_right if not any? shells [ ask right_tanks [ hatch-shells 1 [ set size 1 set color black set x-vel ( sin angle_right * ( Power_right / 100 )) set y-vel ( cos angle_right * ( Power_right / 100 )) set velocity Power_right / 100 ] ] ] end to fire_left if not any? shells [ ask left_tanks [ hatch-shells 1 [ set size 1 set color black set x-vel ( sin angle_left * ( Power_left / 100 )) set y-vel ( cos angle_left * ( Power_left / 100 )) set velocity Power_left / 100 ] ] ] end ; This procedure uses a clever hack to simulate having no ceiling for the projectile ; Basically, if the projectile goes up above the ceiling, it actually wraps around, ; but it becomes hidden, until it comes back down again. Obviously, this method ; isn't bulletproof, but it works pretty well for the purposes of this game. to check-shell if ( pycor = -25 and hidden? = false ) [ hide-turtle ] if ( pycor = 25 and hidden? = true ) [ show-turtle ] if ( hidden? = false ) [ if ( xcor > 37 or ycor < -23 or pcolor = gray ) [ die ] if ( any? targets-here ) [ ask patches in-radius 2 [ set pcolor yellow ] ask patches in-radius 1 [ set pcolor red ] ask targets-here [ die ] die ] set pcolor scale-color sky velocity 2 0 ] end ; Copyright 2008 Uri Wilensky. All rights reserved. ; The full copyright notice is in the Information tab.
There are 2 versions of this model.
This model does not have any ancestors.
This model does not have any descendants.