Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Craz1000

Pages: [1] 2
1
Programs / Master Sword v1.2
« on: December 13, 2021, 12:58:44 am »
Has some bug fixes and the open source version now has access to the score sever for you speed runners.

Just as a note, this was built in QB64 v1.5 as this was the current version when development started. v2.0 does not seem to work right with this game.

EDIT:
Based on the comments I redid the controller code. This should work better now.

2
QB64 Discussion / Framerate issue
« on: November 05, 2021, 10:26:50 pm »

So while working on Stereospace 3 using QB64 2.0 I noticed I was only getting 29FPS. I was confused because at this point the game is barely drawing any sprites to the screen. And with Stereospace 2 and Master Sword which is way more demanding I was maxing out '_LIMIT 60'.

So i went back to QB64 1.5 and got 29 FPS. QB64 1.4 got me 29 as well. 1.3 hits the limit at 60.

Anyone else  run into this?


3
Programs / Stereospace 3 Teaser
« on: October 16, 2021, 08:50:44 pm »
 This is a concept demo for background and effects. Those of you who loved Stereospace 2 can see where this is going :).

 


4
Programs / Honeypot program
« on: September 23, 2021, 11:29:33 am »
This program will listen on port 23. On a connection it will store the IP, then disconnect. once 50 unique IPs are recorded it will create a firewall rule in windows firewall. Rinse and repeat.

5
Programs / Help with keeping oscilloscope real time
« on: July 18, 2021, 11:10:06 pm »
I seem to ask for help a lot it seems lol.

So after completing my Zelda game and posting it here, it has left me with some free time. Enough time to catch up with things I have been putting off around the house. Lately I have been playing with some ideas and concepts, One of which requires an oscilloscope of audio in real time. I have been playing with the _memsound example and another example I have found on here. However I cant seem to get it quite right. What I see graphically is either behind (i=i+2) or ahead (i=i+3) of the audio. I have tried doing a bytes per second on the fly adjustment, a frames per second adjustment, and a "how much time has advanced on the audio since the last display refresh adjustment." Nothing seems to work quite right.

Code: QB64: [Select]
  1. Dim leftchannel As _MEM
  2.  
  3. Display& = _NewImage(600, 200, 32)
  4. Buffer& = _NewImage(600, 200, 32)
  5.  
  6. Screen Display&
  7. _Dest Buffer&
  8.  
  9.  
  10. song& = _SndOpen("Sounds\singing stars.mp3") 'replace drums.ogg with a sound file you have
  11.  
  12.  
  13. leftchannel = _MemSound(song&, 1)
  14.  
  15.  
  16. i = 0
  17. PositionDifference = 2
  18. _SndPlay song&
  19.  
  20.  
  21.     _MemGet leftchannel, leftchannel.OFFSET + i, l% 'get sound data
  22.  
  23.     Locate 1, 1: Print leftchannel.OFFSET; "/"; leftchannel.SIZE, dframes, leftchannel.ELEMENTSIZE
  24.     nextposl = map(l%, -32768, 32767, -_Height / 2, _Height / 2) + (_Height / 2)
  25.     Line (x, prevposl)-(x + 1, nextposl + 2), _RGB32(254, 0, 0), BF
  26.     prevposl = nextposl
  27.  
  28.  
  29.  
  30.  
  31.     x = x + 1
  32.     If x > _Width Then
  33.         x = 0
  34.         dframes = frames
  35.         frames = 0
  36.         _PutImage , Buffer&, Display&
  37.  
  38.         Cls
  39.     End If
  40.     i = i + 2
  41.  
  42.     If i + 2 > leftchannel.SIZE Then Exit Do
  43.     frames = frames + 1
  44.  
  45.  
  46.  
  47.  
  48.  
  49. _SndClose song& 'closing the sound releases the mem blocks
  50.  
  51.  
  52. Function map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  53.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  54.  


