vb大神救命啊,要用VB做弹球游戏!!球死都不会动啊
Dimx_stepAsIntegerDimy_stepAsIntegerDimgametimeAsIntegerPrivateSubCommand1_Click()IfC...
Dim x_step As IntegerDim y_step As IntegerDim gametime As IntegerPrivate Sub Command1_Click()If Command1.Caption = "开始" ThenTimer1.Enabled = TrueTimer2.Enabled = TrueCommand1.Caption = "暂停"Exit SubEnd IfIf Command1.Caption = "暂停" ThenTimer1.Enabled = FalseTimer2.Enabled = FalseCommand1.Caption = "开始"End If
End Sub
Private Sub Command2_Click()EndEnd Sub
Private Sub Form_Load()x_step = 200y_step = 200End SubPrivate Sub PicGameWindow_KeyDown(KeyCode As Integer, Shift As Integer)If KeyCode = 37 ThenIf Plate.X1 < 0 ThenPlate.X1 = 0: Plate.X2 = 2000ElsePlate.X1 = Plate.X1 - 100: Plate.X2 = Plate.X2 - 100End IfEnd If
If KeyCode = 39 ThenIf Plate.X1 > PicGameWindow.Width ThenPlate.X1 = PicGameWindow.Width - 2000: Plate.X2 = PicGameWindow.WidthElsePlate.X1 = Plate.X1 + 100: Plate.X2 = Plate.X2 + 100End IfEnd If
End Sub
Private Sub Timer1_Timer()If Ball.Top < 0 ThenBall.Top = 0: y_step = -y_stepEnd If
If Ball.Left < 0 ThenBall.Left = 0: x_step = -x_stepEnd If
If Ball.Left > PicGameWindow.Width - Ball.Width ThenBall.Left = PicGameWindow.Width - Ball.Widthx_step = -x_stepEnd If
If Ball.Left >= Plate.X1 And Ball.Left <= Plate.X2 And Ball.Top >= Plate.Y1 - Ball.Height ThenBall.Top = Plate.Y1 - Ball.Heighty_step = -y_step * 1.01x_step = -x_step * 1.01Label1.Caption = Label1.Caption + 1End If
Ball.Top = Ball.Top + y_stepBall.Left = Ball.Left + x_stepIf Ball.Top >= PicGameWindow.Height - Ball.Height ThenMsgBox "游戏结束"Command1.Caption = "开始"Timer1.Enabled = FalseBall.Top = 1000Label1.Caption = 0End If
End Sub
Private Sub Timer2_Timer()gametime = gametime + 1Label3.Caption = Str(gametime) + "秒"End Sub
Private Sub Timer3_Timer()Label5.Caption = TimeEnd Sub
label1是得分的空白部分,label3是开始时间的空白部分,label5是当前时间的空白部分
球不会动,时间不会显示,得分不会显示,就那个板会动,还会动的超出游戏界面,这个代码和百度出来的一样啊!!到底是哪里问题!!是有什么空间的属性要改么!!还是我属性设置错了!!!求助啊!!! 展开
End Sub
Private Sub Command2_Click()EndEnd Sub
Private Sub Form_Load()x_step = 200y_step = 200End SubPrivate Sub PicGameWindow_KeyDown(KeyCode As Integer, Shift As Integer)If KeyCode = 37 ThenIf Plate.X1 < 0 ThenPlate.X1 = 0: Plate.X2 = 2000ElsePlate.X1 = Plate.X1 - 100: Plate.X2 = Plate.X2 - 100End IfEnd If
If KeyCode = 39 ThenIf Plate.X1 > PicGameWindow.Width ThenPlate.X1 = PicGameWindow.Width - 2000: Plate.X2 = PicGameWindow.WidthElsePlate.X1 = Plate.X1 + 100: Plate.X2 = Plate.X2 + 100End IfEnd If
End Sub
Private Sub Timer1_Timer()If Ball.Top < 0 ThenBall.Top = 0: y_step = -y_stepEnd If
If Ball.Left < 0 ThenBall.Left = 0: x_step = -x_stepEnd If
If Ball.Left > PicGameWindow.Width - Ball.Width ThenBall.Left = PicGameWindow.Width - Ball.Widthx_step = -x_stepEnd If
If Ball.Left >= Plate.X1 And Ball.Left <= Plate.X2 And Ball.Top >= Plate.Y1 - Ball.Height ThenBall.Top = Plate.Y1 - Ball.Heighty_step = -y_step * 1.01x_step = -x_step * 1.01Label1.Caption = Label1.Caption + 1End If
Ball.Top = Ball.Top + y_stepBall.Left = Ball.Left + x_stepIf Ball.Top >= PicGameWindow.Height - Ball.Height ThenMsgBox "游戏结束"Command1.Caption = "开始"Timer1.Enabled = FalseBall.Top = 1000Label1.Caption = 0End If
End Sub
Private Sub Timer2_Timer()gametime = gametime + 1Label3.Caption = Str(gametime) + "秒"End Sub
Private Sub Timer3_Timer()Label5.Caption = TimeEnd Sub
label1是得分的空白部分,label3是开始时间的空白部分,label5是当前时间的空白部分
球不会动,时间不会显示,得分不会显示,就那个板会动,还会动的超出游戏界面,这个代码和百度出来的一样啊!!到底是哪里问题!!是有什么空间的属性要改么!!还是我属性设置错了!!!求助啊!!! 展开
展开全部
你三个Timer的Interval属性没有设置,其中Timer1是用亮岩凳来控敬旅制小球的移动速度的,Interval属性建议在20到100(单位毫秒)间调整;Timer2是显枣迅示游戏时间的,Interval设为1000(即1秒);Timer3是显示当前时间的,Interval也是1000
追问
x_step和y_step是什么意思呢。我好多是百度的都看不懂
追答
x_step是小球每次移动时向左右移动的距离(单位是缇),如果它是正数,则向右移动,如果是负数,则向左移动;
同理,y_step是小球每次移动时向上下移动的距离,如果它是正数,则向下移动,如果是负数,则向上移动;
x_step与y_step结合,则可控制小球向左上、左下、右上、右下进行斜向运动了。
展开全部
会,时钟没有设置Interval属性吧。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询