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.

Newcomers DBPro Corner / my 2D platformer test, stuck

Author
Message
Pepzi
13
Years of Service
User Offline
Joined: 22nd Feb 2011
Location:
Posted: 13th Sep 2011 17:16
Help, it's me again
Seems my player sprite got stuck
I don't understand why
See the attachment, please unRem the

gosub playerSprites

and the

playerSprites:
Sprite 1, x#, y#, imgNum
return

and please change the path of the images and sprites, thanks!
I just wanted to limit the character from getting through the screen width
If you could explain why, thank you so much!

New to darkbasic

Attachments

Login to view attachments
Pepzi
13
Years of Service
User Offline
Joined: 22nd Feb 2011
Location:
Posted: 13th Sep 2011 18:05
Also, when I hit the edge of a platform it can walk through it; would go like this:



New to darkbasic
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 13th Sep 2011 18:10
That .zip file doesn't have any code in it. You only zipped up the .dbpro file which is just the project information. You need to add the .dba file that has the code.

Pepzi
13
Years of Service
User Offline
Joined: 22nd Feb 2011
Location:
Posted: 13th Sep 2011 18:26
Wow it's sir Grog!
Oops sorry
I paste it on the notepad anyway
Thanks sir grog, you're the one who showes me Andrew Vanbeck's tutorial

New to darkbasic

Attachments

Login to view attachments
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 14th Sep 2011 19:31 Edited at: 14th Sep 2011 19:50
I haven't been knighted... yet.

First it's better to get rid of the absolute path you have for all your media. If you want to use a directory within the project directory you just start with the directory name \ then the file. Once you get rid of the drive and path info it doesn't matter where the file is and it'll still find the media.

This:


To this:


When I first ran it the player seemed to just stay in one place even though he was "falling" so I added a few TEXT commands to see why it was in one place. The PlayerY variable was constantly going up so I was majorly confused when the player didn't move (see attached image).

That's when I saw this (where the remarks are):


With two sprite commands showing the same sprite it keeps resetting the sprite to x# and y# so the player seems to never move. Get rid of one of those SPRITE commands and it'll run right. I'll let you decide if you want to keep the player sprite in the main DO/LOOP or change the one in the PlayerSprites route to use PlayerX and PlayerY instead of X# and Y#.

In the collision routine you can shorten it by putting the platforms in a FOR/NEXT loop and an EXIT once a collision has been detected. If you don't add the EXIT as you get more and more platforms checking all of them even though a collision has been detected would slow it down considerably.



To prevent the player from dropping off the left and right edges of the screen you can just add a reset of the playerX and playerY variables at the bottom of the PlayerInput routine. Also using INKEY$() is ok for checking keys but "r" and "R" are two different things... so if the user has caps lock on and you're checking for "r" it'll never detect that key. It's better to use KEYSTATE() instead so you don't have to worry about the case of the key and you can detect multiple keys at a time with KEYSTATE().



I noticed some of those variables are floats (the # symbol). Generally you don't need floats on anything that is never going to be a number with a decimal. Things like screen coordinates are never going to be half a pixel (like 100.5,320.5) and gravity that ultimately is going to be added to screen coordinates shouldn't either.

You really need to add more comments to your code to help you figure out what everything is doing if you somehow stop coding this for a bit and get back to it later. The more comments you have the easier it is to get back to old projects... believe me it helps.

I didn't see any platforms like the above picture to test the problem you're asking for... did you copy old code accidentally?

Attachments

Login to view attachments
Pepzi
13
Years of Service
User Offline
Joined: 22nd Feb 2011
Location:
Posted: 15th Sep 2011 02:46
Thanks so much sir Grog, the time I read your 3rd paragraph I realized I forgot to change the

playerSprites:
Sprite 1, x#, y#, imgNum
return

to

playerSprites:
Sprite 1, playerX, playerY, imgNum
return


sorry my big mistake XD

thanks for the screen limiting

and here's the problem I was telling
I just hid the first 3 platforms along with the 4th
from


platform1_X(1) = 100
platform1_Y(1) = 30

platform1_X(2) = 40
platform1_Y(2) = 150

platform1_X(3) = 100
platform1_Y(3) = 300

platform1_X(4) = 0
platform1_Y(4) = 720


to


platform1_X(1) = 0
platform1_Y(1) = 720

platform1_X(2) = 0
platform1_Y(2) = 720

platform1_X(3) = 0
platform1_Y(3) = 720

platform1_X(4) = 0
platform1_Y(4) = 720


sir Grog try to insert the character, I mean jump to hit the edge of the platform, on the left (or even right if the platform was short)
~Please use attached

he can walk and jump through it

Thanks sir Grog!

New to darkbasic

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-24 01:54:26
Your offset time is: 2024-11-24 01:54:26