AIde pour un RTS...

Heromega Messages postés 4 Date d'inscription vendredi 2 novembre 2001 Statut Membre Dernière intervention 30 décembre 2002 - 30 déc. 2002 à 02:05
SupraDolph Messages postés 196 Date d'inscription samedi 12 janvier 2002 Statut Membre Dernière intervention 1 septembre 2008 - 30 déc. 2002 à 13:17
Bonsoir tout le monde.
J'ai un gros probléme concerant le dévelloppement d'un jeu de stratégie.

Voilà quelqu'un sait comment placez les batiments?
Je veux dire placer une picture là ou le curseur est sur la feuille et si un batiment est déjà placé juste à cet endroit alors le placement ne se fais pas... vous voyez ce que je veux dire??

Je vous en supplis aidez-moi...

Dimitri

2 réponses

SupraDolph Messages postés 196 Date d'inscription samedi 12 janvier 2002 Statut Membre Dernière intervention 1 septembre 2008 1
30 déc. 2002 à 03:23
Salut Dimitri
j'ai fait une partie de ce que tu demande.
tout d'abord inscrit ce code dans une form et crée 2 picturebox (Picture1 et Picture2)
Tu peut déplacer les 2 pictures.
Dès que tu relâche le boutton de la sourie lors d'un déplacement d'une des 2 pictures, si le coin supperieur gauche de la picture que tu déplace se trouve à l'interieur de l'autre picture, elle revient a sa position initiale.
En fait il faut que tu fasse le test pour tous les points de la picture que tu déplace.

Voila le code :

' Position de X et Y par rapport a l'écran
Private Declare Function GetCursorPos Lib "user32" ( _
lpPoint As PointAPI) As Long

' Position de X et Y par rapport a la fenètre et a GetCursorPos
Private Declare Function ScreenToClient Lib "user32" ( _
ByVal hwnd As Long, _
lpPoint As PointAPI) As Long

Private Type PointAPI
X As Long
Y As Long
End Type
Dim Position As PointAPI

Private Function Positionne(Picturex As PictureBox)
Dim pos As PointAPI
GetCursorPos pos
ScreenToClient Me.hwnd, pos
Picturex.Top = pos.Y * 15 - Picturex.Height / 2
Picturex.Left = pos.X * 15 - Picturex.Width / 2
End Function

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Position.X = Picture1.Left
Position.Y = Picture1.Top
Positionne Picture1
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button Then Positionne Picture1
End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim pos As PointAPI
GetCursorPos pos
ScreenToClient Me.hwnd, posIf (pos.Y * 15 - Picture1.Height / 2) < (Picture2.Top + Picture2.Height) And (pos.Y * 15 - Picture1.Height / 2) > Picture2.Top And (pos.X * 15 - Picture1.Width / 2) < (Picture2.Left + Picture2.Width) And (pos.X * 15 - Picture1.Width / 2) > Picture2.Left Then Picture1.Top Position.Y: Picture1.Left Position.X
End Sub

Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Position.X = Picture2.Left
Position.Y = Picture2.Top
Positionne Picture2
End Sub

Private Sub Picture2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button Then Positionne Picture2
End Sub

Private Sub Picture2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim pos As PointAPI
GetCursorPos pos
ScreenToClient Me.hwnd, posIf (pos.Y * 15 - Picture2.Height / 2) < (Picture2.Top + Picture1.Height) And (pos.Y * 15 - Picture2.Height / 2) > Picture1.Top And (pos.X * 15 - Picture2.Width / 2) < (Picture1.Left + Picture1.Width) And (pos.X * 15 - Picture2.Width / 2) > Picture1.Left Then Picture2.Top Position.Y: Picture2.Left Position.X
End Sub

Bon Prog
SupraDolph
0
SupraDolph Messages postés 196 Date d'inscription samedi 12 janvier 2002 Statut Membre Dernière intervention 1 septembre 2008 1
30 déc. 2002 à 13:17
'Bon j'ai fini voila le code complet Bonne Chance (SupraDolph)

' Position de X et Y par rapport a l'écran
Private Declare Function GetCursorPos Lib "user32" ( _
lpPoint As PointAPI) As Long

