Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [STICKY] Some usefull 2D and 3D tools effects and snippets

Author
Message
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 10th Feb 2019 21:16 Edited at: 7th Mar 2019 23:58
A bare bones 3D Placement editor EDITED


Keys
F1 load an object and then an image to assign to it
f2 save test.data
L to delete all and load objects as set in test.data
<, > rotate object
+,- scale object
w,a,s,d,shift move camera
Clicking and holding mouse rotates mouse around its position
Right Clicking an Object moves camera to concentrate on that object (ie so it would rotate around that object)
arrow keys ,shift move current object

Function
creates a test.data file that can be later used in your program that can load a series of objects
saving there name, scale, xangle, yangle, zangle, xpos ypos, and zpos

Note: It will save the file test.data in the same directory as the last object loaded

Using the data You could then use this function in your program to load position rotate etc your objects
fubar
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 11th Feb 2019 12:43 Edited at: 11th Feb 2019 12:49
Hi fubarpk

Nice programm . I tested loading and placing two objects pressing f1 and f2 ...then I try to load and couldn't fine file ...I just checked every thing in media folder and realize that the file created was "tetest.data" ....it should be "test.data" instead of tetest.data so it was easy to find where was the error ...in line 96 , instead of :

Quote: "saveData(objects,"raw:"+left(ret$,len(ret$)-(len(objects[current].name)+1))+"test.data")"
... I had to write

saveData(objects,"raw:"+left(ret$,len(ret$)-(len(objects[current].name)+3))+"test.data")



with this change, I can now save both objects and load them again pressing L key
When I load a third object and save it again it just is not there...
I realize aswell that when we scale object and save, ....when load it, the object doesn't keep the scaling... I think that should be easy to mend just setting object pivot ...and setting object permanent scale.
I could with object pivot but couldn't with setobjectscalepermanent .

It is not a criticism but rather an observation any way with some adjustements is a good snippet

Edit.
When I place the object and try to save again I have a path error .


I'm not a grumpy grandpa

Attachments

Login to view attachments
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 11th Feb 2019 13:07 Edited at: 11th Feb 2019 13:49
Thanks Chafari
just something I threw together out of necessity

Quote: "saveData(objects,"raw:"+left(ret$,len(ret$)-(len(objects[current].name)+3))+"test.data")"

strange cos 1 works well for me the idea it just determines the raw path by subtracting the length of the last object name as the lengths begin at zero I needed to add one
I seem to recall you saying something about using Vista or something that may be the issue not really sure

Quote: "When I load a third object and save it again it just is not there..."

not sure it may be the array objects will look later I thought if I deleted everything in the array and if I set current to -1 it would work

Quote: "I realize aswell that when we scale object and save, ....when load it, the object doesn't keep the scaling"

the command is there in loadobjects just commented out


Quote: "When I place the object and try to save again I have a path error ."

I think that's because you have loaded with test.data and not loaded another object to get a new path to save to and test.data having a different extension
I should have a variable that sets it so as the file wont save again unless there is changes and perhaps a message displaying if saved or not

Hahahah its bound to have a few bugs I just whipped it up hoping it could be of help to me but thought ide share, it was painstaking trying to place the billboards in KrazyGrandPrix otherwise

EDITED the above code to only allow saves when there is changes and some message boxes so as can see whats happening
fubar
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 13th Feb 2019 01:21 Edited at: 13th Feb 2019 07:33
A Shatter-Sprite Routine
was experimenting with a shatter routine for 2D like I have used for 3D in the Past
could be used when you don't have an exploding sprite animation I guess. The 3D
version is much more effective

for this one I used the below image


PS: I think a shader could do the same effect nicer as what really needs to be done is have all pixels move outward in a circular way and could just have a larger
image than shown with allot of transparency to compensate and move each pixel outwards

Could possibly be improved with a memblock by reading each colour of an image from left to right top to bottom and writing that colour on the image one to the left and one above
for all pixels in the left quarter zone of the image. then repeated for all other quarters as needed. Curious how that will work may or may not try later as I think it may be slow

Experimenting with just two sprites and scaling them doesn't work anywhere near as well I prefer the top snippet ohwell lol
fubar
puzzler2018
User Banned
Posted: 13th Feb 2019 07:11
Wow - this looks interesting.

Cannot wait to test it out later on after work.

On Lemmings - I had the similar premise on shattering the follower in similar manner.

Cool

Tier 1 Developer
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 13th Feb 2019 07:44
Quote: "Wow - this looks interesting."

Ide also like to try as a memblock

where an image is though of as quarters
1,2
3,4
zone 1 pixels would move one to the left and one upward
zone 2 pixels would move one to the right and one upward
zone 3 pixels would move one to the left and one down
zone 4 pixels would move one to the right and one down