6
QB64 Discussion / New project
« on: June 22, 2021, 06:15:12 pm »
Now that my last game is finished with the source released and a somewhat embarrassing release of the online version that was left in test mode, i have a few projects sidelined that i have been eyeing. Guys have any preference on these?

Hacking MMO, this is mostly done but it has no substance to it, it is basically right now a fully working tech demo.
Got a submarine game sort of like silent service that i have some ideas written down
Stereospace 3
A 3D version of my tank game made in 2016. Right now it is a terrain generator with Everquest sound effects.
And another client - server based game based on the movie Contact where you have to find the alien signal and decrypt it by pointing the telescopes at points in the sky. This is mostly a puzzle / problem solving type of game.

7
Programs / Master Sword Online Version
« on: June 20, 2021, 09:12:53 pm »
This is the version that will contact my server and access the leader boards on who can speed run the game the fastest. This version is .exe only and is not compatible with the source code version. The save file is encrypted and if the source version is used it will crash. The game will only show the top 10 players, the website shows all 20. The source code version does not have the encryption code or the code used to communicate to the server to try and keep things fair.

http://craz1000.net

8
Programs / Master Sword finally done
« on: June 19, 2021, 09:17:15 pm »
It has been a little over a year since I started this project. Thanks to some help by bPlus and Petr, I was able to faithfully recreate the original NES Zelda game. This project started after my son played the original game and then found the second disappointing. It also comes with the world editor I used to make the world. Controls are standard W,A,S,D. Q is "B" and E is "A". TAB is "Start". Game auto saves as you go as well. I plan on releasing a version that uses my server to house the leaderboard, just need to know if you guys prefer a speed running type board or a least deaths approach. That version will be .EXE only that way it hides the key used to log into the server and encrypts the save file to try and keep it fair. Controller support is in the game, I personally used a PS4 controller with it so I do not know how other hardware will act. But anyway, ENJOY!

9
QB64 Discussion / Black and White
« on: January 02, 2021, 05:39:15 pm »


So currently at the point where I am adding the death animation or cut scene to the Zelda clone.
I have multiple layers drawn to Sprites&, and Scene&, Which eventually get stacked layer by layer into Buffer& then gets copied to Display& which is what the player sees.

In the original Zelda the screen goes black and white. So I would have to get Buffer& to convert to greyscale before sending it over to Display&
What would be the best way to do this?


10
So I have been at this Zelda game since about march. The game is about 85% complete. Currently building the world at this point.

Is there anyone out there that would like to design the 9 levels?

Just need a drawing of the layout, don't need to code anything.

There is an early build of the game here
https://www.qb64.org/forum/index.php?topic=2410.msg120339#msg120339

11
Programs / HoneyPot
« on: July 01, 2020, 02:11:35 pm »
This will listen on port 23(Telnet) any address that connects will be given the bird and then blocked in windows firewall. Must run with elevated privlages.

12
QB64 Discussion / _LIMIT and Windows Server 2016
« on: May 11, 2020, 06:37:20 pm »
I noticed on my windows server machine the _LIMIT command does not seem to work. The cpu usage always stays high for some reason. And when i run the same exe on a windows 10 machine cpu usage drops when it is supposed to.

Anyone else run into this or know a work around?

13
Programs / My Unified Score Server
« on: May 09, 2020, 12:57:38 pm »
This is the source for the score server i will be using from now on in all of my games.
Of course the "KEY" I use has been removed. It is very easy to add to existing games you have.
If you would also like for my server to service your game i can add it as well.

