More screen functions - drawPoint(), getPoint(), toSprite()
A key missing feature from the language is way to set and read and individual points in the screen buffer.
I suggest adding:
// plot a point
screen.drawPoint(x,y,)
// read a point
rgb=screen.getPoint(x,y)
Another useful function would be to grab a section of the screen and create a sprite from it:
// grab a region of the screen and create a sprite from it
mysprite=screen.toSprite(x,y,w,h)
This sounds great! But a few suggestions that I would like to add on.
Grab a region - if we could grab from inside a polygon that would be even more useful so mysprite=screen.toSprite(x1,y1,x2,y2 ...)
Plot a point - We already have screen.fill functions (obviously) such as screen.fillRound, so if there was just a way to read all pixels in the screen at all times this wouldn't be necessary, right?
So does a screen.getPoint(x,y) which returns the colour value at the screen position work?
My situation where I need to read pixels is for example, to see if a particular area in the screen is vacant.
Imagine a filled screen of blue colour, with say some think black lines drawn at various angles and locations to form a constructed maze.
Now you want your character to roam around with the maze (black colour) only. In other engines it is very easy to just read pixels at particular points from the screen to see if the player is about to collide with (in this case) a blue colour.
I agree. In any case, we can write functions to detect when some cells of a map, some sprites or some shapes are being touched. ;)
getPoint
is definitely needed!
drawPoint
could certainly be handy to have, note that you can also use fillRect or fillRound for that. You could also extend screen when you need it, like this:
screen.drawPoint = function(x,y)
fillRect(x,y,1,1)
end
(if you want thinner points you can change those values of course!)
Regarding toSprite
, what I have in mind for now is to provide an API for creating and drawing on offscreen images / sprites. Along with this API, a function to capture an area of the screen into a sprite could certainly be useful too.
I am currently in holidays thus don't expect me to work on this very soon though!
Right. There is a mymap.get(x,y) function and mymap.set(x,y) as well which can both work. But that reminds me - would line distance estimators work for your game (a.k.a circle to line collision)? It works for any point and any line, and square to line collision is also possible. See below for an an example of circle line collision:
:embed https://microstudio.io/this_name_is_taken/linedistance/8BW2X684/
(green circle is distance, white circle is point of intersection)
That looks like the start to a cool game @that_guy_does_crazy_stuff :)
I just haven't figured out how to win, LOL
Haha, and yep! This actually could be used for some kind of game - like a platformer or something similar.
Plus, the code needed is quite minimal. The unpunched version of the code looks like this:
linedist=function(x1,y1,x2,y2,liner,px,py,pr)
x=px-x1
y=py-y1
altx=x2-x1
alty=y2-y1
dot=x*altx+y*alty
t=dot/(altx^2+alty^2)
t=min(max(t,0),1)
outx=x1+t*altx
outy=y1+t*alty
dist=sqrt((px-outx)^2+(py-outy)^2)-(liner+pr)
dir=atand((px-outx)/(py-outy))
if py>outy then
dir+=180
end
outx-=sind(dir)*(liner+pr)
outy-=cosd(dir)*(liner+pr)
end
YEAH ... learned something new :) oh @that_source_of_wisdom
I'm familiar with the line distance itself, but didn't know how to add a radius to it.
Thanks for that :)
Live Long and ... keep your distance?
No problem! Adding a radius (or 'rounding the edges') of any distance formula is as simple as just subtracting the radius!
There are a few other nice transforms that you can do (eg. smooth transitions, scaling). If you are interested, inigo quilez (creater of shadertoy) has a nice website on distance functions you can see here - https://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm .