home *** CD-ROM | disk | FTP | other *** search
/ PC User 2001 August / APC_Aug2001_CD2.iso / features / devtools / files / lb202win.exe / LB202W.EXE / MAYHEM.BAS < prev    next >
Encoding:
BASIC Source File  |  2000-12-09  |  8.1 KB  |  270 lines

  1.  
  2.     'Mayhem!
  3.     'A Liberty BASIC Game
  4.     'Copyright 1995,2000 Carl Gundel and Steve Woodward
  5.  
  6.     'Mayhem is a game where two tanks shoot at each other in a ramdomly
  7.     'generated landscape!   Each tank's gun is aimed by inputting an
  8.     'angle from the horizon, and a number of pounds of TNT to propell a
  9.     'shell with.
  10.  
  11.     'Note: There is nothing to force the players to
  12.     'take turns while playing.
  13.  
  14.  
  15.     'How to shoot
  16.     '--------------------------------------------------------------------
  17.  
  18.     'Pick an angle from 1 to 90 degrees of the horizon and input it.
  19.     'Then pick a quantity of pounds of TNT to use 1 - 20 (more or less)
  20.     'and input that.  Then click on the fire button!
  21.  
  22.     'Now if you miss, give the other chap a shot at you!  And round you
  23.     'go!!!
  24.  
  25.  
  26.     'Modifying the game
  27.     '--------------------------------------------------------------------
  28.  
  29.     'When you get bored of Mayhem, add features to make it interesting.
  30.     'Try making it three players, or four!  Make the ground invisible
  31.     'so that you have to hit it with a shell to 'feel' your way around it!
  32.     'Add some cool sound effects or a dramatic musical score!
  33.     'Try giving each player a limited number of shells, or a limited
  34.     'quantity of TNT.  Or all of the above with a setup screen!  Use your
  35.     'imagination, and then share your code with all of us!
  36.  
  37.     'Special thanks to Steve Woodward for inspiring me to write this game!
  38.  
  39.     dim terrain(500)
  40.  
  41.     nomainwin
  42.  
  43.     loadbmp "lefttank", "bmp\ltank.bmp"
  44.     loadbmp "righttank", "bmp\rtank2.bmp"
  45.     loadbmp "leftbang", "bmp\lbang.bmp"
  46.     loadbmp "rightbang", "bmp\rbang.bmp"
  47.  
  48.     WindowWidth = 500
  49.     WindowHeight = 435
  50.     UpperLeftX = 10
  51.     UpperLeftY = 10
  52.  
  53.     menu #mayhem, "&Game", "&New Game", [newGame], "&About Mayhem!", [aboutMayhem], "&Exit", [exit]
  54.     statictext #mayhem.statictext1, "Angle", 22, 336, 40, 20
  55.     textbox #mayhem.angleUsa, 70, 331, 100, 25
  56.     statictext #mayhem.statictext3, "TNT", 22, 366, 26, 20
  57.     textbox #mayhem.tntUsa, 70, 361, 45, 25
  58.     button #mayhem, "Fire!", [fireUsa], UL, 120, 361
  59.     statictext #mayhem.statictext2, "Angle", 322, 336, 40, 20
  60.     textbox #mayhem.angleUssr, 370, 331, 100, 25
  61.     statictext #mayhem.statictext4, "TNT", 322, 366, 26, 20
  62.     textbox #mayhem.tntUssr, 370, 361, 45, 25
  63.     button #mayhem, "Fire!", [fireUssr], UL, 420, 361
  64.     open "Mayhem!" for graphics_nsb_nf as #mayhem
  65.     print #mayhem, "trapclose [exit]"
  66.  
  67.  
  68. [newGame]
  69.  
  70.     rate1 = rnd(1) / (rnd(1) * 20 + 10)
  71.     rate2 = rnd(1) / (rnd(1) * 6 + 10)
  72.     windspeed = int(rnd(1) * 50) - 25
  73.     usaX = int(rnd(1) * 100) + 25
  74.     ussrX = int(rnd(1) * 100) + 350
  75.  
  76.     print #mayhem, "cls ; fill cyan ; down ; color brown ; size 2"
  77.  
  78.     for x = 0 to 499 step 2
  79.         holder1 = holder1 + rate1
  80.         holder2 = holder2 + rate2
  81.         holder3 = holder3 + sin(holder2) / 20
  82.         y = 200 + int(sin(holder1) * 75) + int(cos(holder2) * 30) + int(cos(holder3) * 10)
  83.         terrain(x) = y : terrain(x + 1) = y
  84.         print #mayhem, "line "; x; " "; y; " "; x; " 410"
  85.     next x
  86.  
  87.     print #mayhem, "drawbmp lefttank "; usaX - 16; " "; terrain(usaX) - 24;
  88.     for x = usaX - 17 to usaX + 17 : terrain(x) = terrain(usaX) - 8 : next x
  89.  
  90.     print #mayhem, "drawbmp righttank "; ussrX - 16; " "; terrain(ussrX) - 24;
  91.     for x = ussrX - 17 to ussrX + 17 : terrain(x) = terrain(ussrX) - 8 : next x
  92.  
  93.     print #mayhem, "place 10 15"
  94.  
  95.     print #mayhem, "color black ; backcolor cyan"
  96.     if windspeed < 0 then print #mayhem, "\Wind <<"; abs(windspeed); "<<"
  97.     if windspeed = 0 then print #mayhem, "\Wind <<0>>"
  98.     if windspeed > 0 then print #mayhem, "\Wind >>"; windspeed; ">>"
  99.  
  100.  
  101.     print #mayhem, "flush"
  102.     print #mayhem, "segment" : input #mayhem, segId
  103.  
  104.     'comment this line out for OS/2
  105.     'if Platform$ = "Windows" then playwave "tada.wav"
  106.  
  107.  
  108. [main.inputLoop]   'wait here for input event
  109.     input aVar$
  110.     goto [main.inputLoop]
  111.  
  112.  
  113. [fireUsa]   'the USA fires its gun!
  114.  
  115.  
  116.     print #mayhem.angleUsa, "!contents?" : input #mayhem.angleUsa, angle
  117.     print #mayhem.tntUsa, "!contents?" : input #mayhem.tntUsa, tnt
  118.  
  119.     direction = 1
  120.     x = usaX
  121.     y = terrain(x) - 16
  122.  
  123.     goto [trackShell]
  124.  
  125.  
  126.  
  127.  
  128. [fireUssr]   'the USSR fires its gun!
  129.  
  130.  
  131.     print #mayhem.angleUssr, "!contents?" : input #mayhem.angleUssr, angle
  132.     print #mayhem.tntUssr, "!contents?" : input #mayhem.tntUssr, tnt
  133.  
  134.     direction = -1
  135.     x = ussrX
  136.     y = terrain(x) - 16
  137.  
  138.     goto [trackShell]
  139.  
  140.  
  141.  
  142.  
  143.  
  144. [trackShell]
  145.  
  146.     live = 1
  147.     explode = 0
  148.     tnt = tnt * 100
  149.     windEffect = windspeed / 50
  150.     angleXform = angle / 180 * 3.14
  151.     xVelocity = (cos(angleXform) * tnt + 0.001) * direction
  152.     yVelocity = sin(angleXform) * tnt + 0.001
  153.     adjust = 3 / yVelocity
  154.     if abs(xVelocity) > yVelocity then adjust = 3 / xVelocity * direction
  155.     xVelocity = xVelocity * adjust * 2
  156.     yVelocity = yVelocity * adjust * 2
  157.     lastX = 0 : lastY = 0
  158.     print #mayhem, "rule xor"
  159.     while live = 1
  160.         gosub [waitIfNeeded]
  161.         x = x + xVelocity + windEffect
  162.         y = y - yVelocity
  163.         yVelocity = yVelocity - (32 * adjust)
  164.         print #mayhem, "place "; x; " "; y
  165.         print #mayhem, "go 1"
  166.         if lastX = 0 then [firstTimeUsa]
  167.         print #mayhem, "place "; lastX; " "; lastY
  168.         print #mayhem, "go 1"
  169.       [firstTimeUsa]
  170.         lastX = x : lastY = y
  171.         if x < 1 or x > 499 then live = 0
  172.         if live = 1 and y >= terrain(int(max(0,min(x,500)))) then live = 0 : explode = 1
  173.     wend
  174.  
  175.     print #mayhem, "discard ; flush"
  176.  
  177.     if explode = 0 then [main.inputLoop]
  178.  
  179.     explodeX = x
  180.     explodeY = y
  181.     gosub [explosion]
  182.  
  183.     if x >= usaX - 17 and x <= usaX + 17 then [explodeUsa]
  184.     if x >= ussrX - 17 and x <= ussrX + 17 then [explodeUssr]
  185.  
  186.     goto [main.inputLoop]
  187.  
  188. [waitIfNeeded]  'keep the game from running too fast on fast machines
  189.  
  190.     newTime = time$("milliseconds")
  191.     while newTime < oldTime + (30/(tnt/1000))
  192.         newTime = time$("milliseconds")
  193.     wend
  194.     oldTime = newTime
  195.     return
  196.  
  197. [explosion]   'Make an explosion at explodeX explodeY
  198.  
  199.     explodeRate = 2
  200.     explodeSpeed = explodeRate * 100
  201.  
  202.     if hit = 0 then print #mayhem, "rule xor"
  203.     print #mayhem, "size "; explodeRate
  204.     print #mayhem, "place "; explodeX; " "; explodeY
  205.  
  206.     if hit = 1 then explodeSize = 42 else explodeSize = 18
  207.  
  208.     print #mayhem, "circle "; 6 - explodeRate
  209.     for radius =  6 to explodeSize step explodeRate
  210.         print #mayhem, "circle "; radius
  211.         for delay = 1 to explodeSpeed : next delay
  212.         print #mayhem, "circle "; radius - explodeRate
  213.     next radius
  214.     print #mayhem, "circle "; explodeSize
  215.     print #mayhem, "rule over"
  216.  
  217.     print #mayhem, "discard"
  218.  
  219.     return
  220.  
  221.  
  222. [explodeUsa]  'blow up the Usa tank
  223.  
  224.     print #mayhem, "drawbmp leftbang "; usaX - 16; " "; terrain(usaX) - 16
  225.     print #mayhem, "delsegment "; segId
  226.     now$ = time$() : while time$() = now$ : wend
  227.     notice "USSR wins this round!"
  228.     goto [newGame]
  229.  
  230.  
  231. [explodeUssr]  'blow up the Ussr tank
  232.  
  233.     print #mayhem, "drawbmp rightbang "; ussrX - 16; " "; terrain(ussrX) - 16
  234.     print #mayhem, "delsegment "; segId
  235.     now$ = time$() : while time$() = now$ : wend
  236.     notice "USA wins this round!"
  237.     goto [newGame]
  238.  
  239.  
  240. [aboutMayhem]  'Display an "About Mayhem!" dialog box
  241.  
  242.     WindowWidth = 336
  243.     WindowHeight = 150
  244.  
  245.     statictext #main.statictext1, "Mayhem! is a game written in Liberty", 14, 16, 288, 20
  246.     statictext #main.statictext2, "BASIC and is copyright Carl Gundel and", 14, 36, 304, 20
  247.     statictext #main.statictext3, "Steve Woodward, 1995.", 14, 56, 168, 20
  248.     button #main, "OK", [aboutOK], UL, 214, 76
  249.     open "About Mayhem!" for dialog as #main
  250.     print #main, "trapclose [aboutOK]"
  251.  
  252.     goto [main.inputLoop]
  253.  
  254.  
  255. [aboutOK]   'Perform action for the button named 'aboutOK'
  256.  
  257.     close #main
  258.  
  259.     goto [main.inputLoop]
  260.  
  261.  
  262.  
  263. [exit]  'Quit Mayhem!
  264.  
  265.     confirm "Are you sure you want to exit?  We still have all this ammo!"; answer$
  266.     if answer$ <> "yes" then [main.inputLoop]
  267.  
  268.     close #mayhem
  269.     end
  270.