Posted Thu Jan 24, 2008 11:44 PM
Posted Fri Jan 25, 2008 1:17 AM
cvga, on Fri Jan 25, 2008 12:44 AM, said:
Posted Fri Jan 25, 2008 9:14 PM
Posted Fri Jan 25, 2008 11:16 PM
cvga, on Fri Jan 25, 2008 10:14 PM, said:
Posted Sat Jan 26, 2008 4:41 PM
Posted Sat Jan 26, 2008 10:24 PM
cvga, on Sat Jan 26, 2008 5:41 PM, said:
cvga, on Sat Jan 26, 2008 5:41 PM, said:
Posted Sat Jan 26, 2008 10:37 PM
SeaGtGruff, on Sun Jan 27, 2008 4:24 AM, said:
cvga, on Sat Jan 26, 2008 5:41 PM, said:
cvga, on Sat Jan 26, 2008 5:41 PM, said:
Posted Sun Jan 27, 2008 2:41 AM
cvga, on Sat Jan 26, 2008 11:37 PM, said:
Posted Sun Jan 27, 2008 9:15 AM
SeaGtGruff, on Sun Jan 27, 2008 8:41 AM, said:
cvga, on Sat Jan 26, 2008 11:37 PM, said:
Posted Sun Jan 27, 2008 9:54 AM
Posted Sun Jan 27, 2008 2:29 PM
cvga, on Sun Jan 27, 2008 10:54 AM, said:
dim slope = a.b data whole_part etc. end data fractional_part etc. end rem * c = index into data tables a = whole_part[c] b = fractional_part[c] rem * now slope is setMichael
Posted Sun Jan 27, 2008 5:19 PM
Posted Mon Jan 28, 2008 1:27 AM
function div16by8 asm LDX #8 ASL temp2 div16by8_1 ROL BCS div16by8_2 CMP temp3 BCC div16by8_3 div16by8_2 SBC temp3 SEC div16by8_3 ROL temp2 DEX BNE div16by8_1 RTS endJust add the code for this function somewhere in your bB program, where your other subroutines are (i.e., somewhere that your program won't fall into by mistake).
quotient = div16by8 (numerator_hi, numerator_lo, divisor) remainder = temp2For calculating an 8.8 fixed-point slope, you want the remainder to be a fraction of 256, which is why bB's "//" operation won't work (since it returns a remainder that's a fraction of the *divisor*). So I used the following formula:
dim slope = a.b dim p0y = player0y.c player0x = 40 player0y = 20 player1x = 104 player1y = 45You can pass a variable, constant, or numeric literal to a user-defined function, but not an arithmetic expression, so you need to calculate the x and y differences, store them in variables, and then pass the variables. Since this user-defined function is going to use temp1, temp2, and temp3 anyway, you can use them for the differences:
temp1 = player1y - player0y temp2 = player1x - player0x slope = div16by8 (temp1, 0, temp2) b = temp2Note that upon exiting the function, the accumulator will hold an 8-bit quotient, and the remainder will be in temp2, so you need to be sure to store temp2 in the fractional part of the 8.8 slope variable.
rem move sprite on a slope dim slope = a.b dim p0y = player0y.c scorecolor = 142 player0: %11111111 %10000001 %10000001 %10000001 %10000001 %10000001 %11111111 %00000000 end player1: %10000001 %01000010 %00100100 %00011000 %00100100 %01000010 %10000001 %00000000 end player0x = 40 player0y = 20 player1x = 104 player1y = 45 temp1 = player1y - player0y temp2 = player1x - player0x slope = div16by8 (temp1, 0, temp2) b = temp2 loop p0y = 20.0 for player0x = 40 to 104 drawscreen p0y = p0y + slope next goto loop function div16by8 asm LDX #8 ASL temp2 div16by8_1 ROL BCS div16by8_2 CMP temp3 BCC div16by8_3 div16by8_2 SBC temp3 SEC div16by8_3 ROL temp2 DEX BNE div16by8_1 RTS endAlso, note that if you're going to calculate a slope for moving a player like this, you'll probably want to check which is larger, the x difference or the y difference. Then you would divide the smaller by the larger, so the "slope" is always 1 or less than 1, and vary the appropriate coordinate (x or y) by 1, so the sprite doesn't jump too far each time. That is, let's say that xdiff is 5 and ydiff is 20, then if you divide ydiff by xdiff, the slope is 4, which would mean that for each time you add 1 to x, you'd be adding 4 to y, which would make the sprite seem to jump too quickly. On the other hand, if you divide xdiff by ydiff (smaller by larger), the "slope" (or inverse slope) is 0.25, so if you add 1 to *y* each time, and calculate x by adding the "slope" to it, the sprite would seem to move more smoothly.
Edited by SeaGtGruff, Mon Jan 28, 2008 1:31 AM.
0 members, 1 guests, 0 anonymous users