Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7959093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:31:07+00:00 2026-06-04T04:31:07+00:00

So, I have been working on this game for a bit. However, over the

  • 0

So, I have been working on this game for a bit. However, over the past day I have not been able to figure out how to work my collision detection.

The scale at default is equal to 2.

The player is 41*scale by 64*scale.

My player is centered in the middle of the screen in both the x and y axis.

Since the player is centered the world is what moves, those variables are worldx and worldy. The player always stays at the center of the screen.

My tile map is stored in an array and is based on the image pixel color. If the pixel is white at map[x][y] the value is set to 0 else it’s set to the block. Meaning the block does not get rendered.

for x = 0, w-1 do --scans the image and builds the map array
   amap[x] = {}
   for y = 0, h-1 do
      local r, g, b, a = source:getPixel(x, y)
      if r == 255 and g == 255 and b == 255 then
         block = 0
      end
      if r == 255 and g == 100 and b == 0 then
         block = 1
      end
      if r == 130 and g == 125 and b == 0 then
         block = 2
      end
      if r == 76 and g == 76 and b == 76 then
         block = 3
      end
      if r == 255 and g == 0 and b == 255 then
         --this is the spawn pixel yet to build
      end
      amap[x][y] = block
   end
end --end function

function that draws the map

for x = 0, w-1 do --draws the map
   for y = 0, h-1 do
      if amap[x][y] ~= 0 then
         love.graphics.drawq(ImgBlocks, Blocks[amap[x][y]], 32*x*(3/bscale) + worldx, 32*y*(3/bscale) + worldy + jy, 0 , 3/bscale, 3/bscale)
      end
      if amap[x][y] == 4 then  
      end
   end
end --end function

The function needs to return true or false base on if there is collision between player and block.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:31:08+00:00Added an answer on June 4, 2026 at 4:31 am

    Your tiles are 32×32, correct? (from the drawq call) I would recommend you make a function that checks if a point is in a solid tile:

    function pointCollisionTest(x, y)
        -- find which tile the point is in
        local tx, ty = math.floor(x / 32), math.floor(y / 32)
        -- check the tile
        if map[tx][ty] == solid then
            return true
        else
            return false
        end
    end
    

    You’ll have to change the if map[x][y] == solid logic based on how you determine solid tiles, but this code should otherwise work.

    Once you have point collision, the way you make the player collide is by checking each corner of its hitbox (which you should easily be able to determine) against this function whenever the player moves. There are a few ways to do this; I use the relatively simple method of calculating the player’s new position, testing it, then canceling the move entirely if the collision test returns true. You have to check/cancel the x and y components of the move separately, though, so the player can move along walls instead of sticking to them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on this for some time. The script does work and
Can anyone help me with this? I have not been able to find anything
I have been working on an Android game for the past 6 months or
For the past few days, I have been trying to figure out how to
Possible Duplicate: Send NSString via Game Center i have been working on this for
I have been working on a card game in python 3.2 and am not
Have been working on this question for a couple hours and have come close
I have been working on this problem for 2 days now and it's an
I have been working on this for days but I don't get it so
I have been working on this problem for a while now. I am trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.