' Position de X et Y par rapport a la fenètre et a GetCursorPos
Private Declare Function ScreenToClient Lib "user32" ( _
ByVal hwnd As Long, _
lpPoint As PointAPI) As Long

Private Type PointAPI
X As Long
Y As Long
End Type
Dim Position As PointAPI

Private Function Positionne(Picturex As PictureBox)
Dim pos As PointAPI
GetCursorPos pos
ScreenToClient Me.hwnd, pos
Picturex.Top = pos.Y * 15 - Picturex.Height / 2
Picturex.Left = pos.X * 15 - Picturex.Width / 2
End Function

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Position.X = Picture1.Left
Position.Y = Picture1.Top
Positionne Picture1
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button Then Positionne Picture1
End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim pos As PointAPI
GetCursorPos pos
ScreenToClient Me.hwnd, pos
If (pos.Y * 15 - Picture1.Height / 2) < (Picture2.Top + Picture2.Height) And (pos.Y * 15 - Picture1.Height / 2) > Picture2.Top And (pos.X * 15 - Picture1.Width / 2) < (Picture2.Left + Picture2.Width) And (pos.X * 15 - Picture1.Width / 2) > Picture2.Left Or _
(pos.Y * 15 + Picture1.Height / 2) < (Picture2.Top + Picture2.Height) And (pos.Y * 15 + Picture1.Height / 2) > Picture2.Top And (pos.X * 15 - Picture1.Width / 2) < (Picture2.Left + Picture2.Width) And (pos.X * 15 - Picture1.Width / 2) > Picture2.Left Or _
(pos.Y * 15 - Picture1.Height / 2) < (Picture2.Top + Picture2.Height) And (pos.Y * 15 - Picture1.Height / 2) > Picture2.Top And (pos.X * 15 + Picture1.Width / 2) < (Picture2.Left + Picture2.Width) And (pos.X * 15 + Picture1.Width / 2) > Picture2.Left Or _
(pos.Y * 15 + Picture1.Height / 2) < (Picture2.Top + Picture2.Height) And (pos.Y * 15 + Picture1.Height / 2) > Picture2.Top And (pos.X * 15 + Picture1.Width / 2) < (Picture2.Left + Picture2.Width) And (pos.X * 15 + Picture1.Width / 2) > Picture2.Left _Then Picture1.Top Position.Y: Picture1.Left Position.X
End Sub

Private Sub Picture2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Position.X = Picture2.Left
Position.Y = Picture2.Top
Positionne Picture2
End Sub

Private Sub Picture2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button Then Positionne Picture2
End Sub

Private Sub Picture2_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim pos As PointAPI
GetCursorPos pos
ScreenToClient Me.hwnd, pos
If (pos.Y * 15 - Picture2.Height / 2) < (Picture1.Top + Picture1.Height) And (pos.Y * 15 - Picture2.Height / 2) > Picture1.Top And (pos.X * 15 - Picture2.Width / 2) < (Picture1.Left + Picture1.Width) And (pos.X * 15 - Picture2.Width / 2) > Picture1.Left Or _
(pos.Y * 15 + Picture2.Height / 2) < (Picture1.Top + Picture1.Height) And (pos.Y * 15 + Picture2.Height / 2) > Picture1.Top And (pos.X * 15 - Picture2.Width / 2) < (Picture1.Left + Picture1.Width) And (pos.X * 15 - Picture2.Width / 2) > Picture1.Left Or _
(pos.Y * 15 - Picture2.Height / 2) < (Picture1.Top + Picture1.Height) And (pos.Y * 15 - Picture2.Height / 2) > Picture1.Top And (pos.X * 15 + Picture2.Width / 2) < (Picture1.Left + Picture1.Width) And (pos.X * 15 + Picture2.Width / 2) > Picture1.Left Or _
(pos.Y * 15 + Picture2.Height / 2) < (Picture1.Top + Picture1.Height) And (pos.Y * 15 + Picture2.Height / 2) > Picture1.Top And (pos.X * 15 + Picture2.Width / 2) < (Picture1.Left + Picture1.Width) And (pos.X * 15 + Picture2.Width / 2) > Picture1.Left _Then Picture2.Top Position.Y: Picture2.Left Position.X
End Sub
0
Rejoignez-nous