找回密码
 立即注册→加入我们

QQ登录

只需一步,快速开始

搜索
热搜: 下载 VB C 实现 编写
查看: 2365|回复: 2

【VFB】平台接力游戏

[复制链接]
发表于 2018-3-9 14:16:03 | 显示全部楼层 |阅读模式

欢迎访问技术宅的结界,请注册或者登录吧。

您需要 登录 才可以下载或查看,没有账号?立即注册→加入我们

×

1520575826668257.jpg

一个VFB写的小游戏,

鼠标左键给小球撘桥,按下时间越长,这小桥越长。

游戏失败,点右键,重新开始。


源码下载:Basic语言编程群 78458582 进QQ群后,在群共享里下载。




  1. #define Yes                   1
  2. #define No                      0

  3. ' COLORS
  4. #define colPlatForm         RGB(50,50,50)
  5. #define colPlatFormTop         RGB(250,200,0)
  6. #define colWater            RGB(100,100,200)
  7. #define colWaterTop          RGB(255,255,255)
  8. #define colSky            RGB(180,200,250)
  9. #define colStick            colPlatFormTop   'RGB(0,0,250)
  10. #define colPlayerCircle         RGB(250,50,150)
  11. #define colPlayerCircleBorder RGB(250,250,250)

  12. ' MOUSE BUTTOMS
  13. #define LeftButton             1
  14. #define RightButton             2

  15. ' PLATFORM, WATER, ETC POSITIONS AND DIMENSIONS
  16. #define PlatformHeight         200
  17. #define PlatformTop             480 - 200      ' Y-Screen Coordinte
  18. #define PlatformBottom          480            ' Y-Screen Coordinte
  19. #define FirstPlatformLeft      0                ' 50  ' correction required
  20. #define WaterTop               480 - 30         ' Y-Screen Coordinte
  21. #define UnitWidth             30
  22. #define StickThickness         5               ' = platform decoration height
  23. #define MaxStickLength         8 * UnitWidth

  24. ' STATES OF THE STICK
  25. #define NoStick               0
  26. #define VerticalStick         1
  27. #define HorizontalStick         2
  28. #define TurningStick            3
  29. #define CircleRadius            10

  30. #define AsciiLine               "========================================="
  31. #define GameInfo               "    PLATFORM WALKER (c) De'Nivra 2015    "
  32. #define GameMoreInfo            "    A Short Game Written In FreeBasic    "
  33. #define SayPressMouse         "     Press Mouse Left Button To Play     "
  34. #define PlayInstruction         "  Use Mouse Left Button to Play the game "
  35. #define FullScreenInst         "   Press Alt+F4 to play in full screen   "
  36. #define GameLostMessage       "================  GAMELOST  =============="
  37. #define PlayAgainInst         "Press Mouse Right Button To Play New Game"

  38. Type SpacerInfo                 ' for platform width and for gap between platforms
  39.    StartX                      As Integer
  40.    EndX                         As Integer
  41. End Type

  42. Type PlayerInfo
  43.    X                            As Integer
  44.    Y                            As Integer
  45.    ShouldFall                  As Integer
  46. End Type

  47. Type StickInfo
  48.    X                            As Integer
  49.    Y                            As Integer
  50.    Thickness                  As Integer
  51.    Length                     As Integer
  52.    PerfectLength               As Integer
  53.    State                        As Integer
  54. End Type

  55. Dim Shared As SpacerInfo       Platform1, Gap, Platform2, newGap, newPlatform
  56. Dim Shared As PlayerInfo       Player
  57. Dim Shared As Integer          WalkLength, MinWalkLength, MaxWalkLength, FallHeight
  58. Dim Shared As StickInfo         Stick
  59. Dim Shared As Integer          mx,my,mb ' mouse variables
  60. Dim Shared As Integer          BackScreen
  61. Dim Shared As Integer          PlatformsCrossed = -1
  62. Dim Shared As Integer         NextReward ' Points added if player croses platform
  63. Dim Shared As Integer          Score = 0

  64. Function FF_WINMAIN( ByVal hInstance     As HINSTANCE, _
  65.                      ByVal hPrevInstance As HINSTANCE, _
  66.                      ByRef lpCmdLine     As String, _  
  67.                      ByVal iCmdShow      As Long ) As Long


  68. Screen 18,24,2


  69. 'Dim Shared As Integer         PreviousBestScore = 0 ' in current game session


  70. '    LET THE FUN BEGIN
  71.    
  72.    RenderSkyAndWater
  73.    Draw String (160,160) , GameInfo
  74.    Draw String (160,180) , GameMoreInfo
  75.    Draw String (160,200) , AsciiLine
  76.    Draw String (160,240) , PlayInstruction
  77.    Draw String (160,260) , FullScreenInst
  78.    Draw String (160,280) , SayPressMouse
  79.    While mb <> LeftButton: GetMouse mx,my,,mb : Wend
  80.    Sleep 500

  81.    Randomize ,1                ' SEED ... METHOD USING C'S RAND()
  82.    StartNewGame

  83. Do   ' GAME LOOP

  84.    GetMouse mx,my,,mb

  85.    If mb = LeftButton Then

  86.       DoGrowStickAnimation      ' Stick lengthincreases as long as mouse button is pressed
  87.       DoStickTurnAnimation      ' Turn Stick from vertical to horizontal
  88.       ShowStickBridge         ' The Horizontal Stick acts like a bridge
  89.       DoPlayerWalkAnimation   ' Player Walks on Stick Bridge

  90.       ' CHECK WHETHER CURRENT GAME ENDS OR CONTINUES   
  91.          
  92.       Player.ShouldFall = DoPlayerFallCheck()
  93.       
  94.       If Player.ShouldFall = Yes Then
  95.          
  96.          DoPlayerFallAnimation
  97.          ' WAIT FOR USER TO PRESS RIGHT BUTTON
  98.          While mb <> RightButton: GetMouse mx,my,,mb : Wend
  99.          StartNewGame

  100.       Else
  101.          
  102.          ' IF PLAYER DID NOT FALL
  103.          PlatformsCrossed = PlatformsCrossed + 1
  104.          Score = Score + NextReward*10
  105.          NextPlatformSequence
  106.          
  107.       EndIf

  108.       '   REMOVE STICK AND START AGAIN
  109.       Stick.State = NoStick
  110.       
  111.    EndIf
  112.    Sleep 10

  113. Loop Until Len(Inkey)
  114.    Function = True    '如果你想让程序结束,则函数返回 TRUE 。

  115. End Function

  116. Sub RenderStick

  117.    Select Case Stick.State
  118.       Case NoStick: ' draw nothing
  119.       Case VerticalStick: Line (Stick.X,Stick.Y)-Step(StickThickness,-Stick.Length),colStick,BF
  120.       Case HorizontalStick: Line (Stick.X,Stick.Y)-Step(Stick.Length,-StickThickness),colStick,BF
  121.    End Select

  122. End Sub
  123. Sub RenderPlayer

  124.    Circle (Player.X,Player.Y), CircleRadius,colPlayerCircleBorder ,,,,F
  125.    Circle (Player.X,Player.Y), CircleRadius-2, colPlayerCircle   ,,,,f

  126. End Sub

  127. Sub RenderPlatform

  128.    ' Platform 1
  129.    Line (Platform1.StartX,PlatformTop)-(Platform1.EndX,PlatformBottom),colPlatForm,BF ' platform
  130.    Line (Platform1.StartX,PlatformTop)-(Platform1.EndX,PlatformTop-StickThickness),colPlatFormTop,BF   ' platform top

  131.    ' Platform 2
  132.    Line (Platform2.StartX,PlatformTop)-(Platform2.EndX,PlatformBottom),colPlatForm,BF ' platform
  133.    Line (Platform2.StartX,PlatformTop)-(Platform2.EndX,PlatformTop-StickThickness),colPlatFormTop,BF   ' platform top

  134. End Sub
  135. Sub RenderSkyAndWater
  136.    
  137.    Line(0,0)-(640,480),colSky,BF                  ' sky
  138.    Line (0,WaterTop)-(640,480),colWater,BF      ' water
  139.    Line (0,WaterTop)-(640,WaterTop),colWaterTop ' water top

  140.    ShowStatusBar 'temp

  141. End Sub

  142. Function GetRandomWidth As Integer
  143.    
  144.    #define Smallest 1
  145.    #define Largest  4
  146.    Return Smallest + Rnd * (Largest - Smallest)
  147.    
  148. End Function

  149. Sub NextPlatformSequence

  150.    Sleep 1000   'pause for some time

  151.    ' CREAT NEXT PLATFORM (temporary)
  152.    newGap.StartX = Platform2.EndX + 1
  153.    newGap.EndX = newGap.StartX + UnitWidth *GetRandomWidth
  154.    newPlatform.StartX = newGap.EndX + 1
  155.    newPlatform.EndX = newPlatform.StartX  + UnitWidth *GetRandomWidth

  156.    ' DISPLAY NEW PLATFORM
  157.    ScreenSet BackScreen, BackScreen Xor 1
  158.    Line (newPlatform.StartX,PlatformTop)-(newPlatform.EndX,PlatformBottom),colPlatForm,BF ' platform
  159.    Line (newPlatform.StartX,PlatformTop)-(newPlatform.EndX,PlatformTop-StickThickness),colPlatFormTop,BF   ' platform top
  160.    BackScreen = BackScreen Xor 1
  161.    Flip
  162.    Sleep 1000   'PAUSE FOR SOME TIME ... SO THAT USER SEES NEW PLATFORM
  163.    '--------------

  164.    ' SCROLL SCREEN LEFT
  165.    Dim imgtemp As Any Pointer
  166.    imgtemp = ImageCreate (640,480-100)
  167.    Get (0,100)-(639,479), imgtemp
  168.    
  169.    Dim As Integer offset
  170.    Offset = 10
  171.    
  172.    While Platform2.StartX > offset + 10

  173.       Offset = Offset + 4
  174.       
  175.        ' ... PROBLEM HERE: NON SMOOTH SCROLLING ... JITTERY
  176.       ScreenSet BackScreen, BackScreen Xor 1
  177.       Put (-offset,100), imgtemp,PSet
  178.       BackScreen = BackScreen Xor 1
  179.       Flip
  180.       Sleep 17

  181.    Wend
  182.    
  183.    '------------------------------------
  184.    ' UPDATE TO NEW PLATFORMS  ... the temporary platform is then not required
  185.    Platform1.StartX = FirstPlatformLeft
  186.    Platform1.EndX = Platform2.EndX - Platform2.StartX ' move ahead ... second platform becomes first platform
  187.    gap.StartX = Platform1.EndX + 1 ' gap between platforms
  188.    gap.EndX = gap.StartX + newGap.EndX - newGap.StartX
  189.    Platform2.StartX = gap.EndX + 1
  190.    Platform2.EndX = Platform2.StartX  + newPlatform.EndX - newPlatform.StartX
  191.    Player.X = Platform1.EndX- StickThickness - CircleRadius
  192.    Player.Y = PlatformTop-CircleRadius-StickThickness
  193.    Stick.X = Platform1.EndX- StickThickness
  194.    Stick.Y = PlatformTop
  195.    Stick.Length = 0
  196.    NextReward = (5- (Platform2.EndX-Platform2.StartX)/UnitWidth)*1 ' shorter gap more score

  197.    '------------------------------------
  198.    ' RENDER NEW PLATFORMS
  199.    ScreenSet BackScreen, BackScreen Xor 1
  200.    RenderSkyAndWater
  201.    RenderPlatform
  202.    RenderPlayer
  203.    BackScreen = BackScreen Xor 1
  204.    Flip
  205.    Sleep 1000

  206. End Sub

  207. Sub StartNewGame

  208.    ' INITIALISE 2 PLATFORMS WITH GAP

  209.    Platform1.StartX = FirstPlatformLeft
  210.    Platform1.EndX = Platform1.StartX + UnitWidth * GetRandomWidth

  211.    gap.StartX = Platform1.EndX + 1 ' gap between platforms
  212.    gap.EndX = gap.StartX + UnitWidth *GetRandomWidth

  213.    Platform2.StartX = gap.EndX + 1
  214.    Platform2.EndX = Platform2.StartX  + UnitWidth *GetRandomWidth

  215.    Player.X = Platform1.EndX- StickThickness - CircleRadius
  216.    Player.Y = PlatformTop-CircleRadius-StickThickness

  217.    Stick.X = Platform1.EndX- StickThickness
  218.    Stick.Y = PlatformTop
  219.    Stick.Length = 0

  220.    NextReward = (5- (Platform2.EndX-Platform2.StartX)/UnitWidth)*1 ' shorter gap more score
  221.    PlatformsCrossed = 0
  222.    Score = 0

  223.    ScreenSet BackScreen, BackScreen Xor 1
  224.    RenderSkyAndWater
  225.    RenderPlatform
  226.    RenderPlayer
  227.    BackScreen = BackScreen Xor 1
  228.    Flip
  229.    Sleep 1000

  230. End Sub


  231. Sub ShowStatusBar

  232.    Draw String (10,25) , "PLATFORM: " & PlatformsCrossed +1
  233.    Draw String (280,25) , "SCORE: " & Score
  234.    Draw String (500,25) , "NEXT REWARD: " & NextReward * 10

  235. End Sub

  236. Sub ThickLine(x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer, Thickness As Integer, LineColor As Long)

  237.    Dim Slope As Single
  238.    Dim As Integer xDelta = x2-x1, yDelta = y2-y1

  239.    If xDelta = 0 And yDelta = 0 Then
  240.       Circle (x1, y1), Thickness, LineColor, , , , f
  241.       Exit Sub
  242.    EndIf

  243.    If Abs(xDelta) >= Abs(yDelta) Then
  244.       Slope  = yDelta / xDelta
  245.       For I As Integer = x1 To x2 Step Sgn(xDelta)
  246.          Circle (I, Slope * (I - x1) + y1), Thickness, LineColor, , , , f
  247.       Next
  248.    Else
  249.       Slope = xDelta / yDelta
  250.       For I As Integer = y1 To y2 Step Sgn(yDelta)
  251.          Circle (Slope * (I - y1) + x1, I), Thickness, LineColor, , , , f
  252.       Next
  253.    End If

  254. End Sub

  255. Sub DoStickTurnAnimation

  256.    #define Pi             4 * Atn(1)
  257.    #define NintyDegree    Pi/2
  258.    #define TenDegree    NintyDegree/9

  259.    Dim Angle As Single
  260.    For Angle = NintyDegree To 0 Step -TenDegree
  261.       ScreenSet BackScreen, BackScreen Xor 1
  262.       RenderSkyAndWater
  263.       RenderPlatform
  264.       ThickLine Stick.X,Stick.Y, _
  265.       Stick.X+Stick.Length * Cos(Angle), Stick.Y-Stick.Length * Sin(Angle), _
  266.       StickThickness/2,colStick
  267.       RenderPlayer
  268.       BackScreen = BackScreen Xor 1
  269.       Flip
  270.       Sleep 10
  271.    Next

  272. End Sub

  273. Sub DoPlayerWalkAnimation

  274.    WalkLength = Platform2.EndX - Platform1.EndX ' default

  275.    If Stick.Length < gap.EndX - gap.StartX Then WalkLength = Stick.Length
  276.    If Stick.Length > Platform2.EndX - gap.StartX Then WalkLength = Stick.Length

  277.    While (WalkLength > 0 )
  278.       WalkLength = WalkLength - 5
  279.       Player.X = Player.X + 5
  280.       ' Render
  281.       ScreenSet BackScreen, BackScreen Xor 1
  282.       RenderSkyAndWater
  283.       RenderPlatform
  284.       RenderPlayer
  285.       RenderStick
  286.       BackScreen = BackScreen Xor 1
  287.       Flip
  288.       Sleep 10
  289.    Wend

  290. End Sub

  291. Sub ShowStickBridge

  292.    Stick.State = HorizontalStick      ' After Turn, the stick becomes horizontal

  293.    ScreenSet BackScreen, BackScreen Xor 1
  294.    RenderSkyAndWater
  295.    RenderPlatform
  296.    RenderPlayer
  297.    RenderStick
  298.    BackScreen = BackScreen Xor 1
  299.    Flip
  300.    Sleep 10

  301. End Sub

  302. Sub DoGrowStickAnimation

  303.    Stick.State = VerticalStick
  304.    While mb = LeftButton   'Increase Stick and Draw
  305.       GetMouse mx,my,,mb ' check mouse again
  306.       Stick.Length = Stick.Length+5
  307.       If Stick.Length > MaxStickLength Then  Stick.Length = MaxStickLength
  308.       ' Render
  309.       ScreenSet BackScreen, BackScreen Xor 1
  310.       RenderSkyAndWater
  311.       RenderPlatform
  312.       RenderPlayer
  313.       RenderStick
  314.       BackScreen = BackScreen Xor 1
  315.       Flip
  316.       Sleep 10
  317.    Wend

  318. End Sub

  319. Sub DoPlayerFallAnimation

  320.    FallHeight = 200
  321.    Player.X = Player.X + 10

  322.    While (FallHeight > 0 )
  323.       FallHeight = FallHeight - 5
  324.       Player.Y = Player.Y + 5
  325.       ' Render
  326.       ScreenSet BackScreen, BackScreen Xor 1
  327.       RenderSkyAndWater
  328.       RenderPlatform
  329.       RenderPlayer
  330.       RenderStick
  331.       Draw String (160,160) , GameLostMessage
  332.       Draw String (160,200) , PlayAgainInst
  333.       BackScreen = BackScreen Xor 1
  334.       Flip
  335.       Sleep 10
  336.    Wend

  337. End Sub

  338. Function DoPlayerFallCheck As Integer

  339.    MinWalkLength = gap.EndX- gap.StartX
  340.    MaxWalkLength = Platform2.EndX- gap.StartX

  341.    If Stick.Length < MinWalkLength Then Return Yes
  342.    If Stick.Length > MaxWalkLength Then Return Yes
  343.    Return No

  344. End Function
复制代码
回复

使用道具 举报

发表于 2018-3-11 15:18:55 | 显示全部楼层
66666666666
回复 赞! 靠!

使用道具 举报

发表于 2022-5-17 09:57:58 | 显示全部楼层

感谢楼主分享~~~
回复 赞! 靠!

使用道具 举报

本版积分规则

QQ|Archiver|小黑屋|技术宅的结界 ( 滇ICP备16008837号 )|网站地图

GMT+8, 2024-12-22 11:47 , Processed in 0.034142 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表