MausBoy Posted May 29, 2006 Share Posted May 29, 2006 I want to use bB to move a sprite back and forth across the screen in a sine wave, does anyone have any suggestions for the best way to do it? Most old BASIC examples I've looked up don't translate to bB at all. Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted May 30, 2006 Share Posted May 30, 2006 You'll have to precalculate the sine values and store them in your program. Quote Link to comment Share on other sites More sharing options...
+batari Posted May 31, 2006 Share Posted May 31, 2006 You'll have to precalculate the sine values and store them in your program.Depending on what you need, either a few data tables or individual calculations for different angles may work best. You'd want not just pre-calculated trig values, but also those values multiplied by some value (as trig functions usually are.) Actual trigonometry calculations are a little too slow for any practical use in bB. I thought about making a library with a set of 8.8 trig values for 0-90 degrees and interpolate for fractional values (or not...), and this would be reasolably quick to access. The problem is usually the functions are multiplied by some value, which requires a slow 16-bit multiplication loop, and just a few of these would take up all the cycles in a frame. Quote Link to comment Share on other sites More sharing options...
MausBoy Posted June 4, 2006 Author Share Posted June 4, 2006 Precalculated tables will be fine, not a big deal considering the limited resolution. I don't think the addition of a library is necessary but then again I don't know all the ways it could be applied or how people smarter than me would use it. Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted June 4, 2006 Share Posted June 4, 2006 This is how I precalculated the Fireball direction/speed tables for Medieval Mayhem. The code's for REALbasic which I used for the free 2 week demo. Const PI=3.14159 Const PALadjust = 1.2 Const Xadjust = 1.3 dim i as integer dim x(8) as integer dim y(8) as integer dim speed as double dim NTSCxHigh as string dim NTSCxLow as string dim NTSCyHigh as string dim NTSCyLow as string dim PALxHigh as string dim PALxLow as string dim PALyHigh as string dim PALyLow as string for i = 0 to 8 y(i) = 256 * cos(PI/180 * i * 90 / 8) x(i) = Xadjust * 256 * sin(PI/180 *i * 90 /8) next i x(8) = Xadjust * 256 ' adjustment, it's coming out 255 ntscxhigh = "NTSCxHigh" ntscxlow = "NTSCxLow" ntscyhigh = "NTSCyHigh" ntscylow = "NTSCyLow" palxhigh = "PALxHigh" palxlow = "PALxLow" palyhigh = "PALyHigh" palylow = "PALyLow" for speed = 0 to 3.5 step .5 for i = 0 to 8 ntscxhigh = ntscxhigh + chr(10) + " .byte #>" + app.formatspeed(speed * x(i)) + "; speed: " +str(speed) + " direction: " + str(i) ntscxlow = ntscxlow + chr(10) + " .byte #<" + app.formatspeed(speed * x(i))+ "; speed: " +str(speed) + " direction: " + str(i) NTSCyhigh = NTSCyhigh + chr(10) + " .byte #>" + app.formatspeed(speed * y(i))+ "; speed: " +str(speed) + " direction: " + str(i) NTSCyLow = NTSCyLow + chr(10) + " .byte #<" + app.formatspeed(speed * y(i))+ "; speed: " +str(speed) + " direction: " + str(i) PALxhigh = PALxhigh + chr(10) + " .byte #>" + app.formatspeed(PALadjust * speed * x(i)) + "; speed: " +str(speed) + " direction: " + str(i) PALxlow = PALxlow + chr(10) + " .byte #<" + app.formatspeed(PALadjust * speed * x(i))+ "; speed: " +str(speed) + " direction: " + str(i) PALyhigh = PALyhigh + chr(10) + " .byte #>" + app.formatspeed(PALadjust * speed * y(i))+ "; speed: " +str(speed) + " direction: " + str(i) PALyLow = PALyLow + chr(10) + " .byte #<" + app.formatspeed(PALadjust * speed * y(i))+ "; speed: " +str(speed) + " direction: " + str(i) next i for i = 1 to 8 ntscxhigh = ntscxhigh + chr(10) + " .byte #>" + app.formatspeed(speed * x(8-i)) + "; speed: " +str(speed) + " direction: " + str(i+8) ntscxlow = ntscxlow + chr(10) + " .byte #<" + app.formatspeed(speed * x(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+8) NTSCyhigh = NTSCyhigh + chr(10) + " .byte #>" + app.formatspeed(-speed * y(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+8) NTSCyLow = NTSCyLow + chr(10) + " .byte #<" + app.formatspeed(-speed * y(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+8) PALxhigh = PALxhigh + chr(10) + " .byte #>" + app.formatspeed(PALadjust * speed * x(8-i)) + "; speed: " +str(speed) + " direction: " + str(i+8) PALxlow = PALxlow + chr(10) + " .byte #<" + app.formatspeed(PALadjust * speed * x(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+8) PALyhigh = PALyhigh + chr(10) + " .byte #>" + app.formatspeed(-PALadjust * speed * y(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+8) PALyLow = PALyLow + chr(10) + " .byte #<" + app.formatspeed(-PALadjust * speed * y(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+8) next i for i = 1 to 8 ntscxhigh = ntscxhigh + chr(10) + " .byte #>" + app.formatspeed(-speed * x(i)) + "; speed: " +str(speed) + " direction: " + str(i+16) ntscxlow = ntscxlow + chr(10) + " .byte #<" + app.formatspeed(-speed * x(i))+ "; speed: " +str(speed) + " direction: " + str(i+16) NTSCyhigh = NTSCyhigh + chr(10) + " .byte #>" + app.formatspeed(-speed * y(i))+ "; speed: " +str(speed) + " direction: " + str(i+16) NTSCyLow = NTSCyLow + chr(10) + " .byte #<" + app.formatspeed(-speed * y(i))+ "; speed: " +str(speed) + " direction: " + str(i+16) PALxhigh = PALxhigh + chr(10) + " .byte #>" + app.formatspeed(-PALadjust * speed * x(i)) + "; speed: " +str(speed) + " direction: " + str(i+16) PALxlow = PALxlow + chr(10) + " .byte #<" + app.formatspeed(-PALadjust * speed * x(i))+ "; speed: " +str(speed) + " direction: " + str(i+16) PALyhigh = PALyhigh + chr(10) + " .byte #>" + app.formatspeed(-PALadjust * speed * y(i))+ "; speed: " +str(speed) + " direction: " + str(i+16) PALyLow = PALyLow + chr(10) + " .byte #<" + app.formatspeed(-PALadjust * speed * y(i))+ "; speed: " +str(speed) + " direction: " + str(i+16) next i for i = 1 to 7 ntscxhigh = ntscxhigh + chr(10) + " .byte #>" + app.formatspeed(-speed * x(8-i)) + "; speed: " +str(speed) + " direction: " + str(i+24) ntscxlow = ntscxlow + chr(10) + " .byte #<" + app.formatspeed(-speed * x(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+24) NTSCyhigh = NTSCyhigh + chr(10) + " .byte #>" + app.formatspeed(speed * y(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+24) NTSCyLow = NTSCyLow + chr(10) + " .byte #<" + app.formatspeed(speed * y(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+24) PALxhigh = PALxhigh + chr(10) + " .byte #>" + app.formatspeed(-PALadjust * speed * x(8-i)) + "; speed: " +str(speed) + " direction: " + str(i+24) PALxlow = PALxlow + chr(10) + " .byte #<" + app.formatspeed(-PALadjust * speed * x(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+24) PALyhigh = PALyhigh + chr(10) + " .byte #>" + app.formatspeed(PALadjust * speed * y(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+24) PALyLow = PALyLow + chr(10) + " .byte #<" + app.formatspeed(PALadjust * speed * y(8-i))+ "; speed: " +str(speed) + " direction: " + str(i+24) next i next speed efvalues.text = ntscxhigh + chr(10) + chr(10) efvalues.text = efvalues.text + NTSCxLow + chr(10) + Chr(10) efvalues.text = efvalues.text + NTSCyhigh + chr(10) + Chr(10) efvalues.text = efvalues.text + NTSCylow + chr(10) + Chr(10) efvalues.text = efvalues.text + PALxhigh + chr(10) + chr(10) efvalues.text = efvalues.text + PALxLow + chr(10) + Chr(10) efvalues.text = efvalues.text + PALyhigh + chr(10) + Chr(10) efvalues.text = efvalues.text + PALylow + chr(10) + Chr(10) The table's are quite large so I'm not going to include them here. Go hit my blog, download the source and look for the following BALLxHigh .byte #> 0; speed: 0 direction: 0 .byte #> 0; speed: 0 direction: 1 .byte #> 0; speed: 0 direction: 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.