mayhem

This is a translation of the two player Mayhem game that ships with Liberty BASIC. (mayhem.bas) The original program was coded by Carl Gundel and Steve Woodward.

Screenshot




 * Note the two places where Cls [not to be confused with #g Cls("Cyan")] can be inserted. Choose only one when running the code. The difference is -

When Cls is placed directly under //[newGame]//, all frames remain displayed throughout that round. When Cls is placed under //[main.inputLoop]//, directly under //Input "Press ENTER to Load Ammo > ";z$//, only the last 2 frames remain visible.

code format="vbnet" 'Mayhem! 'A Liberty BASIC Game 'Copyright 1995,2000 Carl Gundel and Steve Woodward 'Ported to Run BASIC with permission ' Read Data for Left Tank (USA) Dim LTank(32, 32) ' USA Tank For y = 1 to 32 For x = 1 to 32 Read pixel LTank(x, y) = pixel Next x   Next y    ' Read Data for Right Tank (USSR) Dim RTank(32, 32) ' USSR Tank For y = 1 to 32 For x = 1 to 32 Read pixel RTank(x, y) = pixel Next x   Next y

' Dim terrain boundaries: width = 500 Dim terrain(500)

' Define the graphic area Graphic #g, 500, 400

' New Game starts here [newGame] ' *** Insert Cls here to keep all frames visible within each round ' Cls ' *** ============================================================   Print "Mayhem - Carl Gundel and Steve Woodward" Print "Ported to Run BASIC with permission" Print " " rate1 = Rnd(1) / (Rnd(1) * 20 + 10) rate2 = Rnd(1) / (Rnd(1) * 6 + 10) windspeed = Int(Rnd(1) * 50) - 25 usaX = Int(Rnd(1) * 100) + 25 ussrX = Int(Rnd(1) * 100) + 350 ' Reset explosion variables explodeUSA = 0 explodeUSSR = 0 ' Choose player to go first playerTurn = Int(Rnd(1) * 2)

[main.inputLoop] playerTurn = playerTurn + 1 If playerTurn = 3 Then playerTurn = 1 End If   Input "Press ENTER to Load Ammo > ";z$ ' *** Insert Cls here to keep only the two most recent frames visible within each round Cls ' *** ============================================================   #g Cls("Cyan") #g Color("Brown") #g Size(2)

holder1 = 0 holder2 = 0 holder3 = 0 for x = 0 to 499 step 2 holder1 = holder1 + rate1 holder2 = holder2 + rate2 holder3 = holder3 + sin(holder2) / 20 y = 200 + int(sin(holder1) * 75) + int(cos(holder2) * 30) + int(cos(holder3) * 10) terrain(x) = y : terrain(x + 1) = y       #g Line(x, y, x, 410) next x

' Draw the tanks Gosub [LTank] Gosub [RTank] #g Place(10, 15) #g Color("Black") if windspeed < 0 then #g "\Wind <<"; abs(windspeed); "<<" if windspeed = 0 then #g "\Wind <<0>>" if windspeed > 0 then #g "\Wind >>"; windspeed; ">>"

#g Place(10, 35) #g Color("Black") If playerTurn = 1 Then #g "\USA's Turn to Fire" Else #g "\USSR's Turn to Fire" End If

#g Flush Render #g angle = 0 Input "Angle > ";angle If angle = 0 Then End ' Exit Loop if Desired Input "TNT > ";tnt If tnt <= 1 Then Print "What are you kidding? Put more tnt in there unless you wanna blow yourself up!" playerturn = playerTurn - 1 Goto [main.inputLoop] End If

If playerTurn = 1 Then x = usaX direction = 1 Else x = ussrX direction = -1 End If   y = terrain(x) - 16 ' Draw path of shell live = 1 explode = 0 tnt = tnt * 100 windEffect = windspeed / 50 angleXform = angle / 180 * 3.14 xVelocity = (cos(angleXform) * tnt + 0.001) * direction yVelocity = sin(angleXform) * tnt + 0.001 adjust = 3 / yVelocity if abs(xVelocity) > yVelocity then adjust = 3 / xVelocity * direction xVelocity = xVelocity * adjust * 2 yVelocity = yVelocity * adjust * 2 lastX = 0 : lastY = 0 While live = 1 x = x + xVelocity + windEffect y = y - yVelocity yVelocity = yVelocity - (32 * adjust) #g Place(x, y)       #g Go(1) If lastX > 0 Then #g Place(lastX, lastY) #g Go(1) End If       lastX = x : lastY = y        If x 499 Then live = 0 End If       If (live = 1) and (y >= terrain(int(maxRB(0, minRB(x, 500))))) Then live = 0 : explode = 1 End If   wend

explodeX = x   explodeY = y

If playerTurn = 1 Then n$ = "USA" Else n$ = "USSR" End If

#g Place(10, 55) msg$ = "The ";n$;" misses!" If Abs(explodeX - usaX) < 30 Then msg$ = "USA narrowly escapes!" End If   If Abs(explodeX - ussrX) < 30 Then msg$ = "USSR narrowly escapes!" End If

If playerTurn = 1 Then If (x >= ussrX - 17) and (x <= ussrX + 17) Then explodeUSSR = 1 Gosub [explodeUssr] Else #g Color("Blue") #g "\";msg$ Gosub [explosion] End If   End If

If playerTurn = 2 Then If (x >= usaX - 17) and (x <= usaX + 17) Then explodeUSA = 1 Gosub [explodeUsa] Else #g Color("Red") #g "\";msg$ Gosub [explosion] End If   End If

#g Flush Render #g

If explodeUSSR + explodeUSA = 0 Then Goto [main.inputLoop] End If

Input "Play again? ";yn$

If Upper$(Left$(yn$, 1)) = "Y" Then Goto [newGame] End If

' End program here End

[explosion] 'Make an explosion at explodeX explodeY explodeRate = 2 explodeSpeed = explodeRate * 100 explodeSize = 18 For angle = 1 to 360 #g Place(explodeX, explodeY) #g turn(angle) If angle/2 = Int(angle/2) Then #g Color("Black") Else #g Color("White") End If       #g go(Int(Rnd(1) * explodeSize) + Int(explodeSize/2)) Next angle Return

[explodeUsa] 'blow up the Usa tank #g Color("Red") #g Place(10, 55) #g "\The USSR strikes!" explodeSize = 42 For angle = 1 to 360 #g Place(usaX - 16, terrain(usaX) - 16) #g turn(angle) If angle/2 = Int(angle/2) Then #g Color("Red") Else #g Color("Yellow") End If       #g go(Int(Rnd(1) * explodeSize) + Int(explodeSize/2)) Next angle Return

[explodeUssr] 'blow up the Ussr tank #g Color("Blue") #g Place(10, 55) #g "\The USA strikes!" explodeSize = 42 For angle = 1 to 360 #g Place(ussrX - 16, terrain(ussrX) - 16) #g turn(angle) If angle/2 = Int(angle/2) Then #g Color("Red") Else #g Color("Yellow") End If       #g go(Int(Rnd(1) * explodeSize) + Int(explodeSize/2)) Next angle Return

[LTank] ' USA Tank x1 = usaX - 16 y1 = terrain(usaX) - 24 for y = 1 to 32 For x = 1 to 32 hue$ = hue$(LTank(x, y)) rHue = Val(Word$(hue$, 1)) gHue = Val(Word$(hue$, 2)) bHue = Val(Word$(hue$, 3)) If hue$ <> "" Then #g Color(rHue, gHue, bHue) #g Set(x + x1, y + y1) End If       Next x    Next y    For x = usaX - 17 to usaX + 17 terrain(x) = terrain(usaX) - 8 Next x   Return

[RTank] 'USSR Tank x2 = ussrX - 16 y2 = terrain(ussrX) - 24 for y = 1 to 32 For x = 1 to 32 hue$ = hue$(RTank(x, y)) rHue = Val(Word$(hue$, 1)) gHue = Val(Word$(hue$, 2)) bHue = Val(Word$(hue$, 3)) #g Color(rHue, gHue, bHue) #g Set(x + x2, y + y2) Next x   Next y    For x = ussrX - 17 to ussrX + 17 terrain(x) = terrain(ussrX) - 8 Next x   Return

Function minRB(n1, n2) minRB = n1   If n2 < n1 Then minRB = n2   End If End Function

Function maxRB(n1, n2) maxRB = n1   If n2 > n1 Then maxRB = n2   End If End Function

Function hue$(nColor) Select Case nColor Case 1 ' Cyan hue$ = "0 255 255" Case 2 ' Red hue$ = "255 0 0" Case 3 ' Yellow hue$ = "255 255 0" Case 4 ' Olive Green hue$ = "128 153 0" Case 5 ' Blue hue$ = "0 0 128" Case 6 ' Light Gray hue$ = "192 192 192" Case 7 ' Medium Gray hue$ = "140 140 140" Case 8 ' Dark Gray hue$ = "128 128 128" Case 9 ' White hue$ = "255 255 255" End Select End Function

[LTankData] Data 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 Data 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 Data 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 Data 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 Data 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1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, 6, 7, 7 Data 1, 1, 1, 9, 6, 6, 6, 6, 4, 6, 6, 6, 4, 6, 6, 6, 4, 6, 6, 6, 4, 6, 6, 6, 4, 6, 6, 6, 4, 6, 6, 7 Data 1, 1, 1, 9, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7 Data 1, 1, 1, 9, 6, 6, 4, 6, 6, 6, 4, 6, 6, 6, 4, 6, 6, 6, 4, 6, 6, 6, 4, 6, 6, 6, 4, 6, 6, 6, 6, 7 Data 1, 1, 1, 1, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 1 Data 1, 1, 1, 1, 1, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 1, 1 Data 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7 Data 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4, 7, 4 code

The graphics render at a reasonable speed with a high speed internet connection. This may not be the case with dial-up. The tank graphics are plotted pixel by pixel. The code will be modified as soon as Run BASIC is able to support loading of bitmaps from disk files. Hopefully this will increase the speed for dial-up internet users.