注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

你想快速掌握安卓编程吗

 
 
 

日志

 
 

[例程]跳动的球体(Smiley模块)  

2015-08-19 14:47:53|  分类: B.游戏 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
'Class module
Sub Class_Globals
Private animator As SpriteAnimator
Private sensor As PhoneSensors
Private SIZE = 12%x As Float
Private mbd As BitmapData
Private JUMP_SPEED As Float = -4%y
Private bricks As List
Private gm As GameManager
End Sub

Public Sub Initialize (bd As BitmapData, vBricks As List, vGm As GameManager)
mbd = bd
gm = vGm
mbd.DestRect.Initialize(50%x, 85%y, 50%x + SIZE, 90%y + SIZE)
bricks = vBricks
animator.Initialize
Dim r As Rect
animator.SetFrames(bd, Array As Rect(r), Array As Bitmap(LoadBitmap(File.DirAssets, "smiley.gif")))
animator.width = SIZE
animator.height = SIZE
sensor.Initialize2(sensor.TYPE_ORIENTATION, 0)
animator.vy = JUMP_SPEED
End Sub

Private Sub Sensor_SensorChanged (Values() As Float)
animator.vx = -PerXToCurrent(Max(-30, Min(30, Values(2))) / 10)
End Sub

Public Sub Tick
animator.vy = animator.vy + 0.2%y
mbd.Rotate = mbd.Rotate + animator.vx / 1%x
animator.Tick(mbd)
If animator.vy > 0 Then 'check for collisions on the way bottom
For Each brck As Brick In bricks
If brck.bd.DestRect.Left < mbd.DestRect.CenterX AND brck.bd.DestRect.Right > mbd.DestRect.CenterX Then
If mbd.DestRect.Bottom < brck.bd.DestRect.Top AND mbd.DestRect.Bottom + animator.vy + 0.2%y > brck.bd.DestRect.Top Then
'adjust the speed so the smiley will touch the brick on the next tick.
animator.vy = brck.bd.DestRect.Top - mbd.DestRect.Bottom - 0.2%y
Else If mbd.DestRect.Bottom = brck.bd.DestRect.Top Then
animator.vy = JUMP_SPEED
gm.PlaySound(gm.BOUNCE_SOUND, 1)
If brck.disappearing Then
brck.Shrink
End If
Exit
End If
End If
Next
End If
If animator.vy < 0 AND mbd.DestRect.Top < 40%y Then
'scroll the background
gm.ScrollDown(-animator.vy / 1.5)
mbd.DestRect.Top = mbd.DestRect.Top - animator.vy / 2
mbd.DestRect.Bottom = mbd.DestRect.Bottom - animator.vy / 2
End If
'instead of ending the game we bounce the smiley
If mbd.DestRect.Bottom >= 100%y Then animator.vy = JUMP_SPEED
End Sub

Public Sub StartSensor
sensor.StartListening("Sensor")
End Sub

Public Sub StopSensor
sensor.StopListening
End Sub
  评论这张
 
阅读(58)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017