Bonjour
je suis en train de créer un jeu en 2D avec des avions (1 que le joueur doit contrôler et divers ennemis) son but sera d’éliminer tout les ennemis qui arriveront par vagues.
J'ai créé l'avion contrôlé par le joueur mais j'ai des problèmes au niveau du code qui fais se diriger l'avion de l' ennemis (nommé You2) toujours vers l'avion du joueur
L'avion tourne en fonction de "Direct2" Qui est un rectangle
le code si dessous ne fonctionne que si You2 est en haut a droite de l'avion du joueur:
Code vb : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 Private Sub M1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles M1.Tick Dim cas As String = "!" 'Principal If You.Top < You2.Top And You.Left < You2.Left And Direct2.Width < 8 Then cas = "+" If You.Top < You2.Top And You.Left < You2.Left And 16 <= Direct2.Width Then cas = "+" If You.Top < You2.Top And You.Left < You2.Left And 8 <= Direct2.Width < 16 Then cas = "-" If You.Top < You2.Top And You.Left > You2.Left And Direct2.Width < 4 Then cas = "+" If You.Top < You2.Top And You.Left > You2.Left And 12 <= Direct2.Width Then cas = "+" If You.Top < You2.Top And You.Left > You2.Left And 4 <= Direct2.Width < 12 Then cas = "-" If You.Top > You2.Top And You.Left < You2.Left And 4 <= Direct2.Width < 12 Then cas = "+" If You.Top > You2.Top And You.Left < You2.Left And Direct2.Width < 4 Then cas = "-" If You.Top > You2.Top And You.Left < You2.Left And 12 <= Direct2.Width Then cas = "-" If You.Top > You2.Top And You.Left > You2.Left And 16 <= Direct2.Width Then cas = "-" If You.Top > You2.Top And You.Left > You2.Left And Direct2.Width < 8 Then cas = "-" If You.Top > You2.Top And You.Left > You2.Left And 8 <= Direct2.Width < 16 Then cas = "+" If cas = "+" Then cas = cas Else If cas = "-" Then cas = cas Else er.Visible = True If cas = "+" Then cas = cas Else If cas = "-" Then cas = cas Else Info.Text = Info.Text + "[ErreurSup][001]Le cas de la trajectoire de You2 n'est pas égal a <<+>> ou <<->> ! " If cas = "+" Then Direct2.Width = Direct2.Width + 1 If cas = "-" Then Direct2.Width = Direct2.Width - 1 '+++ If Direct2.Width = 1 Then Direct2.Width = 17 If Direct2.Width = 18 Then Direct2.Width = 2 'classic If Direct2.Width = 2 Then You2.Top = You2.Top + 0 If Direct2.Width = 2 Then You2.Left = You2.Left + 4 If Direct2.Width = 3 Then You2.Top = You2.Top - 2 If Direct2.Width = 3 Then You2.Left = You2.Left + 4 If Direct2.Width = 4 Then You2.Top = You2.Top - 4 If Direct2.Width = 4 Then You2.Left = You2.Left + 4 If Direct2.Width = 5 Then You2.Top = You2.Top - 4 If Direct2.Width = 5 Then You2.Left = You2.Left + 2 If Direct2.Width = 6 Then You2.Top = You2.Top - 4 If Direct2.Width = 6 Then You2.Left = You2.Left + 0 If Direct2.Width = 7 Then You2.Top = You2.Top - 4 If Direct2.Width = 7 Then You2.Left = You2.Left - 2 If Direct2.Width = 8 Then You2.Top = You2.Top - 4 If Direct2.Width = 8 Then You2.Left = You2.Left - 4 If Direct2.Width = 9 Then You2.Top = You2.Top - 2 If Direct2.Width = 9 Then You2.Left = You2.Left - 4 If Direct2.Width = 10 Then You2.Top = You2.Top + 0 If Direct2.Width = 10 Then You2.Left = You2.Left - 4 If Direct2.Width = 11 Then You2.Top = You2.Top + 2 If Direct2.Width = 11 Then You2.Left = You2.Left - 4 If Direct2.Width = 12 Then You2.Top = You2.Top + 4 If Direct2.Width = 12 Then You2.Left = You2.Left - 4 If Direct2.Width = 13 Then You2.Top = You2.Top + 4 If Direct2.Width = 13 Then You2.Left = You2.Left - 2 If Direct2.Width = 14 Then You2.Top = You2.Top + 4 If Direct2.Width = 14 Then You2.Left = You2.Left + 0 If Direct2.Width = 15 Then You2.Top = You2.Top + 4 If Direct2.Width = 15 Then You2.Left = You2.Left + 2 If Direct2.Width = 16 Then You2.Top = You2.Top + 4 If Direct2.Width = 16 Then You2.Left = You2.Left + 4 If Direct2.Width = 17 Then You2.Top = You2.Top + 2 If Direct2.Width = 17 Then You2.Left = You2.Left + 4 End Sub
Merci de vos réponses
je reviendrais régulièrement voir les nouvelles réponses
Partager