Quantcast
Channel: VBForums - Games and Graphics Programming
Viewing all 263 articles
Browse latest View live

GDIPLUS: how convert vbcolor or commondialog color to GDIPLUS color?

$
0
0
how convert vbcolor or commondialog color to GDIPLUS color?

[RESOLVED] GDI: how draw a cursor\ani to a Memory DC?

$
0
0
see how i create a Memory DC:
Code:

Public Sub NewImage(width As Long, height As Long, Optional backcolor As Long = White)
    If (ImageBitmap) Then
        SelectObject ImageHDC, OldImageBitmap
        DeleteObject ImageBitmap
        DeleteDC ImageHDC
    End If
    If (ImageGraphics) Then GdipDeleteGraphics ImageGraphics
    ImageHDC = CreateCompatibleDC(GetDC(0))
    If (ImageHDC = 0) Then Debug.Print "error"
    ImageBitmap = CreateCompatibleBitmap(GetDC(0), width, height)
    If (ImageBitmap = 0) Then Debug.Print "error on ImageBitmap"
    OldImageBitmap = SelectObject(ImageHDC, ImageBitmap)
    Dim hBrush As Long
    hBrush = CreateSolidBrush(backcolor)
    If (hBrush = 0) Then Debug.Print "error on brush"
    Dim rect As rect
    rect.Left = 0
    rect.Top = 0
    rect.Bottom = height
    rect.Right = width
    If (FillRect(ImageHDC, rect, hBrush) = 0) Then Debug.Print "error on FillRect"
    ImageBackColor = backcolor
    lngwidth = width
    lngheight = height
    DeleteObject hBrush
End Sub

now see how i read the file and draw the cursor to it:
Code:

Public Sub FromFile(FileName As String)
    If (hBitmap) Then GdipDisposeImage (hBitmap)
    If (CurAni) Then DeleteObject (CurAni)
   
    imgType = GetImageType(FileName)
    If (imgType = ANI Or imgType = CUR) Then
        Debug.Print "cursor" 'yes it's printed
        CurAni = LoadImage(App.hInstance, FileName, IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE)
             
        NewImage 100, 100
        'If (DrawIconEx(GetWindowDC(GetForegroundWindow()), 0, 0, CurAni, 0, 0, 0, 1, DI_NORMAL Or DI_IMAGE) = 0) Then Debug.Print "error on draw cursor: " & GetLastError
        If (DrawIconEx(ImageHDC, 0, 0, CurAni, 0, 0, 0, 1, DI_NORMAL Or DI_IMAGE) = 0) Then Debug.Print "error on draw cursor: " & GetLastError
       
    Else
       
        Call GdipLoadImageFromFile(StrPtr(FileName), hBitmap)
        NewImage width, height
        GdipCreateFromHDC ImageHDC, hGraphics
        GdipDrawImage hGraphics, hBitmap, 0, 0
        GdipDeleteGraphics hGraphics
    End If
End Sub

heres how i draw on form:
Code:

Public Sub Draw(DestinationHDC As Long, Optional Transparent As Boolean = True)
    RaiseEvent BeforeDrawImage(intSelectedFrame)
    If (ImageHDC = 0) Then Debug.Print "no hDC"
    If (Transparent = True) Then
        Dim BF As Long
        Const USE_BITMAP_ALPHA = &H1000000 'AC_SRC_ALPHA scaled up to the 4th byte of a long
        BF = 128 * &H10000  'semi transparent ignoring bitmaps alpha channel
        BF = 255 * &H10000 Or USE_BITMAP_ALPHA 'fully opaque using bitmaps alpha channel
        Dim btMap As BITMAP
        If (GetObject(ImageBitmap, Len(btMap), btMap) = 0) Then Debug.Print "error"
        Dim s As BITMAPINFO
        Dim BytesPerScanLine As Long
        s.bmiHeader.biSize = 40
        s.bmiHeader.biPlanes = 1
        s.bmiHeader.biBitCount = 24
        s.bmiHeader.biHeight = height
        s.bmiHeader.biWidth = width
        s.bmiHeader.biPlanes = btMap.bmPlanes
        s.bmiHeader.biCompression = 0
        BytesPerScanLine = ((s.bmiHeader.biWidth * 3) + 3) And &HFFFFFFFC
        s.bmiHeader.biSizeImage = BytesPerScanLine * s.bmiHeader.biHeight
        Dim ImageData() As Byte
        ReDim ImageData(3, s.bmiHeader.biWidth, s.bmiHeader.biHeight)
        GetDIBits ImageHDC, ImageBitmap, 0, s.bmiHeader.biHeight, ImageData(0, 0, 0), s, 0
       
        If (ImageData(0, 0, 0) = 0) Then 'testing if have a alpha value
            AlphaBlend DestinationHDC, 0, 0, width, height, ImageHDC, 0, 0, width, height, BF
        Else
            TransparentBlt DestinationHDC, 0, 0, width, height, ImageHDC, 0, 0, width, height, GetPixel(ImageHDC, 0, 0)
        End If
    Else
        BitBlt DestinationHDC, 0, 0, width, height, ImageHDC, 0, 0, vbSrcCopy
    End If
   
    'DrawIconEx DestinationHDC, 0, 0, CurAni, 0, 0, 0, 1, DI_NORMAL Or DI_IMAGE 'works
End Sub

the DrawIconEx() don't give me any error. so why the cursor isn't drawed on Memory DC?
(on form is drawed, i had tested)

How to create Animated GIFs

$
0
0
Hey everyone, I just wanted to say that VBforums is awesome! Out of every online community I have been in, this one has been the most supportive. Thanks!

Anyway, I have been trying for a couple of days now at work to compile a series of images into an animated GIF using the GDI+ library. I don't have access to any other image processing libraries so if at all possible I'd like to stick to using that one. I am putting together a program to automate some on screen actions in a 3D program and take screen shots at the same time. Those screen shots are saved to the Hard drive and are named chronologically. So far this functionality has been developed and is working well.

At this point though I am not sure what to do. I have seen some online examples in C# using the GDI+ library but I don't understand it. I have been studying and testing portions of code from the following link:

http://www.dreamincode.net/forums/to...ssing-program/

Specifically the Assemble() subroutine where according to the author is where the animated GIF is made (Below it can be viewed).

There is miscellaneous code in there pertaining to Form controls, but besides those, it seems like the images are being looped through one at a time and being opened with BinaryWriter, and eventually saved to a MemoryStream in the format of a GIF. At the end of the subroutine it looks like the compiled GIF is displayed in a PictureBox form control. At least this is what I gathered so far.

I don't quite understand how the image is being assembled though. I have never used MemoryStream or BinaryWriter before and it looks the image is saved to MemoryStream before it's finally displayed. Also, what are the Bytes data type for and what does that accomplish?

Can somebody help me make sense of what is going on this code. Is this going to help me create and save an animated GIF with my screenshots or should I resort to using something else?

Thank you for your time.