I think that could give a nice effect still not like it works in 3d as parts lol but might look good

then return the new image
replace old image with new one
maybe delete old image for code housekeeping

just will have to have a think about memblocks first as a slight incorrect placement will cause program crashes
fubar
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 14th Feb 2019 22:03
Nice work fubarpk I try to press spacebar twice but couldn't get it repit
I'm not a grumpy grandpa
puzzler2018
User Banned
Posted: 17th Feb 2019 19:11
So just that we dont loose touch with this - may come in handy with lots of things

Object Mesh Building



Left click block to raise
Right click block to lower

Space and mouse move changes camera

Tier 1 Developer
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 17th Feb 2019 19:16 Edited at: 18th Feb 2019 05:55
Thanks puzzler ive spent ages going through threads in the past
to find code that's buried deep in some other code in one of the pages
Object Mesh Building
Changed to the following this way it don't ever error and a few other things like crater creation etc
fubar
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 5th Apr 2019 01:00 Edited at: 5th Apr 2019 01:01
2D Clouds Sprite Shader


3D Clouds Shader Same as above but 3D version
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 24th May 2019 00:12
factorial function
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
shiku316
6
Years of Service
User Offline
Joined: 6th Nov 2017
Location:
Posted: 24th May 2019 08:11
Hi! didn't know where to post my question, but since its 3d related and need a little snippet i thought about posting here.
Does anyone know how to get multiplayer with game guru loader? Any orientation will be greatly appreciated.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 24th May 2019 09:11
@shiku316 you would do best to start your own thread as more people would see it
and your more likely to find a solution to your problem
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 2nd Jul 2019 01:02
not sure how useful people will find this
but if you want to pixelate the texture of a 3D object using a shader

fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 2nd Jul 2019 10:05
@ fubarpk This will come very handy for my retro game . Thanks for sharing
I'm not a grumpy grandpa
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 2nd Jul 2019 15:15 Edited at: 2nd Jul 2019 15:56
thanks glad you like it Chafari
I was thinking it could be used to bring things in and out of resolution like (use arrow keys)


or to imitate digital tv reception problems
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 2nd Jul 2019 16:32
Yeah !! You are a genius !! this could be useful for camera depth making object more blured in the distance ...I will make some test later on .
I'm not a grumpy grandpa
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 2nd Jul 2019 17:12
Thanks
Ive been playing with the scanline shader


works better if you use a proper model
if you look at the ps file there is a line that can be commented un commented to remove the staticky look
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 2nd Jul 2019 23:16 Edited at: 2nd Jul 2019 23:17
That is nice ...could be used for some kinda hologram .

I made some test based on your first pixelate shader . I think could be done the camera depth with it ...this snipet needs some adjustements but here's what I have so far.




I'm not a grumpy grandpa

Attachments

Login to view attachments
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 2nd Jul 2019 23:32
That's quite interesting chafari
i didnt have muros.png so i used my own brick texture which might be different dimmensions
but i see the effect your creating. Could be good for an old retro game remake and using it
real time. I was originally thinking it might be good for an intro sequence where the objects
started off pixelated and slowly come into view at the beginning of the game. Then they could be
set to no shader so they revert back to default and no speed loss. Which could also be acheived
with a sprite shader but you couldnt have camera panning into the scene. Combined with your
effect could make for a great intro. VERY INTERESTING
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 14th Jul 2019 03:46 Edited at: 14th Jul 2019 04:07
Been playing with Character Controllers and I figured basic car physics can be achieved
Basic Car Physics Its nowhere as sophisticated as blinks bullet car physics but it
may be usefull for a retro remake, the demo also shows that jumps are achievable


PS: the camera angles are bad but easily fixable
the main thing I find is the steering isn't correct but im sure there is a formula out there that calculates a steering
amount based on present velocity and strafe movements could be used for a sliding algorithm
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 14th Jul 2019 04:41
Nice work
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 26th Jul 2019 20:37 Edited at: 26th Jul 2019 20:37
A Sprite Shader effect needs a texture assigned to the sprite

fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Qugurun
Valued Member
9
Years of Service
User Offline
Joined: 8th Dec 2014
Playing: AppGameKit
Posted: 27th Jul 2019 11:22 Edited at: 30th Jul 2019 15:38
https://www.instagram.com/qugurun/
Rick Nasher
6
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 3rd Aug 2019 23:12
I find the Basic Car Physics thingy rather interesting. Is their a specific reason you didn't use box=CreateObjectBox ( 2, 2, 4)? For it appears to be working just as well.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 4th Aug 2019 09:36
Thanks Rick I was playing with the angle of the ramp hoping I could make it work at a greater angle
i found Get3DPhysicsCharacterControllerMaxSlope( objID ) helps but changing it to much really
created some unusual behaviour









fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 18th Aug 2019 07:55
I have here a shader that I am using in macroaction which basically turns any object above a set point transparent
and any point below a set point transparent
fade.vs


fade.ps

to use the shader I set all objects I want to transparency ie in part etc like the following


i set it up to its alpha value like the following and set the players position for the shader as follows

fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 6th Sep 2019 01:29
Image 3D file loader
Im not sure how useful people will find this, but it basically loads an image and depending on the colour of the pixels of the image
loads a 3D object into the world at that pixel location in the 3D world. It requires a text file like the following that maps the colour to
an object and texture for that object
test.map

main.agc

It was originally designed to convert 2D games to 3D and uses constants that can be changed for the tile width,height depth etc
it requires two png images in the above example to get it to work but the code is just an example of how it could be used and allows
for several different layers to be saved.

PSAs the original idea was to convert 2D games to 3D for best results it is assumed that all 3D objects are the same size as
each other.
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 23rd Sep 2019 05:16 Edited at: 23rd Sep 2019 13:31
Kinda work in progress but its meant to give the effect of melting the object
Note works best if pivot is at the bottom


PS if you uncomment this //a=clamp(a,0.0,1.0);
it wont go below the bottom. The scaling is kinda wrong and currently wont play animations


why not use setobjectscale you may ask because then you would have to set the object position
each time for the same effect
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 28th Oct 2019 00:42 Edited at: 28th Oct 2019 00:45
Another 2D snow example this time using a shader.
you will see that the house sprite appears to have snow going behind and infront of it at same time
this can be changed by setting the house sprites depth
no media required

fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
DannyD
6
Years of Service
User Offline
Joined: 29th Aug 2017
Location:
Posted: 28th Oct 2019 01:42 Edited at: 28th Oct 2019 01:42
@fubarpk
Thanks for all the help full examples

Unfortunate, I don't see any snow with the latest 2d Snow example. Only the red house

Thanks Mate!

EDITED: Works 100% in Classic, but not in Studio...
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 30th Nov 2019 02:34 Edited at: 30th Nov 2019 03:29
Some functions that should make accessing mesh memblocks easier (Does not support quads unfortunately)

integer GetPolysFromMemBlock(id as integer)
id = memblock id
integer = The number of polys in this mesh

tPoly = GetPolyFromMemblock(id as integer, n as integer)
id = memblock id
n = poly (from 0 through (GetPolysFromMemBlock() - 1))
tPoly = tPoly.vertex is a table containing information for the 3 vertex that make up the poly
tPoly.vertex.pos - Position of vertex x, y, z
tPoly.vertex.normal - Vertex normal x, y, z
tPoly.vertex.uv - Vertex uv u, v
tPoly.vertex.color - Color of vertex (if supplied)

I'm thinking it would be entirely possible to make a SaveObject() function using this code

NOTE : The GetPolyFromMemblock() will SetErrorMode(2) on exit. It needs to SetErrorMode(0) because if some of the vertex data is missing it will crash

To demonstrate this code will draw an objects wire mesh



Haven't given given it a super dooper test but it seems to work for primitives and i tried it on one of my models

Attachments

Login to view attachments
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 30th Nov 2019 02:39
Thanks Blink that could come in very handy
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 30th Nov 2019 02:47
No worries matey.
Just remember it draws the wire mesh using the vertex information so if you move or rotate the object the wire frame stays at 0,0,0
If you want the wireframe to accurately reflect the objects state then you would need to CloneObject(), FixObjectPivot(clone) and then use the clone to create your Mesh MemBlock
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 12th Dec 2019 06:53 Edited at: 12th Dec 2019 07:02
not sure if anyone will find this useful but a timer countdown shader

if your after healthbar shaders there is much better ones on the shader thread I just thought ide have a play
ps you need the attached png and your good to go
HAHAHAHA think I need one of those gui shader creators to really grasp them
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk

Attachments

Login to view attachments
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 1st Mar 2020 01:47 Edited at: 1st Mar 2020 04:37
here is kinda a matrix shader
I don't really like the way it turned out but thought ide share

you could change this
WriteLine(file," finalColor *= vec3( (g/2.)*(resolution.y-gl_FragCoord.y)/resolution.y, g/2., g );")
to this if you just want green
WriteLine(file," finalColor *= vec3( 0, g/2., 0);")

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 1st Mar 2020 03:12
Nice!
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 19th Mar 2020 21:04
I think it might be a good idea to pin this thread. I've been in here for help quite a few times
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 19th Mar 2020 22:02
Thanks blink not so sure I want to pin my own threads tho hahahahahah
hope you are well

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 19th Mar 2020 23:28
Here, use mine . lol
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 18th Jun 2020 06:47
GlobalToLocal3D()
This function will take a world point and convert it to the co-ordinate space of an object. (A bit like GetSpriteXFromWorld() only for objects)
It is very handy to determine a point relative to an object.
So if the returned x value is positive then the point is on the right hand side
If the returned z value is negative then the point is behind the object
If the returned y value is positive then the point is above the object

