1
Coding / Re: Tile-Based Collisions and Leveling
« on: April 27, 2012, 05:23:55 pm »
Sounds like a very useful reference to have. I use a ton of touchy diagonals in my game, so I'm sure I for one would find it helpful.
I don't support this at all. [madrassauce] is a constructive member of the community, who consistently contributes to open discussion, spriting threads, coding threads, you name it. ... I know [madrassauce] made that one thread, but everyone has bad days, right?That said, [madrassauce], I don't know if liking dogs that much is healthy...
// --- Let's pretend for now that J and K are keys in your game.
playerstate = 0;
if keyboard_check_pressed(vk_anykey){
if (keyboard_check_direct(ord('W')) || keyboard_check_direct(ord('S'))) {playerstate+=1;break;}
if keyboard_check_direct(ord('J')) {playerstate+=2;break;}
if keyboard_check_direct(ord('K')) {playerstate+=4;break;}
}
// --- Key Controls --- //
if keyboard_check_pressed(vk_anykey){
switch (keyboard_lastkey){
case (ord('A')): {playerstate+=0;break;}// --- Should check single keys pressed, to add the proper playerstate
case (ord('D')): {playerstate+=0;break;}
case (ord('W')): {playerstate+=1;break;}
case (ord('S')): {playerstate+=1;break;}
//
// --- Key Controls --- //
if keyboard_check_pressed(vk_anykey){
switch (keyboard_lastkey){
case (ord('A')):
case (ord('D')): {playerstate+=0;break;}
case (ord('W')):
case (ord('S')): {playerstate+=1;break;}
//
Here, I've "chained" the cases -- do you follow me? This is equivalent to the previous code box.// --- Key Controls --- //
if keyboard_check_pressed(vk_anykey){
switch (keyboard_lastkey){
case (ord('W')):
case (ord('S')): {playerstate+=1;break;}
//
// --- Key Controls --- //
if keyboard_check_pressed(vk_anykey){
switch (keyboard_lastkey){
case (ord('W')):
case (ord('S')): {playerstate+=1;break;}
//
case (ord('A')) & (ord('D')): {playerstate+=0;break;}// --- Should check double ups of keys pressed, to add the proper playerstate
case (ord('A')) & (ord('W')): {playerstate+=1;break;}
case (ord('A')) & (ord('S')): {playerstate+=1;break;}
case (ord('D')) & (ord('W')): {playerstate+=1;break;}
case (ord('D')) & (ord('S')): {playerstate+=1;break;}
case (ord('W')) & (ord('S')): {playerstate+=1;break;}
//
}}
& is a bitwise operator, and I don't think you meant to use it here. What you want is either && or and, both of which are the logical conjunction. Also, let's remove that extra code, and the case where you add 0 in the second half:// --- Key Controls --- //
if keyboard_check_pressed(vk_anykey){
switch (keyboard_lastkey){
case (ord('W')):
case (ord('S')): {playerstate+=1;break;}
//
case (ord('A')) && (ord('W')):
case (ord('A')) && (ord('S')):
case (ord('D')) && (ord('W')):
case (ord('D')) && (ord('S')):
case (ord('W')) && (ord('S')): {playerstate+=1;break;}
//
}}
That's a little nicer to look at, and more efficient too. But there are a couple problems here that become increasingly clear.// --- Key Controls --- //
if keyboard_check_pressed(vk_anykey){
switch (keyboard_lastkey){
case (ord('W')):
case (ord('S')): {playerstate+=1;break;}
}}
if keyboard_check_released(vk_anykey){
switch (keyboard_lastkey){
case (ord('W')):
case (ord('S')): {playerstate-=1;break;}
}}
Since the code can be shrunken so much, it seems to me that it probably doesn't yet do what you want it to do. Please come back with some more information about your code's intended function. // --- Key Controls --- //
if keyboard_check_pressed(vk_anykey){
if (keyboard_lastkey == ord('W') || keyboard_lastkey == ord('S')) {playerstate+=1;break;}
}
if keyboard_check_released(vk_anykey){
if (keyboard_lastkey == ord('W') || keyboard_lastkey == ord('S')) {playerstate-=1;break;}
}
(Notice the use of ||, the logical disjunction.)I could write it myself, but Goodnight was the one who had it all ready; written nicely and near perfect.That's a pretty terrible attitude. Like I said before, did it have other features?
Oh well, I knew it was a bad idea to come here for help.