home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lb091.zip / MAYHEM.BAS < prev    next >
BASIC Source File  |  1995-08-29  |  7KB  |  228 lines

  1.  
  2.     'Mayhem!
  3.     'A Liberty BASIC Game
  4.     'Copyright Carl Gundel and Steve Woodward, 1995
  5.  
  6.     dim terrain(500)
  7.  
  8.     nomainwin
  9.  
  10.     loadbmp "lefttank", "ltank.bmp"
  11.     loadbmp "righttank", "rtank2.bmp"
  12.     loadbmp "leftbang", "lbang.bmp"
  13.     loadbmp "rightbang", "rbang.bmp"
  14.  
  15.     WindowWidth = 500
  16.     WindowHeight = 435
  17.     UpperLeftX = 10
  18.     UpperLeftY = 10
  19.  
  20.     menu #mayhem, "&Game", "&New Game", [newGame], "&About Mayhem!", [aboutMayhem], "&Exit", [exit]
  21.     statictext #mayhem.statictext1, "Angle", 22, 336, 40, 20
  22.     textbox #mayhem.angleUsa, 70, 331, 100, 25
  23.     statictext #mayhem.statictext3, "TNT", 22, 366, 26, 20
  24.     textbox #mayhem.tntUsa, 70, 361, 45, 25
  25.     button #mayhem, "Fire!", [fireUsa], UL, 120, 361
  26.     statictext #mayhem.statictext2, "Angle", 322, 336, 40, 20
  27.     textbox #mayhem.angleUssr, 370, 331, 100, 25
  28.     statictext #mayhem.statictext4, "TNT", 322, 366, 26, 20
  29.     textbox #mayhem.tntUssr, 370, 361, 45, 25
  30.     button #mayhem, "Fire!", [fireUssr], UL, 420, 361
  31.     open "Mayhem!" for graphics_nsb_nf as #mayhem
  32.     print #mayhem, "trapclose [exit]"
  33.  
  34.  
  35. [newGame]
  36.  
  37.     rate1 = rnd(1) / (rnd(1) * 20 + 10)
  38.     rate2 = rnd(1) / (rnd(1) * 6 + 10)
  39.     windspeed = int(rnd(1) * 50) - 25
  40.     usaX = int(rnd(1) * 100) + 25
  41.     ussrX = int(rnd(1) * 100) + 350
  42.  
  43.     print #mayhem, "cls ; fill cyan ; down ; color brown ; size 2"
  44.  
  45.     for x = 0 to 499 step 2
  46.         holder1 = holder1 + rate1
  47.         holder2 = holder2 + rate2
  48.         holder3 = holder3 + sin(holder2) / 20
  49.         y = 200 + int(sin(holder1) * 75) + int(cos(holder2) * 30) + int(cos(holder3) * 10)
  50.         terrain(x) = y : terrain(x + 1) = y
  51.         print #mayhem, "line "; x; " "; y; " "; x; " 410"
  52.     next x
  53.  
  54.     print #mayhem, "drawbmp lefttank "; usaX - 16; " "; terrain(usaX) - 24;
  55.     for x = usaX - 17 to usaX + 17 : terrain(x) = terrain(usaX) - 8 : next x
  56.  
  57.     print #mayhem, "drawbmp righttank "; ussrX - 16; " "; terrain(ussrX) - 24;
  58.     for x = ussrX - 17 to ussrX + 17 : terrain(x) = terrain(ussrX) - 8 : next x
  59.  
  60.     print #mayhem, "place 10 15"
  61.  
  62.     print #mayhem, "color black ; backcolor cyan"
  63.     if windspeed < 0 then print #mayhem, "\Wind <<"; abs(windspeed); "<<"
  64.     if windspeed = 0 then print #mayhem, "\Wind <<0>>"
  65.     if windspeed > 0 then print #mayhem, "\Wind >>"; windspeed; ">>"
  66.  
  67.  
  68.     print #mayhem, "flush"
  69.     print #mayhem, "segment" : input #mayhem, segId
  70.  
  71.     'comment this line out for OS/2
  72.     'if Platform$ = "Windows" then playwave "tada.wav"
  73.  
  74.  
  75. [main.inputLoop]   'wait here for input event
  76.     input aVar$
  77.     goto [main.inputLoop]
  78.  
  79.  
  80. [fireUsa]   'the USA fires its gun!
  81.  
  82.  
  83.     print #mayhem.angleUsa, "!contents?" : input #mayhem.angleUsa, angle
  84.     print #mayhem.tntUsa, "!contents?" : input #mayhem.tntUsa, tnt
  85.  
  86.     direction = 1
  87.     x = usaX
  88.     y = terrain(x) - 16
  89.  
  90.     goto [trackShell]
  91.  
  92.  
  93.  
  94.  
  95. [fireUssr]   'the USSR fires its gun!
  96.  
  97.  
  98.     print #mayhem.angleUssr, "!contents?" : input #mayhem.angleUssr, angle
  99.     print #mayhem.tntUssr, "!contents?" : input #mayhem.tntUssr, tnt
  100.  
  101.     direction = -1
  102.     x = ussrX
  103.     y = terrain(x) - 16
  104.  
  105.     goto [trackShell]
  106.  
  107.  
  108.  
  109.  
  110.  
  111. [trackShell]
  112.  
  113.     live = 1
  114.     explode = 0
  115.     tnt = tnt * 100
  116.     windEffect = windspeed / 50
  117.     angleXform = angle / 180 * 3.14
  118.     xVelocity = (cos(angleXform) * tnt + 0.001) * direction
  119.     yVelocity = sin(angleXform) * tnt + 0.001
  120.     adjust = 3 / yVelocity
  121.     if abs(xVelocity) > yVelocity then adjust = 3 / xVelocity * direction
  122.     xVelocity = xVelocity * adjust * 2
  123.     yVelocity = yVelocity * adjust * 2
  124.     lastX = 0 : lastY = 0
  125.     print #mayhem, "rule xor"
  126.     while live = 1
  127.         x = x + xVelocity + windEffect
  128.         y = y - yVelocity
  129.         yVelocity = yVelocity - (32 * adjust)
  130.         print #mayhem, "place "; x; " "; y
  131.         print #mayhem, "go 1"
  132.         if lastX = 0 then [firstTimeUsa]
  133.         print #mayhem, "place "; lastX; " "; lastY
  134.         print #mayhem, "go 1"
  135.       [firstTimeUsa]
  136.         lastX = x : lastY = y
  137.         if x < 1 or x > 499 then live = 0
  138.         if live = 1 and y >= terrain(int(x)) then live = 0 : explode = 1
  139.     wend
  140.  
  141.     print #mayhem, "discard ; flush"
  142.  
  143.     if explode = 0 then [main.inputLoop]
  144.  
  145.     explodeX = x
  146.     explodeY = y
  147.     gosub [explosion]
  148.  
  149.     if x >= usaX - 17 and x <= usaX + 17 then [explodeUsa]
  150.     if x >= ussrX - 17 and x <= ussrX + 17 then [explodeUssr]
  151.  
  152.     goto [main.inputLoop]
  153.  
  154.  
  155. [explosion]   'Make an explosion at explodeX explodeY
  156.  
  157.     explodeRate = 2
  158.     explodeSpeed = explodeRate * 100
  159.  
  160.     if hit = 0 then print #mayhem, "rule xor"
  161.     print #mayhem, "size "; explodeRate
  162.     print #mayhem, "place "; explodeX; " "; explodeY
  163.  
  164.     if hit = 1 then explodeSize = 42 else explodeSize = 18
  165.  
  166.     print #mayhem, "circle "; 6 - explodeRate
  167.     for radius =  6 to explodeSize step explodeRate
  168.         print #mayhem, "circle "; radius
  169.         for delay = 1 to explodeSpeed : next delay
  170.         print #mayhem, "circle "; radius - explodeRate
  171.     next radius
  172.     print #mayhem, "circle "; explodeSize
  173.     print #mayhem, "rule over"
  174.  
  175.     print #mayhem, "discard"
  176.  
  177.     return
  178.  
  179.  
  180. [explodeUsa]  'blow up the Usa tank
  181.  
  182.     print #mayhem, "drawbmp leftbang "; usaX - 16; " "; terrain(usaX) - 16
  183.     print #mayhem, "delsegment "; segId
  184.     now$ = time$() : while time$() = now$ : wend
  185.     notice "USSR wins this round!"
  186.     goto [newGame]
  187.  
  188.  
  189. [explodeUssr]  'blow up the Ussr tank
  190.  
  191.     print #mayhem, "drawbmp rightbang "; ussrX - 16; " "; terrain(ussrX) - 16
  192.     print #mayhem, "delsegment "; segId
  193.     now$ = time$() : while time$() = now$ : wend
  194.     notice "USA wins this round!"
  195.     goto [newGame]
  196.  
  197.  
  198. [aboutMayhem]  'Display an "About Mayhem!" dialog box
  199.  
  200.     WindowWidth = 336
  201.     WindowHeight = 150
  202.  
  203.     statictext #main.statictext1, "Mayhem! is a game written in Liberty", 14, 16, 288, 20
  204.     statictext #main.statictext2, "BASIC and is copyright Carl Gundel and", 14, 36, 304, 20
  205.     statictext #main.statictext3, "Steve Woodward, 1995.", 14, 56, 168, 20
  206.     button #main, "OK", [aboutOK], UL, 214, 76
  207.     open "About Mayhem!" for dialog as #main
  208.     print #main, "trapclose [aboutOK]"
  209.  
  210.     goto [main.inputLoop]
  211.  
  212.  
  213. [aboutOK]   'Perform action for the button named 'aboutOK'
  214.  
  215.     close #main
  216.  
  217.     goto [main.inputLoop]
  218.  
  219.  
  220.  
  221. [exit]  'Quit Mayhem!
  222.  
  223.     confirm "Are you sure you want to exit?  We still have all this ammo!"; answer$
  224.     if answer$ <> "yes" then [main.inputLoop]
  225.  
  226.     close #mayhem
  227.     end
  228.