For this to work you need to fix an object to the center/pivot of your object and pass that id to the function.



fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 18th Jun 2020 10:23
thanks blink you always have such great things to contribute to the community

anyone else feel free to add stuff

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 10th Jul 2020 03:55 Edited at: 12th Jul 2020 16:39
For those that didnt follow my Macroaction Thread, here is shader that turns all objects above a given range transparent
and all objects below a given range. This may help when people are recreating a 2.5d game with several floor levels as you
really only want to have the floor the player is on in full visibility



this line SetShaderConstantByName(fadeShader,"myCoord",-5,5,1,1) //should be used with a calculation from the players y coords
eg SetShaderConstantByName(fadeShader,"myCoord",getObjectY(player.collisionID)-5,(getObjectY(player.collisionID)+12),1,1)

the above version of the shader makes it transparent above and below given ranges the following variation restricts the transparency between the height parameters
note it now has x coords and y coords to pass (myCoordX and myCoordY)

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 14th Jul 2020 02:42 Edited at: 6th Aug 2020 06:01
Ive attached the source code to the following video
i couldnt get the bones perfectly in side the model but i worked around that
by creating a second shader which is an inverse effect of the first
The animations created in Mixamo


fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk

Attachments

Login to view attachments
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 14th Nov 2020 01:16 Edited at: 14th Nov 2020 01:16
Handy function to help debug sprites. Just add a call to DumpDebug() where you want to examine where sprites are
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 14th Nov 2020 18:16
getting the location of a sprite and angle so as a bullet can be positioned correctly can be a little tricky sometimes
usually its as simple as

but sometimes you need to use more advanced methods
1>

2>courtesy of virtual nomad


code copied from discord

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 1st Jan 2021 05:23 Edited at: 1st Jan 2021 21:28
using a memblock to grayscale


the same using a shader


fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 14th Jan 2021 00:44 Edited at: 16th Jan 2021 19:13
Map generator using the Random Walk Algorithm
1>Makes a two dimensional map of walls
2>Chooses a random starting point on the map
3>While the number of tunnels is not zero
3>Chooses a random length from maximum allowed length
4>Chooses a random direction to turn to (right, left, up, down)
5>Draws a tunnel in that direction while avoiding the edges of the map
6>Decrements the number of tunnels and repeats the while loop
7>Returns the map with the changes

Note: the larger the maxTurn is compared to the dimensions, the denser the map will be.
The larger the maxLength is compared to the dimensions, the more “tunnel-y” it will look.
Its a commonly known and used algorithym and has known issues that are commonly known
try it copy paste (run repeat) give it a go. There is also a simple character/monster movement in documented
source below.



Map integration
1>black tiles cant do anything here
0>white tiles area to move
2>red tiles area to discover
3>yellow tiles items
4>green tile you as player
4>blue tiles monsters

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 26th Jan 2021 18:17 Edited at: 26th Jan 2021 18:31
SOME MATH FUNCTIONS (without using built in vector commands)

2D distance calculation function

3D distance calculation

4D distance calculation a time derivative (but i use for in/out)[/b]

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 27th Jan 2021 10:11 Edited at: 27th Jan 2021 10:17
For such a small amount of code, there are quite a few things wrong with (or could be improved within) your distance function.

Firstly: you shouldn't restrict the input/output to integers. Even if you're working with a fixed 2D grid that can only have integer inputs, the output should be a float.
For example, take the inputs 0, 0, and 1, 2. The distance between those two coordinates is 2.36. Which is definitely not the same as 2 even in a fixed grid system.
Restricting the output to an integer means that the values (0, 0, 1, 2) and (0, 0, 0, 2) would both return 2 and therefore give the same resulting distance, which is clearly not the case.

Secondly: the POW() function is a recursive function and therefore slower than calling the multiplication twice.
2*2 is faster than POW(2, 2)

Thirdly: calling ABS() is a wasted function call. ABS() removes the negation of a value (eg, -2.36 becomes 2.36). However, the calculation of the distance function will always return a positive value, so you can eliminate that step entirely.

A faster and more accurate distance function would be:


You can even improve that further by removing the sqrt() function and instead check for distance squared.

If you use the second variant, then instead of searching for a distance of say 5, you would search for 5 squared or (5 * 5) or 25. Which is a lot quicker than square rooting the distance.
In a one-off call you might think "so what?". But if you are checking the distance of 1000's of items every frame it soon adds up and every little helps.

Login to post a reply

Server time is: 2024-03-29 10:45:20
Your offset time is: 2024-03-29 10:45:20