从右到左和正弦曲线移动的代码

来源:百度知道 编辑:UC知道 时间:2024/05/28 00:01:20
这是我昨天问的问题. 也许会让你们更容易理解.

http://zhidao.baidu.com/question/94661979.html

我按照正确答案改完了. 运行完美的. 从左到右我会. 但是我就不知道怎样让图片从右到左来回移动. 正弦曲线(就是/\/\/\这样的移动)我也不会. 斜着来回移动我会的.

先请看我的代码和截图(点开图片).

Dim MoveFishx As Integer
Dim step As Integer

MoveFishx = 10
For step = 1 To 2000

'小黄鱼的移动(斜着来回)
If (Fishy.Left) >= (Form1.Width - Fishy.Width) Or (Fishy.Top) >= (Form1.Height - Fishy.Height) Then
MoveFishx = -10
ElseIf (Fishy.Left <= 0) Or (Fishy.Top <= 0) Then
MoveFishx = 10
Timer1.Enabled = False

End If
Fishy.Left = Fishy.Left + MoveFishx
Fishy.Top = Fishy.Top + MoveFishx

'螃蟹的移动(从左到右)
If (Crab.Left) >= (Form1.Width - Crab.Width) Then
MoveFishx = -15
ElseIf (Crab.Left <= 0) Then
MoveFishx

啊哦,这么久,还没人回答,那我抛砖引玉,给点思路方法:
一、Shark从右到左来回移动
很简单,其实你已会了,就是到窗体左右边界时,改变Left属性的增量的正负就搞定。
二、还有Dophin从上往下正弦曲线移动, 小黄鱼从下往上正弦曲线移动
这其实就是你说的/\/\/\路线吧,用sin函数就能搞定。
给你个左右移动正弦的小例子(振幅就是S路线的上下幅度):
Fishy.Left = Fishy.Left + MoveFishx
Fishy.Top = Fishy.Top + Int(Sin((i / (2 * 振幅)) * 3.1415926) * MoveFishx)

有不明白的,可以百度HI我。

/\/\/\这样的移动是由上下移动和左右移动复合起来的

'代码直接复制,加timer1控件,以form1为例
Dim sType As Boolean
Dim lType As Boolean

Private Sub Form_Load()
Timer1.Interval = 10
End Sub

Private Sub Timer1_Timer()
If sType = False Then
Form1.Top = Form1.Top + 80
Else
Form1.Top = Form1.Top - 80
End If
If Form1.Top > 5000 Then sType = True
If Form1.Top < 1000 Then sType = False

If lType = False Then
Form1.Left = Form1.Left + 100
Else
Form1.Left = Form1.Left - 100
End If
If Form1.Left > 20000 Then lType = Tr