Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / [SOLVED] World Barriers

Author
Message
Nationalcrafter67
5
Years of Service
User Offline
Joined: 6th Oct 2018
Location:
Posted: 16th Nov 2018 19:42
Alright, I've been stuck on this from the beginning. Making barriers, that prevent sprites from not only leaving the screen, but also from passing through what should be walls. I've tried using SetPhysicsWall(), and that just causes the sprite to spiral out of control. This isn't a game where physics are needed, it's just a top down RPG style game as far as movement. Any help is appreciated, thanks!

The author of this post has marked a post as an answer.

Go to answer

blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 20th Nov 2018 09:53
Create a sprite and use SetSpriteShapeChain() and AddfSpriteShapeChain() to add boundaries to your game
Nationalcrafter67
5
Years of Service
User Offline
Joined: 6th Oct 2018
Location:
Posted: 20th Nov 2018 20:04
Thanks for your swift reply blink0k. Are those CMD's used in combination with the visual editor?
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 21st Nov 2018 09:27
How are you controlling the movement?
If you don't want physics you can place sprites as walls, detect collision with a wall then move in the opposite direction manually.
life's one big game
spec= i5 4ghz, 16gb ram, Nvidia 1070ti gpu
Nationalcrafter67
5
Years of Service
User Offline
Joined: 6th Oct 2018
Location:
Posted: 22nd Nov 2018 04:52
//Call functions for player movement animations
function walkDown()
CreateSprite(1,1)
AddSpriteAnimationFrame ( 1, LoadImage ( "Down(1).png" ) )
AddSpriteAnimationFrame ( 1, LoadImage ( "Down(2).png" ) )
AddSpriteAnimationFrame ( 1, LoadImage ( "Down(3).png" ) )
AddSpriteAnimationFrame ( 1, LoadImage ( "Down(4).png" ) )
PlaySprite ( 1, 10, 1, 1, 4 )
DeleteSprite(7)
DeleteSprite(11)
DeleteSprite(15)
DeleteSprite(28)
endfunction
function walkUp()

CreateSprite(15,15)
AddSpriteAnimationFrame (15, LoadImage("Up(0).png"))
AddSpriteAnimationFrame (15, LoadImage("Up(1).png"))
AddSpriteAnimationFrame (15, LoadImage("Up(2).png"))
AddSpriteAnimationFrame (15, LoadImage("Up(3).png"))
PlaySprite(15,10,1,1,4)
DeleteSprite(1)
DeleteSprite(7)
DeleteSprite(11)
DeleteSprite(28)

endfunction
function walkLeft()
CreateSprite(7,7)
AddSpriteAnimationFrame ( 7, LoadImage ( "Left(1).png" ) )
AddSpriteAnimationFrame ( 7, LoadImage ( "Left(2).png" ) )
AddSpriteAnimationFrame ( 7, LoadImage ( "Left(3).png" ) )
AddSpriteAnimationFrame ( 7, LoadImage ( "Left(4).png" ) )
PlaySprite(7, 10, 1, 1, 4)
DeleteSprite(1)
DeleteSprite(11)
DeleteSprite(15)
DeleteSprite(28)
endfunction
function walkRight()
CreateSprite(11,11)
AddSpriteAnimationFrame (11, LoadImage("Right(0).png"))
AddSpriteAnimationFrame (11, LoadImage("Right(1).png"))
AddSpriteAnimationFrame (11, LoadImage("Right(2).png"))
AddSpriteAnimationFrame (11, LoadImage("Right(3).png"))
PlaySprite(11,10,1,1,4)
DeleteSprite(1)
DeleteSprite(7)
DeleteSprite(15)
DeleteSprite(28)
endfunction