LeaderServer.bas
Code: QB64: [Select]
  1. '********************************************************************************
  2. '* Leaderboard Server v1.0 5/9/20
  3. '*
  4. '* This will keep track, back up, and service up to 100 clients at the same time
  5. '* Can also write to a website if you wish
  6. '* Requires ipcommsg.bi from ipcomtools
  7. '*
  8. '********************************************************************************
  9.  
  10.  
  11. _TITLE "Score Server v1.0 - Online since: " + DATE$ + " - " + TIME$
  12.  
  13. TYPE LeaderBoardObject
  14.     Score AS INTEGER
  15.     User AS STRING * 15
  16.  
  17. TYPE ClientObject
  18.     IP AS STRING * 15
  19.     Active AS INTEGER
  20.     ColR AS INTEGER
  21.     ColG AS INTEGER
  22.     ColB AS INTEGER
  23.  
  24. DIM SHARED GamesServiced AS INTEGER
  25. GamesServiced = 1 'Changes how many games the server currently handles
  26.  
  27. DIM SHARED Leaderboard(GamesServiced, 20) AS LeaderBoardObject
  28. DIM SHARED Client(100)
  29. DIM SHARED ClientInfo(100) AS ClientObject
  30. DIM SHARED CONNECTION
  31.  
  32. DIM SHARED UpdateTimer
  33.  
  34. UpdateTimer = _FREETIMER
  35. ON TIMER(UpdateTimer, 300) UpdateServer 'backs up every 5 minutes
  36. TIMER(UpdateTimer) ON
  37.  
  38. LoadDatabase
  39.  
  40. Display& = _NEWIMAGE(1024, 768, 32)
  41. SCREEN Display&
  42.  
  43.  
  44. HOST = _OPENHOST("TCP/IP:3571")
  45.  
  46. IF HOST <> 0 THEN
  47.     DO
  48.         _LIMIT 5
  49.         NEWCLIENT = _OPENCONNECTION(HOST)
  50.  
  51.         IF NEWCLIENT THEN 'when client connects. if it has an open spot will accept connection
  52.             FOR x = 1 TO 100
  53.                 IF ClientInfo(x).Active = 0 THEN
  54.                     Client(x) = NEWCLIENT
  55.                     ClientInfo(x).IP = RIGHT$(_CONNECTIONADDRESS(NEWCLIENT), 15)
  56.                     ClientInfo(x).ColR = INT(RND * 155) + 100
  57.                     ClientInfo(x).ColG = INT(RND * 155) + 100
  58.                     ClientInfo(x).ColB = INT(RND * 155) + 100
  59.                     PRINT RTRIM$(ClientInfo(x).IP); " connected."
  60.                     ClientInfo(x).Active = 1
  61.                     EXIT FOR
  62.                 END IF
  63.             NEXT x
  64.         ELSE
  65.         END IF
  66.  
  67.  
  68.  
  69.         FOR Scan = 1 TO 100 'find if any new messages are waiting from each of the clients
  70.             IF Client(Scan) THEN
  71.  
  72.                 COLOR _RGB(ClientInfo(Scan).ColR, ClientInfo(Scan).ColG, ClientInfo(Scan).ColB)
  73.                 IF ClientInfo(Scan).Active = 1 THEN MSG$ = WAITFORREPLY$(Client(Scan))
  74.  
  75.                 '********************************************************************************
  76.                 ' Code for recieving a new high score
  77.                 '********************************************************************************
  78.                 IF MSG$ = "SENDSCORE" THEN
  79.                     SENDMSG Client(Scan), "GAMENO"
  80.                     GameID = VAL(WAITFORREPLY$(Client(Scan)))
  81.                     SENDMSG Client(Scan), "OK"
  82.                     User$ = WAITFORREPLY$(Client(Scan))
  83.                     'CheckIfUserBanned
  84.                     SENDMSG Client(Scan), "SCORE"
  85.                     Score = VAL(WAITFORREPLY$(Client(Scan)))
  86.  
  87.                     Position = 0
  88.                     FOR x = 1 TO 20
  89.                         IF Score > Leaderboard(GameID, x).Score THEN Position = x: EXIT FOR
  90.                     NEXT x
  91.  
  92.                     IF Position < 20 THEN
  93.                         FOR x = 20 TO Position STEP -1
  94.                             Leaderboard(GameID, x).Score = Leaderboard(GameID, x - 1).Score
  95.                             Leaderboard(GameID, x).User = Leaderboard(GameID, x - 1).User
  96.                         NEXT x
  97.                     END IF
  98.  
  99.                     Leaderboard(GameID, Position).Score = Score
  100.                     Leaderboard(GameID, Position).User = User$
  101.  
  102.                     IF GameID = 1 THEN PRINT "Stereospace2 Board Updated by:"; ClientInfo(Scan).IP
  103.                     MSG$ = ""
  104.  
  105.                     '********************************************************************************
  106.                     ' Code for when client requests the scoreboard
  107.                     '********************************************************************************
  108.                 ELSEIF MSG$ = "GETBOARD" THEN
  109.                     SENDMSG Client(Scan), "GAMENO"
  110.                     GameID = VAL(WAITFORREPLY$(Client(Scan)))
  111.                     SENDMSG Client(Scan), "OK"
  112.                     FOR x = 1 TO 20
  113.                         IF WAITFORREPLY$(Client(Scan)) = "NAME" THEN SENDMSG Client(Scan), RTRIM$(Leaderboard(GameID, x).User)
  114.                         IF WAITFORREPLY$(Client(Scan)) = "SCORE" THEN SENDMSG Client(Scan), STR$(Leaderboard(GameID, x).Score)
  115.                         IF WAITFORREPLY$(Client(Scan)) = "OK" THEN SENDMSG Client(Scan), "NEXT"
  116.                     NEXT x
  117.                     SENDMSG Client(Scan), "DONE"
  118.                     IF GameID = 1 THEN PRINT "Stereospace2 Board Sent to:"; ClientInfo(Scan).IP
  119.                     MSG$ = ""
  120.  
  121.                     '********************************************************************************
  122.                     ' Code for when client requests to close connection
  123.                     '********************************************************************************
  124.                 ELSEIF MSG$ = "CLOSE" THEN
  125.                     SENDMSG Client(Scan), "GOODBYE"
  126.                     ClientInfo(Scan).Active = 0
  127.                     CLOSE #Client(Scan)
  128.                     PRINT "Connection to: "; RTRIM$(ClientInfo(Scan).IP); " closed."
  129.                     MSG$ = ""
  130.  
  131.  
  132.                     '********************************************************************************
  133.                     ' Code for when client requests to be verified
  134.                     '********************************************************************************
  135.                 ELSEIF MSG$ = "HELLO" THEN
  136.                     'CheckIfIPIsBanned
  137.                     SENDMSG Client(Scan), "OK"
  138.                     IF WAITFORREPLY$(Client(Scan)) = "READY" THEN
  139.                         Tmp = INT(RND * 256) + 1 'generate random number for verification
  140.                         SENDMSG Client(Scan), STR$(Tmp) 'send number to client
  141.                         'PW = 'insert math to manipulate random number. Make sure client has same formula
  142.                         Test = VAL(WAITFORREPLY$(Client(Scan))) 'wait for client to send verification code
  143.                         IF PW = Test THEN ' if client got same result as server then verified
  144.                             SENDMSG Client(Scan), "LOCKED"
  145.                             PRINT "Connection to: "; RTRIM$(ClientInfo(Scan).IP); " Locked."
  146.                         ELSE
  147.                             PRINT "Got:"; Test; " instead of"; PW; "disconnecting"
  148.                             ClientInfo(Scan).Active = 0
  149.                             CLOSE #Client(Scan)
  150.                             PRINT "Connection to: "; RTRIM$(ClientInfo(Scan).IP); " closed."
  151.                         END IF
  152.                         MSG$ = ""
  153.                     END IF
  154.  
  155.  
  156.                 END IF
  157.             END IF
  158.         NEXT Scan
  159.  
  160.     LOOP
  161.  
  162.  
  163. '********************************************************************************
  164. ' Backs up server, checks if connections are still active
  165. '********************************************************************************
  166. SUB UpdateServer
  167.     COLOR _RGB(100, 100, 100)
  168.     PRINT "Checking all active connections"
  169.     FOR x = 1 TO 100
  170.         IF ClientInfo(x).Active = 1 THEN
  171.             SENDMSG Client(x), "PING"
  172.             IF WAITFORREPLY$(Client(x)) <> "PONG" THEN
  173.                 ClientInfo(x).Active = 0
  174.                 CLOSE #CONNECTION
  175.                 PRINT "Connection to: "; RTRIM$(ClientInfo(x).IP); " closed."
  176.  
  177.             END IF
  178.         END IF
  179.     NEXT x
  180.  
  181.     PRINT "Backing up database"
  182.  
  183.     FOR x = 1 TO GamesServiced
  184.         IF x = 1 THEN File$ = "Stereospace2.dat"
  185.         OPEN File$ FOR OUTPUT AS #1
  186.         FOR y = 1 TO 20
  187.             PRINT #1, RTRIM$(Leaderboard(x, y).User)
  188.             PRINT #1, Leaderboard(x, y).Score
  189.         NEXT y
  190.         PRINT #1, "EOF";
  191.         PRINT #1, 0
  192.         CLOSE #1
  193.     NEXT x
  194.     PRINT "Writing to web server"
  195.     WriteWebsite
  196.     PRINT "Done"
  197.  
  198.  
  199. '********************************************************************************
  200. ' Loads backed up leaderboards from all games
  201. '********************************************************************************
  202. SUB LoadDatabase
  203.     FOR x = 1 TO GamesServiced
  204.         IF x = 1 THEN File$ = "Stereospace2.dat"
  205.         OPEN File$ FOR INPUT AS #1
  206.         FOR y = 1 TO 20
  207.             INPUT #1, Leaderboard(x, y).User
  208.             INPUT #1, Leaderboard(x, y).Score
  209.         NEXT y
  210.         CLOSE #1
  211.         IF x = gameserviced THEN EXIT FOR
  212.     NEXT x
  213.  
  214.  
  215. '********************************************************************************
  216. ' Website code for server. must edit
  217. '********************************************************************************
  218. SUB WriteWebsite
  219.     'OPEN "C:\inetpub\wwwroot\Scores.html" FOR OUTPUT AS #1
  220.     'PRINT #1, "<html>"
  221.     'PRINT #1, "<head>"
  222.     'PRINT #1, "<link rel="; CHR$(34); "stylesheet"; CHR$(34); " type="; CHR$(34); "text/css"; CHR$(34); " href="; CHR$(34); "css/style.css"; CHR$(34); " />"
  223.     'PRINT #1, "</head>"
  224.     'PRINT #1, "<body>"
  225.     'PRINT #1, "<br><br>"
  226.     'PRINT #1, "<center>"
  227.     'PRINT #1, "<table width=80% border=0>"
  228.     'PRINT #1, "<tr><td>Stereospace 2</tr></td>"
  229.     'FOR y = 1 TO 20
  230.     '    PRINT #1, "<tr><td>"
  231.     'PRINT #1, RTRIM$(Leaderboard(1, y).User); "</td><td>"; Leaderboard(1, y).Score; "</tr></td>"
  232.     'NEXT y
  233.     'PRINT #1, "</table>"
  234.     'PRINT #1, "</body>"
  235.     'PRINT #1, "<body>"
  236.     'PRINT #1, "</html>"
  237.     'CLOSE #1
  238.  
  239.  
  240. '$include:'ipcommsg.bi'
  241.  


