Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Psychopathetica

Member Since 05 Apr 2011
Offline Last Active Yesterday, 08:04 PM

#5127136 Empty Array In Structures

Posted by Psychopathetica on 28 January 2014 - 11:52 PM

Such a royal pain to comprehend on why something so simple can be so cryptic. Back when I was learning VB6 14 years ago, doing empty arrays in structures to be redeclared later wasnt so hard:

Private Type MyStruct
     MyArray() As Byte
End Type

Dim Test As MyStruct

Private Sub Form_Load()
     ReDim Test.MyArray(10) As Byte
End Sub

Even with VB.Net theres no issue:

Public Class Form1

    Private Structure MyStruct
        Dim MyArray() As Byte
    End Structure

    Dim Test As MyStruct

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ReDim Test.MyArray(10)
    End Sub
End Class

And although itll work in C++ to use a pointer and make it an array later (I think), I still kinda find it funny that you have to go through including the library vector, using vector<your data type here>, Resizing the vector, store the address of the vector into a pointer buffer to be used as an array by static_casting<char *>, load the data into that buffer and possibly put it back into the vector array. Mega fail Microsoft on not keeping it simple.




#5126873 Empty Array In Structures

Posted by Psychopathetica on 27 January 2014 - 11:41 PM

Hey there. I wanna be able to have some way of being able to use an empty array inside a structure to be reinitialized later on. The reason why is cause it will have an unknown number of elements until a file is loaded, and then I can reinitialize the array to an appropriate size and start storing data. The only thing I can think of for a solution since in C++ you cant have empty arrays in structures is to make a pointer to a variable in the structure:

#include <iostream>
using namespace std;

struct Test_Structure
{
     unsigned char *myarray;
};

Test_Structure test;

int main()
{
	unsigned char some_other_array[10];
	test.myarray = new unsigned char[10];
	cout << "test.myarray: " << sizeof(test.myarray) << endl;
	cout << "some_other_array: " << sizeof(some_other_array) << endl;
	system("pause");
	return 0;
}

However if you were to run that, it only shows the size of the pointer rather than the whole array. Can I still the pointer as an array? Or is there another way around using empty arrays from structures?




#5126516 Hexadecimals

Posted by Psychopathetica on 26 January 2014 - 10:04 AM

But the thing is that all those methods still involve the console window. If you were wanting to save it to file, or a listbox, label, or messagebox, couldn't you use sprintf() to put the result in a string and display it using any of those?

 

[EDIT]

Seems like Im right:

#include <windows.h>
#include <string>
using namespace std;

int main()
{
	int number = 11;
	string Text[255];
	sprintf((char *)Text, "The hexadecimal value of number is: %x", number);
	MessageBox(NULL, (char *)Text, "typedef", MB_OK);

	return 0;
}

And although it works on VS 2012, I tried it on VS 2013, and I got a warning saying it might be unsafe, use sprintf_s instead. Very strange. And even then the console window crashes afterwards no matter which sprintf I use.

 

As an experiment I even tried not using a Messagebox, and displayed it in the console window. It works until I close the console window, then crashes. Its only if I comment out the sprintf_s that it doesnt crash:

#include <windows.h>
#include <string>
#include <iostream>
using namespace std;

int main()
{
	int number = 11;
	string Text[255];
	sprintf_s((char *)Text, sizeof(Text),"The hexadecimal value of number is: %x", number);
	//MessageBox(NULL, (char *)Text, "typedef", MB_OK);
	cout << (char *)Text << endl;
	system("pause");
	return 0;
}



#5111532 VC++ 2010 Express How Do I Change The EXE Icon?

Posted by Psychopathetica on 23 November 2013 - 11:46 PM

Yea I did all that, and now its saying this:

1>LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt

I also am aware that for some reason the resource.h file needs a blank line at the end, which it has. So now I am stuck on this part. i would have gotten to this post earlier but I've been working a lot lol. Sorry for the late reply tongue.png

 

[EDIT] Found the solution over in stackoverflow!!!

If disabling incremental linking doesn't work for you, and turning off "Embed Manifest" doesn't work either, then search your path for multiple versions of CVTRES.exe.

By debugging with the /VERBOSE linker option I found the linker was writing that error message when it tried to invoke cvtres and it failed.

