Option Strict On Public Class Form1 'image de fond Dim MonFond As Image = DessineMonFond() 'image figure a déplacer Dim Monperso As Image = DessineMonPerso() 'point de déplacement Dim MonPoint As Point Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'on applique au formulaire un buffer tampon pour réduire les scintillements Me.DoubleBuffered = True 'on définit un point de départ MonPoint = New Point(100, 100) 'on repeint le formulaire en entier Me.Invalidate(Me.ClientRectangle) End Sub Private Sub Form1_Keydown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown 'en fonction des touches, on change les coordonnées du point Select Case e.KeyCode Case Keys.Right MonPoint.X += 2 Case Keys.Left MonPoint.X -= 2 Case Keys.Up MonPoint.Y -= 2 Case Keys.Down MonPoint.Y += 2 End Select 'ici on ne repeint que la partie du formulaire dont le dessin change Me.Invalidate(New Rectangle(MonPoint.X - 2, MonPoint.Y - 2, 24, 24)) End Sub Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint 'dessin du fond e.Graphics.DrawImage(MonFond, New Point(0, 0)) 'dessin du motif e.Graphics.DrawImage(Monperso, MonPoint) End Sub 'fonction générant l'image du fond Private Function DessineMonFond() As Image Dim b As New Bitmap(300, 300) Dim g As Graphics = Graphics.FromImage(b) g.FillRectangle(Brushes.GreenYellow, 0, 0, b.Width, b.Height) g.FillEllipse(Brushes.Yellow, 50, 50, 150, 150) Return CType(b.Clone, Image) End Function 'fonction générant un motif à délacer Private Function DessineMonPerso() As Image Dim b As New Bitmap(20, 20) Dim g As Graphics = Graphics.FromImage(b) g.FillEllipse(Brushes.Red, New Rectangle(2, 2, 10, 10)) g.FillEllipse(Brushes.Blue, New Rectangle(4, 12, 7, 7)) Return CType(b.Clone, Image) End Function End Class
Exemple avec un déplacement vers la gauche ----------- | __ | | | |xx | | |__|xx | | | |__________
Me.Invalidate(New Rectangle(MonPoint.X - 2, MonPoint.Y - 2, 35, 52))
Et ensuite comment donner un nom comme PN_MARIO à ce personnage ??
Dim Mario as Point
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionIf e.KeyValue Keys.Right And recuppos False Then 'droite If PN_MARIO.Location.X + 20 < 688 Then recuppos = True PN_MARIO.Location = New Point(PN_MARIO.Location.X + 4, PN_MARIO.Location.Y) PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.droite hbwait(50) ' PN_MARIO.Location = New Point(PN_MARIO.Location.X + 4, PN_MARIO.Location.Y) PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.droite2 hbwait(50) ' PN_MARIO.Location = New Point(PN_MARIO.Location.X + 4, PN_MARIO.Location.Y) PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.droite3 hbwait(50) ' PN_MARIO.Location = New Point(PN_MARIO.Location.X + 4, PN_MARIO.Location.Y) PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.droite4 hbwait(50) ' PN_MARIO.Location = New Point(PN_MARIO.Location.X + 4, PN_MARIO.Location.Y) PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.droite hbwait(50) posX = PN_MARIO.Location.X posY = PN_MARIO.Location.Y 'hbwait(100) recuppos = False Exit Sub Else Exit Sub End If ElseIf e.KeyValue Keys.Left And recuppos False Then 'gauche If PN_MARIO.Location.X - 20 > -1 Then recuppos = True PN_MARIO.Location = New Point(PN_MARIO.Location.X - 4, PN_MARIO.Location.Y) PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.gauche hbwait(50) ' PN_MARIO.Location = New Point(PN_MARIO.Location.X - 4, PN_MARIO.Location.Y) PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.gauche2 hbwait(50) ' PN_MARIO.Location = New Point(PN_MARIO.Location.X + 4, PN_MARIO.Location.Y) PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.gauche3 hbwait(50) ' PN_MARIO.Location = New Point(PN_MARIO.Location.X - 4, PN_MARIO.Location.Y) PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.gauche4 hbwait(50) ' PN_MARIO.Location = New Point(PN_MARIO.Location.X - 4, PN_MARIO.Location.Y) PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.gauche hbwait(50) posX = PN_MARIO.Location.X posY = PN_MARIO.Location.Y 'hbwait(100) recuppos = False Exit Sub Else Exit Sub End If ElseIf e.KeyValue Keys.Up And recuppos False Then 'haut If PN_MARIO.Location.Y - 20 > -1 Then recuppos = True PN_MARIO.Location = New Point(PN_MARIO.Location.X, PN_MARIO.Location.Y - 4) PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.haut hbwait(50) ' PN_MARIO.Location = New Point(PN_MARIO.Location.X, PN_MARIO.Location.Y - 4) PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.haut2 hbwait(50) ' PN_MARIO.Location = New Point(PN_MARIO.Location.X, PN_MARIO.Location.Y - 4) PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.haut3 hbwait(50) ' PN_MARIO.Location = New Point(PN_MARIO.Location.X, PN_MARIO.Location.Y - 4) PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.haut4 hbwait(50) ' PN_MARIO.Location = New Point(PN_MARIO.Location.X, PN_MARIO.Location.Y - 4) PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.haut hbwait(50) posX = PN_MARIO.Location.X posY = PN_MARIO.Location.Y 'hbwait(100) recuppos = False Exit Sub Else Exit Sub End If ElseIf e.KeyValue Keys.Down And recuppos False Then 'bas If PN_MARIO.Location.Y + 20 < 686 Then recuppos = True PN_MARIO.Location = New Point(PN_MARIO.Location.X, PN_MARIO.Location.Y + 4) PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.bas hbwait(100) ' PN_MARIO.Location = New Point(PN_MARIO.Location.X, PN_MARIO.Location.Y + 4) PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.bas2 hbwait(100) ' PN_MARIO.Location = New Point(PN_MARIO.Location.X, PN_MARIO.Location.Y + 4) PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.bas3 hbwait(100) ' PN_MARIO.Location = New Point(PN_MARIO.Location.X, PN_MARIO.Location.Y + 4) PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.bas4 hbwait(100) ' PN_MARIO.Location = New Point(PN_MARIO.Location.X, PN_MARIO.Location.Y + 4) PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.bas hbwait(100) posX = PN_MARIO.Location.X posY = PN_MARIO.Location.Y 'hbwait(100) recuppos = False Exit Sub Else Exit Sub End If
Private Sub map_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint 'dessin du fond e.Graphics.DrawImage(MonFond, New Point(0, 0)) 'dessin du motif e.Graphics.DrawImage(Monperso, MonPoint) End Sub Private Function DessineMonFond() As Image Dim b As New Bitmap(700, 700) Dim g As Graphics = Graphics.FromImage(b) 'g.FillRectangle(Brushes.AliceBlue, 0, 0, 700, 700) g.DrawImage(WindowsApplication1.My.Resources.Resources.carré, 0, 0, 20, 20) 'g.FillEllipse(Brushes.Yellow, 50, 50, 150, 150) Return CType(b.Clone, Image) End Function 'fonction générant un motif à délacer Private Function DessineMonPerso() As Image Dim b As New Bitmap(20, 20) Dim g As Graphics = Graphics.FromImage(b) g.DrawImage(WindowsApplication1.My.Resources.Resources.droite, 0, 0, 31, 48) 'g.FillEllipse(Brushes.Red, New Rectangle(2, 2, 10, 10)) 'g.FillEllipse(Brushes.Blue, New Rectangle(4, 12, 7, 7)) Return CType(b.Clone, Image) End Function
Dim b As New Bitmap( 'ici la hauteur , 'ici la largeur)
Me.Invalidate(New Rectangle(MonPoint.X - 2, MonPoint.Y - 2, 24, 24))
posX = Module2.posXF(posX) posY = Module2.posYF(posY) niveauheros = Module2.niveauherosF(niveauheros) mapheros = Module2.mapherosF(mapheros) attaque_main_min = Module2.attaque_main_minF(attaque_main_min) attaque_main_max = Module2.attaque_main_maxF(attaque_main_max) vieheros = Module2.vieherosF(vieheros) vieherosmax = Module2.vieherosmaxF(vieherosmax) PN_MARIO.Location = New Point(posXF(posX), posYF(posY))
posX = CInt(Module2.posXF(CStr(posX))) posY = CInt(Module2.posYF(CStr(posY))) niveauheros = CInt(Module2.niveauherosF(niveauheros)) mapheros = Module2.mapherosF(mapheros) attaque_main_min = Module2.attaque_main_minF(attaque_main_min) attaque_main_max = Module2.attaque_main_maxF(attaque_main_max) vieheros = Module2.vieherosF(vieheros) vieherosmax = Module2.vieherosmaxF(vieherosmax)
Me.Invalidate(New Rectangle(MonPoint.X - 2, MonPoint.Y - 2, 31, 48))
Option Strict On Imports MySql.Data.MySqlClient Public Class map 'image de fond Dim MonFond As Image = DessineMonFond() 'image figure a déplacer Dim monperso As Image = DessineMonPerso() 'monperso 'point de déplacement Dim PN_MARIO As Rectangle Public recuppos As Boolean = False 'Combat Public posX As Integer Public posY As Integer Public attaque_main_max As Integer Public attaque_main_min As Integer Public niveauheros As Integer Public vieheros As Integer Public vieherosmax As Integer Public mapheros As String 'End Combat Public ConnexionSql2 As String = "Database=***;" & "Data Source=***;" & "User Id=***;Password=***;" & "Connection Timeout=20" Public connection2 As New MySqlConnection(ConnexionSql2) Private Sub Form2_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing posX = PN_MARIO.X posY = PN_MARIO.Y Dim query2 As String "UPDATE users SET posX @posX" Dim query3 As String "UPDATE users SET posY @posY" Dim Command2 As New MySqlCommand(query2, connection2) Dim Command3 As New MySqlCommand(query3, connection2) Command2.Prepare() Command2.Parameters.AddWithValue("@posX", posX) Command2.ExecuteNonQuery() Command3.Prepare() Command3.Parameters.AddWithValue("@posY", posY) Command3.ExecuteNonQuery() ' MsgBox("Au revoir :)") ' identification.NotifyIcon1.Visible = False identification.ShowInTaskbar = True identification.Visible = True connection2.Close() End Sub Public Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load connection2.Open() Me.DoubleBuffered = True Me.Invalidate(Me.ClientRectangle) posX = CInt(Module2.posXF(CStr(posX))) posY = CInt(Module2.posYF(CStr(posY))) niveauheros = CInt(Module2.niveauherosF(niveauheros)) mapheros = Module2.mapherosF(mapheros) attaque_main_min = Module2.attaque_main_minF(attaque_main_min) attaque_main_max = Module2.attaque_main_maxF(attaque_main_max) vieheros = Module2.vieherosF(vieheros) vieherosmax = Module2.vieherosmaxF(vieherosmax) Dim user = identification.userbon PN_MARIO.X = posX PN_MARIO.Y = posY Me.Text = user & " - ****** 2013" If recuppos = False Then Else Exit Sub End If 'on applique au formulaire un buffer tampon pour réduire les scintillements 'on définit un point de départ 'on repeint le formulaire en entier End Sub Public Sub Form2_Keydown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown 'ici on ne repeint que la partie du formulaire dont le dessin change If e.KeyValue Keys.Right And recuppos False Then 'droite If PN_MARIO.X + 20 < 688 Then recuppos = True PN_MARIO.X += 4 'PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.droite hbwait(50) ' PN_MARIO.X += 4 'PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.droite2 hbwait(50) ' PN_MARIO.X += 4 'PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.droite3 hbwait(50) ' PN_MARIO.X += 4 'PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.droite4 hbwait(50) ' PN_MARIO.X += 4 'PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.droite hbwait(50) posX = PN_MARIO.X posY = PN_MARIO.Y 'hbwait(100) recuppos = False Exit Sub Else Exit Sub End If ElseIf e.KeyValue Keys.Left And recuppos False Then 'gauche If PN_MARIO.X - 20 > -1 Then recuppos = True PN_MARIO.X -= 4 'PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.gauche hbwait(50) ' PN_MARIO.X -= 4 'PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.gauche2 hbwait(50) ' PN_MARIO.X -= 4 'PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.gauche3 hbwait(50) ' PN_MARIO.X -= 4 'PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.gauche4 hbwait(50) ' PN_MARIO.X -= 4 'PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.gauche hbwait(50) posX = PN_MARIO.X posY = PN_MARIO.Y 'hbwait(100) recuppos = False Exit Sub Else Exit Sub End If ElseIf e.KeyValue Keys.Up And recuppos False Then 'haut If PN_MARIO.Y - 20 > -1 Then recuppos = True PN_MARIO.Y -= 4 'PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.haut hbwait(50) ' PN_MARIO.Y -= 4 'PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.haut2 hbwait(50) ' PN_MARIO.Y -= 4 'PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.haut3 hbwait(50) ' PN_MARIO.Y -= 4 'PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.haut4 hbwait(50) ' PN_MARIO.Y -= 4 'PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.haut hbwait(50) posX = PN_MARIO.X posY = PN_MARIO.Y 'hbwait(100) recuppos = False Exit Sub Else Exit Sub End If ElseIf e.KeyValue Keys.Down And recuppos False Then 'bas If PN_MARIO.Y + 20 < 686 Then recuppos = True PN_MARIO.Y += 4 'PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.bas hbwait(50) ' PN_MARIO.Y += 4 'PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.bas2 hbwait(50) ' PN_MARIO.Y += 4 'PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.bas3 hbwait(50) ' PN_MARIO.Y += 4 'PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.bas4 hbwait(50) ' PN_MARIO.Y += 4 'PN_MARIO.BackgroundImage = WindowsApplication1.My.Resources.Resources.bas hbwait(50) posX = PN_MARIO.X posY = PN_MARIO.Y 'hbwait(100) recuppos = False Exit Sub Else Exit Sub End If Else Exit Sub End If Else Exit Sub End If Me.Invalidate(New Rectangle(PN_MARIO.X - 2, PN_MARIO.Y - 2, 35, 52)) End Sub Private Sub PN_MARIO_Click(sender As Object, e As System.EventArgs) MsgBox("X : " & PN_MARIO.X & "; Y : " & PN_MARIO.Y & "; Niveau : " & niveauheros & "; Map : " & mapheros) End Sub Private Sub map_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint 'dessin du fond e.Graphics.DrawImage(MonFond, New Point(0, 0)) 'dessin du motif e.Graphics.DrawImage(Monperso, PN_MARIO) End Sub Private Function DessineMonFond() As Image Dim b As New Bitmap(700, 700) Dim g As Graphics = Graphics.FromImage(b) 'g.FillRectangle(Brushes.AliceBlue, 0, 0, 700, 700) g.DrawImage(WindowsApplication1.My.Resources.Resources.carré, 0, 0, 20, 20) 'g.FillEllipse(Brushes.Yellow, 50, 50, 150, 150) Return CType(b.Clone, Image) End Function 'fonction générant un motif à délacer Private Function DessineMonPerso() As Image Dim b As New Bitmap(31, 48) Dim g As Graphics = Graphics.FromImage(b) g.DrawImage(WindowsApplication1.My.Resources.Resources.droite, 0, 0, 31, 48) 'g.FillEllipse(Brushes.Red, New Rectangle(2, 2, 10, 10)) 'g.FillEllipse(Brushes.Blue, New Rectangle(4, 12, 7, 7)) Return CType(b.Clone, Image) End Function End Class
Private BufferredGraphic As BufferedGraphics Private CurrentContext As BufferedGraphicsContext
BufferredGraphic = Me.CurrentContext.Allocate(Panel1.CreateGraphics(), Panel1.DisplayRectangle) BufferredGraphic.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality BufferredGraphic.Graphics.Clear(Color.Cornsilk) BufferredGraphic.Graphics.DrawPolygon(mypen, points)