vb打磚塊游戲代碼_第1頁
vb打磚塊游戲代碼_第2頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、1/ 10 新建窗體,添加 picture1,timer1,label1,option1(0-3)以下保存在模塊 module1.bas 中:Public Type stdball ox As Integer oy As Integer ballcolor As ColorConstantsspeed As IntegerEnd TypePublic Type stdspark posx As Integer posy As Integer angle As Integersparkcolor As ColorConstants speed As Integer size As Integer

2、End TypePublic Type stdsparks ox As Integer oy As Integer spark(9) As stdsparkEnd Type 以下保存在窗體代碼中 :Dim ball(9) As stdball, sparks(9) As stdsparks, x0 As Single, y0 As Single Const pi = 3.Private Sub Form_Load() initialgame 2, 1End SubPrivate Sub picture1_MouseDown(Button As Integer, Shift As Integer

3、, x AsSingle, y As Single)For i = 0 To 9If (x - ball(i).ox)八2 + (y - ball(i).oy)八2 0 Then Label1.Tag = Split(Label1.Tag, *)(0) - 1 &* & Split(Label1.Tag, *)(1) Label1.Caption = 分數(shù): & Split(Label1.Tag, *)(0) & vbCrLf & 能量: &Split(Label1.Tag, *)(1)End SubPrivate Sub picture1_Mo

4、useMove(Button As Integer, Shift As Integer, x AsSingle, y As Single)x0 = x:y0 = yEnd SubPrivate Sub Option1_Click(index As Integer)initialgame index + 1, 0End SubPrivate Sub Timer1_Timer()Picture1.BackColor = Picture1.BackColorFor i = 0 To 9 drawball i drawspark iNextEnd SubSub ini tialball(ByVal i

5、n dex As In teger)初始化圓球4/ 10Dim awx() As Integer, n As Integer 將游戲窗口 picturel 沿 x 軸等分 15 段(每段 50), 10 個球隨機占用這 15 段,為保證每一段內只有一個球,awx()用來存 儲未被占用的斷的中點 x(圓球球心)坐標For x = 0 To 14 計 算存儲未被占用的段For i = 0 To 9If ball(i).ox = x * 50 + 25 Then Exit For NextIf i = 10 ThenReDim Preserve awx(n) awx(n) = x * 50 + 25

6、 n = n + 1End IfNextball(i ndex).ox = awx(l nt(R nd * n)隨機選擇未被占用的段 ball(index).oy =Int(Rnd * (-100)ball(index).speed = lnt(Rnd * Me.Tag + 1)下 落速度ball(index).ballcolor =QBColor(lnt(Rnd * 15) 顏 色 End SubSub ini tialspark(ByVal in dex As In teger) 初 始 化 火 花sparks(index).ox =ball(index).ox 爆 炸圓心 sparks(

7、index).oy = ball(index).oyFor i = 0 To 9sparks(i ndex).spark(i).posx = ball(i ndex).ox 火花位置sparks(index).spark(i).posy = ball(index).oysparks(index).spark(i).angle = Int(Rnd * 361) * pi / 180 角 度sparks(i ndex).spark(i).sparkcolor = ball(i ndex).ballcolor 顏色5/ 10sparks(index).spark(i).speed = Int(Rnd

8、 * 15 + 10)速 度sparks(index).spark(i).size = Int(Rnd * 12 + 5)大 小NextEnd SubSub drawball(ByVal index As In teger)畫圓球Picture1.FillStyle = 0 實 體填充Picture1.FillColor = ball(index).ballcolor 填 充顏色Picture1.DrawWidth = 1 線寬 1ball(index).oy = ball(index).oy + ball(index).speed 計 算圓球 y 軸位置Picture1.Circle (ba

9、ll(index).ox, ball(index).oy), 20, vbWhitePicture1.FillColor = vbWhite 高光顏色Picture1.Circle (ball(index).ox + 15 * Cos(3625 - 2 * ball(index).oy) * pi /2900),ball(index).oy - 15 * Sin(3625 - 2 * ball(index).oy) * pi / 2900), 3,vbWhitePicture1.DrawWidth = 4Picture1.Circle (ball(index).ox, ball(index).

10、oy), 15, vbWhite, (2175+ball(index).oy) * pi / 1450, ball(index).oy * pi / 1450If (x0 - ball(i ndex).ox)八2 + (y0 - ball(i ndex).oy)八2 Picturel.ScaleHeight Ther 判斷落地initialball indexIf Split(Label1.Tag, *)(1) 1 Ther 能 量減 1Label1.Tag = Split(Label1.Tag, *)(0) & * & Split(Label1.Tag,*)(1) - 1La

11、bel1.Captior = 分數(shù): & Split(Label1.Tag, *)(0) & vbCrLf & 能量: & Split(Label1.Tag, *)(1)ElseLabel1.Captior = 分數(shù): & Split(Label1.Tag, *)(0) & vbCrLf & 能量: 0MsgBox 你失敗了,別灰心,降低難度,請重來!initialgame IIf(Me.Tag 1, Me.Tag - 1, 1), 1End If7/ 10End IfEnd SubSub drawspark(ByVal in dex A

12、s In teger)畫火花If sparks(index).ox 0 And sparks(index).oy 0 Thenisout = 1For i = 0 To 9If Abs(sparks(index).spark(i).posx - sparks(index).ox) 100 AndAbs(sparks(index).spark(i).posy - sparks(index).oy) 50 Thenisout = 0sparks(index).spark(i).posx = sparks(index).spark(i).posx+sparks(index).spark(i).spe

13、ed * Cos(sparks(index).spark(i).angle)sparks(index).spark(i).posy = sparks(index).spark(i).posy -sparks(index).spark(i).speed * Sin(sparks(index).spark(i).angle)Picture1.DrawWidth = sparks(index).spark(i).sizePicture1.PSet (sparks(index).spark(i).posx, sparks(index).spark(i).posy),sparks(index).spar

14、k(i).sparkcolor End IfNextIf isout = 1 Then sparks(index).ox = 0: sparks(index).oy = 0End If End SubSub in itialgame(ByVal level As In teger, ByVai isclear As In tege 初始化游戲Option1(0).Caption = 簡單Option1(1) .Caption = 中等8/ 10Option1(2) .Caption = 較難Option1(3) .Caption = 高級Option1(level - 1).Value = True 設 置單選框選中當前難度級別Timer1.Interval = 20Me.ScaleMode = 3像素模式Picture1.ScaleMode = 3 設 置游戲窗口信息Picture1

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論