LeaderClient.bh
Code: QB64: [Select]
  1. '*************************************************************
  2. '* LeaderClient.bh
  3. '*
  4. '* Header for LeaderClient.bi
  5. '**************************************************************
  6.  
  7. TYPE LeaderBoardObject
  8.     Score AS INTEGER
  9.     User AS STRING * 15
  10.  
  11.  
  12. DIM SHARED LeaderBoard(20) AS LeaderBoardObject
  13. DIM SHARED Server
  14. DIM SHARED ServerAddress AS STRING
  15.  
  16. 'GameID must be unique to every game on your server
  17. GameID =  1
  18. ServerAddress = 'Insert server's address
  19.  



LeaderClient.bi
Code: QB64: [Select]
  1. '****************************************************************************
  2. '* Leaderboard Client v1.0
  3. '*
  4. '* Handles leaderboard communication to server.
  5. '* Requires ipcommsg.bi from ipcomtools
  6. '*
  7. '****************************************************************************
  8.  
  9.  
  10.  
  11.  
  12. '**************************************************************************
  13. '* Gets leader board info from server
  14. '**************************************************************************
  15. FUNCTION GetLeaderBoard
  16.     GetLeaderBoard = 0
  17.     SENDMSG Server, "GETBOARD"
  18.     IF WAITFORREPLY$(Server) = "GAMENO" THEN SENDMSG Server, STR$(GameID)
  19.  
  20.     IF WAITFORREPLY$(Server) = "OK" THEN
  21.         FOR x = 1 TO 20
  22.             SENDMSG Server, "NAME"
  23.             LeaderBoard(x).User = WAITFORREPLY$(Server)
  24.             SENDMSG Server, "SCORE"
  25.             LeaderBoard(x).Score = VAL(WAITFORREPLY$(Server))
  26.             SENDMSG Server, "OK"
  27.             IF WAITFORREPLY$(Server) <> "NEXT" THEN EXIT SUB
  28.         NEXT x
  29.         IF WAITFORREPLY$(Server) = "DONE" THEN GetLeaderBoard = 1
  30.     END IF
  31.  
  32. '**************************************************************************
  33. '* Ends session
  34. '**************************************************************************
  35. SUB CloseConnection
  36.     SENDMSG Server, "CLOSE"
  37.     IF WAITFORREPLY$(Server) = "GOODBYE" THEN CLOSE #Server
  38.  
  39.  
  40. '**************************************************************************
  41. '* Opens connection to server, and handles authentication
  42. '**************************************************************************
  43. FUNCTION OpenConnection
  44.     Server = _OPENCLIENT("TCP/IP:3571:" + ServerAddress)
  45.     IF Server THEN
  46.         SENDMSG Server, "HELLO"
  47.         Step2$ = WAITFORREPLY$(Server)
  48.         IF Step2$ = "OK" THEN
  49.             SENDMSG Server, "READY"
  50.             Tmp = VAL(WAITFORREPLY$(Server)) 'Get random number from server
  51.             PW = 'insert custom math formula to verify with server and manipulate "Tmp".
  52.             SENDMSG Server, STR$(PW) 'Send Key
  53.             IF WAITFORREPLY$(Server) = "LOCKED" THEN
  54.                 OpenConnection = 1 'Verified
  55.             ELSE
  56.                 OpenConnection = 0
  57.             END IF
  58.         ELSEIF Step2$ = "BANNED" THEN
  59.             OpenConnection = 2
  60.         END IF
  61.     ELSE
  62.         OpenConnection = 0
  63.     END IF
  64.  
  65.  
  66. '*************************************************************************
  67. '* Sends score to server
  68. '*************************************************************************
  69. FUNCTION SendScore (User$, Score)
  70.     SendScore = 0
  71.     SENDMSG Server, "SENDSCORE"
  72.     IF WAITFORREPLY$(Server) = "GAMENO" THEN SENDMSG Server, STR$(GameID)
  73.     IF WAITFORREPLY$(Server) = "OK" THEN
  74.         SENDMSG Server, User$
  75.         Step2$ = WAITFORREPLY$(Server)
  76.         IF Step2$ = "SCORE" THEN
  77.             SENDMSG Server, STR$(Score)
  78.             SendScore = 1
  79.         ELSEIF Step2$ = "BANNED" THEN
  80.             SendScore = 2
  81.         END IF
  82.     END IF
  83.  
  84.  
  85.  
  86.  
  87. '$include:'ipcommsg.bi'
  88.  