Code:

    Public Sub Assemble(ByVal But As Integer)
        Me.Cursor = Cursors.WaitCursor
        'Variable declaration
        Dim memoryStream As MemoryStream
        Dim binaryWriter As BinaryWriter
        Dim image As Image
        Dim buf1 As [Byte]()
        Dim buf2 As [Byte]()
        Dim buf3 As [Byte]()
        memoryStream = New MemoryStream()
        buf2 = New [Byte](18) {}
        buf3 = New [Byte](7) {}
        buf2(0) = 33
        'extension introducer
        buf2(1) = 255
        'application extension
        buf2(2) = 11
        'size of block
        buf2(3) = 78
        'N
        buf2(4) = 69
        'E
        buf2(5) = 84
        'T
        buf2(6) = 83
        'S
        buf2(7) = 67
        'C
        buf2(8) = 65
        'A
        buf2(9) = 80
        'P
        buf2(10) = 69
        'E
        buf2(11) = 50
        '2
        buf2(12) = 46
        '.
        buf2(13) = 48
        '0
        buf2(14) = 3
        'Size of block
        buf2(15) = 1
        '
        buf2(16) = 0
        '
        buf2(17) = 0
        '
        buf2(18) = 0
        'Block terminator
        buf3(0) = 33
        'Extension introducer
        buf3(1) = 249
        'Graphic control extension
        buf3(2) = 4
        'Size of block
        buf3(3) = 9
        'Flags: reserved, disposal method, user input, transparent color
        buf3(4) = 10 ' 88
        If ckSlide.Checked = True Then
            'Delay time low byte
            buf3(5) = 1
            'Delay time high byte
            buf3(6) = 0
        Else
            'Delay time low byte
            buf3(5) = 0 '1
            'Delay time high byte
            buf3(6) = 255
        End If

        'Transparent color index
        buf3(7) = 0
        'Block terminator

        NewName = GetNewName1()
        lbOutput.Text = NewName
        binaryWriter = New BinaryWriter(File.Open(NewName, FileMode.Create))

        For picCount As Integer = 0 To ImageArray.Count - 1 'stringCollection.Count - 1

            Select Case But
                Case 1
                    'Animate
                    image = Bitmap.FromFile(ImageArray(picCount))
                    If ckDark.Checked = True Then image = Dark(image)
                    If rbSepiaTone.Checked = True Then image = Sepia(image)
                    If rbGrayScale.Checked = True Then image = Grayscale(image)
                    If ckGhost.Checked = True Then Ghost(image)
                    If ckFlip.Checked = True Then image.RotateFlip(RotateFlipType.RotateNoneFlipX)
                Case 2
                    If MemPic IsNot Nothing Then
                        image = MemPic(picCount)
                        If ckDark.Checked = True Then image = Dark(image)
                        If rbSepiaTone.Checked = True Then image = Sepia(image)
                        If rbGrayScale.Checked = True Then image = Grayscale(image)
                        If ckGhost.Checked = True Then Ghost(image)
                        If ckFlip.Checked = True Then image.RotateFlip(RotateFlipType.RotateNoneFlipX)
                    Else
                        MessageBox.Show("Please Select Something")
                    End If

            End Select
            image.Save(memoryStream, ImageFormat.Gif)
            buf1 = memoryStream.ToArray()

            If picCount = 0 Then
                'only write these the first time....
                binaryWriter.Write(buf1, 0, 781)
                'Header & global color table
                'Application extension
                binaryWriter.Write(buf2, 0, 19)
            End If
            binaryWriter.Write(buf3, 0, 8)
            'Graphic extension
            binaryWriter.Write(buf1, 781, buf1.Length - 782)
            'Image data
            ' If picCount = stringCollection.Count - 1 Then
            If picCount = ImageArray.Count - 1 Then
                'only write this one the last time....
                'Image terminator
                binaryWriter.Write(";")
            End If


            memoryStream.SetLength(0)
            Progress.Value = 100 * picCount / ImageArray.Count
        Next

        binaryWriter.Close()
        pbSelect.Invalidate()
        memoryStream.Close()
        Me.Cursor = Cursors.Default
        pbSelect.Image = image.FromFile(ImageArray(N))
        pbSelect.Refresh()
        Progress.Value = 0
    End Sub

[VB 6] I want make a project to can read PSD File and show layers in transparent form in vb6

$
0
0
hi.

I want make a project to can read PSD File and show layers in transparentform in vb6.any way ?


for example i have 2 layer in PSD File and their name are Button and Button_Over,so i want read two layers and show in transparent form and when i move my mouse on button

layer,show Button_over layer on it.

I found samples to can read psd file and show layers on form but cant show on transparent form?

The Fun Games Created With Excel VBA Codes

$
0
0
There are three games in three separate workbooks:
1. Tetris
2. Find Matches
3. Rocket

Attached Files

Where's all the threads

$
0
0
I only see 3 threads not counting this one

EDIT

Never mind. I see what the reason was

I would like for my spaceship to face in the proper direction

$
0
0
This is what I have so far. If you click anywhere, the spaceship will rotate 90 degrees. What I am trying to do is a little confusing. I want the player to be able to click anywhere around the spaceship.

If the player clicks above and to the right, then I want the spaceship to face up or right. If it faces up or right, then the facing direction depends on what was further in the click (x or y). If the player clicked further right then up, then the ship will face right, if the player clicked further up then right, then the ship should face up.

How can I do this?

Spaceship image
Name:  spaceship.gif
Views: 41
Size:  988 Bytes

Code:

Public Class Form1


    Dim bm As New Bitmap("spaceship.gif")


    Dim spaceshipx As Integer = 250
    Dim spaceshipy As Integer = 250


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


    End Sub


    Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
        e.Graphics.DrawImage(bm, spaceshipx - 16, spaceshipy - 16)
    End Sub


    Private Sub PictureBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseDown
        bm.RotateFlip(RotateFlipType.Rotate90FlipNone)
        PictureBox1.Invalidate()
    End Sub
End Class

Attached Images
 

[VB.NET] [RESOLVED] transform a sprite to move with the camera

$
0
0
Edit,
Nm, I have this fixed. I dropped the sprites and simply drawing everything using vertexBuffers.


Hey all,
I have an app that currently uses GDI to drawing pdf page renderings (images) and it provides markup tools so the user can modify the pdf docs. This has been working great until I was handed a 5000px X 3000px image with 40-50 markups. This kind of made GDI snort cough and gag.

I've start moving that portion of the app to DirectX (because I have some (a little) experience with it). To draw the original image I have created a quad on the XY plane (z=0) and use the image to create a texture. When I draw the quad, I set the texture and draw the image. This works great. I have also implement pan and zoom which basically moves the camera around. To pan, I move the camera in a plane parallel to the XY plane. To zoom I simply change the camera's Z coordinate. This all works fine.

