Jump to content
  • Advertisement

Rico Solana

Member
  • Content count

    2
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Rico Solana

  • Rank
    Newbie

Personal Information

  • Role
    Programmer
  • Interests
    Programming

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Rico Solana

    LUA Smooth tile movement

    I agree with you that I could check for the next tile and wait a time for the animation to finish, but I suppose that the reason I had complex math was because objects are capable of colliding with other objects without being in the center of each tile. If I were to use the method you had, moving from tile to tile and in-between each tile movement waiting for the animation of movement to finish, Pacman would have to wait the entire frametime of the animation until a command can be entered; then can move (This mainly applies to moving backwards -- doesn't apply to turning towards a side because Pacman can only turn towards an empty space when in the center of a tile -- the animation would be canceled by then). Do you have an idea/suggestion for that? (I've been working on this since December; so anxious to get it over with; to call it a day; to close the book...)
  2. You know Pacman, the game with the pellet eating monster; I'm trying to recreate that (Mrs Pacman actually). Because the game is arranged in a series of 28 x 31 tiles, smooth collision for this is difficult to recreate. Here's the tilemap: nodemap = { {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, {1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1}, {1,1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1,1}, {1,1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1,1}, {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}, {1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1}, {1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1}, {1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1}, {1,0,0,0,0,1,1,0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,1,1,1,0,1,1}, {1,1,0,1,1,1,1,0,1,1,1,1,1,0,1,1,0,1,1,1,1,1,0,1,1,1,1,0,1,1}, {1,1,0,1,1,1,1,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,1,1,1,1,0,1,1}, {1,1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1,1}, {1,1,0,1,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,1,0,1,1,1,1,0,1,1}, {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}, {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} } This is my collision code (And explanations for each segment): -- Make Pacmans position consist of a single decimal (because over time a number of 1.899999994 will occur and that's ugly) mrspacman.x = math.floor(mrspacman.x*10)/10 mrspacman.y = math.floor(mrspacman.y*10)/10 --If an arrowkey was pressed (Think of this as "A new direction was queued") if (mrspacman.nextDirection) then -- If Pacman is in the center of a tile, then if (mrspacman.x == math.floor(mrspacman.x)) and (mrspacman.y == math.floor(mrspacman.y)) then -- If the tile in front of Pacman is empty, set direction to that if (nodemap[mrspacman.y-math2.sin(mrspacman.dir)][mrspacman.x+math2.cos(mrspacman.dir)]~=1) then mrspacman.dz = mrspacman.dir -- Disable this queue mrspacman.nextDirection = false end end end -- If Pacman is NOT in the center of a tile if (mrspacman.x ~= math.floor(mrspacman.x)) or (mrspacman.y ~= math.floor(mrspacman.y)) then -- Constantly move forwards mrspacman.x = mrspacman.x + (math2.cos(mrspacman.dz)*mrspacman.speed) mrspacman.y = mrspacman.y - (math2.sin(mrspacman.dz)*mrspacman.speed) else -- If the tile in front of Pacman is empty, move to that tile if (nodemap[mrspacman.y-math2.sin(mrspacman.dz)][mrspacman.x+math2.cos(mrspacman.dz)] ~= 1) then mrspacman.x = mrspacman.x + (math2.cos(mrspacman.dz)*mrspacman.speed) mrspacman.y = mrspacman.y - (math2.sin(mrspacman.dz)*mrspacman.speed) end end The above results in this (sometimes unable to go backwards, movement is sometimes faster towards a vector compared to the opposite vector, will stop when going back, and freeze...) How can I implement this smooth movement? math2.cos / math2.sin is just a custom table I created with those 2 trig functions (makes code cleaner looking, and I don't have to mess with accuracy of converting deg-->rad.) mrspacman.speed has a value of .1
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!