基于VB6.0射击游戏的实现急急!!!!!求救

基于VB6.0射击游戏的实现急急!!!!!求救,第1张

你是要源程序,还是要安装软件

角色击中标志

为了使程序中的仙人掌、游戏角色和射击时发射的子d可以移动,需要向项目中添加定时器tmrMouseCnt和Timer1,在这两个定时响应函数中完成不同对象的移动功能。在游戏运行后,为了使用户可以通过键盘和鼠标来 *** 作游戏的角色,实现射击的功能,需要添加鼠标消息和键盘消息处理函数。例如,对于角色1来说,可以通过上下键来移动,空格键来射击,对于角色2来说,鼠标左右键控制移动,双击实现射击。在射击过程中,要处理两个细节,一个细节是子d与仙人掌及角色的区域重叠问题,当子d与仙人掌重叠时让子d隐藏起来,与角色重叠时表示击中目标,游戏结束。这里需要判断何时两个区域有重叠,解决这个问题的方法是使用API函数IntersectRect,用它来判断两个区域是否有重叠。另一个细节是子d射击过程中需要添加"呼啸"的声音和击中目标时添加人物惨叫的声音,来达到逼真的效果,为了实现这个功能,需要向程序中添加语音文件(程序中的语音文件分别为:BANGWAV和OH!!WAV),然后通过API函数sndPlaySound来实现。另外,在对象移动的过程中,需要注意移动到边缘位置的情况处理。

程序的具体实现代码如下:

SHOOTOUTBAS

Option Explicit

' Data type required by the IntersectRect function

Type tRect

Left As Long

Top As Long

Right As Long

Bottom As Long

End Type

' Windows API rectangle functions

Declare Function IntersectRect Lib "user32" (lpDestRect As tRect, lpSrc1Rect As tRect, lpSrc2Rect As tRect) As Long

' Functions and constants used to play sounds

Declare Function sndPlaySound Lib "winmmdll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

' Constant used with sndPlaySound function

Global Const SND_ASYNC = &H1

'----------------------------------------------------------

' SHOOTOUTFRM

Option Explicit

' KeyCodes for keyboard action

Const KEY_SPACE = &H20

Const KEY_UP = &H26

Const KEY_DOWN = &H28

' Number of Twips to move player on each key or mouse event

Const PlayerIncrement = 45

' Constants for mouse action

Const NO_BUTTON = 0

Const LBUTTON = 1

Const RBUTTON = 2

' Boolean that indicates if mouse button has been pressed down

Dim MouseButtonDown As Integer

' Number of bullets either player can have in use at one time

Const NUM_BULLETS = 6

' Booleans indicating if player 0 or player 1 have just fired

Dim GunFired(0 To 1) As Integer

' Start the game by enabling the main timer and hiding the start button

Private Sub btnStart_Click()

Timer1Enabled = True

btnStartVisible = False

End Sub

' Check if the two Images intersect, using the IntersectRect API call

Private Function Collided(imgA As Image, imgB As Image) As Integer

Dim A As tRect

Dim B As tRect

Dim ResultRect As tRect

' Copy information into tRect structure

ALeft = imgALeft

ATop = imgATop

BLeft = imgBLeft

BTop = imgBTop

' Calculate the right and bottoms of rectangles needed by the API call

ARight = ALeft + imgAWidth - 1

ABottom = ATop + imgAHeight - 1

BRight = BLeft + imgBWidth - 1

BBottom = BTop + imgBHeight - 1

' IntersectRect will only return 0 (false) if the

' two rectangles do NOT intersect

Collided = IntersectRect(ResultRect, A, B)

End Function

' Double-clicking the mouse fires Player 1's gun

Private Sub Form_DblClick()

Dim rc As Integer

If Not Timer1Enabled Then Exit Sub

GunFired(1) = True

rc = sndPlaySound(AppPath & "\BANGWAV", SND_ASYNC)

End Sub

' This event handles Player 0's game action via the keyboard

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Dim rc As Integer

Static InKeyDown As Integer

If Not Timer1Enabled Then Exit Sub

If InKeyDown Then Exit Sub

InKeyDown = True

DoEvents

Select Case KeyCode

Case KEY_UP

imgPlayer(0)Top = imgPlayer(0)Top - PlayerIncrement

If imgPlayer(0)Top < 0 Then imgPlayer(0)Top = 0

Case KEY_SPACE

GunFired(0) = True

rc = sndPlaySound(AppPath & "\BANGWAV", SND_ASYNC)