To place the markups in the drawing, I have created a sprite wrapper that contains the location and texture for the markup (the texture is created from an image made using GDI). When it comes time to draw the markups, I use a single sprite, call the its Draw method and pass the texture, and location. This too works but it's drawing the sprites in screen coordinates, not in world coordinates, so I believe they need to be transformed, but I don't know how.

Can some explain to me how I need to transform my sprites so they go where I need them to be?

Here is vb.net code I'm using to draw the sprite. It gets called from the game loop. I am using vb.net, but I can translate from just about any other language (c++ no so good, but I'll give it a go if need be).


VB.net Code:
  1. Private Sub DrawSprite(ByVal _wrapper As spriteWrapper)
  2.        
  3.         Static mSprite As New Sprite(device)
  4.      
  5.         mSprite.Begin(SpriteFlags.None)
  6.  
  7.         Dim center As Vector3 = New Vector3(0.0F, 0.0F, 0.0F) 'the upper left corner of the sprite is 0,0
  8.         Dim position As Vector3 = New Vector3(_wrapper.Location.X, _wrapper.Location.Y, 0)
  9.  
  10.         mSprite.Draw(_wrapper.texture,
  11.                    Rectangle.Empty,
  12.                    center,
  13.                    position,
  14.                    Color.White)
  15.  
  16.         mSprite.End()
  17.     End Sub

Thanks for looking!
kevin

[VB.NET] Setting up an array to show multiple layers of graphics

$
0
0
Hello, to start off i am a student in a Visual basic programming class, so im pretty new to VB and coding in general. For an assignment we have to recreate a game or create a new game, and i decided to do a simple version of an old favorite of mine, Advance Wars. It is similar to fire emblem or many other turn based strategy games in mechanics. So far i have created a picturebox array and set the background image of the pictureboxes to be the grass background that i made, and i couldnt figure out how to put the buildings and environment images on top of the grass background, so i set up specific for loops setting the tiles i wanted to the image i wanted, which works decently well, but im not sure how i can put soldiers and other units onto the battlefield and allow them movement without changing the tiles that are in the background like the grass or buildings. I tried setting the array as a 3d array and putting the soldiers on the highest z coordinate, but it didnt appear to do anything. I looked up this post: http://www.vbforums.com/showthread.p...rs-of-graphics and tried to implement XNA into my project, but im not really sure how XNA works or how i should change what i currently have to work with XNA. I'm sorry if i don't explain everything very well, im not really sure what i should say because i havent really done this before. Is there an easier way to code what im trying to do, or is learning XNA and using it the easiest way to do this? This is what i have as far as the code is concerned:

Code:

Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Graphics
Imports Microsoft.Xna.Framework.Input


Public Class Game1
    Inherits System.Windows.Forms.Form

    Dim Grid(,,) As Cell



    Private Sub Game1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.Show()
        Me.Focus()
        Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        Me.WindowState = FormWindowState.Maximized
     
        'Setting Up Array
        ReDim Grid(15, 9, 2)
        For x = 0 To 15
            For y = 0 To 9
                For z = 1 To 1
                    'MessageBox.Show(x & " " & y)
                    Grid(x, y, z) = New Cell
                    AddHandler Grid(x, y, z).Click, AddressOf TileSelect_click
                    Grid(x, y, z).Height = 90
                    Grid(x, y, z).Width = 90
                    Grid(x, y, z).Top = y * 90
                    Grid(x, y, z).Left = x * 90
                    Me.Controls.Add(Grid(x, y, z))
                    Grid(x, y, z).BackgroundImageLayout = ImageLayout.Stretch
                    'Grid(x, y, z).BackColor = Color.LawnGreen
                    Grid(x, y, z).BackgroundImage = My.Resources.Grass_Texture_v2
                    'Grid(x, y, z).City = True
                Next
            Next
        Next

        'Blue Buildings
        For x = 1 To 1
            For y = 1 To 1
                For z = 1 To 1

                    Grid(x, y, z).BackgroundImageLayout = ImageLayout.Stretch
                    Grid(x, y, z).BackgroundImage = My.Resources.Blue_Capital_Grass
                    Grid(x, y, z).Blue = True
                    Grid(x, y, z).Capital = True
                Next
            Next
        Next
        For x = 0 To 1
            For y = 0 To 0
                For z = 1 To 1
                    Grid(x, y, z).BackgroundImageLayout = ImageLayout.Stretch
                    Grid(x, y, z).BackgroundImage = My.Resources.Blue_City_Grass
                    Grid(x, y, z).Blue = True
                    Grid(x, y, z).City = True
                Next
            Next
        Next
        For x = 0 To 0
            For y = 2 To 2
                For z = 1 To 1

                    Grid(x, y, z).BackgroundImageLayout = ImageLayout.Stretch
                    Grid(x, y, z).BackgroundImage = My.Resources.Blue_City_Grass
                    Grid(x, y, z).Blue = True
                    Grid(x, y, z).City = True
                Next
            Next
        Next
        For x = 2 To 2
            For y = 1 To 2
                For z = 1 To 1

                    Grid(x, y, z).BackgroundImageLayout = ImageLayout.Stretch
                    Grid(x, y, z).BackgroundImage = My.Resources.Blue_Factory_Grass
                    Grid(x, y, z).Blue = True
                    Grid(x, y, z).Factory = True
                Next
            Next
        Next


        'Red Buildings
        For x = 14 To 14
            For y = 8 To 8
                For z = 1 To 1
                    Grid(x, y, z).BackgroundImageLayout = ImageLayout.Stretch
                    Grid(x, y, z).BackgroundImage = My.Resources.Red_Capital_Grass
                    Grid(x, y, z).Red = True
                    Grid(x, y, z).Capital = True
                Next
            Next
        Next
        For x = 14 To 15
            For y = 9 To 9
                For z = 1 To 1

                    Grid(x, y, z).BackgroundImageLayout = ImageLayout.Stretch
                    Grid(x, y, z).BackgroundImage = My.Resources.Red_City_Grass
                    Grid(x, y, z).Red = True
                    Grid(x, y, z).City = True
                Next
            Next
        Next
        For x = 15 To 15
            For y = 7 To 7
                For z = 1 To 1

                    Grid(x, y, z).BackgroundImageLayout = ImageLayout.Stretch
                    Grid(x, y, z).BackgroundImage = My.Resources.Red_City_Grass
                    Grid(x, y, z).Red = True
                    Grid(x, y, z).City = True
                Next
            Next
        Next
        For x = 13 To 13
            For y = 7 To 8
                For z = 1 To 1
                    Grid(x, y, z).BackgroundImageLayout = ImageLayout.Stretch
                    Grid(x, y, z).BackgroundImage = My.Resources.Red_Factory_Grass
                    Grid(x, y, z).Red = True
                    Grid(x, y, z).Factory = True
                Next
            Next
        Next

        'Neutral Buildings
        For x = 7 To 7
            For y = 4 To 4
                For z = 1 To 1
                    Grid(x, y, z).BackgroundImageLayout = ImageLayout.Stretch
                    Grid(x, y, z).BackgroundImage = My.Resources.Open_Factory_Grass
                    Grid(x, y, z).Neutral = True
                    Grid(x, y, z).Factory = True
                Next
            Next
        Next
        For x = 6 To 6
            For y = 3 To 3
                For z = 1 To 1
                    Grid(x, y, z).BackgroundImageLayout = ImageLayout.Stretch
                    Grid(x, y, z).BackgroundImage = My.Resources.Open_City_Grass
                    Grid(x, y, z).Neutral = True
                    Grid(x, y, z).City = True
                Next
            Next
        Next
        For x = 8 To 8
            For y = 5 To 5
                For z = 1 To 1
                    Grid(x, y, z).BackgroundImageLayout = ImageLayout.Stretch
                    Grid(x, y, z).BackgroundImage = My.Resources.Open_City_Grass
                    Grid(x, y, z).Neutral = True
                    Grid(x, y, z).City = True
                Next
            Next
        Next

        'Environment
        For x = 5 To 9
            For y = 2 To 2
                For z = 1 To 1
                    Grid(x, y, z).BackgroundImageLayout = ImageLayout.Stretch
                    Grid(x, y, z).BackgroundImage = My.Resources.Mountain_Texture_Grass
                    Grid(x, y, z).Mountain = True
                Next
            Next
        Next
        For x = 5 To 9
            For y = 6 To 6
                For z = 1 To 1
                    Grid(x, y, z).BackgroundImageLayout = ImageLayout.Stretch
                    Grid(x, y, z).BackgroundImage = My.Resources.Mountain_Texture_Grass
                    Grid(x, y, z).Mountain = True
                Next
            Next
        Next
        For x = 9 To 9
            For y = 3 To 5
                For z = 1 To 1
                    Grid(x, y, z).BackgroundImageLayout = ImageLayout.Stretch
                    Grid(x, y, z).BackgroundImage = My.Resources.Trees_Texture_Grass
                    Grid(x, y, z).Trees = True
                Next
            Next
        Next
        For x = 5 To 5
            For y = 3 To 5
                For z = 1 To 1
                    Grid(x, y, z).BackgroundImageLayout = ImageLayout.Stretch
                    Grid(x, y, z).BackgroundImage = My.Resources.Trees_Texture_Grass
                    Grid(x, y, z).Trees = True
                Next
            Next
        Next


    Private Sub TileSelect_click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim MyTile As Cell = sender
        If MyTile.Factory = True Then
            ReDim Grid(15, 9, 0)

            For x = 3 To 3
                For y = 1 To 1
                    For z = 0 To 0

                        Grid(x, y, z) = New Cell
                        Grid(x, y, z).BackgroundImageLayout = ImageLayout.Stretch
                        Grid(x, y, z).Image = My.Resources.Blue_Soldier
                        Grid(x, y, z).Soldier = True
                        MessageBox.Show("Soldier Created")
                    Next
                Next
            Next

        End If
        If MyTile.Capital = True Then
            MessageBox.Show("This is a Capital")
        End If
    End Sub

