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 / Alternative sprite rotation

Author
Message
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 29th Jun 2009 15:22
I'm aware of the dbRotateSprite command. It rotates the sprite TO a certain angle. But I'm looking for a command that rotates the sprite FOR a certain angle...

example:

if i say dbRotateSprite (1,90)

the sprite is turned in this direction --->

and if i say dbRotatSprite (1,90) again
the sprite is still --->

i want it to be facing down the second time i call the command. (i want it to rorate for another 90 degrees)
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 29th Jun 2009 15:30
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 29th Jun 2009 21:21


Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 29th Jun 2009 22:55
Thanx this helped me a great deal!

I made a little code here it is:



when i press w the ant changes angle for 90 degrees. But when i press the button once the rotation happens atleast twice. What do i do, to make the rotation to happen only once when i press the button once?
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 29th Jun 2009 23:09
I have another similar code in wich i want the ant to change direction randomly, so i need my rand () to choose between numbers of -20 to 20, how is that achievable? i tried rand()%20-40 ..that didn't work...
bloodmage2
15
Years of Service
User Offline
Joined: 14th Jun 2009
Location:
Posted: 29th Jun 2009 23:18
well, you could do

(rand()40)-20, because it subtracts 20, it allows the min to be -20(in case rand returns -1) and the max to be 20 (in case rand returns 1);

-to the optimist, the glass is half full. to the pessimist, it is half empty, to the engineer, it is twice as big as it needs to be.
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 29th Jun 2009 23:21
Try: dbRnd(40) - 20
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 30th Jun 2009 16:18
Ok i finished the pcode... but i don't like it too much... i have noticed that the program always chooses the same random numbers every time i run it.. the ant always does the exact same thing. How the hell is that random? How do i make each run unique?
Krisacz
15
Years of Service
User Offline
Joined: 3rd Mar 2009
Location: UK, Manchester
Posted: 30th Jun 2009 17:05
Hi! I another thread I've posted you that code:

It's randomizing number from given minimum and maximum range.

Also to make random numbers more random insert:

somewhere after screen settings e.g.
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 30th Jun 2009 17:35
One other trick I've done, usually with dice based games, is to keep kicking over the random number generator inside a loop, without using the results, while waiting for the user to input something, whether it's a keystroke or a mouse click. This way the program is a bit more random in the use of the random numbers.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 1st Jul 2009 13:53
Wow, thanks, you guys were alot of help, only one question remains unanswered... i'll just copy+paste it.

when i press w the ant changes angle for 90 degrees. But when i press the button once the rotation happens atleast twice. What do i do, to make the rotation to happen only once when i press the button once?
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 1st Jul 2009 15:19
Remember, the key state functions you're using indicate that the key is pressed. It doesn't mean it was just pressed and released, it could mean it's still pressed. As long as you hold the key down it will report true every time through the loop.

You need to figure out a way, usually using a boolean type, to note when a key was already pressed so you don't react to it again and then unset the boolean when the key is no longer pressed.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Krisacz
15
Years of Service
User Offline
Joined: 3rd Mar 2009
Location: UK, Manchester
Posted: 1st Jul 2009 17:40 Edited at: 1st Jul 2009 18:26
Exactly like Lilith said, some code example for extra help:


In that case code "something, something...." will be executed only ones for every W key pressed, even if you will press and hold it.
Bipo
15
Years of Service
User Offline
Joined: 25th May 2009
Location:
Posted: 1st Jul 2009 17:43
Lilith is right. Boolean type is a smart way... in my game I'm using a short delay before checking again (which is probably not the most elegant solution) but the reason I'm posting is because I just saw some code that seemed to be an ideal way of handling the problem.

Simply insert: while (dbKeyState(17)==1) {} prior to rotating.

That is:

if (dbKeyState(17)==1)
{
while (dbKeyState(17)==1) {}
dbRotateSprite (SPRITE_ID,dbWrapValue(dbSpriteAngle(SPRITE_ID)+angle));
}

The program 'waits' (looping) in the while statement for the key to be released before rotating. Upon exit there is no undesired re-entry of the key pressed loop.

(I guess the only potential problem could be that the user would hold the key and temporarily stop the game loop...)

Anyway, it's another option and it's a simple 1 liner. OK. Coffee time for me.
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 7th Jul 2009 13:34
I see where you are going with that Lilith, but somehow it doesn't work... perhaps i did something wrong? here's the code:

Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 10th Jul 2009 00:56
Anyone?
Bran flakes91093
16
Years of Service
User Offline
Joined: 13th Sep 2008
Location: Crazy Land
Posted: 10th Jul 2009 02:37
bool KeyPressed is a local variable, which means it's value gets deleted upon exiting the function scope, and re-initialized when the function is called again. Declare it as static so it retains it's value and doesn't ever go out of scope.



Your_Health = (My_Mood == HAPPY) ? 100 : NULL;
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 10th Jul 2009 14:01
Yep, that worked. Thank you all.

Login to post a reply

Server time is: 2024-10-01 05:49:35
Your offset time is: 2024-10-01 05:49:35