Ipcommsg.bi
Code: QB64: [Select]
  1. '**********************************************************************
  2. '* Ipcommsg.bi v1.1
  3. '*
  4. '* IP COMMUNICATION TOOLS. MESSAGING ONLY
  5. '*
  6. '* ABILITIES:
  7. '* MESSAGE SENDING / RECIEVING
  8. '**********************************************************************
  9.  
  10.  
  11. '**********************************************************************
  12. '* SENDMSG SENDS RAW STRING
  13. '**********************************************************************
  14. SUB SENDMSG (CONNECTION, MSG$)
  15.     MSG$ = UCASE$(MSG$)
  16.     PUT #CONNECTION, , MSG$
  17. '**********************************************************************
  18.  
  19.  
  20. '**********************************************************************
  21. '* WAITFORREPLY$ HANGS AND WAITS FOR DATA TO BE TRANSMITTED BEFORE TIMEOUT
  22. '**********************************************************************
  23. FUNCTION WAITFORREPLY$ (CONNECTION)
  24.     T! = TIMER
  25.     DO
  26.         GET #CONNECTION, , RPL$
  27.     LOOP UNTIL RPL$ <> "" OR TIMER > T! + 3
  28.  
  29.     IF TIMER > T! + 3 THEN
  30.         WAITFORREPLY$ = "TIMEOUT"
  31.     ELSE
  32.         WAITFORREPLY$ = RTRIM$(RPL$)
  33.     END IF
  34. '**********************************************************************
  35.  

