一、vb 聲音代碼 除了beep還有別的么?我寫了一個射擊游戲的程序,想要一個特別的聲音。不要api,簡單的。
VB 內置聲音就只有Beep() .建議你用API 吧,畢竟游戲程序是不能缺少真實的聲音的(至少用戶會覺得你很用心去設計它)..
二、額~~嘿 VB 不懂的地方
。。。。恢復到初始狀態得看你的“初始狀態”是怎樣
btnStart.enabled=true 是讓那個按鈕可以被用戶按下
如果用戶按下這個按鈕就可以了,那么這樣
btnStart_click
應該就是了
三、求VB設計的小游戲 代碼
打地鼠好做一點:
窗體上放上背景圖,控件放二個Label,一個顯示分數及升級分數,另一個顯示時間;一個Image顯示地鼠圖形(要透明背景);一個Timer控制時間顯示;另外將窗體的鼠標設置為錘子。
在Image的單擊事件中分值增加就好了。
四、vb 打冰雹游戲
'新建窗體,添加picture1,timer1,label1,option1(0-3)
’以下保存在模塊module1.bas中:
public type stdball
ox as integer
oy as integer
ballcolor as colorconstants
speed as integer
end type
public type stdspark
posx as integer
posy as integer
angle as integer
sparkcolor as colorconstants
speed as integer
size as integer
end type
public type stdsparks
ox as integer
oy as integer
spark(9) as stdspark
end type
'以下保存在窗體代碼中:
dim ball(9) as stdball, sparks(9) as stdsparks, x0 as single, y0 as single
const pi = 3.14159265
private sub form_load()
initialgame 2, 1
end sub
private sub picture1_mousedown(button as integer, shift as integer, x as single, y as single)
for i = 0 to 9
if (x - ball(i).ox) ^ 2 + (y - ball(i).oy) ^ 2 < 400 then
initialspark i
initialball i
label1.tag = split(label1.tag, *)(0) + 1 & * & split(label1.tag, *)(1)
label1.caption = 分數: & split(label1.tag, *)(0) & vbcrlf & 能量: & split(label1.tag, *)(1)
if split(label1.tag, *)(0) = 25 then msgbox 好樣的,繼續努力!
if split(label1.tag, *)(0) = 50 then msgbox 太棒了,再射中50個你就過關了,努力啊!
if split(label1.tag, *)(0) = 100 then
msgbox 恭喜你過關了,增加難度,再繼續!
initialgame 3, 0
end if
if split(label1.tag, *)(0) = 150 then initialgame 4, 0
exit sub
end if
next
if split(label1.tag, *)(0) > 0 then label1.tag = split(label1.tag, *)(0) - 1 & * & split(label1.tag, *)(1)
label1.caption = 分數: & split(label1.tag, *)(0) & vbcrlf & 能量: & split(label1.tag, *)(1)
end sub
private sub picture1_mousemove(button as integer, shift as integer, x as single, y as single)
x0 = x: y0 = y
end sub
private sub option1_click(index as integer)
initialgame index + 1, 0
end sub
private sub timer1_timer()
picture1.backcolor = picture1.backcolor
for i = 0 to 9
drawball i
drawspark i
next
end sub
sub initialball(byval index as integer) '初始化圓球
dim awx() as integer, n as integer '將游戲窗口picture1沿x軸等分15段(每段50),10個球隨機占用這15段,為保證每一段內只有一個球,awx()用來存儲未被占用的斷的中點x(圓球球心)坐標
for x = 0 to 14 '計算存儲未被占用的段
for i = 0 to 9
if ball(i).ox = x * 50 + 25 then exit for
next
if i = 10 then
redim preserve awx(n)
awx(n) = x * 50 + 25
n = n + 1
end if
next
ball(index).ox = awx(int(rnd * n)) '隨機選擇未被占用的段
ball(index).oy = int(rnd * (-100))
ball(index).speed = int(rnd * me.tag + 1) '下落速度
ball(index).ballcolor = qbcolor(int(rnd * 15)) '顏色
end sub
sub initialspark(byval index as integer) '初始化火花
sparks(index).ox = ball(index).ox '爆炸圓心
sparks(index).oy = ball(index).oy
for i = 0 to 9
sparks(index).spark(i).posx = ball(index).ox '火花位置
sparks(index).spark(i).posy = ball(index).oy
sparks(index).spark(i).angle = int(rnd * 361) * pi / 180 '角度
sparks(index).spark(i).sparkcolor = ball(index).ballcolor '顏色
sparks(index).spark(i).speed = int(rnd * 15 + 10) '速度
sparks(index).spark(i).size = int(rnd * 12 + 5) '大小
next
end sub
sub drawball(byval index as integer) '畫圓球
picture1.fillstyle = 0 '實體填充
picture1.fillcolor = ball(index).ballcolor '填充顏色
picture1.drawwidth = 1 '線寬1
ball(index).oy = ball(index).oy + ball(index).speed '計算圓球y軸位置
picture1.circle (ball(index).ox, ball(index).oy), 20, vbwhite
picture1.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, vbwhite
picture1.drawwidth = 4
picture1.circle (ball(index).ox, ball(index).oy), 15, vbwhite, (2175 + ball(index).oy) * pi / 1450, ball(index).oy * pi / 1450 'pi * 3 / 2, 2 * pi
if (x0 - ball(index).ox) ^ 2 + (y0 - ball(index).oy) ^ 2 < 400 then '計算被瞄準的圓球
picture1.drawwidth = 1
picture1.fillcolor = vbred
picture1.circle (ball(index).ox, ball(index).oy), 3, vbwhite
picture1.fillstyle = 1 '透明填充
picture1.circle (ball(index).ox, ball(index).oy), 30, vbred
picture1.line (ball(index).ox - 30, ball(index).oy)-(ball(index).ox + 30, ball(index).oy), vbred
picture1.line (ball(index).ox, ball(index).oy - 30)-(ball(index).ox, ball(index).oy + 30), vbred
end if
if ball(index).oy - 25 > picture1.scaleheight then '判斷落地
initialball index
if split(label1.tag, *)(1) > 1 then '能量減1
label1.tag = split(label1.tag, *)(0) & * & split(label1.tag, *)(1) - 1
label1.caption = 分數: & split(label1.tag, *)(0) & vbcrlf & 能量: & split(label1.tag, *)(1)
else
label1.caption = 分數: & split(label1.tag, *)(0) & vbcrlf & 能量:0
msgbox 你失敗了,別灰心,降低難度,請重來!
initialgame iif(me.tag > 1, me.tag - 1, 1), 1
end if
end if
end sub
sub drawspark(byval index as integer) '畫火花
if sparks(index).ox <> 0 and sparks(index).oy <> 0 then
isout = 1
for i = 0 to 9
if abs(sparks(index).spark(i).posx - sparks(index).ox) < 100 and abs(sparks(index).spark(i).posy - sparks(index).oy) < 50 then
isout = 0
sparks(index).spark(i).posx = sparks(index).spark(i).posx + sparks(index).spark(i).speed * 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).size
picture1.pset (sparks(index).spark(i).posx, sparks(index).spark(i).posy), sparks(index).spark(i).sparkcolor
end if
next
if isout = 1 then sparks(index).ox = 0: sparks(index).oy = 0
end if
end sub
sub initialgame(byval level as integer, byval isclear as integer) '初始化游戲
option1(0).caption = 簡單
option1(1).caption = 中等
option1(2).caption = 較難
option1(3).caption = 高級
option1(level - 1).value = true '設置單選框選中當前難度級別
timer1.interval = 20
me.scalemode = 3 '像素模式
picture1.scalemode = 3 '設置游戲窗口信息
picture1.autoredraw = true
picture1.width = 760
picture1.height = 500
if isclear = 1 then '清零積分和能量
label1.caption = 分數:0 & vbcrlf & 能量:5
label1.tag = 0*5
end if
me.tag = level '保存當前等級
for i = 0 to 9 '初始化球圓球信息
initialball i
next
end sub