It turned out that I had two versions of this utility in my path. One at C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\cvtres.exe and one at C:\Windows\Microsoft.NET\Framework\v4.0.30319\cvtres.exe. After VS2012 install, the VS2010 version of cvtres.exe will no longer work. If that's the first one in your path, and the linker decides it needs to convert a .res file to COFF object format, the link will fail with LNK1123.

(Really annoying that the error message has nothing to do with the actual problem, but that's not unusual for a Microsoft product.)

Just delete/rename the older version of the utility, or re-arrange your PATH variable, so that the version that works comes first.

So VS 2012 corrupted the file. Simply renaming cvtres.exe or deleting it from your VS 2010 folder will have the compiler use the other one. It changed the icon so now I'm happy =D I hope this comes a learning experience to those who have both 2010 and 2012 express editions.




#5072973 [RESOLVED]World of Warcraft Image Effect (Spell Cooldown) With Source Code!

Posted by Psychopathetica on 26 June 2013 - 09:53 AM

I know this is an old topic but I figured it out a long time ago. The solution was to overlap the squared spell icon with a perfectly squared diamond the same size only rotated 45 degrees that darken the spell icon. That darkened diamond is then split into 8 triangle slices like a pizza, and gets clipped around the entire square as it rotates, so you only see it within the spell icon. It starts at 8 and as it rotates to shrink the first polys of the group, it cuts it down to 7. Then 6, then 5, 4, 3, 2, and ultimately 1. This can be done at any cooldown time you desire, and it does it very smooth, and accurately. Here is the code:

Option Explicit

Private Type CUSTOM_VERTEX_TYPE
    X As Single
    Y As Single
    Z As Single
    RHW As Single
    Color As Long
    Specular As Long
    TU As Single
    TV As Single
End Type

Private Type Vector
    X As Single
    Y As Single
End Type

Private Type Spell_Type
    Position As Vector
    Angle As Single
    Texture As Direct3DTexture8
    Width As Long
    Height As Long
    Half_Width As Long
    Half_Height As Long
    Image_Size As Long
    Vertex_List(3) As CUSTOM_VERTEX_TYPE
    Vertex_List2(23) As CUSTOM_VERTEX_TYPE
    Clip_Region(3, 3) As CUSTOM_VERTEX_TYPE
    Cooldown_Amount As Single
    Cooldown_Time As Single
    Milliseconds As Single
    Cooldown_Flag As Boolean
    Polycount As Long
End Type

Private Declare Function timeGetTime Lib "winmm.dll" () As Long

'Some color depth constants to help make the DX constants more readable.
Private Const COLOR_DEPTH_16_BIT As Long = D3DFMT_R5G6B5
Private Const COLOR_DEPTH_24_BIT As Long = D3DFMT_A8R8G8B8
Private Const COLOR_DEPTH_32_BIT As Long = D3DFMT_X8R8G8B8

Private Const PI As Double = 3.141592576

'The 2D (Transformed and Lit) vertex format.
Private Const CUSTOM_VERTEX As Long = D3DFVF_XYZRHW Or D3DFVF_TEX1 Or D3DFVF_DIFFUSE Or D3DFVF_SPECULAR

Private DX As DirectX8 'The master DirectX object.
Private D3D As Direct3D8 'Controls all things 3D.
Private Device As Direct3DDevice8 'Represents the hardware rendering.
Private D3DX As D3DX8

Private Fullscreen_Enabled As Boolean 'Helps determine whether it's fullscreen mode.
Private Fullscreen_Width As Long
Private Fullscreen_Height As Long
Private Running As Boolean 'Helps determine whether the main game loop is running.

Private Main_Font As D3DXFont
Private Main_Font_Description As IFont
Private Text_Rect As RECT

Private Spell As Spell_Type

Public Sub Setup_Spell()
    With Spell
        .Position.X = frmMain.ScaleWidth / 2
        .Position.Y = frmMain.ScaleHeight / 2
        .Width = 200
        .Height = 200
        .Half_Width = .Width / 2
        .Half_Height = .Height / 2
        .Cooldown_Amount = 60 'seconds
        Load_Texture App.Path & "\Death Coil.bmp", D3DColorRGBA(255, 255, 255, 255)
        Create_Spell_Polygon Spell
    End With
End Sub

Private Function Get_Elapsed_Time() As Single
    Get_Elapsed_Time = Abs(timeGetTime / 1000)
End Function

'This function will make it much easier to setup the vertices with the info it needs.
Private Function Create_Custom_Vertex(X As Single, Y As Single, Z As Single, RHW As Single, Color As Long, Specular As Long, TU As Single, TV As Single) As CUSTOM_VERTEX_TYPE
    Create_Custom_Vertex.X = X
    Create_Custom_Vertex.Y = Y
    Create_Custom_Vertex.Z = Z
    Create_Custom_Vertex.RHW = RHW
    Create_Custom_Vertex.Color = Color
    Create_Custom_Vertex.Specular = Specular
    Create_Custom_Vertex.TU = TU
    Create_Custom_Vertex.TV = TV
End Function

Private Function Line_Intersect(ByVal L1_X1 As Single, ByVal L1_Y1 As Single, ByVal L1_X2 As Single, ByVal L1_Y2 As Single, _
                                  ByVal L2_X1 As Single, ByVal L2_Y1 As Single, ByVal L2_X2 As Single, ByVal L2_Y2 As Single, _
                                  ByRef Intersection As Vector) As Boolean
    'Denominator for ua and ub are the same, so store this calculation
    Dim Denominator As Double
    Dim n_a As Double
    Dim n_b As Double
    Denominator = (L2_Y2 - L2_Y1) * (L1_X2 - L1_X1) - (L2_X2 - L2_X1) * (L1_Y2 - L1_Y1)

      'n_a and n_b are calculated as seperate values for readability
     ' Dim n_a As Double =

      'Dim n_b As Double =


      'If ua >= 0D AndAlso ua <= 1D AndAlso ub >= 0D AndAlso ub <= 1D Then
      '   Intersection.X = L1.X1 + (ua * (L1.X2 - L1.X1))
      '   Intersection.Y = L1.Y1 + (ua * (L1.Y2 - L1.Y1))
       '  Return True
      'End If

    'n_a and n_b are calculated as seperate values for readability
    n_a = (L2_X2 - L2_X1) * (L1_Y1 - L2_Y1) - (L2_Y2 - L2_Y1) * (L1_X1 - L2_X1)
    n_b = (L1_X2 - L1_X1) * (L1_Y1 - L2_Y1) - (L1_Y2 - L1_Y1) * (L1_X1 - L2_X1)
    
    ' Make sure there is not a division by zero - this also indicates that
    ' the lines are parallel.
    ' If n_a and n_b were both equal to zero the lines would be on top of each
    ' other (coincidental).  This check is not done because it is not
    ' necessary for this implementation (the parallel check accounts for this).
    If Denominator = 0 Then
        Line_Intersect = False
        Exit Function
    End If
    
    ' Calculate the intermediate fractional point that the lines potentially intersect.
    Dim ua As Double: ua = n_a / Denominator
    Dim ub As Double: ub = n_b / Denominator
    
    ' The fractional point will be between 0 and 1 inclusive if the lines
    ' intersect.  If the fractional calculation is larger than 1 or smaller
    ' than 0 the lines would need to be longer to intersect.
    
    If ua >= 0 And ua <= 1 And ub >= 0 And ub <= 1 Then
        Intersection.X = L1_X1 + (ua * (L1_X2 - L1_X1))
        Intersection.Y = L1_Y1 + (ua * (L1_Y2 - L1_Y1))
        Line_Intersect = True
        Exit Function
    End If

   Line_Intersect = False
End Function

Private Function DirectX_Initialize() As Boolean
    On Error GoTo Error_Handler
    
    Dim Display_Mode As D3DDISPLAYMODE 'Display mode desciption.
    Dim Screen As D3DPRESENT_PARAMETERS 'Backbuffer and viewport description.
    
    Set DX = New DirectX8 'Creates the DirectX object.
    Set D3D = DX.Direct3DCreate() 'Creates the Direct3D object using the DirectX object.
    Set D3DX = New D3DX8
    
    If Fullscreen_Enabled = True Then
    
        'Now that we are working with fullscreen mode, we must set up the
        'screen resolution to switch to, rather than use the default screen
        'resolution.
        
        Display_Mode.Width = Fullscreen_Width
        Display_Mode.Height = Fullscreen_Height
        Display_Mode.Format = COLOR_DEPTH_32_BIT
    
        Screen.Windowed = False 'The app will be in fullscreen mode.
        Screen.BackBufferCount = 1 '1 backbuffer only
        Screen.BackBufferWidth = Display_Mode.Width 'Match the backbuffer width with the display width
        Screen.BackBufferHeight = Display_Mode.Height 'Match the backbuffer height with the display height
        Screen.hDeviceWindow = frmMain.hWnd 'Use frmMain as the device window.
        
    Else
    
        D3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, Display_Mode 'Use the current display mode that you
                                                                        'are already on. Incase you are confused, I'm
                                                                        'talking about your current screen resolution. ;)
        
        Screen.Windowed = True 'The app will be in windowed mode.
    
    End If
    
    Screen.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC 'Refresh when the monitor does.
    Screen.BackBufferFormat = Display_Mode.Format 'Sets the format that was retrieved into the backbuffer.
    
    'Creates the rendering device with some useful info, along with the info
    'we've already setup for Screen.
    Set Device = D3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, frmMain.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, Screen)
    
    Device.SetVertexShader CUSTOM_VERTEX 'Set the type of vertex shading. (Required)
    
    'Right here will alphablend the polygon
    Device.SetRenderState D3DRS_ALPHABLENDENABLE, True
    
    Device.SetTextureStageState 0, D3DTSS_COLOROP, D3DTOP_MODULATE
    Device.SetTextureStageState 0, D3DTSS_COLORARG1, D3DTA_TEXTURE
    Device.SetTextureStageState 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE
                   
    Device.SetTextureStageState 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE
    Device.SetTextureStageState 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE
    Device.SetTextureStageState 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE
    
    Device.SetRenderState D3DRS_SRCBLEND, D3DBLEND_SRCALPHA
    Device.SetRenderState D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA
    Device.SetRenderState D3DRS_BLENDOP, D3DBLENDOP_ADD
    
    'These lines are not needed, but it's nice to be able to filter the
    'textures to make them look nicer.
    
    Device.SetTextureStageState 0, D3DTSS_MINFILTER, D3DTEXF_POINT
    Device.SetTextureStageState 0, D3DTSS_MAGFILTER, D3DTEXF_POINT


    Exit Function
    
