Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
this is my code

VB
Public Class Form1
    Dim m = 0

    Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        Timer1.Stop()
        Timer2.Stop()
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Start()


    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If (m = 1) Then
            v.Location = New Point(v.Location.X - 10, v.Location.Y)
        End If

        If (m = 2) Then
            v.Location = New Point(v.Location.X + 10, v.Location.Y)
        End If

        If (m = 0) Then

        End If


    End Sub
    Dim bullet As New PictureBox
    Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown

        Timer1.Start()

        If e.KeyCode = Keys.Space Then
            Timer2.Start()
        End If

        If e.KeyCode = Keys.Left Then
            m = 1
        End If

        If e.KeyCode = Keys.Right Then
            m = 2
        End If

        If (v.Location.X <= 0) Then
            v.Location = New Point(v.Location.X = 874, v.Location.Y)
        End If

        If (v.Location.X >= 875) Then
            v.Location = New Point(v.Location.X = 1, v.Location.Y)
        End If



    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        bullet.BackColor = Color.Red
        bullet.Width = 20
        bullet.Height = 40
        bullet.Visible = True

        bullet.Location = New Point(v.Location.X, v.Location.Y + 1)
    End Sub
End Class



I have almost everything setup for a basic shooting game, but I just don't know I I am ment to do the shooting, I have the animation for it, but the images don't appear, I think I might have a few things in the wrong spot.

key = v is the moving spaceship
bullet is the bullets
and there all pictureboxs, please ask me if you don't understand what some things are.
Posted

1 solution

This code is so bad that you cannot hope for successful development of a game even this simple.

The problems include: 1) hard-coded values like 10, 875, 20, 40; what's worse, they are repeated and/or related; this problem is fatal; 2) an idea to use PictureBox where a direct rendering in a control is required; this problem may not be fatal, but may compromise both development and performance; 3) using System.Windows.Forms.Timer which is completely unsuitable here; not using thread; this problem maybe not 100% fatal, but it will prohibit smooth animation for sure; you need to one of the other timer classes and/or threads with Invoke/BeginInvoke; 4) non-semantic variable names like Form1, Form1_Load, Form1_KeyUp which violates Microsoft naming convention; this is not the fatal problem but shows that you have no idea of maintenance of the code; in particular, all auto-generated names should be renamed to something semantic, if you take development seriously, of course; 5) you have asked 106 questions by the moment of writing; and I counted only 7 answers which you accepted even though some of the answers were good; and I see many signs that you failed to understand the answers and no signs that you ever were able to use the answers for your work; this problem looks absolutely hopeless.

I'm not trying to say that you are not able to do software development; that would be not fair. It would be safe to say that you are not doing any serious development right now and need a lot of learning; and the real problem is that you don't show any signs of being able to learn from your mistakes and from advice, and this is the biggest problem.

Also, I cannot see any signs of any your accomplishments. You start asking question on new areas without any success in the fields you had asked a while ago. Are you looking for something easier? There is no such thing.

I already gave up to provide any help to you, after many unsuccessful attempts. I provided so many fine detail, long lists of manuals, articles and help pages on particular topics to read about, all in vain. Now I'm starting to warn other experts that answering your question is a waste of time. Nobody wants to get frustrated be the useless effort.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900