Post by eyfenna on Jul 18, 2019 13:51:59 GMT -6
The GetPixel(x,y) function allows to code a quick collision detection algorithm based on a colour at a position:
Sub DrawEndBoxes()
Canvas (0)
SetColor(RGB(0,255,255))
BoxFill (100,100,200,200)
end sub
sub DrawBlockBox()
Canvas (0)
SetColor(RGB(255,0,0))
BoxFill (100,100,200,200)
End Sub
Sub DrawCharacter(x,y)
Canvas (0)
SetColor(RGB(255,255,255))
BoxFill(x-4,y-4,x+4,y+4)
End Sub
Sub ScanSurrounding(x,y, byRef ub, byref db, byref rb, byref lb)
Canvas (1)
xl = GetPixel(x-5,y)
xr = GetPixel(x+5,y)
yu = GetPixel(x,y-5)
yd = GetPixel(x,y+5)
ub = 0
db = 0
rb = 0
lb = 0
if xl = RGB(0,255,255) then
lb = -1
end if
if xr = RGB(0,255,255) then
rb = -1
end if
if yu = RGB(0,255,255) then
ub = -1
end if
if yd = RGB(0,255,255) then
db = -1
end if
end sub
WindowOpen ( 0, "TEST WINDOW", 100, 100, 640, 480, 0 )
CanvasOpen ( 0, 640, 480, 0, 0, 640, 480, 0 )
CanvasOpen ( 1, 640, 480, 0, 0, 640, 480, 1 )
dim Position[2]
Position[0] = 320
Position[1] = 240
dim ub
dim db
dim rb
dim lb
While (true)
ClearCanvas
DrawBlockBox()
ScanSurrounding(Position[0],Position[1],ub,db,rb,lb)
If key(K_UP) Then
if ub = 0 then
Position[1] = Position[1] - 0.5
end if
ElseIf key(K_DOWN) Then
if db = 0 then
Position[1] = Position[1] + 0.5
end if
End If
If key(K_LEFT) Then
if lb = 0 then
Position[0] = Position[0] - 0.5
end if
ElseIf key(K_RIGHT) Then
if rb = 0 then
Position[0] = Position[0] + 0.5
end if
End if
Canvas (0)
ClearCanvas
DrawEndBoxes()
DrawCharacter(Position[0],Position[1])
Update()
Wend
the getPixel function seems to retrieve the color from the frontbuffer (the picture that is visible on the screen) or the backbuffer (the buffer that is going to get drawn)
However if it is possible to modifiy it to get the colour of a pixel from a canvas then a graphic primitive can act as the place for a signal. Depending on wether the canvas is opaque or transparent this marker for the signal could be seen.
In games collision detection is vital, however also checking if something is an upgrade, if there is a teleporter to another place, or if something is an enemy, or if a sprite is on land or in for example water (slower movement speed) are part of collision detection. With a mechanism based on colour coding this could be done in a visible manner and provide 16.581.375 states that a specific behaviour in a program gets activated.