Page 1 of 1

Moving a char w/o ifs, keyup, keydown and global codes..

PostPosted: Mon Feb 07, 2011 12:30 pm
by poopbrigade
heres a simple code to make your char move without any ifs. XD

in Draw actor -> Script editor
Code: Select all
char *key=GetKeyState();



y-=(5*key[KEY_w])*((1/(key[KEY_d]+key[KEY_a]+key[KEY_s]+1)));
y+=(5*key[KEY_s])*((1/(key[KEY_d]+key[KEY_a]+key[KEY_w]+1)));
x-=(5*key[KEY_a])*((1/(key[KEY_d]+key[KEY_w]+key[KEY_s]+1)));
x+=(5*key[KEY_d])*((1/(key[KEY_w]+key[KEY_a]+key[KEY_s]+1)));

no_if_wsad.zip
XD Happy..
(8.54 KiB) Downloaded 73 times

I dunno if someone has already done this, but I'm just post'n might help some1 in someway XD


Inspired by DST's post in
viewtopic.php?f=5&t=6854&start=15


1+ to DST XD

Re: Moving a char w/o ifs, keyup, keydown and global codes..

PostPosted: Mon Feb 07, 2011 8:54 pm
by Game A Gogo
Code: Select all
char*key=GetKetState();
y+=((5*key[KEY_s])*((1/(key[KEY_d]+key[KEY_a]+key[KEY_w]+1))))-((5*key[KEY_w])*((1/(key[KEY_d]+key[KEY_a]+key[KEY_s]+1))));
x+=((5*key[KEY_d])*((1/(key[KEY_w]+key[KEY_a]+key[KEY_s]+1))))-((5*key[KEY_a])*((1/(key[KEY_d]+key[KEY_w]+key[KEY_s]+1))));


you have y+= and y-=. they both do the "same" thing, but reversed, so it's easy to intergrate it into one single function. since if you add a negative, it's like substration :)

Re: Moving a char w/o ifs, keyup, keydown and global codes..

PostPosted: Mon Feb 07, 2011 11:34 pm
by poopbrigade
Thanx learned a new thing XD
do you have anyother tricks in your sleve?
+1

Re: Moving a char w/o ifs, keyup, keydown and global codes..

PostPosted: Mon Feb 07, 2011 11:49 pm
by Game A Gogo
if conditions doesn't limit themselves to "if(condition){}"
here's something interesting when you can jump twice, so you would need to hold numbers of jump in a var.
so to make your actor jump, you could do this:
Code: Select all
yvelocity-=(jump_count>0)*key[KEY_space];

as you can see, no if's is used. But there is a still a condition check in process, so it requires pretty much the same amount of cpu process.

Re: Moving a char w/o ifs, keyup, keydown and global codes..

PostPosted: Mon Feb 07, 2011 11:59 pm
by poopbrigade
WoW XD I could give you another point but I've used it already.