End Class

I have the Cell Class which just inherits PictureBox and then declares Booleans for what the tiles are, like .Red or .Soldier

Again im sorry im so new, i know some of VB, and therefore some understanding of C#, but i know nothing about XNA or how it works. How i want the game to function in the end is a turn based strategy game where each player get an amount of funds per turn, which is based on the number of buildings they own, which they can spend at factories to purchase units varying in cost and power (total of 4 units: Infantry, Recon, Artillery, Tank). The main goal is to take over the enemy player's Capital building. Buildings can be taken over by infantry. The battle system works on a system where each unit starts at 10 health and deals damage based on the weapon they have and the armor/lack of armor of their opponent. Thanks for any help.

GDIPLUS: how draw the point Z?

$
0
0
it's easy using\draw the X and Y points. but i don't understand how i can draw the Z. can anyone explain to me how can i draw the point Z?
(i never used the Z and i didn't learned from school)

GDIPLUS: how we draw dots above a line?

$
0
0
how we can draw dots across a line?
see the image:
Name:  pontos nas coordenadas.jpg
Views: 16
Size:  30.6 KB
like you see the red dots(are ellipses) aren't above the line, unless i resize the form.
heres the code:
Code:

Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        SetStyle(ControlStyles.ResizeRedraw, True)
    End Sub

    Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim s As Graphics = e.Graphics
        s.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
        s.DrawLine(Pens.Black, New Point(0, 0), New Point(Me.ClientSize.Width, Me.ClientSize.Height))
        s.DrawLine(Pens.Black, New Point(CInt(Me.ClientSize.Width / 2), 0), New Point(CInt(Me.ClientSize.Width / 2), Me.ClientSize.Height))
        s.DrawLine(Pens.Black, New Point(0, CInt(Me.ClientSize.Height / 2)), New Point(Me.ClientSize.Width, CInt(Me.ClientSize.Height / 2)))
        Dim x As Integer = 0
        For y As Integer = 0 To Me.ClientSize.Height Step 10
            'For x As Integer = 0 To Me.ClientSize.Width Step 10

            s.FillEllipse(Brushes.Red, New Rectangle(CInt(x - (10 / 2) + 1), CInt(y - (10 / 2) + 1), 9, 9))
            x += 22
            'Next
        Next
    End Sub

how can i correct the calculation?
Attached Images
 

GDIPLUS: can i rotate on diferent way?

$
0
0
using Matrix.RoateAt(), we can rotate the image like the clock.
but we can rotate on horizontal and vertical way?

[RESOLVED] GDIPLUS: how we draw dots above a line?

$
0
0
how we can draw dots across a line?
see the image:
Name:  pontos nas coordenadas.jpg
Views: 190
Size:  30.6 KB
like you see the red dots(are ellipses) aren't above the line, unless i resize the form.
heres the code:
Code:

Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        SetStyle(ControlStyles.ResizeRedraw, True)
    End Sub

    Private Sub Form1_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim s As Graphics = e.Graphics
        s.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
        s.DrawLine(Pens.Black, New Point(0, 0), New Point(Me.ClientSize.Width, Me.ClientSize.Height))
        s.DrawLine(Pens.Black, New Point(CInt(Me.ClientSize.Width / 2), 0), New Point(CInt(Me.ClientSize.Width / 2), Me.ClientSize.Height))
        s.DrawLine(Pens.Black, New Point(0, CInt(Me.ClientSize.Height / 2)), New Point(Me.ClientSize.Width, CInt(Me.ClientSize.Height / 2)))
        Dim x As Integer = 0
        For y As Integer = 0 To Me.ClientSize.Height Step 10
            'For x As Integer = 0 To Me.ClientSize.Width Step 10

            s.FillEllipse(Brushes.Red, New Rectangle(CInt(x - (10 / 2) + 1), CInt(y - (10 / 2) + 1), 9, 9))
            x += 22
            'Next
        Next
    End Sub

how can i correct the calculation?
Attached Images
 

Fishing Program

$
0
0
I'm just a fan of fishing and would like to create a game. I already have a plan of it. Which is the next step?

Approaching a MOO 1 style game - Ways to do a map and place stars

$
0
0
Anyway if you aren't familiar with Masters of Orion 1, it uses a 2D map of space with stars spread randomly around. Although it shows stars in all practical terms the stars are actually planets that may or may not be habitable.

The game map can be several sizes (24 to 100+ stars). When performing your turn you see only a portion of the entire game map (basically zoomed in so you can see details) then when the game is processing your commands and figuring out what the Computer players are doing it displays the entire map with ship movement etc being displayed. You can also get the zoomed out view during your turn by hitting the "Map" button. Clicking on stars/ships displays its details in a sidebar.

Everything on the map is clickable and when you do click on a star, ship, monster, whatever, it switches back to the zoomed in view with the clicked item centered and highlighted (or close enough to centered if the object was on the edges of the map).

Navigating around the map is done by simply clicking near the edges and the view slides in that direction.

Ships in the game travel in a straight line between stars and distances are calculated as the crow flies, not by any kind of grid cell counts though there is obviously some form of grid use when it comes to star placements.

So I'm looking for suggestions on how to achieve this kind of 2D graphics functionality (not necessarily code, just point to examples/write ups/whatever you think would be useful). I'm flying blind as I've never even attempted something in the 2D map realm, its all a mystery at the moment.

As an example, how to place stars and ships and make them selectable?. Should I have some sort in internal grid (math only) for placements? Something like a grid where the click position is divided by the number of cells which gives an index to look up data (either X/Y or a single dimension calculated by an X index and adding Y * XMax (e.g. one row has 200 positions, clicking in the area of the first row gives X + 0, second row gives X + 200, third X + 400, you get the idea). Or am I barking up the wrong tree entirely?

Next is the map graphic - sticking a picture in a scrolling picture box is probably not going to cut it (though it might, this is just my assumption).

I found an old bit of source for a similar game and it used Gorgon library (which I believe is the same idea as XNA/Monoplay). I get the feeling I should probably look into some form of library for 2D games. Anyone have a favorite?

I'll stop babbling now. Looking forward to any suggestions people may have!

[VB.NET] I'm porting the HoloToolKit to VB.NET, is it worth it? [WORK IN PROGRESS]

$
0
0
If you guys haven't heard Microsoft has started its Mixed Reality journey with Hololens and the open-source library HoloToolKit. Unfortunately, Unity doesn't support VB as a scripting language although there may be some hope as they transition to .NET Standard in the future. In the meantime, I've decided to port the HoloToolKit to VB. But there is a lot of code that needs to be ported to class libraries that can only target .NET Framework 3.5. Do you have thoughts on whether of not this is worth the investment? After all, Microsoft is adding new code to the repository all the time, but it is all in C#. All Unity tutorials are in C# as well. It would be extremely difficult to keep up with it if I don't have some outside help. This was the only Visual Basic forum I could find, so I could use all the helping hands I could get. I don't want to mix C# scripts with VB dlls either. Any thoughts on how to proceed?

The original HoloToolKit (written in C#): https://github.com/microsoft/HoloToolkit-Unity

Here's my fork of the HoloToolKit (re-written in VB class libraries): https://github.com/dvdalimi/HoloToolkit-Unity-VB/wiki

I have a problem getting this raycasting example to work

$
0
0
First of all, I am copying lodevs c++ tutorial on raycasting. I got it to work partway, but my inexperience got me stuck in several different points. I'm posting the code here. You will need a picturebox and a timer to get this to run. It is a windows forms application.

If you run it and use the w-a-s-d keys, turn left and right a couple of key presses. You will notice that there is an anomaly and the room is not rendered the way it is in the map array. I don't know why.
Another problem I have, is that I did not correctly copy the timing routine from lodevs example. I'm not sure how to set that up in visual basic. So I am using a timer for the steps. I am guessing that maybe because its exactly 100 milliseconds between ticks, that i get the the artifacts. How can I fix this. i understand that this is a big question and that it takes considerable knowledge to perhaps get this going, but maybe there is an expert here that knows 3D graphics. As for Visual Basic, I initially noticed that in raycasting, the example's performance is really good. So it is a possible project, that I would like to take further once I understand this.

Since it's my first post, I think I shouldn't post a link. Just google "Lodev's raycasting" graphics tutorial and it should come up with the C++ example webpage so you can compare my effort.

Thank you.

Code:

Public Class frmMain
    Dim w As Integer = 512
    Dim h As Integer = 384


    Const mapWidth As Integer = 23
    Const mapHeight As Integer = 23


    Dim worldMap(mapWidth, mapHeight) As Integer


    Dim posX As Double = 22
    Dim posY As Double = 12
    Dim dirX As Double = -1
    Dim dirY As Double = 0
    Dim planeX As Double = 0
    Dim planeY As Double = 0.66


    Dim backbuffer As New Bitmap(w, h)
    Dim g_backbuffer As Graphics = Graphics.FromImage(backbuffer)


    Private Sub frmMain_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
        Init()


        myTimer.Interval = 100
        myTimer.Start()
    End Sub


    Private Sub Init()
        worldMap = {{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
                    {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 0, 0, 0, 0, 0, 0, 4, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 0, 0, 0, 0, 0, 0, 4, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 0, 0, 0, 0, 0, 0, 4, 0, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
                    {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}}
    End Sub


    Dim s As New Stopwatch


    Private Sub GameLoop()
        g_backbuffer.Clear(Color.Black)
        For x As Integer = 0 To w - 1
            Dim cameraX As Double = 2 * x / w - 1
            Dim rayPosX As Double = posX
            Dim rayPosY As Double = posY
            Dim rayDirX As Double = dirX + planeX * cameraX
            Dim rayDirY As Double = dirY + planeY * cameraX


            Dim mapX As Integer = CInt(rayPosX)
            Dim mapY As Integer = CInt(rayPosY)


            Dim sideDistX As Double
            Dim sideDistY As Double


            Dim deltaDistX As Double = Math.Sqrt(1 + (rayDirY * rayDirY) / (rayDirX * rayDirX))
            Dim deltaDistY As Double = Math.Sqrt(1 + (rayDirX * rayDirX) / (rayDirY * rayDirY))
            Dim perpWallDist As Double


            Dim stepX As Integer
            Dim stepY As Integer


            Dim hit As Integer = 0
            Dim side As Integer


            If rayDirX < 0 Then
                stepX = -1
                sideDistX = (rayPosX - mapX) * deltaDistX
            Else
                stepX = 1
                sideDistX = (mapX + 1.0 - rayPosX) * deltaDistX
            End If
            If rayDirY < 0 Then
                stepY = -1
                sideDistX = (rayPosY - mapY) * deltaDistY
            Else
                stepY = 1
                sideDistY = (mapY + 1.0 - rayPosY) * deltaDistY
            End If


            While hit = 0
                If sideDistX < sideDistY Then
                    sideDistX += deltaDistX
                    mapX += stepX
                    side = 0
                Else
                    sideDistY += deltaDistY
                    mapY += stepY
                    side = 1
                End If
                If worldMap(mapX, mapY) > 0 Then
                    hit = 1
                End If
            End While
            If side = 0 Then
                perpWallDist = (mapX - rayPosX + (1 - stepX) / 2) / rayDirX
            Else
                perpWallDist = (mapY - rayPosY + (1 - stepY) / 2) / rayDirY
            End If


            Dim lineHeight As Integer = CInt(h / perpWallDist)


            Dim drawStart As Double = -lineHeight / 2 + h / 2
            If drawStart < 0 Then
                drawStart = 0
            End If
            Dim drawEnd As Double = lineHeight / 2 + h / 2
            If drawEnd >= h Then
                drawEnd = h - 1
            End If


            Dim colr As Color
            Select Case worldMap(mapX, mapY)
                Case 1
                    colr = Color.Red
                Case 2
                    colr = Color.Green
                Case 3
                    colr = Color.Blue
                Case 4
                    colr = Color.White
                Case Else
                    colr = Color.Yellow
            End Select


            If side = 1 Then
                colr = Color.FromArgb(colr.R \ 2, colr.G \ 2, colr.B \ 2)
            End If


            g_backbuffer.DrawLine(New Pen(colr), x, CInt(drawStart), x, CInt(drawEnd))
        Next
    End Sub


    Dim moveSpeed As Double
    Dim rotSpeed As Double


    Private Sub pbView_Paint(sender As Object, e As PaintEventArgs) Handles pbView.Paint
        e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
        e.Graphics.PixelOffsetMode = Drawing2D.PixelOffsetMode.Half
        e.Graphics.DrawImage(backbuffer, 0, 0)
    End Sub


    Private Sub frmMain_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
        Select Case e.KeyCode
            Case Keys.W
                If worldMap(CInt(posX + dirX * moveSpeed), CInt(posY)) = 0 Then
                    posX += dirX * moveSpeed
                End If
                If worldMap(CInt(posX), CInt(posY + dirY * moveSpeed)) = 0 Then
                    posY += dirY * moveSpeed
                End If
                pbView.Invalidate()
            Case Keys.S
                If worldMap(CInt(posX - dirX * moveSpeed), CInt(posY)) = 0 Then
                    posX -= dirX * moveSpeed
                End If
                If worldMap(CInt(posX), CInt(posY - dirY * moveSpeed)) = 0 Then
                    posY -= dirY * moveSpeed
                End If
            Case Keys.D
                Dim oldDirX As Double = dirX
                dirX = dirX * Math.Cos(-rotSpeed) - dirY * Math.Sin(-rotSpeed)
                dirY = oldDirX * Math.Sin(-rotSpeed) + dirY * Math.Cos(-rotSpeed)
                Dim oldPlaneX As Double = planeX
                planeX = planeX * Math.Cos(-rotSpeed) - planeY * Math.Sin(-rotSpeed)
                planeY = oldPlaneX * Math.Sin(-rotSpeed) + planeY * Math.Cos(-rotSpeed)
            Case Keys.A
                Dim oldDirX As Double = dirX
                dirX = dirX * Math.Cos(rotSpeed) - dirY * Math.Sin(rotSpeed)
                dirY = oldDirX * Math.Sin(rotSpeed) + dirY * Math.Cos(rotSpeed)
                Dim oldPlaneX As Double = planeX
                planeX = planeX * Math.Cos(rotSpeed) - planeY * Math.Sin(rotSpeed)
                planeY = oldPlaneX * Math.Sin(rotSpeed) + planeY * Math.Cos(rotSpeed)
        End Select
    End Sub


    Private Sub myTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles myTimer.Tick
        moveSpeed = 1.0
        rotSpeed = 1.0
        GameLoop()
        pbView.Invalidate
    End Sub
End Class

[VB 6] [Partially resolved, only audio issues remaining] Flashing Sprites Non-Async .WAV

$
0
0
Having issues with sprites flickering and flashing and whatnot. I'd like to pay a consultant to help me wrap my head around BitBlt, or a more simple approach.

Is there a 3rd party imagebox control which acts the same as a VB6 picture but doesn't cause flicker when moved across the screen with a timer?

Yesterday I made my first VB6 "game" for my friend Courtney in which you jump over coconuts. It's called coconut jumper, a creative name I'm sure you're all very impressed with. I'd use .NET but I'm old, stubborn and .NET can get off my lawn.

Anyway, here's that:



I started looking into this and came across FireXol's BitBlt tutorial, but I'm not entirely sure I understand it.



There appear to be two images for each image in order to make the image draw out as transparent. One with a black background and another with white. Is this standard practice?

How would walking animation be achieved, as seen in Coconut Jumper?

Also, are there any cut and dry examples of true async WAV playing? For example, I was unable to add a "jumping" sound effect to play over the background music without stopping the background music from playing. I used the following for audio:

Code:

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
To play:

Code:

PlaySound App.Path & "\assets\music.wav", ByVal 0&, SND_ASYNC
To stop the WAV on Form_Unload:

Code:

PlaySound App.Path & "\assets\music.wav", ByVal 0&, SND_MEMORY
For good measure here is most of the source to Coconut Jumper to give you a better understanding of my skills or lackthereof. I removed " tmrCoconut2_Timer()" to make it fit ITT because it's basically just a copy of tmrCoconut_Timer(). I also left out the Module code which contains

Code:

Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
and code for random number generation (RandomNum)

Code:

Option Explicit
 
Private Const SND_APPLICATION = &H80        ' look for application specific association
Private Const SND_ALIAS = &H10000    ' name is a WIN.INI [sounds] entry
Private Const SND_ALIAS_ID = &H110000    ' name is a WIN.INI [sounds] entry identifier
Private Const SND_ASYNC = &H1        ' play asynchronously
Private Const SND_FILENAME = &H20000    ' name is a file name
Private Const SND_LOOP = &H8        ' loop the sound until next sndPlaySound
Private Const SND_MEMORY = &H4        ' lpszSoundName points to a memory file
Private Const SND_NODEFAULT = &H2        ' silence not default, if sound not found
Private Const SND_NOSTOP = &H10        ' don't stop any currently playing sound
Private Const SND_NOWAIT = &H2000      ' don't wait if the driver is busy
Private Const SND_PURGE = &H40              ' purge non-static events for task
Private Const SND_RESOURCE = &H40004    ' name is a resource name or atom
Private Const SND_SYNC = &H0        ' play synchronously (default)
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Dim flag As Boolean

Dim bgMove As Integer
Dim spriteMove As Integer
Dim spritePosition As Integer
Dim isJumpingDown As Boolean
Dim coconutsJumped As Integer
Dim isWalkingLeft As Boolean
Dim throwIt As Boolean
Dim currentVariation As Integer

Private Sub Form_Load()
   
    currentVariation = 1
    Me.Width = 6410
    Me.Height = 10110
    imgIntro.Top = 0
    spritePosition = 1
    Set imgSprite.Picture = LoadPicture(App.Path & "\assets\" & spritePosition & ".gif")
    Set imgCoconut.Picture = LoadPicture(App.Path & "\assets\coconut.gif")
    Set imgCoconut2.Picture = LoadPicture(App.Path & "\assets\coconut.gif")
    Set imgSpacebar.Picture = LoadPicture(App.Path & "\assets\spacebar1.gif")
    Set imgArrow.Picture = LoadPicture(App.Path & "\assets\arrow1.gif")
    PlaySound App.Path & "\assets\i.wav", ByVal 0&, SND_ASYNC

End Sub

Private Sub lblTryAgain_Click()

    imgCoconut.Left = 10920
    imgCoconut2.Left = 10920
    lblGameOver.Caption = ""
    lblJumped.Caption = "c o c o n u t s  j u m p e d : 0"
    coconutsJumped = 0
    Set imgCoconut.Picture = LoadPicture(App.Path & "\assets\coconut.gif")
    Set imgCoconut2.Picture = LoadPicture(App.Path & "\assets\coconut.gif")
    tmrSpinCoconuts.Enabled = True
    tmrLoadCoconut2.Enabled = True
    tmrSprite.Enabled = True
    tmrCoconut.Enabled = True
    tmrLoadCoconut2.Enabled = True
    lblTryAgain.Visible = False
    PlaySound App.Path & "\assets\music.wav", ByVal 0&, SND_ASYNC
   
End Sub

Private Sub tmrBG_Timer()


    If imgBG.Left > -26800 Then
        imgBG.Left = imgBG.Left - 100
    Else
        imgBG.Left = 0
        bgMove = 0
    End If
    spriteMove = spriteMove + 1
    If spriteMove > 3 Then
        spriteMove = 0
        If spritePosition < 4 Then
            spritePosition = spritePosition + 1
            Set imgSprite.Picture = LoadPicture(App.Path & "\assets\" & spritePosition & ".gif")
        Else
            spritePosition = 1
            Set imgSprite.Picture = LoadPicture(App.Path & "\assets\" & spritePosition & ".gif")
        End If
    End If

End Sub

Private Sub tmrCoconut_Timer()

    If throwIt = True Then
        If imgCoconut.Left > 6000 Then
            If imgCoconut.Top = 5520 = False Then
                imgCoconut.Top = imgCoconut.Top + 35
                If imgCoconut.Top > 9000 Then
                    imgCoconut.Top = 5520
                End If
                If imgCoconut.Top < 5790 Then
                    If imgCoconut.Top > 5100 Then
                        imgCoconut.Top = 5520
                    End If
                End If
            Else
                imgCoconut.Top = 5520
            End If
        End If
    Else
        imgCoconut.Top = 5520
    End If

    If imgCoconut.Left < 0 Then
        imgCoconut.Left = 10920
        coconutsJumped = coconutsJumped + 1
        lblJumped.Caption = "c o c o n u t s  j u m p e d : " & coconutsJumped
        Dim RNG1 As String
        RNG1 = RandomNum(1, 2)
        If RNG1 = 1 Then
            throwIt = True
            imgCoconut.Top = 4320
        Else
            throwIt = False
            imgCoconut.Top = 5520
        End If
    End If

    If coconutsJumped <= 15 Then
        imgCoconut.Left = imgCoconut.Left - 50
    End If

    If coconutsJumped = 16 Then
        imgCoconut.Left = imgCoconut.Left - 75
    End If

    If coconutsJumped = 17 Then
        imgCoconut.Left = imgCoconut.Left - 135
    End If

    If coconutsJumped = 18 Then
        imgCoconut.Left = imgCoconut.Left - 140
    End If

    If coconutsJumped = 19 Then
        imgCoconut.Left = imgCoconut.Left - 145
    End If

    If coconutsJumped = 20 Then
        imgCoconut.Left = imgCoconut.Left - 150
    End If
   
    If coconutsJumped = 21 Then
        imgCoconut.Left = imgCoconut.Left - 160
    End If
   
    If coconutsJumped = 22 Then
        imgCoconut.Left = imgCoconut.Left - 175
    End If
    If coconutsJumped >= 23 Then
        imgCoconut.Left = imgCoconut.Left - 190
    End If

    Dim howCloseRight As Integer
    howCloseRight = imgSprite.Left + imgCoconut.Left

    Dim howCloseBottom As Integer
    howCloseBottom = imgSprite.Top + imgCoconut.Top

   
    If howCloseRight < 7395 Then
        If howCloseBottom > 10199 Then
            If imgCoconut.Left > 3500 Then
                PlaySound App.Path & "\assets\fail.wav", ByVal 0&, SND_ASYNC
                tmrSpinCoconuts.Enabled = False
                Set imgCoconut.Picture = LoadPicture(App.Path & "\assets\coconutend.gif")
                Set imgCoconut2.Picture = LoadPicture(App.Path & "\assets\coconutend.gif")
                If imgSprite.Left = 3600 Then
                    lblGameOver.Caption = "u ded fam"
                Else
                    imgSprite.Left = 3600
                    lblGameOver.Caption = "u can't turn and run from deez nuts. das y u ded"
                End If
                tmrCoconut.Enabled = False
                tmrCoconut2.Enabled = False
                tmrLoadCoconut2.Enabled = False
                tmrRestartCoconut2.Enabled = False
                tmrBG.Enabled = False
                tmrSprite.Enabled = False
                lblTryAgain.Visible = True
            End If
        End If
    End If

End Sub

Private Sub tmrIntro_Timer()

    imgIntro.Visible = False
   
    Me.Height = 6630
    Me.Width = 11055

    tmrLoadCoconut2.Interval = RandomNum(15, 20) & 638
    tmrSprite.Enabled = True
    tmrCoconut.Enabled = True
    tmrLoadCoconut2.Enabled = True
    tmrIntro.Enabled = False

    imgSpacebar.Visible = True
    imgArrow.Visible = True
   
    tmrMusic.Enabled = True

End Sub

Private Sub tmrJump_Timer()

    If isJumpingDown = False Then
        If imgSprite.Top > 3570 Then
            imgSprite.Top = imgSprite.Top - 65
        Else
            isJumpingDown = True
        End If
    Else
        If imgSprite.Top >= 4680 Then
            imgSprite.Top = 4680
            isJumpingDown = False
        Else
            imgSprite.Top = imgSprite.Top + 65
        End If
    End If

End Sub

Private Sub tmrLoadCoconut2_Timer()

    tmrCoconut2.Enabled = True

    tmrLoadCoconut2.Enabled = False

End Sub

Private Sub tmrMusic_Timer()
    PlaySound App.Path & "\assets\i.wav", ByVal 0&, SND_MEMORY
    PlaySound App.Path & "\assets\music.wav", ByVal 0&, SND_ASYNC
    tmrMusic.Enabled = False
End Sub

Private Sub tmrRestartCoconut2_Timer()

    tmrLoadCoconut2.Enabled = True
    tmrRestartCoconut2.Enabled = False
    Exit Sub

End Sub

Private Sub tmrSpinCoconuts_Timer()

    currentVariation = currentVariation + 1
    If currentVariation = 4 Then
        currentVariation = 1
    End If
    Set imgCoconut.Picture = LoadPicture(App.Path & "\assets\coconut" & currentVariation & ".gif")
    Set imgCoconut2.Picture = LoadPicture(App.Path & "\assets\coconut" & currentVariation & ".gif")

End Sub

Private Sub tmrSprite_Timer()

    If GetAsyncKeyState(vbKeySpace) < 0 Then
        Set imgSpacebar.Picture = LoadPicture(App.Path & "\assets\spacebar2.gif")
        tmrJump.Enabled = True
    Else
        Set imgSpacebar.Picture = LoadPicture(App.Path & "\assets\spacebar1.gif")
        tmrJump.Enabled = False
        imgSprite.Top = 4680
    End If
   
    If GetAsyncKeyState(vbKeyRight) < 0 Then
        Set imgArrow.Picture = LoadPicture(App.Path & "\assets\arrow2.gif")
        isWalkingLeft = False
        If imgBG.Left > -13400 Then
            If imgSprite.Left < 3600 Then
                imgSprite.Left = imgSprite.Left + 100
            End If
            imgBG.Left = imgBG.Left - 100
        Else
            imgBG.Left = 0
            bgMove = 0
        End If
        spriteMove = spriteMove + 1
        If spriteMove > 3 Then
            spriteMove = 0
            If spritePosition < 4 Then
                spritePosition = spritePosition + 1
                Set imgSprite.Picture = LoadPicture(App.Path & "\assets\" & spritePosition & ".gif")
            Else
                spritePosition = 1
                Set imgSprite.Picture = LoadPicture(App.Path & "\assets\" & spritePosition & ".gif")
            End If
        End If
        Exit Sub
    Else
        Set imgArrow.Picture = LoadPicture(App.Path & "\assets\arrow1.gif")
        tmrBG.Enabled = False
        If GetAsyncKeyState(vbKeyLeft) < 0 Then
        isWalkingLeft = True
        If imgBG.Left > -13420 Then
            If imgSprite.Left > 0 Then
                imgSprite.Left = imgSprite.Left - 200
            End If
        Else
            imgBG.Left = 0
            bgMove = 0
        End If
        spriteMove = spriteMove + 1
        If spriteMove > 3 Then
            spriteMove = 0
            If spritePosition < 4 Then
                spritePosition = spritePosition + 1
                Set imgSprite.Picture = LoadPicture(App.Path & "\assets\b" & spritePosition & ".gif")
            Else
                spritePosition = 1
                Set imgSprite.Picture = LoadPicture(App.Path & "\assets\b" & spritePosition & ".gif")
            End If
        End If
        Exit Sub
        Else
            tmrBG.Enabled = False
            Exit Sub
        End If
        Exit Sub
    End If

End Sub

My Skype is p@dillac1 (@ = a) or I can be reached here via PM or just respond ITT!

Thanks!

[VB.NET] how can I remove the drawn line in the panel if it didn't successfully hit the point?

$
0
0
Code:

Public Class Form1
    Dim N As New Random
    Dim X, Y As Integer
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        Dim Mg As Drawing.Graphics = Me.Panel3.CreateGraphics
        Dim Mp As New Pen(Brushes.White, 1)
        Dim redBrush As New SolidBrush(Color.Red)
        Dim X1, Y1, X2, Y2 As Integer
        Dim V, A, T, G As Single
        V = TextBox3.Text
        A = TextBox4.Text
        G = 9.81
        X2 = 0
        Y2 = 0
        T = 0
        Do Until T > 2 * V * Math.Sin(A * Math.PI / 180) / G
            X1 = V * Math.Cos(A * Math.PI / 180) * T
            Y1 = V * Math.Sin(A * Math.PI / 180) * T - (1 / 2) * G * T ^ 2
            Mg.DrawLine(Mp, CInt(X2), 450 - CInt(Y2), CInt(X1), 450 - CInt(Y1))
            If (CInt(X1) - 2 <= X And X <= CInt(X1) + 2) And (CInt(Y1) - 2 <= Y And Y < CInt(Y1) + 2) Then
                Dim msgRslt As MsgBoxResult = MsgBox("Congratulations... You HIT the point.!" & vbNewLine & "Play Another Game? ", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Game Play")
                If msgRslt = MsgBoxResult.Yes Then
                    MsgBox("New ball location is generated", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "New Game")
                    Me.Panel3.Refresh()
                ElseIf msgRslt = MsgBoxResult.No Then
                    Me.Close()
                End If
                Exit Sub

            End If

            T = T + 0.01
            X2 = X1
            Y2 = Y1

        Loop

    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Me.Close()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Me.Panel3.Refresh()
        Dim Mg As Drawing.Graphics = Me.Panel3.CreateGraphics
        Dim Mp As New Pen(Brushes.Red, 1)
        X = N.Next(450)
        Y = N.Next(450)
        TextBox1.Text = X
        TextBox2.Text = Y
        Mg.FillEllipse(Brushes.Yellow, X, 450 - Y, 3, 3)
        Button2.Enabled = True
    End Sub

End Class

[RESOLVED] DirectX 9 on C++: how draw an image transparent?

$
0
0
heres how i create the surface:
Code:

//creating a backbuffer surface for get the sprite:
        LPDIRECT3DSURFACE9 surface;
        LPDIRECT3DSURFACE9 backbuffer;
        hResult=d3ddev->GetBackBuffer( 0,0,D3DBACKBUFFER_TYPE_MONO,&backbuffer);
        hResult=d3ddev->CreateOffscreenPlainSurface(58,80,D3DFMT_X8R8G8B8,D3DPOOL_DEFAULT,&surface,NULL);

heres how i get the image from file\resource:
Code:

/Getting the sprite:
        //hResult=D3DXLoadSurfaceFromResource(surface,NULL,NULL, GetModuleHandle(NULL),MAKEINTRESOURCE(ResourceID),NULL,D3DX_DEFAULT,0,NULL);
        hResult= D3DXLoadSurfaceFromFile( surface,NULL,NULL,"C:\\Users\\Cambalinho\\Documents\\CB\\testdx\\Bleu Battle.bmp",NULL,D3DX_DEFAULT,D3DCOLOR_XRGB(0,0,0),NULL );
        if ( FAILED( hResult ) ) MessageBox(NULL,"Error","erro",MB_OK);

heres how i draw it on buffer:
Code:

/Draw the sprite:
        RECT imRect={100,50,158,130};//destination rect
        d3ddev->StretchRect(surface,NULL,backbuffer,&imRect, D3DTEXF_NONE);

the image is drawed. but isn't transparent. why isn't transparent?
Viewing all 263 articles
Browse latest View live




Latest Images