-
-
Save BitPuffin/1393457 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'Gör det möjligt att hantera grafik | |
Imports System.Drawing | |
Public Class Form2 | |
'Grafikvariablar | |
Dim G As Graphics | |
Dim BBG As Graphics | |
Dim GDragon As Graphics | |
'Rektanglar | |
Dim sRect As Rectangle | |
Dim dRect As Rectangle | |
'Bilden som är i pictureboxen (Assassin) | |
Dim bmp As Bitmap | |
Dim BB As Bitmap | |
'Karaktärens X- och Y-koordinater | |
Dim GuyX As Integer = 275 | |
Dim GuyY As Integer = 475 | |
'Bilden som är i pictureboxen (Frost Dragon) | |
Dim bmpDragon As Bitmap | |
Dim BBDragon As Bitmap | |
'Frost dragon's X- och Y-koordinater | |
Dim DragonX As Integer = 275 | |
Dim DragonY As Integer = 50 | |
'Gör det möjligt för karaktären att gå framåt (W), bakåt (S), höger (D) och vänster (A) | |
Private Sub Form2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown | |
Select Case e.KeyCode | |
Case Keys.W | |
'Karaktärens Y-koordinat | |
GuyY = GuyY - 5 | |
bmp = New Bitmap(pTiles2.Image) | |
Case Keys.S | |
'Karaktärens Y-koordinat | |
GuyY = GuyY + 5 | |
bmp = New Bitmap(pTiles.Image) | |
Case Keys.A | |
'Karaktärens X-koordinat | |
GuyX = GuyX - 5 | |
bmp = New Bitmap(pTiles4.Image) | |
Case Keys.D | |
'Karaktärens X-koordinat | |
GuyX = GuyX + 5 | |
bmp = New Bitmap(pTiles3.Image) | |
'Byter till Form1 när man trycker på "Esc"-knappen på tangentbordet | |
Case Keys.Escape | |
Form1.Show() | |
Me.Hide() | |
End Select | |
DrawAll() | |
End Sub | |
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load | |
'Karaktären (Assassin) | |
bmp = New Bitmap(pTiles2.Image) | |
G = Me.CreateGraphics | |
'Samma storlek som Formet | |
BB = New Bitmap(Me.Width, Me.Height) | |
'Frost Dragon | |
bmpDragon = New Bitmap(pTilesDragon.Image) | |
GDragon = Me.CreateGraphics | |
'Samma storlek som Formet | |
BBDragon = New Bitmap(Me.Width, Me.Height) | |
End Sub | |
Private Sub DrawAll() | |
'Koordinater | |
Dim X, Y As Integer | |
'Ritar X-koordinat | |
For X = 0 To 15 | |
'Ritar Y-koordinat | |
For Y = 0 To 15 | |
sRect = New Rectangle(0, 0, 50, 50) | |
'Ritar ut rutornas storlek i pixlar | |
dRect = New Rectangle(X * 50, Y * 50, 50, 50) | |
'Säger åt den att rita pixlar | |
G.DrawImage(bmp, dRect, sRect, GraphicsUnit.Pixel) | |
Next | |
Next | |
'Ritar Karaktär (Placerar honom efter loopen så att han hamnar över marken) | |
'Gör den vita färgen runt karaktären transparent så att han inte rör sig i en vit ruta | |
bmp.MakeTransparent(Color.White) | |
sRect = New Rectangle(50, 0, 50, 50) | |
G.DrawImage(bmp, GuyX, GuyY, sRect, GraphicsUnit.Pixel) | |
'Sista ritningen (Karaktär) | |
G = Graphics.FromImage(BB) | |
BBG = Me.CreateGraphics | |
BBG.DrawImage(BB, 0, 0, Me.Width, Me.Height) | |
'Ritar Frost Dragon(Placerar Frost Dragon efter loopen så att den hamnar över marken) | |
'Gör den vita färgen runt Frost Dragon transparent så att den inte rör sig i en vit ruta | |
bmpDragon.MakeTransparent(Color.White) | |
sRect = New Rectangle(70, 0, 70, 70) | |
GDragon.DrawImage(bmpDragon, DragonX, DragonY, sRect, GraphicsUnit.Pixel) | |
'Sista ritningen (Frost Dragon) | |
GDragon = Graphics.FromImage(BBDragon) | |
BBG = Me.CreateGraphics | |
BBG.DrawImage(BBDragon, 0, 0, Me.Width, Me.Height) | |
End Sub | |
Private Sub Form2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint | |
DrawAll() | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment