Phillip Posted December 24, 2015 Share Posted December 24, 2015 Hello all,Ive been dicking around with GDIplus functions lately, and right now im just testing some things out with it. Ive got images being generated on the screen, and a "player" whos also being generated on the screen, right in the middle. Ive coded most of it, but it feels very choppy. Can someone have a look at my code to see if im missing anything/ doing anything wrong:expandcollapse popup#include <ColorConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Misc.au3> #include <Array.au3> #include <GDIPlus.au3> Opt("MouseCoordMode", 2) Opt("PixelCoordMode", 2) HotKeySet("{esc}", "esc") ;HotKeySet("{1}", "test") Func esc() Exit _GDIPlus_Shutdown() EndFunc ;==>esc $gui = GUICreate("map", 1600, 1000) GUISetState() _GDIPlus_Startup() $gfx = _GDIPlus_GraphicsCreateFromHWND($gui) $Bitmap = _GDIPlus_BitmapCreateFromGraphics(600, 400, $gfx) ;create bitmap $buffer = _GDIPlus_ImageGetGraphicsContext($Bitmap) ;create buffer $grass = _GDIPlus_ImageLoadFromFile("C:\users\phill\desktop\survivor\pics\terrain\grass.jpg") $player = _GDIPlus_ImageLoadFromFile("C:\users\phill\desktop\survivor\pics\terrain\player.jpg") $water = _GDIPlus_ImageLoadFromFile("C:\users\phill\desktop\survivor\pics\terrain\water.jpg") ;Next ;$y += 1 ;wend $count = 0 $p = 1 $p1 = 2 $p2 = 10 $p3 = 5 $p4 = 8 draw() func draw() _GDIPlus_GraphicsClear($buffer, 0x7F000000) ;clear buffer $y = 0 while $y <> 40 for $i = 0 to 60 _GDIPlus_GraphicsDrawImage($buffer, $grass, $i * 10, $y * 10) ;draws grass if $i >= $p1 + 15 and $i <= $p2 + 15 and $y >= $p3 + 15 and $y <= $p4 + 15 then _GDIPlus_GraphicsDrawImage($buffer, $water, $i * 10, $y * 10) ;draws water endif if $i = 30 and $y = 20 Then ; player _GDIPlus_GraphicsDrawImage($buffer, $player, $i * 10, $y * 10) ;draws the player endif Next $y += 1 wend _GDIPlus_GraphicsDrawImageRect($gfx, $Bitmap, 500, 300, 600, 400) ;copy to bitmap endfunc While 1 Select case _IsPressed(41) and _IsPressed(57) ;left and up $p1 += 1 $p2 += 1 $p3 += 1 $p4 += 1 draw() case _IsPressed(44) and _IsPressed(57) ;right and up $p1 -= 1 $p2 -= 1 $p3 += 1 $p4 += 1 draw() case _IsPressed(41) and _IsPressed(53) ;left and down $p1 += 1 $p2 += 1 $p3 -= 1 $p4 -= 1 draw() case _IsPressed(44) and _IsPressed(53) ;right and down $p1 -= 1 $p2 -= 1 $p3 -= 1 $p4 -= 1 draw() case _IsPressed(41) ;left $p1 += 1 $p2 += 1 $p3 += 0 $p4 += 0 draw() case _IsPressed(44) ;right $p1 -= 1 $p2 -= 1 $p3 -= 0 $p4 -= 0 draw() case _IsPressed(53) ; down $p1 += 0 $p2 += 0 $p3 -= 1 $p4 -= 1 draw() case _IsPressed(57) ;up $p1 -= 0 $p2 -= 0 $p3 += 1 $p4 += 1 draw() EndSelect ;draw() WEndAs you can see, you can use the WASD keys to "move around". Ive also uploaded the images for you to use.I feel like it can be a lot smoother, i just have no idea how to do it.Thanks for any help at all! Link to comment Share on other sites More sharing options...
InunoTaishou Posted December 24, 2015 Share Posted December 24, 2015 (edited) The WM_KEYDOWN message would help and make things a bit easier. Also, you're exiting before shutting down GDIPlus and you're not disposing of your GDI variables before exiting, your math on the player coordinates is inverted, and WASD actually moves the water, not the player (:P). This might give you an idea on where to go<snip>When you start adding collision to your map you could check the coordinate first, if the space is valid then do the math, otherwise not.If you wanted to get really detailed on your map, instead of clearing the graphic every time you could check the tile the player is standing on before moving, draw the player in the new tile, then overwrite the old player spot with the correct tile. (I.e., if the player is standing at 10, 10 and moves to the right, at x0, y0, width10, height10 is supposed to be a grass tile, draw the player at 20, 10 then draw a grass at 0, 0). Just keep an array of the map and what each tile is supposed to be and add the row/column of the tile standing on and moving to. This way you're not redrawing every single time and your draw function just got cut down to 1/3 the size it was beforeFunc draw(Const $iOldRow, Const $iOldColumn, Const $iNewRow, Const $iNewColumn) ; Get the tile to draw at the $iOldRow and $iOldColumn _GDIPlus_GraphicsDrawImage($buffer, $player, $iNewRow * 10, $iNewColumn * 10) _GDIPlus_GraphicsDrawImage($buffer, $aMap[$iOldRow][$iOldColumn], $iOldRow * 10, $iOldColumn * 10) _GDIPlus_GraphicsDrawImageRect($gfx, $Bitmap, 500, 300, 600, 400) ;copy to bitmap EndFunc Edited December 24, 2015 by Melba23 Removed code Link to comment Share on other sites More sharing options...
Phillip Posted December 24, 2015 Author Share Posted December 24, 2015 (edited) Hey man,Firstly, thanks for the response. The player not moving is intended, he is suppose to be in the center of the map, with the map moving around him as you hit the movement keys.Im planning on generating the map through an array, but with the player being static in the middle, i dont know if i can do it another way other than redrawing the entire area everytime you move.Also, i tried implementing your WM_KEYDOWN message function, but that just made it feel more clunky and slower.Furthermore: Thanks for pointing out my error with disposing the images and the GDIshutdown, completely missed that haha. Edited December 24, 2015 by Phillip Link to comment Share on other sites More sharing options...
InunoTaishou Posted December 24, 2015 Share Posted December 24, 2015 Ah I see, if that's your plan then you would probably need to redraw it every time (Unless you wanted to get really detailed, create a complete graphics image of the whole map first, store it in memory and don't touch it! Draw the map, adjusting the x/y coordinates of where to start drawing, and then draw the player on top. Sounds complicated and there's probably an easier and more efficient way of doing it, just have to get the GDIPlus gurus to give a better answer lol) Link to comment Share on other sites More sharing options...
Phillip Posted December 24, 2015 Author Share Posted December 24, 2015 mmm, it does sound complicated lol. Ill have to see how i go with it, or if anyone has any other ideas/ suggestions.Thanks for the help regardless! much appreciated Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 24, 2015 Moderators Share Posted December 24, 2015 InunoTaishou,What you posted was essentially a keylogger and has been removed - please read this announcement to understand the limits on what is permitted here.As I fully realise that you were not intending to post a keylogger I will take no further action. Have a good Xmas.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now