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.

Dark GDK / array based movement

Author
Message
Patrick987
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location:
Posted: 1st Apr 2010 08:17
i need help figuring out a way to code array based movement. I know that you would have an array of 0's and a 1 where the player is but i dont know how to edit the array to move the player any help would be greatly appreciated
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 1st Apr 2010 09:54
Elaborate a bit more, do you just want grid based movement so your player(and other items) are confined to moving in steps of a set size? Or do you actually want to have a multidimensional array that stores level data in a grid, sort of like an image? If it's the latter, then you first need to learn how to make multidimensional arrays, the rest should then be easy, assuming you externally store the current grid location of the player.

Patrick987
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location:
Posted: 1st Apr 2010 17:07
i just want grid based movement where if you press a button to move the player but dont hold it then you only move one space on the grid but if you hold it you move from one spot to another like the old top down RPGs
Pilz X Schizo
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Massachusetts, USA
Posted: 1st Apr 2010 17:51
Your not really moving the player in the array, the array is used to hold all your map data then like Dark Coder said you have 2 variables to store the player X and Y, ex: pX and pY. Then all you need to do is add or subtract from those values each time a direction key is pressed, so if you press the left key you subtract 1 from pX and for the right key you add 1 to pX, same for y, up = -1 from pY and down = +1 to pY. So then all you have to do in your map drawing loop is check to see if the Xtile and Ytile your drawing matches the pX and pY variables and draw the player.
Patrick987
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location:
Posted: 2nd Apr 2010 05:00
ok i got it to work thanks to both of you for the help
Patrick987
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location:
Posted: 6th Apr 2010 00:36
one more problem i have no idea at all how to do collision using an array all i know is that you out 0 where you can walk and 1 where you cant
Pilz X Schizo
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Massachusetts, USA
Posted: 6th Apr 2010 02:57
Well there are a few simple ways to do this.

1 - When you press a direction key check the spot in the map array where you going to move the player and see if you can move there, if you can then move them.

example:


Also you can store the players Old position in 2 variables OldX, OldY befor you move, check the tile the player is on, then if you cant move there set the position back to the old position.

example:


Hope that helps.
Patrick987
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location:
Posted: 6th Apr 2010 06:55
thank you that helped a lot i couldnt get the first one to work but the second one worked great

Login to post a reply

Server time is: 2024-10-02 03:44:32
Your offset time is: 2024-10-02 03:44:32