//---------------------------------------------
//Down
if px > 215 and px < 265 and py > 745 and py < 795 and GetPointerState()
SetViewOffset(spritex , spritey+y#)
sy = sy + 3
SetSpritePosition(1,sx,sy)

//Up
elseif px > 215 and px < 265 and py > 680 and py < 735 and GetPointerState()
SetViewOffset(spritex , spritey-y#)
sy = sy - 3
SetSpritePosition(15,sx,sy)

//Left
elseif px > 151 and px < 205 and py > 745 and py < 795 and GetPointerState()

SetViewOffset ( spritex-x#, spritey )
sx = sx - 3
SetSpritePosition(7,sx,sy)

//Right
elseif px > 275 and px < 327 and py > 745 and py < 795 and GetPointerState()

SetViewOffset ( spritex+x#, spritey )
sx = sx + 3
SetSpritePosition(11,sx,sy)
endif

if px > 215 and px < 265 and py > 745 and py < 795 and GetPointerPressed()
walkDown()
elseif GetPointerReleased()
StopSprite(1)
endif

if px > 215 and px < 265 and py > 680 and py < 735 and GetPointerPressed()
walkUp()
elseif GetPointerReleased()
StopSprite(15)
endif

if px > 151 and px < 205 and py > 745 and py < 795 and GetPointerPressed()
walkLeft()
elseif GetPointerReleased()
StopSprite(7)
endif

if px > 275 and px < 327 and py > 745 and py < 795 and GetPointerPressed()
walkRight()
elseif GetPointerReleased()
StopSprite(11)
endif


So, this is probably the most absurd way to get player movement to function, "Poorly albeit", but it's what I was able to make heads and tails of. On the user interface there are up, down, left, and right arrows. When the program detects that the players mouse, or finger is in that area and is positively clicking, or tapping and holding, it moves said sprite in that direction. To create individual sprites for collisions would be an insurmountable task, and would likely take months of very fine tuning to get working correctly. It works fine for the borders, Top, Bottom, Left, and Right, but for the intricate details on the actual map. Trees, plants, house walls, chairs, tables, etc. If it's the only option, by golly I'll do it, but if there are other options, then I'm all for it.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 23rd Nov 2018 23:28 Edited at: 23rd Nov 2018 23:33
Couple of things there you might want to look at
1. You don't have to create the sprite every time.
2. A Better option would be to put ALL your sprite animations into one sprite and use PlaySprite( iSpriteIndex, fFps, iLoop, iFromFrame, iToFrame ) to play the appropriate animation
Something like this



As far as movement is concerned how do you want to move your character? using cursor keys or mouse or what?
Nationalcrafter67
5
Years of Service
User Offline
Joined: 6th Oct 2018
Location:
Posted: 26th Nov 2018 02:59
Again, thank you for the swift response, as well as the example blink0k, you're awesome. The sprite movement will be done with the users screen tap to specific coordinates, as such.

if px > 151 and px < 205 and py > 745 and py < 795 and GetPointerPressed()
endif

There is a GUI which has up, down, left, and right arrow keys, acting as keys on a keyboard, but respond to touch.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 26th Nov 2018 06:25
What is the significance of those numbers? 151,205,745 and 795
Nationalcrafter67
5
Years of Service
User Offline
Joined: 6th Oct 2018
Location:
Posted: 27th Nov 2018 20:32
They would be X and Y coordinates. If the players finger on X is greater than 151 and less than 205, and the players finger on Y is greater than 745 and less than 795, and they are physically tapping the screen, it will continue within the if loop. Similar to how a keyboard works, but in a more digital environment. I tried to use buttons, with setbuttonposition(), but I couldn't figure out how to either make the buttons invisible, or change their gui, so I went with this option. Works great honestly!

Also, small update, I've managed to get barriers working for the most part using CreateSprite() and GetSpriteCollision() setting the players speed to 0 on the x or y axis depending on the collision direction. Likely going to take me a very long time to get them all in place, since there are roughly 176 barriers needed for this particular world set.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 27th Nov 2018 21:17 Edited at: 28th Nov 2018 06:27
This post has been marked by the post author as the answer.
Ok. Maybe have a look at arrays and then you can easily loop through the barriers to test for collisions
So if you create a file called "barriers.txt" in your media folder in your project
Then add the following lines to barriers.txt (Make sure barrier.png is in your "media" folder too and make sure there are NO spaces in the file)
barrier.png
5,27
7,39
46,89


Now you can read through that file and use the image and values to position barriers in your game


Now you will have an array that you can use to check collisions like this
Nationalcrafter67
5
Years of Service
User Offline
Joined: 6th Oct 2018
Location:
Posted: 28th Nov 2018 17:29
That worked exactly as anticipated, very much appreciated blink0k, you've been an outstanding help in this. Cheers, and happy holidays!

Login to post a reply

Server time is: 2024-04-26 20:33:59
Your offset time is: 2024-04-26 20:33:59