Case KEY_DOWN

imgPlayer(0)Top = imgPlayer(0)Top + PlayerIncrement

If imgPlayer(0)Top > (picDesertScaleHeight -

imgPlayer(0)Height) Then

imgPlayer(0)Top = picDesertScaleHeight -

imgPlayer(0)Height

End If

End Select

InKeyDown = False

End Sub

Private Sub Form_Load()

Dim i As Integer

Timer1Interval = 22

Timer1Enabled = False

MouseButtonDown = NO_BUTTON

For i = 1 To NUM_BULLETS - 1

Load imgLBullet(i)

Load imgRBullet(i)

Next

End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

MouseButtonDown = Button

End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

MouseButtonDown = NO_BUTTON

End Sub

' The main game timer

Private Sub Timer1_Timer()

Const CactusIncrement = 30

Const BulletIncrement = 300

Const NumCacti = 2

Dim i As Integer

Dim rc As Integer

' Move the roving cacti

For i = 0 To NumCacti - 1

imgCactus(i)Top = imgCactus(i)Top - CactusIncrement

If imgCactus(i)Top < -imgCactus(i)Height Then

imgCactus(i)Top = picDesertHeight

End If

Next

' Did player 0 fire a bullet

If GunFired(0) Then

GunFired(0) = False

' Find a spare (invisible) bullet

For i = 0 To NUM_BULLETS - 1

If Not imgLBullet(i)Visible Then

imgLBullet(i)Top = imgPlayer(0)Top

imgLBullet(i)Left = imgPlayer(0)Left +

(imgPlayer(0)Width / 2)

imgLBullet(i)Visible = True

Exit For

End If

Next

End If

' Did player 1 fire a bullet

If GunFired(1) Then

GunFired(1) = False

' Find a spare (invisible) bullet

For i = 0 To NUM_BULLETS - 1

If Not imgRBullet(i)Visible Then

imgRBullet(i)Top = imgPlayer(1)Top

imgRBullet(i)Left = imgPlayer(1)Left -

(imgPlayer(1)Width / 2)

imgRBullet(i)Visible = True

Exit For

End If

Next

End If

' Move Visible Bullets

For i = 0 To NUM_BULLETS - 1

' Move player 0's bullets

If imgLBullet(i)Visible Then

imgLBullet(i)Left = imgLBullet(i)Left + BulletIncrement

If Collided(imgLBullet(i), imgCactus(0)) Then

imgLBullet(i)Visible = False

ElseIf Collided(imgLBullet(i), imgCactus(1)) Then

imgLBullet(i)Visible = False

ElseIf imgLBullet(i)Left > picDesertScaleWidth Then

imgLBullet(i)Visible = False

ElseIf Collided(imgLBullet(i), imgPlayer(1)) Then

imgLBullet(i)Visible = False

imgPlayer(1)Picture = imgRIPPicture

Timer1Enabled = False

rc = sndPlaySound(AppPath & "\OH!!WAV", SND_ASYNC)

End If

End If

' Move player 1's bullets

If imgRBullet(i)Visible Then

imgRBullet(i)Left = imgRBullet(i)Left - BulletIncrement

If Collided(imgRBullet(i), imgCactus(0)) Then

imgRBullet(i)Visible = False

ElseIf Collided(imgRBullet(i), imgCactus(1)) Then

imgRBullet(i)Visible = False

ElseIf imgRBullet(i)Left < -imgRBullet(i)Width Then

imgRBullet(i)Visible = False

ElseIf Collided(imgRBullet(i), imgPlayer(0)) Then

imgRBullet(i)Visible = False

imgPlayer(0)Picture = imgRIPPicture

Timer1Enabled = False

rc = sndPlaySound(AppPath & "\OH!!WAV", SND_ASYNC)

End If

End If

Next

End Sub

' Handle Player 1's movement (up and down)

Private Sub tmrMouseCntl_Timer()

If Not Timer1Enabled Then Exit Sub

Select Case MouseButtonDown

Case RBUTTON

imgPlayer(1)Top = imgPlayer(1)Top - PlayerIncrement

If imgPlayer(1)Top < 0 Then imgPlayer(1)Top = 0

Case LBUTTON

imgPlayer(1)Top = imgPlayer(1)Top + PlayerIncrement

If imgPlayer(1)Top > (picDesertScaleHeight -

imgPlayer(1)Height) Then

imgPlayer(1)Top = picDesertScaleHeight -

imgPlayer(1)Height

End If

End Select