14
QB64 Discussion / Script support in future versions of QB64?
« on: May 02, 2020, 09:05:46 pm »
I would really love to be able to have txt files with code than an exe can run without compiling it. For sprite based games with enemies that have specific behaviors, one could make a generic engine that can do anything really. Or mod existing games without having to give the source out.

15
QB64 Discussion / Image color swap, Part 2
« on: April 08, 2020, 10:37:46 pm »
The original post was locked. However I have an update on progress.

I originally asked for a way to swap colors on a sprite to keep me from photoshoping the same sprite numerous times for color effects. Petr gave me this function... which works flawlessly.

Code: QB64: [Select]
  1. FUNCTION swapcolor (handle, oldcolor~&, newcolor~&)
  2.     DIM m AS _MEM, c AS _UNSIGNED LONG
  3.     swapcolor = _COPYIMAGE(handle, 32)
  4.     m = _MEMIMAGE(swapcolor)
  5.     DO UNTIL a& = m.SIZE - 4
  6.         a& = a& + 4
  7.         c~& = _MEMGET(m, m.OFFSET + a&, _UNSIGNED LONG)
  8.         IF c~& = oldcolor~& THEN _MEMPUT m, m.OFFSET + a&, newcolor~&
  9.     LOOP
  10.     _MEMFREE m

However I also happen to use this same function to make the sprites "flash" random colors when they take damage. The issue is when this is ran a few thousand times the game hard crashes without warning and without the "On Error" command catching it. When i run task manager the memory usage goes up and up until it reaches a point and the game window closes without warning. To be sure i disabled the use of this function and memory usage stays down and the game ran for two hours without a problem. _MEM is very new to me and I dont quite understand it yet.

So my questions are...
1)why is this happening? If it is using _MEMFREE to release m then in theory memory usage shouldn't climb like the way it is.

2)how could I fix this? and if not is there maybe a way to do this without using _MEM since i suspect that is the culprit.

Pages: [1] 2