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! / Problem with programming animation

Author
Message
hot_coder
20
Years of Service
User Offline
Joined: 11th Jun 2004
Location:
Posted: 2nd Jul 2004 20:27
I have had DarkBasic for about a week now and have been having great fun with it. I have been playing around with the "runner.bmp" program and a couple of problems which are mainly jumping.

1. The character continues to travel upwards when the jump key is held

2. How do I make the character face the other way when the leftkey is
pressed. (I know it's something to do with the mirror command)

Since the code is so short I'll not provide it in the code snippet

and post your improvements as well

rem make character walk left
IF LEFTKEY()=1 THEN image=image+1: IF image>12 THEN image=2

rem make character jump and react to gravity
IF UPKEY()=1 THEN jump=1: IF jump=1 AND ypos<250 THEN ypos=ypos-10
IF UPKEY()=1 THEN jump=1: IF jump=1 AND ypos>250 THEN ypos=ypos+10

IF UPKEY()=0 THEN jump=0: IF jump=0 AND ypos<299 THEN ypos=ypos+10

note: Xvariable=300 Yvariable=300
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 2nd Jul 2004 21:52 Edited at: 2nd Jul 2004 22:16
Hmm the code seems to have a few problems.

IF UPKEY()=1 THEN jump=1: IF jump=1 AND ypos<250 THEN ypos=ypos-10
IF UPKEY()=1 THEN jump=1: IF jump=1 AND ypos>250 THEN ypos=ypos+10

Ypos will soon be >250 then it will swap to <250 and be in a constant loop cycle of those two figures.

Here is partly how to change direction.
if keystate(205)=1 and dir=0 then mirror sprite 1:dir=1
if keystate(203)=1 and dir=1 then mirror sprite 1:dir=0


I would post the rest of it but I have an hangover at the moment.

hot_coder
20
Years of Service
User Offline
Joined: 11th Jun 2004
Location:
Posted: 3rd Jul 2004 07:57
Thanks for the code. Yet I still can't solve the problem of when the upkey is held, the character travels up to the Y-250 mark and stops. It stays until the upkey is no longer held. Oh and what do you do to make the character pause for 0.5 seconds after it has jumped.

I'm working on a firing routine I'm using Reapermans exp2 image, which is a image of a fireball. I don't understand how to postion and reset. I have read Reapermans excellent 2D Shooter guide, but
don't understand how to convert to my program

My basic routine for firing is

IF SPACEKEY()=1 THEN fire=1: IF fire=1 THEN SHOW SPRITE 2
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 3rd Jul 2004 19:21
Okay, on the jumping code....

the trouble is, from what I have seen in my own code as well as that of others, is that jumping is "too strongly based" in the upkey() detection. What I mean is, we often detect the upkey() without regard to whether ot not the character is already jumping, so the detection should be;

if upkey()=1 and jumping=0 then jumping=1 : <jump up code>

and the reverse is also true, if your character is falling.

if jump=1 and object position y() = maxlimit then jump = 2 : <falling code>

and then, when the objcet hits the ground;

if jump=2 and object position y()= ground height then jump = 0

to reset it all for another jump in the upkey is still held.

That's my two cents to this topic.. hope it helps.
S.

Any truly great code should be indisguishable from magic.
hot_coder
20
Years of Service
User Offline
Joined: 11th Jun 2004
Location:
Posted: 7th Jul 2004 00:44
THANKS SandraD

I'm almost there. The problem is now if the upkey is held until the character reaches the ground level it continues to travel down past the y-300 mark and when the upkey is pressed again it travels down the way as if it was still falling, but it is fine as long as the upkey is no longer held before it reaches y-300
MY CODE

rem falling code

IF UPKEY()=1 THEN jump=1: IF jump=1 AND ypos>200 THEN ypos=ypos+5
IF UPKEY()=0 THEN jump=0: IF jump=0 AND ypos<299 THEN ypos=ypos+5
IF UPKEY()=1 AND ypos=200 THEN jump=2: IF jump=2 AND ypos=300 THEN jump=0

note:jump=0 in the 4th line due to it word wrapping
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 8th Jul 2004 04:04
Well, from my understanding of the IF...THEN construction, if you place additional commands after an IF...THEN using the colon break then the entire line won't be processed if the IF fails. Thus in the third line there you have a double condition, in that UPKEY() must be pressed and ypos is equal to 200, AND jump equals 2 and ypos equals 300. (An obvious impossibility.) So if the lines are formatted like this, the jump=0 would never be reached at all.

That is why I suggested the UPKEY() AND YPOS tests, or the UPKEY() and JUMP equals tests, to avoid striking a condition when the precise situation was not being met. This might require a few more lines, but it works for me...

S.

Any truly great code should be indisguishable from magic.
hot_coder
20
Years of Service
User Offline
Joined: 11th Jun 2004
Location:
Posted: 9th Jul 2004 06:46
Thanks I've finally done it, but I'm still stuck on the firing routine. I have a fireball of coordinates

Left(0,21) Top(22,0) Right(43,21) Bottom(22,41)

I don't understand how to create and position it in relation to my character. Every time I press the spacebar the program says image does not exist.

Login to post a reply

Server time is: 2025-05-16 20:37:01
Your offset time is: 2025-05-16 20:37:01