End Sub

我有EXCEL上发射炮d的VBA码,我自主编写,可以看到炮d轨迹,爆炸声和象图(自己先准备文件),复原,再发,适用小孩玩。

Sub d射轨迹时间函数()

'采用时间值循环,语句变得更少。

For t = 01 To 30

SelectionShapeRangeIncrementLeft 20

h = 20 - 98 t t / 200

SelectionShapeRangeIncrementTop -h

ApplicationWait Now() + TimeValue("00:00:1") '系统暂停1秒;

Next t

…… ’在这里插入声象效果。

End sub

'以下可以插入声象效果和状态复原,方便下一次运行。

ActiveSheetShapes("Picture 19")Select

SelectionShapeRangeIncrementTop -280# '爆炸,小图。

ApplicationWait Now() + TimeValue("00:00:1") '系统暂停1秒;

ActiveSheetShapes("Object 9")Select

SelectionVerb Verb:=xlPrimary '出现炮声。

ApplicationWait Now() + TimeValue("00:00:2") '系统暂停2秒;

ActiveSheetShapes("Picture 15")Select

SelectionShapeRangeIncrementTop -280# ''爆炸,依次扩大。

ApplicationWait Now() + TimeValue("00:00:3") '系统暂停1秒;

ActiveSheetShapes("Picture 15")Select

SelectionShapeRangeIncrementTop 280# '撤消爆炸痕迹,图象复位。

ActiveSheetShapes("Picture 19")Select

SelectionShapeRangeIncrementTop 280#

ActiveSheetShapes("Picture 6")Select '炮d复位

SelectionShapeRangeIncrementLeft -60825

SelectionShapeRangeIncrementTop 177#

End Sub

 射击类游戏(一)

第二部分开始类的编写:

1、首先打开Flash CS4 (CS3、CS4或CS5没什么大的区别)新建项目,按确定。打开项目面板。图:新建项目

2、点击右边的第一个三角按钮(项目),在下拉菜单中选"新建项目"。在d出新建项目面板项目名称:填入项目名称。在根文件夹:项中点击右边的浏览按钮,浏览到准备存放项目的目录,按确定。在ActionScript版本:选ActionScript 30 。单击"创建项目"按钮,这样项目就建好了。图:项目面板

3、把AirRaidfla文件复制到项目文件夹下(省去制作界面)。点击下面的"创建类"图标,在d出的创建类面板类:的文本框中填入文件名:AirRaid 单击创建类按钮。这样类就创建好了并为我们写好了类的框架,我们可以在框架中添加我们的代码了。图:创建类

图:填入类名

图:类的框架

4、编写AirRaidas类

AirRaidas类:文档类 AirRaid类是游戏的控制器,绑定AirRaidfla 。负责生成界面上的飞机、火炮、子d。显示得分,子d的剩余数量。注册了键盘按下,释放侦听器,接收用户的键盘 *** 作。注册了进入帧事件侦听器,进行碰撞检测。定义一个飞机计时器,随机生成飞机。检测剩余子d的数目,当子d数为零时也就是主角死亡了,移除界面上的飞机,火炮,跳转到重玩按钮。

package {

public class AirRaid extends MovieClip {

private var aagun:AAGun;//火炮

private var airplanes:Array;//飞机数组

private var bullets:Array;//子d数组

public var leftArrow, rightArrow:Boolean;

private var nextPlane:Timer;//不定时生成飞机的计时器

private var shotsLeft:int;//得分文本

private var shotsHit:int;//子d数文本

// 初始化得分数和子d数

// 生成炮加入到舞台上

// 生成飞机、子d数组

// 键盘按下、释放事件侦听器

stageaddEventListener(KeyboardEventKEY_DOWN,keyDownFunction);

// 进入帧事件侦听器,检测子d击中飞机的碰撞检测。

addEventListener(EventENTER_FRAME,checkForHits);

// 生成下一架飞机

setNextPlane();

}

//不定时生成飞机

public function setNextPlane() {

//1000毫秒至2000毫秒之间生成一架飞机

nextPlanestart();

}

public function newPlane(event:TimerEvent) {

// 随机的边、速度和高度

// 生成飞机

var p:Airplane = new Airplane(side,speed,altitude);

// 碰撞检测

}

}

if ((shotsLeft == 0) && (bulletslength == 0)) {

endGame();

}

}

// 按下键盘

