我正在使用vb.net构建墙防游戏。到目前为止,我已经取得了相当多的成就,但我有一个主要问题和几个小问题,我可以使用一些帮助。
我的主要问题是这个问题,我的坏人应该在碰壁时对我的墙造成伤害。截至目前他们没有,我不确定为什么损坏不会从墙壁健康中减去。我把坏人和墙都设置为我创建的新类,是的我知道我没有使用我创建的所有属性,称为Character。
接下来我的小问题是这些。 A)当左右移动时,我的球员运动似乎变得模糊。 B)我不能让我的玩家一次发动多次攻击。一次只能在屏幕上有一枚导弹。当我添加更多导弹时,它会使所有移动减速到几乎完全停止。 C)我已经尝试让坏人尽可能靠近墙壁计算,但是当我将它们移动得比他们更接近时,游戏会锁定。
我在这里添加了所有代码,非常感谢任何想法或帮助!
Option Explicit On
Option Strict On
Option Infer Off
Public Class Form1
Public Class Character
Private _intHealth As Integer
Private _intDamage As Integer
Private _intSpeed As Integer
Private _blnRanged As Boolean
Public Property Health As Integer
Get
Return _intHealth
End Get
Set(value As Integer)
If value > 0 Then
_intHealth = value
Else
_intHealth = 0
End If
End Set
End Property
Public Property Damage As Integer
Get
Return _intDamage
End Get
Set(value As Integer)
If value > 0 Then
_intDamage = value
Else
_intDamage = 0
End If
End Set
End Property
Public Property Speed As Integer
Get
Return _intSpeed
End Get
Set(value As Integer)
If value > 0 Then
_intSpeed = value
Else
_intSpeed = 0
End If
End Set
End Property
Public Property Ranged As Boolean
Get
Return _blnRanged
End Get
Set(value As Boolean)
_blnRanged = value
End Set
End Property
Public Sub New()
_intHealth = 0
_intDamage = 0
_intSpeed = 0
_blnRanged = False
End Sub
Public Sub New(ByVal Health As Integer, Damage As Integer, Speed As Integer, Ranged As Boolean)
_intHealth = Health
_intDamage = Damage
_intSpeed = Speed
_blnRanged = Ranged
End Sub
End Class
Dim picTest(10) As PictureBox ' images for bad guys
Dim badTest(10) As Character ' values for bad guys
Dim goodWall As Character
Dim collision As Boolean ' to check for impact with good guy and bad guy (can be modified)
Dim newPos As Point ' used to move our good guy around with the arrow keys
Dim newShot As Point ' used to center the shot on the knights image
Dim pbxMissle As New PictureBox 'used for missle fired from good guy
Dim chrMissle As New Character ' missle attibutes
Dim intBadCount As Integer
Private Sub form1_keydown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If collision = False Then
Select Case e.KeyCode
Case Keys.Right
If pbxBow.Location.X < 1125 Then
newPos.Y = pbxBow.Location.Y
newPos.X = pbxBow.Location.X + 8
End If
Case Keys.Left
If pbxBow.Location.X > 4 Then
newPos.Y = pbxBow.Location.Y
newPos.X = pbxBow.Location.X - 8
End If
Case Keys.Space
newShot.Y = pbxBow.Location.Y
newShot.X = pbxBow.Location.X + 30
pbxMissle.Location = newShot
pbxMissle.Visible = True
chrMissle = New Character(0, 10, 10, False)
End Select
pbxBow.Location = newPos
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim intK As Integer = 10 ' it is a mess, but I am just setting things in the load event
Timer1.Enabled = False
For intJ As Integer = 0 To 10
picTest(intJ) = New PictureBox
picTest(intJ).Height = 128
picTest(intJ).Width = 75
picTest(intJ).Left = intK
picTest(intJ).Top = 25
picTest(intJ).Image = Project_2.My.Resources.Resources.knight3a
picTest(intJ).Visible = False
picTest(intJ).Enabled = True
pbxMissle.Height = 10
pbxMissle.Width = 5
pbxMissle.BackColor = Color.Black
pbxMissle.Location = pbxBow.Location
pbxMissle.Visible = False
Controls.Add(pbxMissle)
Controls.Add(picTest(intJ))
badTest(intJ) = New Character(10, 10, 1, False)
goodWall = New Character(100, 0, 0, False)
intK += 100
Next intJ
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Timer1.Interval = 500
' collision detection
If collision = False Then
intBadCount = 11 ' countdown for game over
If pbxMissle.Visible = True Then 'moves the missle before the check for collision
pbxMissle.Location = New Point(pbxMissle.Left, pbxMissle.Top - chrMissle.Speed)
End If
For intI As Integer = 0 To 10
If picTest(intI).Visible = True Then
If picTest(intI).Bounds.IntersectsWith(pbxWall.Bounds) Then ' checks for collision with knight and wall
goodWall.Health = goodWall.Health - badTest(intI).Damage
If goodWall.Health = 0 Then
pbxBow.Enabled = False
Timer1.Stop()
MessageBox.Show("Game Over", "Game Over", MessageBoxButtons.OK)
'Exit For
End If
ElseIf picTest(intI).Bounds.IntersectsWith(pbxMissle.Bounds) Then ' checks for collision with missle and bad guys
picTest(intI).Visible = False
pbxMissle.Visible = False
ElseIf picTest(intI).Bottom < pbxWall.Top - 45 Then ' moves bad guys based on speed if not at bottom
picTest(intI).Location = New Point(picTest(intI).Left, picTest(intI).Top + badTest(intI).Speed)
Else
picTest(intI).Location = New Point(picTest(intI).Left, 25) ' moves bad guy back to top
End If
End If
If picTest(intI).Visible = False Then ' if bad guy hit by missle visible set to false this counts how many have been hit
intBadCount -= 1
End If
If intBadCount = 0 Then 'check for remaining bad guys. 11 in the array if all are visible false then winner
Timer1.Stop()
MessageBox.Show("You Won!" & vbNewLine & "All enemies defeated!", "Game Over", MessageBoxButtons.OK)
End If
Next intI
End If
End Sub
Private Sub StartToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles StartToolStripMenuItem1.Click
Dim intZ As Integer = 10 ' this resets the game board for a new game after a win, loss or first start
Dim intRandom As New Random
Timer1.Enabled = False
For intReset As Integer = 0 To 10
picTest(intReset).Height = 128
picTest(intReset).Width = 75
picTest(intReset).Left = intZ
picTest(intReset).Top = intRandom.Next(-300, 25)
picTest(intReset).Image = Project_2.My.Resources.Resources.knight3a ' can sub with another image ***********
picTest(intReset).Visible = False
picTest(intReset).Enabled = True
Controls.Add(picTest(intReset))
badTest(intReset).Speed = intRandom.Next(10, 50)
intZ += 100
Next intReset
For intL As Integer = 0 To 10
picTest(intL).Visible = True
Next
pbxBow.Top = 559
pbxBow.Left = 559
Refresh()
collision = False
Timer1.Enabled = True
End Sub
End Class
答案 0 :(得分:1)
第一:你确定伤害大于0
goodWall.Health = goodWall.Health - badTest(intI).Damage
第二:你确定健康状况不小于0
If goodWall.Health = 0 Then