Collision Issues
Yes, to the last 39 people that seen this, you're not crazy, you've seen this post before. This is just an update so you can actually view the game in its demo phase so you can see everything. If you copy my code and publish it as your own without giving credit, I will not be happy.
Otherwise, I am trying to write my own first game as a beginner. I am using microscript 2.0 and nothing else in it. However, my playable character "tabbox" passes through the tiles I've added on the map (which is a floor using the tile "cloud" in a basic 36*24 map) and does not collide with them (it is not published publicly since I'm starting to work on it). They are given no gravity as they behave as a regular computer tab, but sentient. What should I do/add/remove to my pre-existing code where my character can be stopped by such tile(s)? Any help would be appreciated!
Project link (sorry for not posting it last time):
https://microstudio.io/i/Starline/tabboxdemov1/
ok so make sure to use my library since this update code uses it and I fixed all the collision issues
basically what was happening was you where checking x and y even though the actual sprite was centered always and only the map was moving so I put it to a fixed position the lib is https://microstudio.dev/i/AJiscool/msaddons/ just add that and this code and it will work
init = function()
mode = "title"
x = 140
y = 45.5
currentSprite = "tabbox"
map = maps["level1"]
curMap = "level1"
tileSize = 16
half = tileSize / 2
solidTiles = [ 1,2 ]
end
update = function()
if mode == "title" then
updateTitleScreen()
elsif mode == "play" then
currentSprite = "tabbox"
speed = 1.5
if keyboard.LEFT then
if mapHit(-7.5,0,curMap) or mapHit(-7.5,-4.5,curMap) or mapHit(-7.5,4.5,curMap) then
else
x -= speed
end
currentSprite = "tabbox_left"
end
if keyboard.RIGHT then
if mapHit(7.5,0,curMap) or mapHit(7.5,-4.5,curMap) or mapHit(7.5,4.5,curMap) then
else
x += speed
end
currentSprite = "tabbox_right"
end
if keyboard.UP then
if mapHit(0,4.5,curMap) or mapHit(7.5,4.5,curMap) or mapHit(-7.5,4.5,curMap) then
else
y += speed
end
currentSprite = "tabbox_up"
end
if keyboard.DOWN then
if mapHit(0,-4.25,curMap) or mapHit(7.5,-4.25,curMap) or mapHit(-7.5,-4.25,curMap) then
else
y -= speed
end
currentSprite = "tabbox_down"
end
camX = x - 150
camY = y - 100
end
end
draw = function()
screen.clear()
if mode == "title" then
drawTitleScreen()
elsif mode == "play" then
drawgame()
end
end
drawgame = function()
screen.clear("#FFF")
screen.setScale(3,3)
screen.drawMap( "level1", -camX, -camY, 300, 200)
screen.setScale(1)
screen.drawSprite(currentSprite, 0, 0, 60)
end
Your library made collisions work in my non demo version and TabBox hits them just fine without passing through. I credited you and your library in my Doc file of it as well, so thanks! :)