public function keyDownFunction(event:KeyboardEvent) {

if (eventkeyCode == 37) {

leftArrow = true;

} else if (eventkeyCode == 39) {

rightArrow = true;

} else if (eventkeyCode == 32) {

fireBullet();

}

}

// 释放键盘

public function keyUpFunction(event:KeyboardEvent) {

if (eventkeyCode == 37) {

leftArrow = false;

} else if (eventkeyCode == 39) {

rightArrow = false;

}

}

// 生成新的子d

public function fireBullet() {

if (shotsLeft <= 0) return;

var b:Bullet = new Bullet(aagunx,aaguny,-300);

addChild(b);

bulletspush(b);

shotsLeft--;

showGameScore();

}

public function showGameScore() {

showScoretext = String("得分: "+shotsHit);

showShotstext = String("剩余子d: "+shotsLeft);

}

// 从数组获取飞机

public function removePlane(plane:Airplane) {

for(var i in airplanes) {

if (airplanes[i] == plane) {

airplanessplice(i,1);

break;

}

}

}

// 获取数组的一个子d

public function removeBullet(bullet:Bullet) {

for(var i in bullets) {

if (bullets[i] == bullet) {

bulletssplice(i,1);

break;

}

}

}

// 游戏结束,移除界面上的东西。

public function endGame() {

// 移除飞机

for(var i:int=airplaneslength-1;i>=0;i--) {

airplanes[i]deletePlane();

}

airplanes = null;

aagundeleteGun();

aagun = null;

// 移除侦听器

stageremoveEventListener(KeyboardEventKEY_DOWN,keyDownFunction);

stageremoveEventListener(KeyboardEventKEY_UP,keyUpFunction);

removeEventListener(EventENTER_FRAME,checkForHits);

nextPlanestop();

nextPlane = null;

gotoAndStop("gameover");

}

}

}

5、编写AAGunas类

创建类的方法同第3步。首先选中库中的AAGun元件,打开项目面板创建类。在"将类邦定到库元件"前面打勾,点下"使用所选库元件"的单选按钮。图:邦定库元件

AAGun类:邦定库中的炮元件,向左移动向右移动,检测边界,自动消毁。

package {

import flashdisplay;

import flashevents;

import flashutilsgetTimer;

public class AAGun extends MovieClip {

static const speed:Number = 1500;

private var lastTime:int; // 控制移动的Timer

public function AAGun() {

// q的初始位置

thisx = 275;

thisy = 340;

//运动

addEventListener(EventENTER_FRAME,moveGun);

}

public function moveGun(event:Event) {

// 得到时差

var timePassed:int = getTimer() - lastTime;

lastTime += timePassed;

// 现在的位置

var newx = thisx;

// 移动到左边

if (MovieClip(parent)leftArrow) {

newx -= speedtimePassed / 1000;

}

// 移动到右边

if (MovieClip(parent)rightArrow) {

newx += speedtimePassed / 1000;

}

// 检测边界

if (newx < 10) newx = 10;

if (newx > 540) newx = 540;

// 更新位置

thisx = newx;

}

// 移除屏幕上的炮和事件

public function deleteGun() {

parentremoveChild(this);

removeEventListener(EventENTER_FRAME,moveGun);

}

}

}

新建文件Airplaneas

Airplane类:邦定库中的飞机元件。随机产生飞机,随机的速度,产生5种飞机样式,检测是否飞出边界,检测被子d击中。自动毁灭和爆炸效果。

// 飞机的速度、方向

// 控制移动的Timer

//左右移动

//检测边界

// 检测碰撞,子d击中飞机跳转到帧标签"explode"演示爆炸动画。

// 移除舞台上的飞机和事件

新建文件Bulletas

Bullet类:邦定库中的子d元件。控制子d的飞行方向,检测子d是否飞出屏幕。

