Color Based Collisions
I’m making a basic topdown 2d game and I am wondering how I would make collisions if the player is touching a certain color.
Here is the basic move player:
if keyboard.UP then
player.y += player.speed
player.walkingDir = "up"
end
if keyboard.DOWN then
player.y -= player.speed
player.walkingDir = "down"
end
if keyboard.RIGHT then
player.x += player.speed
player.walkingDir = "right"
end
if keyboard.LEFT then
player.x -= player.speed
player.walkingDir = "left"
end
You can use PaulSts Screen Tool Library :)
https://microstudio.dev/i/PaulSt/screentoolslibrary/
It can be used to get the color of pixels on the screen, just check the documentation.
You can use your player coordinates and then (if needed) you add an offset in x/y depending on the walkingDir.
You can use Quick-Engine, to create a non-solid sprite object that has a sprite of a certain color attached, then check the collision between that color object and the player.
init = function()
Quick.init()
Quick.gravity = 0 //for top-down
player = Quick.addSprite('player_sprite', 0, 0, 32, 32)
color_trigger = Quick.addSprite("greenObject_sprite", 0, 0, 32, 32)
color_trigger.solid = false
showWalls = true
end
update = function()
if Quick.spriteCollision(color_trigger, player) then
showWalls = false
end
end