Computer Science Canada Moving character's unit collision |
Author: | Beaver Tails [ Sat Mar 29, 2014 6:38 pm ] | ||
Post subject: | Moving character's unit collision | ||
What is it you are trying to achieve? <Replace all the <> with your answers/code and remove the <>> What is the problem you are having? <Answer Here> Describe what you have tried to solve this problem <Answer Here> Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here>
Please specify what version of Turing you are using <Answer Here> |
Author: | Beaver Tails [ Sat Mar 29, 2014 6:40 pm ] |
Post subject: | RE:Moving character\'s unit collision |
Sorry, i screwed up the post so heres the edit What is it you are trying to achieve? The character to not collide with the shop What is the problem you are having? cant get the character to get to not collide with the shop. I've looked unit collision up on the fourms but i'm using true (only 1 of each x and y value) but others are using false (2 of each x and y value). |
Author: | Insectoid [ Sat Mar 29, 2014 7:19 pm ] |
Post subject: | RE:Moving character\'s unit collision |
Assuming your collision detection is between rectangles, you need to have 2 x and y values per unit. If you only have one x and y, then you probably have a width & height, and can use those to create the 2nd x and y pair. From there, you just do what the tutorials tell you. |
Author: | Beaver Tails [ Mon Mar 31, 2014 10:16 pm ] |
Post subject: | RE:Moving character\'s unit collision |
characterSprite := Sprite.New (Pic.FileNew ("character.bmp")) Sprite.SetPosition (characterSprite, x, y, true); Sprite.Show (characterSprite) loop Input.KeyDown(chars) if chars(KEY_UP_ARROW) then if y < maxy - 16 then y := y + moveSpeed end if end if if chars(KEY_DOWN_ARROW) then if y > 16 then y:= y - moveSpeed end if end if if chars(KEY_LEFT_ARROW) then if x > 16 then x:= x - moveSpeed end if end if if chars(KEY_RIGHT_ARROW) then if x < maxx - 16 then x:= x + moveSpeed end if end if Sprite.SetPosition (characterSprite, x, y, true); delay (10) end loop For the sprite, it will only have 2 values since it is on true mode and i don't want to make it false |
Author: | Insectoid [ Tue Apr 01, 2014 6:54 am ] |
Post subject: | RE:Moving character\'s unit collision |
Use a little math to figure out how to transform those 2 values into the 4 that you need. |
Author: | Beaver Tails [ Wed Apr 02, 2014 5:37 pm ] |
Post subject: | RE:Moving character\'s unit collision |
you mean creating 4 new values? (x,y) x1 = x + 50 x2 = x + 100 ??? |
Author: | Insectoid [ Wed Apr 02, 2014 8:26 pm ] |
Post subject: | RE:Moving character\'s unit collision |
You're getting there. Let's say your sprite is 50x50 pixels. (x, y) is in the middle of the picture. To get the top-right corner, you add half the width to the X value and half the height to the Y value; (x+25, y+25). Now that you have the top-right, you only need the bottom-left. How do you think you'd do that? |