扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:刘涛 来源:天极网 2007年10月19日
关键字:
Option Explicit ’API Declares Private Declare Function GetTickCount _ Lib "kernel32" () As Long Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, _ ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, _ ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long Private Declare Function SetPixelV Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, _ ByVal y As Long, ByVal crColor As Long) As Long Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer Private Const VK_DOWN = &H28 ’ Vertical speed of the craft Private vSpeed As Double ’ The y coordinate of the craft Private LandY As Double ’ The amount of fuel left Private Fuel As Double |
txtvspeed.Text = Format(vSpeed, "0.0") txtfuel.Text = Format(Fuel, "0.0") txtheight.Text = Format(picEarth.ScaleHeight - piclander.ScaleHeight - 30 - LandY, "0.0") |
Static curtime As Long Dim timenow As Long Dim timediff As Long |
If curtime = 0 Then ’ Draw the earth picEarth.Line (0, picEarth.ScaleHeight - 30) -(picEarth.ScaleWidth, picEarth.ScaleHeight), vbWhite, BF Randomize Timer Dim starx As Long, stary As Long For starx = 0 To picEarth.ScaleWidth For stary = 0 To picEarth.ScaleHeight - 30 If Rnd * 1000 < 5 Then SetPixelV picEarth.hdc, starx, stary, vbYellow End If Next Next timenow = GetTickCount curtime = timenow End If |
Destination = Source XOR Destination |
’etc...curtime = timenow Else timenow = GetTickCount ’ If it isn’t the first time, put back the previous background BitBlt picEarth.hdc, 150, LandY, piclander.ScaleWidth, _ piclander.ScaleHeight, piclander.hdc, 0, 0, vbSrcInvert ’ End If... |
timediff = timenow - curtime |
’ Calculate new vertical speed based on g vSpeed = vSpeed - ((timediff / 1000) * 10) |
If GetAsyncKeyState(VK_DOWN) <> 0 Then If Fuel > 0 Then ’ Apply thrust: 15 is the acceleration produced vSpeed = vSpeed + ((timediff / 1000) * 15) Fuel = Fuel - ((timediff / 1000) * 150) ’ Check that fuel does not go below 0 If Fuel < 0 Then Fuel = 0 Else Beep End If End If |
LandY = LandY - vSpeed ’ Update text boxes txtvspeed.Text = Format(vSpeed, "0.0") txtfuel.Text = Format(Fuel, "0.0") txtheight.Text = Format(picEarth.ScaleHeight _ - piclander.ScaleHeight - 30 - LandY, "0.0") ’ Update the ’last called time’ curtime = timenow |
’ If it has touched down... If LandY >= picEarth.ScaleHeight - 30 - piclander.ScaleHeight Then ’ Make sure that it is on the surface LandY = picEarth.ScaleHeight - 30 - piclander.ScaleHeight txtheight.Text = Format(picEarth.ScaleHeight - piclander.ScaleHeight - 30 - LandY, "0.0") ’ Stop the timer and disable the pause button... ’ the game is over! tmrgravity.Enabled = False ’ Figure out if it was a safe landing or not, ’ and paint the appropriate craft If vSpeed > -2 Then ’ If it was safe, then the craft remains intact BitBlt picEarth.hdc, 150, LandY, piclander.ScaleWidth, piclander.ScaleHeight, piclander.hdc, 0, 0, vbSrcInvert MsgBox "Congratulations! You have landed successfully!" Else ’ If it was moving too fast, it blows up! BitBlt picEarth.hdc, 150, LandY, piclander.ScaleWidth, piclander.ScaleHeight, picsmash.hdc, 0, 0, vbSrcInvert MsgBox "Smash! Oooops!" End If Else ’ paint the craft into its new position. BitBlt picEarth.hdc, 150, LandY, piclander.ScaleWidth, _ piclander.ScaleHeight, piclander.hdc, 0, 0, vbSrcInvert End If |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者