Break all (mon premier projet de jeu)

Description

Bah voila, je suis en train d'essayer de creer un casse brique. J'avais reussit a faire rebondir la balle sur la barre selon 5 angles definit suivant l'endroit ou tapait la balle sur la barre. Mais suite a un gros plantage g tout perdu. Je suis donc en train de refaire le code mais la ca ne marche pas. Je ne trouve pas mon erreure. Donc si vous pouvez m'aider dans ce projet.... Ou meme optiizer le code qui, je doit l'avouer est tres bordelique. Je suis un debutant, je ne me suis mit au VB que depuis kelkes semaines et sans pouvoir y accorder bcp de temps, alors soyer indulgent svp.
(G mit ce code dans le niveau 2 car je ne sais pas a quoi correspond les niveaux, 1 = plus dur ou plus facile ?)

Source / Exemple :


'Declaration des variables
Dim barA As Integer
Dim barB As Integer
Dim barC As Integer
Dim barD As Integer
Dim barE As Integer
Dim barF As Integer
Dim barZ As Integer
Dim xxx As Integer
Dim yyy As Integer
Dim ballx As Integer
Dim bally As Integer
Private Sub Form_Load()
'On plave la barre
pctBARRE01.Left = (Me.Width - pctBARRE01.Width) / 2
pctBARRE01.Top = Me.Height - (3 * pctBARRE01.Height)
pctBARRE02.Left = pctBARRE01.Left - ((pctBARRE02.Width - pctBARRE01.Width) / 2)
pctBARRE02.Top = pctBARRE01.Top
'On place la balle
pctBALL.Left = (Me.Width - pctBALL.Width) / 2
pctBALL.Top = pctBARRE02.Top - pctBALL.Height - 25
'On place le boutton quitter
cmdEXIT.Height = pctBARRE01.Height
cmdEXIT.Top = Me.Height - cmdEXIT.Height
cmdEXIT.Left = Me.Width - Me.Width
cmdEXIT.Width = Me.Width
'On definit les valeurs par defaut
xxx = 100
yyy = 100
ballx = 0
bally = 0
End Sub
Private Sub form_click()
'Lancement de la balle
If pctBALL.Left <> (Me.Width - pctBALL.Width) / 2 Or pctBALL.Top <> pctBARRE02.Top - pctBALL.Height - 25 Then
    Exit Sub
Else
    If ballx <> 0 Then
    Exit Sub
    Else:
    ballx = 0
    bally = -100
    End If
End If
End Sub
Private Sub form_keypress(keyascii As Integer)
If keyascii = 52 Then 'Si la touche 4 est pressée alors
    If pctBARRE01.Visible = True Then pctBARRE01.Left = pctBARRE01.Left - xxx
    If pctBARRE02.Visible = True Then pctBARRE02.Left = pctBARRE02.Left - xxx
End If
If keyascii = 54 Then 'Si la touche 6 est pressée alors
    If pctBARRE01.Visible = True Then pctBARRE01.Left = pctBARRE01.Left + yyy
    If pctBARRE02.Visible = True Then pctBARRE02.Left = pctBARRE02.Left + yyy
End If
If keyascii = 53 Then 'Touche de test de changement de barre
    If pctBARRE01.Visible = True Then
        pctBARRE01.Visible = False
        pctBARRE02.Left = pctBARRE01.Left - ((pctBARRE02.Width - pctBARRE01.Width) / 2)
        pctBARRE02.Visible = True
    Else:
        pctBARRE01.Left = pctBARRE02.Left + ((pctBARRE02.Width - pctBARRE01.Width) / 2)
        pctBARRE01.Visible = True
        pctBARRE02.Visible = False
    End If
End If
End Sub
Private Sub timREFRESH_Timer()
'On definit les valeur de deplacements
If pctBARRE01.Left > 25 Then xxx = 100
If pctBARRE01.Left < Me.Width - pctBARRE01.Width - 25 Then yyy = 100
If pctBARRE02.Left > 25 Then xxx = 100
If pctBARRE02.Left < Me.Width - pctBARRE02.Width - 25 Then yyy = 100
'on vérifie que la balle n'est pas sous le niveau de la barre
If pctBALL.Top = Me.Height - (2 * pctBARRE01.Height) Then
    MsgBox "PERDU!!!", vbOKOnly, "Gestion:"
    'On replace la barre
    pctBARRE01.Left = (Me.Width - pctBARRE01.Width) / 2
    pctBARRE01.Top = Me.Height - (3 * pctBARRE01.Height)
    pctBARRE02.Left = pctBARRE01.Left - ((pctBARRE02.Width - pctBARRE01.Width) / 2)
    pctBARRE02.Top = pctBARRE01.Top
    'On replace la balle
    pctBALL.Left = (Me.Width - pctBALL.Width) / 2
    pctBALL.Top = pctBARRE02.Top - pctBALL.Height - 25
    ballx = 0
    bally = 0
