+Random Terrain Posted September 14, 2011 Share Posted September 14, 2011 I need to cycle from $40 to $46, then from $46 to $40, but I need to do it twice in a row. The only thing I can think of uses bloated code, a whole variable as a counter and too many bits. Is there a simpler, easier way to ping pong though a range of colors for a certain number of times? Thanks. Quote Link to comment Share on other sites More sharing options...
disjaukifa Posted September 14, 2011 Share Posted September 14, 2011 Random That's how I do it. I just use a frame counter for a continues loop. If you only need to be done twice you could either use bit operators or a for loop and use the temp5 variable for your for loop. Quote Link to comment Share on other sites More sharing options...
jrok Posted September 14, 2011 Share Posted September 14, 2011 (edited) I need to cycle from $40 to $46, then from $46 to $40, but I need to do it twice in a row. The only thing I can think of uses bloated code, a whole variable as a counter and too many bits. Is there a simpler, easier way to ping pong though a range of colors for a certain number of times? Thanks. Since the color array is static, how about just use a pointer and a data table. data colorflash $40,$42,$44,$46,$44,$42,$40,$42,$44,$46,$44,$42,$40 end Loop COLUBK = 0 if a < colorflash_length-1 then a = a + 1 : COLUBK = colorflash[a] if joy0fire then a = 0 drawscreen goto Loop Edited September 14, 2011 by jrok 2 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted September 14, 2011 Author Share Posted September 14, 2011 Since the color array is static, how about just use a pointer and a data table. data colorflash $40,$42,$44,$46,$44,$42,$40,$42,$44,$46,$44,$42,$40 end Loop COLUBK = 0 if a < colorflash_length-1 then a = a + 1 : COLUBK = colorflash[a] if joy0fire then a = 0 drawscreen goto Loop That's a heck of a lot easier than the stupid, bloated crap I was trying to do. Thanks. Quote Link to comment Share on other sites More sharing options...
ScumSoft Posted September 14, 2011 Share Posted September 14, 2011 I would just do this instead: dim color = a dim FrameNum = b rem set starting color color = $40 Loop drawscreen FrameNum = FrameNum + 1 rem cycle color from 40 and 46 every other frame if FrameNum{0} then color = color ^ 6 COLUBK = color goto Loop Quote Link to comment Share on other sites More sharing options...
jrok Posted September 14, 2011 Share Posted September 14, 2011 (edited) I would just do this instead: dim color = a dim FrameNum = b rem set starting color color = $40 Loop drawscreen FrameNum = FrameNum + 1 rem cycle color from 40 and 46 every other frame if FrameNum{0} then color = color ^ 6 COLUBK = color goto Loop I was working under the assumption that he wanted to limit RAM usage, and have an effect that was simple to restart and stop after two iterations. My version uses 22 more bytes of ROM, but it only uses 1 byte of RAM and resets to defaults after two flashes. And - maybe I was wrong in assuming this - but I figured that the "flash" effect itself was something that would start when a certain condition was triggered, like a ship being smacked with a missile, and stop after a certain duration. In that spirit, I put together a little demo showing how 9 bits can be used to trigger a color & sound event. This could be optimized in a bunch of ways (including storing both the color and sound effect in a single data table), but I get the feeling that this is somewhat along the lines of what RT was looking for. Hit_Effect.bas Hit_Effect.bas.bin Edited September 14, 2011 by jrok Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted September 14, 2011 Author Share Posted September 14, 2011 I would just do this instead . . . Thanks. Using data was good for this situation because I ended up changing the pattern and added a series of different colors at the end of it. Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted September 15, 2011 Author Share Posted September 15, 2011 . . . but I get the feeling that this is somewhat along the lines of what RT was looking for. I needed to change the color of the score background after shooting 100 bits of seaweed. Data worked great for what I ended up doing. I hoped to upload the latest unfinished version of Seaweed Assault today, but it's taking longer than I planned. Quote Link to comment Share on other sites More sharing options...
ScumSoft Posted September 15, 2011 Share Posted September 15, 2011 No problem, it's all good. Thought this was like that other post looking to flip 255 and 1, with only two values returned. Don't mind me carry on. 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.