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.

DarkBASIC Professional Discussion / Help with using Flags

Author
Message
MoonMan
21
Years of Service
User Offline
Joined: 14th May 2004
Location:
Posted: 4th Jun 2004 07:42
I've posted this before in the 2D Section of this forum, but I didn't exactly get the answer I was looking for. Although I do appreciate all the help I have received.

I'm trying to recreat a sort of SNES Zelda game and I've done a good job at it as well, but I seem to have run into a problem of some sort.

I want a specific sprite to play after releasing Left Arrow or Right Arrow. Something like...

IF LEFTKEY()=0 THEN SPRITE X, X, X, X

The problem is, by default all the arrow keys are set at 0 (If I'm correct, please do correct me if I'm wrong) so basicly all of the sprites would be going off at the same time.

Pincho replied back (Thanks, you're a big help) with a reply requesting I used a flag system of some sort. The problem is, and I'm a new comer, I don't truely understand how to use it.

Please if anyone could help me out in this little delima.

Thank you in advance.
Lost in Thought
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 4th Jun 2004 08:01 Edited at: 4th Jun 2004 08:03
Why not just make up a variable that says when left arrow has been pressed and then released?
something like

Then reset Left_Key_Release to 0 to start all over again. Hope this helps. But there may be an easier way. This is what I use or similar.
[edit] put these before your loop begins "Left_Key_Pressed = 0" and
"Left_Key_Released = 0"

"People don't fail ..... they stop trying." Specs. P4 2.8GHz 800 FSB | 512MB DDR333
GeForce FX 5200 AGP 256MB | Windows XP Pro Full
MoonMan
21
Years of Service
User Offline
Joined: 14th May 2004
Location:
Posted: 4th Jun 2004 08:33 Edited at: 4th Jun 2004 08:37
This is really weird. I tried out your code, it seemed to work perfect, but later it completely messed up.

I used the code like this for both the Leftkey and Rightkey

LEFTKEY
Quote: "
IF LEFTKEY()=1 THEN LEFT_KEY_PRESSED = 1
IF LEFT_KEY_PRESSED = 1
IF LEFTKEY()=0
LEFT_KEY_RELEASED = 1
LEFT_KEY_PRESSED = 0
ENDIF
ENDIF
IF LEFT_KEY_RELEASED = 1 THEN SPRITE 2, X#, Y#, FRAME_STAND_LEFT
IF LEFT_KEY_PRESSED = 1 THEN X#=X#-2.5 : SPRITE 2, X#, Y#, FRAME_LEFT
"


And Here's the Rightkey

Quote: "
IF RIGHTKEY()=1 THEN RIGHT_KEY_PRESSED = 1
IF RIGHT_KEY_PRESSED = 1
IF RIGHTKEY()=0
RIGHT_KEY_RELEASED = 1
RIGHT_KEY_PRESSED = 0
ENDIF
ENDIF
IF RIGHT_KEY_RELEASED = 1 THEN SPRITE 2, X#, Y#, FRAME_STAND_RIGHT
IF RIGHT_KEY_PRESSED = 1 THEN X#=X#+2.5 : SPRITE 2, X#, Y#, FRAME_RIGHT
"


So here's the problem. After pressed Left it stops the sprite (Like I want it to) then after pressing Right it stops the sprite, but when pressing left again it messes up and gets stuck on Right's stop sprite and just moves left. No animation or anything.

Thanks for the suggestion though, I appreciate any other suggestions towards this topic.
MoonMan
21
Years of Service
User Offline
Joined: 14th May 2004
Location:
Posted: 4th Jun 2004 11:51
Nevermind Pincho helped me out, thanks for the help though.
Lost in Thought
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 4th Jun 2004 17:47 Edited at: 4th Jun 2004 17:49
Glad you got it working. You have to manually reset RIGHT_KEY_RELEASED and LEFT_KEY_RELEASED to zero after it does what you want it to so it can start all over again. If not it will stay at 1 I can't test it right now but would be something like.


"People don't fail ..... they stop trying." Specs. P4 2.8GHz 800 FSB | 512MB DDR333
GeForce FX 5200 AGP 256MB | Windows XP Pro Full
MoonMan
21
Years of Service
User Offline
Joined: 14th May 2004
Location:
Posted: 5th Jun 2004 10:25 Edited at: 6th Jun 2004 05:03
Thanks for the code there, I tried both Pincho's code and yours, I like using your code a bit more because it doesn't glitch the graphics at the start. Except now I need to make a sort of Placement spirit so the collision detection code doesn't mess up. If I do put something like

Sprite 2, X, Y, FRAME_STAND_DOWN

Your code doesn't work anymore because the sprite doesn't stick onto the screen. Sorry if this doesn't make any sense, if you could post back I could try to explain it a bit deeper.

Thanks.

EDIT: I figured this part out
MoonMan
21
Years of Service
User Offline
Joined: 14th May 2004
Location:
Posted: 6th Jun 2004 01:26
If you could, explain to me how you coded your collision detection using this method. It would be a lot of help to me. Thanks
Lost in Thought
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 6th Jun 2004 06:16
You mean collision detection for the sprites? I haven't tried collision with sprites yet. Mostly I code 3d. If you will post how you are trying to do the collision I could probably convert it over to this method and put comments in to help.

"People don't fail ..... they stop trying." Specs. P4 2.8GHz 800 FSB | 512MB DDR333
GeForce FX 5200 AGP 256MB | Windows XP Pro Full
MoonMan
21
Years of Service
User Offline
Joined: 14th May 2004
Location:
Posted: 6th Jun 2004 06:28 Edited at: 6th Jun 2004 06:30
Sure no problem. Basicly I'm using a method of storing the old values of X and Y then placing them back after collision is detected. At the moment this seems to be working, but I don't get the "slide on the wall" effect that you get in the SNES version of Zelda... AKA... Walking into a wall and press a different direction. Which results into a sort of sliding against the wall.

I'm sure this method of collision detection is very simple and basic, if there is some other way. Please do inform me about it.

Thanks

Quote: "

X#=260
Y#=327
...

...
Oldx=X#
Oldy=Y#
...

...
IF Sprite Collision(2,7)>0
X#=Oldx
Y#=Oldy
Endif
...

"
Lost in Thought
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 6th Jun 2004 06:50 Edited at: 6th Jun 2004 08:37
I don't quite understand what you mean by the sliding against a wall. I have never played zelda on snes. Could you explain it a bit more? Do you want the player to walk into the wall and if you hit the other direction he will stay at the wall and face the other direction and then start to actually move away from the wall on the next loop?

[edit] Or do you mean if he jumps into the wall he will still raise up? Like sliding up the wall and then back down the wall?

"People don't fail ..... they stop trying." Specs. P4 2.8GHz 800 FSB | 512MB DDR333
GeForce FX 5200 AGP 256MB | Windows XP Pro Full
MoonMan
21
Years of Service
User Offline
Joined: 14th May 2004
Location:
Posted: 6th Jun 2004 17:12
It's like this...

On the left side there is a wall with collision detection, If my guys walks into the wall it will look as if he's still running into the wall, but he'll stay stationary. While he's still running into thte wall if you Press Up and Press Left at the same time, He'll look like he's running into the wall and sort of slide up while doing so. If you press Down and Left at the same time He'll continue (running left) into the wall and sliding down. Wall's Down, Right and Up have the same effects.

If running Up into the North wall, He'll look as if he's running Up and continues to run into the wall but moving no where. If you press Up and Left he'll continue running Up into the wall but sliding Left and same thing with Right Key.

I hope this explains what I'm trying to say, if you need any other explanation just say so. Thanks for helping me out.
pizzaman
21
Years of Service
User Offline
Joined: 18th Feb 2004
Location: Gateshead, UK
Posted: 6th Jun 2004 17:40 Edited at: 6th Jun 2004 21:53
hey moonman

try this example, it's van B's array collision with sliding collision it's a bit hard to see though



the bit of code marked in ******* is how the collision code works
basically it gets the coordinates of the 4 corners of the box then performs an equation to turn each x ordinate and y ordinate of the corners into which x tile and y tile in the array they are on. Then if they're on a tile they shouldn't be on the box gets moved back to where it was before the collision happened

sorry if i haven't explained this well enough - just send a post of what you dont undestand

anyways hope this helps
pizzaman
Lost in Thought
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 7th Jun 2004 00:35
Thats pretty cool collision there

"People don't fail ..... they stop trying." Specs. P4 2.8GHz 800 FSB | 512MB DDR333
GeForce FX 5200 AGP 256MB | Windows XP Pro Full
MoonMan
21
Years of Service
User Offline
Joined: 14th May 2004
Location:
Posted: 9th Jun 2004 06:26
Maybe it's just me, but I can't get this code to work. I'm not exactly a Professional at DarkBasic.

Login to post a reply

Server time is: 2025-06-12 11:02:58
Your offset time is: 2025-06-12 11:02:58