'On s'arrange pour que lorsque la barre touche un coter, la valeur de deplacement
'concernant le deplacement vers ce coter prenne la valeur de 0
'Premiere barre, deplacement vers la gauche
If pctBARRE01.Left < 25 Then
    pctBARRE01.Left = 0
    xxx = 0
    yyy = 100
End If
If pctBARRE01.Left > Me.Width - pctBARRE01.Width - 25 Then
    pctBARRE01.Left = Me.Width - pctBARRE01.Width
    xxx = 100
    yyy = 0
End If
If pctBARRE02.Left < 25 Then
    pctBARRE02.Left = 0
    xxx = 0
    yyy = 100
End If
If pctBARRE02.Left > Me.Width - pctBARRE02.Width - 25 Then
    pctBARRE02.Left = Me.Width - pctBARRE02.Width
    xxx = 100
    yyy = 0
End If
'Deplacement de la balle
pctBALL.Left = pctBALL.Left + ballx
pctBALL.Top = pctBALL.Top + bally
'Fait rebondir la balle contre le haut de l'écran
If pctBALL.Top <= 0 Then
    pctBALL.Top = 0
    bally = -bally
End If
'Fait rebondir sur le coter gauche de l'ecran
If pctBALL.Left < 0 Then
    pctBALL.Left = 0
    ballx = -ballx
End If
'Fait rebondir la balle sur le coter droit de l'ecran
If pctBALL.Left > Me.Width - pctBALL.Width Then
    pctBALL.Left = Me.Width - pctBALL.Width
    ballx = -ballx
End If
'Verification de la hauteur de la balle
If pctBALL.Top >= pctBARRE01.Top Then
    If pctBALL.Top <= pctBARRE01.Top + 15 Then GoTo BonneHauteur
End If
Exit Sub
'Si la balle est a la hauteur de la balle alors on execute ce code
BonneHauteur:
'Verification de la barre visible
If pctBARRE01.Visible = True Then GoTo barre01V:
If pctBARRE02.Visible = True Then GoTo barre02V:
Exit Sub
'Si la barre 01 est visible alors on execute ce code
barre01V:
'On definit la valeur de barZ
barZ = (pctBALL.Width + pctBARRE01.Width) / 5
'On definit les 5 parties de la barre suivant la barre
barA = pctBARRE01.Left - (pctBALL.Width / 2)
barB = barA + barZ
barC = barB + barZ
barD = barC + barZ
barE = barD + barZ
barF = barE + barZ
'Les differentes vitesse suivant la partie de la barre touchee
'Les differentes vitesse permettent le changement d'angle
If pctBALL.Left >= barA Then
    If pctBALL.Left <= barB Then
        bally = -25
        ballx = -75
    End If
End If
If pctBALL.Left >= barB Then
    If pctBALL.Left <= barC Then
        bally = -50
        ballx = -50
    End If
End If
If pctBALL.Left >= barC Then
    If pctBALL.Left <= barD Then
        bally = -75
        ballx = 0
    End If
End If
If pctBALL.Left >= barD Then
    If pctBALL.Left <= barE Then
        bally = -50
        ballx = 50
    End If
End If
If pctBALL.Left >= barE Then
    If pctBALL.Left <= barF Then
        bally = -25
        ballx = 75
    End If
End If
Exit Sub
barre02V:
'On definit la valeur de barZ
barZ = (pctBALL.Width + pctBARRE02.Width) / 5
'On definit les 5 parties de la barre suivant la barre
barA = pctBARRE02.Left - (pctBALL.Width / 2)
barB = barA + barZ
barC = barB + barZ
barD = barC + barZ
barE = barD + barZ
barF = barE + barZ
'Les differentes vitesse suivant la partie de la barre touchee
'Les differentes vitesse permettent le changement d'angle
If pctBALL.Left >= barA Then
    If pctBALL.Left <= barB Then
        bally = -25
        ballx = -75
    End If
End If
If pctBALL.Left >= barB Then
    If pctBALL.Left <= barC Then
        bally = -50
        ballx = -50
    End If
End If
If pctBALL.Left >= barC Then
    If pctBALL.Left <= barD Then
        bally = -75
        ballx = 0
    End If
End If
If pctBALL.Left >= barD Then
    If pctBALL.Left <= barE Then
        bally = -50
        ballx = 50
    End If
End If
If pctBALL.Left >= barE Then
    If pctBALL.Left <= barF Then
        bally = -25
        ballx = 75
    End If
End If

Exit Sub
End Sub
Private Sub cmdEXIT_click()
'On quitte l'application
End
End Sub

Conclusion :


Si vous etes decider a m'aider, revener de temp en temp ici, je ferai des mise a jour de temps en temps qd j'aurai reussit a progresser.
Encore merci a tout ceux ki voudront bien m'aider

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.