package {

import flashdisplayMovieClip;

import flasheventsEvent;

import flashutilsgetTimer;

import flashutilsTimer;

import flasheventsTimerEvent;

public class Bullet extends MovieClip {

private var dy:Number; // 子d的速度、方向。

private var lastTime:int;

public function Bullet(x,y:Number, speed: Number) {

// 初始位置

thisx = x;

thisy = y;

// 得到速度

dy = speed;

// 动画

lastTime = getTimer();

addEventListener(EventENTER_FRAME,moveBullet);

public function moveBullet(event:Event) {

// 得到时差

var timePassed:int = getTimer()-lastTime;

lastTime += timePassed;

// 子d运动

thisy += dytimePassed/1000;

// 子d越过屏幕的顶端

if (thisy < 0) {

deleteBullet();

// 移除舞台的子d和事件

public function deleteBullet() {

MovieClip(parent)removeBullet(this);

parentremoveChild(this);

removeEventListener(EventENTER_FRAME,moveBullet);

所有的类文件完成保存后,回到AirRaidfla场景,按Ctrl+Enter组合键测试,看看你的成果吧!

简单的学个Flash,很好学,还可以做动画,很有用。大型游戏要学VB或者C++,编得游戏画质不行。3DMAX是做特效的,你想做个游戏,不是一两年搞得了的,有专门教这个的班。

我是玩CF的~高手说不上~但如果你单挑对q我还是有信心的~基本你如果玩的是M4的就两颗子d

点射~AK就不要了~AK只能以抢一q的打~因为后座力很大~

打的时候人体左右移动~q头对准的头~点他就可以了~最好就是压下q~这样的准确度会高点~

我自己做的

Dim x11 As Double

Dim x22 As Double

Dim y11 As Double

Dim y22 As Double

Dim m As Boolean

Dim j As Integer

Dim l As Integer

Private Sub Command1_Click()

Timer1Interval = 100

Command1Visible = False

End Sub

Private Sub Form_Load()

MsgBox "在窗体里点击左键不放来改变射击方向,释放左键后射击"

End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

Dim temp As Double

If Line1X1 < Line1X2 Then

Line1Y1 = Line1Y2 - Line1X2 (Line1Y2 - Line1Y1) / (Line1X2 - Line1X1)

Line1X1 = 0

For i = 0 To 6

temp = Line1X2 - (Line1X2 - Line1X1) (Line1Y2 - Shape1(i)Top) / (Line1Y2 - Line1Y1)

If temp >= Shape1(i)Left And temp <= Shape1(i)Left + Shape1(i)Width Then

m = True

j = i

l = Shape1(i)Left

MeCaption = Split(MeCaption, "分")(0) + 1 & "分"

Exit For

End If

Next

Timer2Interval = 500

Else

Line1Y1 = Line1Y2 - (Form1Width - Line1X2) (Line1Y2 - Line1Y1) / (Line1X1 - Line1X2)

Line1X1 = Form1Width

For i = 0 To 6

temp = Line1X2 + (Line1X1 - Line1X2) (Line1Y2 - Shape1(i)Top) / (Line1Y2 - Line1Y1)

If temp >= Shape1(i)Left And temp <= Shape1(i)Left + Shape1(i)Width Then

m = True

j = i

l = Shape1(i)Left

MeCaption = Split(MeCaption, "分")(0) + 1 & "分"

Exit For

End If

Next

Timer2Interval = 500

End If

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button = 1 Then

Line1X1 = X

x11 = Line1X1

x22 = Line1X2

y11 = Line1Y1

y22 = Line1Y2

End If

End Sub

Private Sub Timer1_Timer()

Shape1(0)Left = IIf(Shape1(0)Left >= Form1Width, 0, Shape1(0)Left + 100)

Shape1(1)Left = IIf(Shape1(1)Left >= Form1Width, 0, Shape1(1)Left + 150)

Shape1(2)Left = IIf(Shape1(2)Left >= Form1Width, 0, Shape1(2)Left + 200)

Shape1(3)Left = IIf(Shape1(3)Left >= Form1Width, 0, Shape1(3)Left + 160)

Shape1(4)Left = IIf(Shape1(4)Left >= Form1Width, 0, Shape1(4)Left + 90)

Shape1(5)Left = IIf(Shape1(5)Left >= Form1Width, 0, Shape1(5)Left + 210)

Shape1(6)Left = IIf(Shape1(6)Left >= Form1Width, 0, Shape1(6)Left + 260)

End Sub

Private Sub Timer2_Timer()

Line1X1 = 4080

Line1X2 = 4080

Line1Y1 = 3960

Line1Y2 = 4680

Timer2Interval = 0

End Sub

Private Sub Timer3_Timer()

If m = True Then Shape1(j)Top = Shape1(j)Top + 100: Shape1(j)Left = l

If Shape1(j)Top > Form1Height + 200 Then m = False

End Sub

以上就是关于基于VB6.0射击游戏的实现急急!!!!!求救全部的内容,包括:基于VB6.0射击游戏的实现急急!!!!!求救、跪求基于VB程序设计的射击类游戏!!要源代码!!最好是自己做的!!悬赏50分,给答案最好的那个啊!!、如何制作简单的射击类(比CS还要简单的)游戏等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/10125552.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存