SeaGtGruff, on Mon Jun 27, 2011 4:17 PM, said:
I think this form is more consistent with languages that let you define a variable as a BIT or BOOLEAN type, so it's probably the better (i.e., easier to use) method. Of course, with this method you don't need to dim Direction at all, unless you want to be able to refer to the Direction variable in addition to its defined bits. So just use def North=a{3} and so on if you don't plan to refer to Direction by itself.
Lately, I've been doing stuff like the examples below so I won't forget that I'm using bits and so I'll know exactly what bits I'm using:
rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' rem ' All-purpose bits for various jobs. rem ' rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' dim BitOp_All_Purpose_01 = t dim BitOp0_Debounce_Reset = t dim BitOp1_Debounce_FireB = t dim BitOp2_Game_Over = t dim BitOp7_Missile1_Moving = t rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' rem ' Player0/Missile1 direction bits. rem ' rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' dim BitOp_P0_M1_Direction = u dim BitOp0_Player0_Direction_Up = u dim BitOp1_Player0_Direction_Down = u dim BitOp2_Player0_Direction_Left = u dim BitOp3_Player0_Direction_Right = u dim BitOp4_Missile1_Direction_Up = u dim BitOp5_Missile1_Direction_Down = u dim BitOp6_Missile1_Direction_Left = u dim BitOp7_Missile1_Direction_Right = u
rem ****************************************************************
rem *
rem * Clears 7 of the 8 All_Purpose_01 bits.
rem *
rem * ---- The 2nd bit is not cleared because BitOp2_Game_Over{2}
rem * ---- is used to control how the program is reset.
rem *
rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
rem '
BitOp_All_Purpose_01 = BitOp_All_Purpose_01 & %00000100
rem ****************************************************************
rem *
rem * Clears all 8 Player0/Missile1 direction bits.
rem *
rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
rem '
BitOp_P0_M1_Direction = 0
rem ****************************************************************
rem ****************************************************************
rem *
rem * Fire Button
rem *
rem * ---- If fire button is pressed appropriately and Missile1
rem * ---- is not moving, turn on Missile1 movement.
rem *
rem ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
rem '
rem ' If the fire button is not pressed, skip this section.
rem '
rem ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
rem '
if !joy0fire then BitOp1_Debounce_FireB{1} = 0 : goto Skip_Fire
rem ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
rem '
rem ' If the fire button has not been released since starting,
rem ' skip this section.
rem '
rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
rem '
if BitOp1_Debounce_FireB{1} then goto Skip_Fire
rem ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
rem '
rem ' If Missile1 is moving, skip this section.
rem '
rem ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
rem '
if BitOp7_Missile1_Moving{7} then goto Skip_Fire
rem ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
rem '
rem ' Turn on Missile1 movement.
rem '
rem ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
rem '
BitOp7_Missile1_Moving{7} = 1
rem ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
rem '
rem ' Set up starting position of Missile1.
rem '
rem ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
rem '
missile1y = player0y - 4 : missile1x = player0x + 4
rem ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
rem '
rem ' Take a snapshot of Player0 direction so Missile1 will
rem ' stay on track until it hits something.
rem '
rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
rem '
BitOp4_Missile1_Direction_Up{4} = BitOp0_Player0_Direction_Up{0}
BitOp5_Missile1_Direction_Down{5} = BitOp1_Player0_Direction_Down{1}
BitOp6_Missile1_Direction_Left{6} = BitOp2_Player0_Direction_Left{2}
BitOp7_Missile1_Direction_Right{7} = BitOp3_Player0_Direction_Right{3}
Skip_Fire
I went back to regular bitops when I had some weird, random problems with def in that crappy seaweed game I was trying to finish.
I'm tempted to try some version of def again, but I'll probably end up getting lost in the code again, even if I don't get weird errors.
Edited by Random Terrain, Wed Jun 29, 2011 4:48 PM.