Error_Handler:
    
    MsgBox "An error occured while initializing DirectX", vbCritical
    Shutdown
    DirectX_Initialize = False
End Function

Private Sub Create_Spell_Polygon(ByRef Spell As Spell_Type)
    With Spell
        .Vertex_List(0) = Create_Custom_Vertex(.Position.X - .Half_Width, .Position.Y - .Half_Height, 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 0, 0)
        .Vertex_List(1) = Create_Custom_Vertex(.Position.X + .Half_Width, .Position.Y - .Half_Height, 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 1, 0)
        .Vertex_List(2) = Create_Custom_Vertex(.Position.X - .Half_Width, .Position.Y + .Half_Height, 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 0, 1)
        .Vertex_List(3) = Create_Custom_Vertex(.Position.X + .Half_Width, .Position.Y + .Half_Height, 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 1, 1)
    End With
End Sub

Private Sub Create_Spell_Cooldown_Polygon(ByRef Spell As Spell_Type, ByVal X As Single, ByVal Y As Single, ByVal Size As Long)
    Dim Offset As Long
    Dim Half_Offset As Long
    Dim Color As Long
    Dim Rotate As Vector
    Dim Clipped As Boolean, Clip_Intersection As Vector
    
    With Spell
        .Clip_Region(0, 0) = Create_Custom_Vertex(X - Size, Y - Size, 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 0, 0)
        .Clip_Region(0, 1) = Create_Custom_Vertex(X + Size, Y - Size, 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 1, 0)
        .Clip_Region(0, 2) = Create_Custom_Vertex(X - Size, Y - (Size / 2), 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 0, 1)
        .Clip_Region(0, 3) = Create_Custom_Vertex(X + Size, Y - (Size / 2), 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 1, 1)
        
        .Clip_Region(1, 0) = Create_Custom_Vertex(X + (Size / 2), Y - Size, 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 0, 0)
        .Clip_Region(1, 1) = Create_Custom_Vertex(X + Size, Y - Size, 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 1, 0)
        .Clip_Region(1, 2) = Create_Custom_Vertex(X + (Size / 2), Y + Size, 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 0, 1)
        .Clip_Region(1, 3) = Create_Custom_Vertex(X + Size, Y + Size, 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 1, 1)
        
        .Clip_Region(2, 0) = Create_Custom_Vertex(X - Size, Y + (Size / 2), 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 0, 0)
        .Clip_Region(2, 1) = Create_Custom_Vertex(X + Size, Y + (Size / 2), 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 1, 0)
        .Clip_Region(2, 2) = Create_Custom_Vertex(X - Size, Y + Size, 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 0, 1)
        .Clip_Region(2, 3) = Create_Custom_Vertex(X + Size, Y + Size, 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 1, 1)
        
        .Clip_Region(3, 0) = Create_Custom_Vertex(X - Size, Y - Size, 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 0, 0)
        .Clip_Region(3, 1) = Create_Custom_Vertex(X - (Size / 2), Y - Size, 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 1, 0)
        .Clip_Region(3, 2) = Create_Custom_Vertex(X - Size, Y + Size, 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 0, 1)
        .Clip_Region(3, 3) = Create_Custom_Vertex(X - (Size / 2), Y + Size, 0, 1, D3DColorRGBA(255, 255, 255, 255), 0, 1, 1)
    
        Offset = Size
        Half_Offset = Offset / 2
        Color = D3DColorRGBA(0, 0, 0, 155)
    
        If .Angle < 90 Then
            Rotate.X = X + (0 * Cos((.Angle) * (PI / 180)) - (-Offset) * Sin((.Angle) * (PI / 180)))
            Rotate.Y = Y + (0 * Sin((.Angle) * (PI / 180)) + (-Offset) * Cos((.Angle) * (PI / 180)))
            If .Angle >= 0 And .Angle < 45 Then
                .Polycount = 8
                Clipped = Line_Intersect(Rotate.X, Rotate.Y, X, Y, .Clip_Region(0, 2).X, .Clip_Region(0, 2).Y, .Clip_Region(0, 3).X, .Clip_Region(0, 3).Y, Clip_Intersection)
                If Clipped = True Then
                    .Vertex_List2(0) = Create_Custom_Vertex(Clip_Intersection.X, Clip_Intersection.Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(1) = Create_Custom_Vertex(X + Half_Offset, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(2) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(3) = Create_Custom_Vertex(X + Half_Offset, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(4) = Create_Custom_Vertex(X + Half_Offset, Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(5) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(6) = Create_Custom_Vertex(X + Half_Offset, Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(7) = Create_Custom_Vertex(X + Half_Offset, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(8) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(9) = Create_Custom_Vertex(X + Half_Offset, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(10) = Create_Custom_Vertex(X, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(11) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(12) = Create_Custom_Vertex(X, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(13) = Create_Custom_Vertex(X - Half_Offset, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(14) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(15) = Create_Custom_Vertex(X - Half_Offset, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(16) = Create_Custom_Vertex(X - Half_Offset, Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(17) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(18) = Create_Custom_Vertex(X - Half_Offset, Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(19) = Create_Custom_Vertex(X - Half_Offset, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(20) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(21) = Create_Custom_Vertex(X - Half_Offset, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(22) = Create_Custom_Vertex(X, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(23) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                End If
            ElseIf .Angle >= 45 And .Angle < 90 Then
                .Polycount = 7
                Clipped = Line_Intersect(Rotate.X, Rotate.Y, X, Y, .Clip_Region(1, 0).X, .Clip_Region(1, 0).Y, .Clip_Region(1, 2).X, .Clip_Region(1, 2).Y, Clip_Intersection)
                If Clipped = True Then
                    .Vertex_List2(0) = Create_Custom_Vertex(Clip_Intersection.X, Clip_Intersection.Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(1) = Create_Custom_Vertex(X + Half_Offset, Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(2) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(3) = Create_Custom_Vertex(X + Half_Offset, Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(4) = Create_Custom_Vertex(X + Half_Offset, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(5) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(6) = Create_Custom_Vertex(X + Half_Offset, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(7) = Create_Custom_Vertex(X, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(8) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(9) = Create_Custom_Vertex(X, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(10) = Create_Custom_Vertex(X - Half_Offset, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(11) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(12) = Create_Custom_Vertex(X - Half_Offset, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(13) = Create_Custom_Vertex(X - Half_Offset, Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(14) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
    
                    .Vertex_List2(15) = Create_Custom_Vertex(X - Half_Offset, Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(16) = Create_Custom_Vertex(X - Half_Offset, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(17) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(18) = Create_Custom_Vertex(X - Half_Offset, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(19) = Create_Custom_Vertex(X, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(20) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                End If
            End If
        ElseIf .Angle >= 90 And .Angle < 180 Then
            Rotate.X = X + ((Offset * Cos((.Angle - 90) * (PI / 180))) - (0 * Sin((.Angle - 90) * (PI / 180))))
            Rotate.Y = Y + ((Offset * Sin((.Angle - 90) * (PI / 180))) + (0 * Cos((.Angle - 90) * (PI / 180))))
            If .Angle >= 90 And .Angle < 135 Then
                .Polycount = 6
                Clipped = Line_Intersect(Rotate.X, Rotate.Y, X, Y, .Clip_Region(1, 0).X, .Clip_Region(1, 0).Y, .Clip_Region(1, 2).X, .Clip_Region(1, 2).Y, Clip_Intersection)
                If Clipped = True Then
                    .Vertex_List2(0) = Create_Custom_Vertex(Clip_Intersection.X, Clip_Intersection.Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(1) = Create_Custom_Vertex(X + Half_Offset, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(2) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                
                    .Vertex_List2(3) = Create_Custom_Vertex(X + Half_Offset, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(4) = Create_Custom_Vertex(X, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(5) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(6) = Create_Custom_Vertex(X, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(7) = Create_Custom_Vertex(X - Half_Offset, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(8) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(9) = Create_Custom_Vertex(X - Half_Offset, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(10) = Create_Custom_Vertex(X - Half_Offset, Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(11) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(12) = Create_Custom_Vertex(X - Half_Offset, Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(13) = Create_Custom_Vertex(X - Half_Offset, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(14) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(15) = Create_Custom_Vertex(X - Half_Offset, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(16) = Create_Custom_Vertex(X, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(17) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                End If
            ElseIf .Angle >= 135 And .Angle < 180 Then
                .Polycount = 5
                Clipped = Line_Intersect(Rotate.X, Rotate.Y, X, Y, .Clip_Region(2, 0).X, .Clip_Region(2, 0).Y, .Clip_Region(2, 1).X, .Clip_Region(2, 1).Y, Clip_Intersection)
                If Clipped = True Then
                    .Vertex_List2(0) = Create_Custom_Vertex(Clip_Intersection.X, Clip_Intersection.Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(1) = Create_Custom_Vertex(X, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(2) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(3) = Create_Custom_Vertex(X, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(4) = Create_Custom_Vertex(X - Half_Offset, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(5) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(6) = Create_Custom_Vertex(X - Half_Offset, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(7) = Create_Custom_Vertex(X - Half_Offset, Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(8) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(9) = Create_Custom_Vertex(X - Half_Offset, Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(10) = Create_Custom_Vertex(X - Half_Offset, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(11) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(12) = Create_Custom_Vertex(X - Half_Offset, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(13) = Create_Custom_Vertex(X, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(14) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                End If
            End If
        ElseIf .Angle >= 180 And .Angle <= 270 Then
            Rotate.X = X + ((0 * Cos((.Angle - 180) * (PI / 180))) - (Offset * Sin((.Angle - 180) * (PI / 180))))
            Rotate.Y = Y + ((0 * Sin((.Angle - 180) * (PI / 180))) + (Offset * Cos((.Angle - 180) * (PI / 180))))
            If .Angle >= 180 And .Angle < 225 Then
                .Polycount = 4
                Clipped = Line_Intersect(Rotate.X, Rotate.Y, X, Y, .Clip_Region(2, 0).X, .Clip_Region(2, 0).Y, .Clip_Region(2, 1).X, .Clip_Region(2, 1).Y, Clip_Intersection)
                If Clipped = True Then
                
                    .Vertex_List2(0) = Create_Custom_Vertex(Clip_Intersection.X, Clip_Intersection.Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(1) = Create_Custom_Vertex(X - Half_Offset, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(2) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(3) = Create_Custom_Vertex(X - Half_Offset, Y + Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(4) = Create_Custom_Vertex(X - Half_Offset, Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(5) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(6) = Create_Custom_Vertex(X - Half_Offset, Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(7) = Create_Custom_Vertex(X - Half_Offset, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(8) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(9) = Create_Custom_Vertex(X - Half_Offset, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(10) = Create_Custom_Vertex(X, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(11) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                End If
            ElseIf .Angle >= 225 And .Angle < 270 Then
                .Polycount = 3
                Clipped = Line_Intersect(Rotate.X, Rotate.Y, X, Y, .Clip_Region(3, 1).X, .Clip_Region(3, 1).Y, .Clip_Region(3, 3).X, .Clip_Region(3, 3).Y, Clip_Intersection)
                If Clipped = True Then
                    .Vertex_List2(0) = Create_Custom_Vertex(Clip_Intersection.X, Clip_Intersection.Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(1) = Create_Custom_Vertex(X - Half_Offset, Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(2) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(3) = Create_Custom_Vertex(X - Half_Offset, Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(4) = Create_Custom_Vertex(X - Half_Offset, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(5) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(6) = Create_Custom_Vertex(X - Half_Offset, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(7) = Create_Custom_Vertex(X, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(8) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                End If
            End If
        Else
            Rotate.X = X + ((-Offset * Cos((.Angle - 270) * (PI / 180))) - (0 * Sin((.Angle - 270) * (PI / 180))))
            Rotate.Y = Y + ((-Offset * Sin((.Angle - 270) * (PI / 180))) + (0 * Cos((.Angle - 270) * (PI / 180))))
            If .Angle >= 270 And .Angle < 315 Then
                .Polycount = 2
                Clipped = Line_Intersect(Rotate.X, Rotate.Y, X, Y, .Clip_Region(3, 1).X, .Clip_Region(3, 1).Y, .Clip_Region(3, 3).X, .Clip_Region(3, 3).Y, Clip_Intersection)
                If Clipped = True Then
                    .Vertex_List2(0) = Create_Custom_Vertex(Clip_Intersection.X, Clip_Intersection.Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(1) = Create_Custom_Vertex(X - Half_Offset, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(2) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                    
                    .Vertex_List2(3) = Create_Custom_Vertex(X - Half_Offset, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(4) = Create_Custom_Vertex(X, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(5) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                End If
            ElseIf .Angle >= 315 And .Angle < 360 Then
                .Polycount = 1
                Clipped = Line_Intersect(Rotate.X, Rotate.Y, X, Y, .Clip_Region(0, 2).X, .Clip_Region(0, 2).Y, .Clip_Region(0, 3).X, .Clip_Region(0, 3).Y, Clip_Intersection)
                If Clipped = True Then
                    .Vertex_List2(0) = Create_Custom_Vertex(Clip_Intersection.X, Clip_Intersection.Y, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(1) = Create_Custom_Vertex(X, Y - Half_Offset, 0, 1, Color, 0, 0, 0)
                    .Vertex_List2(2) = Create_Custom_Vertex(X, Y, 0, 1, Color, 0, 0, 0)
                End If
            End If
        End If
    End With
End Sub

Private Sub Load_Texture(ByRef File_Path As String, ByVal Transparency_Color As Long)
    Set Spell.Texture = D3DX.CreateTextureFromFileEx(Device, _
                                                    File_Path, _
                                                    512, 512, _
                                                    0, _
                                                    0, _
                                                    D3DFMT_A8R8G8B8, _
                                                    D3DPOOL_MANAGED, _
                                                    D3DX_FILTER_POINT, _
                                                    D3DX_FILTER_POINT, _
                                                    Transparency_Color, _
                                                    ByVal 0, _
                                                    ByVal 0)
End Sub

Private Sub Draw_Spell_Polygon(ByRef Spell As Spell_Type)
    With Spell
        Device.SetTexture 0, .Texture
        Device.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, .Vertex_List(0), Len(.Vertex_List(0))
        If .Cooldown_Flag = True Then
            .Cooldown_Time = Get_Elapsed_Time - .Milliseconds
            Create_Spell_Cooldown_Polygon Spell, .Position.X, .Position.Y, .Width
            Device.SetTexture 0, Nothing
            Device.DrawPrimitiveUP D3DPT_TRIANGLELIST, .Polycount, .Vertex_List2(0), Len(.Vertex_List2(0))
            If .Cooldown_Time >= .Cooldown_Amount Then .Cooldown_Time = .Cooldown_Amount
            .Angle = ((.Cooldown_Time / .Cooldown_Amount) * 360)
            If .Angle <= 0 Then .Angle = 0
            If .Angle >= 360 Then
                .Angle = 360
                .Cooldown_Flag = False
            End If
        End If
    End With
End Sub

Public Sub Draw_Text(Text As String, X As Single, Y As Single, Width As Long, Height As Long, Font_Name As String, Font_Size As Long, Color As Long, Optional Font_Bold As Boolean = False, Optional Font_Italic As Boolean = False)
    
    'World of Warcraft uses Bookman Old Style
    
    'NOTE TO SELF - This crashes when you alt tab out and come back in for some reason
    Dim Font As New StdFont
    
    If Device.TestCooperativeLevel = D3D_OK Then
        Font.Name = Font_Name
        Font.Size = Font_Size
        If Font_Bold = True Then Font.Bold = True
        If Font_Italic = True Then Font.Italic = True
        Set Main_Font_Description = Font
        Set Main_Font = D3DX.CreateFont(Device, Main_Font_Description.hFont)
        
        Text_Rect.Left = X + 0
        Text_Rect.Top = Y + 0
        Text_Rect.Right = X + Width
        Text_Rect.bottom = Y + Height
        
        D3DX.DrawText Main_Font, Color, Text, Text_Rect, DT_TOP Or DT_LEFT
    End If
    
End Sub

Private Sub Render()
    Device.Clear 0, ByVal 0, D3DCLEAR_TARGET, D3DColorRGBA(0, 0, 255, 0), 1#, 0
    Device.BeginScene
    Draw_Spell_Polygon Spell
    Draw_Text "Seconds: " & CStr(Spell.Cooldown_Time), 50, 25, 500, 25, "ariel", 8, D3DColorRGBA(255, 255, 255, 255)
    Device.EndScene
    Device.Present ByVal 0, ByVal 0, 0, ByVal 0
End Sub

Private Sub Game_Loop()
    Do While Running = True
        Render
        DoEvents
    Loop
End Sub

Private Sub Shutdown()
    Running = False
    
    'Unload all of the DirectX objects.
    
    Set Spell.Texture = Nothing
    Set D3DX = Nothing
    Set Device = Nothing
    Set D3D = Nothing
    Set DX = Nothing
    
    Unload Me
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyEscape Then
        Shutdown
    End If
End Sub

Private Sub Form_Load()
    If MsgBox("Click Yes to go to full screen (Recommended)", vbQuestion Or vbYesNo, "Options") = vbYes Then Fullscreen_Enabled = True
    
    frmMain.Show
    frmMain.ScaleMode = vbPixels
    
    Fullscreen_Width = 1024
    Fullscreen_Height = 768
    
    DirectX_Initialize
    Setup_Spell
    Running = True
    Game_Loop
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 1 Then
        If Spell.Cooldown_Flag = False Then
            Spell.Angle = 0
            Spell.Cooldown_Time = 0
            Spell.Milliseconds = Get_Elapsed_Time
            Spell.Cooldown_Flag = True
        End If
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Shutdown
End Sub





#5013666 A-Star Path Following Questions

Posted by Psychopathetica on 23 December 2012 - 08:42 AM

Basically the player is you or anyone that plays the game. When you, the player, move and end up on the next tile, the entire A* Path of the monster changes by getting cleared, then it recalculates the A* Path for a new path for the monster to follow. That way the monster can goto the proper end destination, which is at the player itself. I never thought of using the tiles themselves but its probably gonna be hell changing it all to do that. But now that I think about it... it all makes sense. Heres why. I had the A* Path collect a series of coordinates based on the pixel location of every node. When the monster moves left towards the next tile, the first pixel from the top left of the monster being inside the left tile will recalculate the coordinates of the monster showing its inside the next tile.And since my path following code was having the monster move to the next tile being (-1) of the next path, this would make the monster try move to the tile after that! Its no wonder why the monster was draging on the walls in corners moving left / up, while right / down was normal.




PARTNERS