pouët.net

Go to bottom

wrapping w/out an array

category: general [glöplog]
 
I have some dots scrolling across the screen. The code looks like this.

Code: #include <allegro.h> #include <iostream> #include <string.h> #include <sstream> #include <fstream> using namespace std; //SYSTEM SETUP GLOBALS #define sysXres 1024 #define sysYres 768 #define sysBpp 16 BITMAP * gbmp; int systemInit(); int updateScreen(); int main(){ systemInit(); int inc = sysXres / 10; while(!key[KEY_ESC]){ //draw dots for(int offset = 0; offset < 1024; offset++){ for(int pixel = 0; pixel + offset < 1024; pixel += 200){ putpixel(gbmp, pixel + offset, 300, makecol(200,200,200)); } rest(10); updateScreen(); if(key[KEY_ESC]){break;} } } } END_OF_MAIN() //systems init; mouse, gfx, keys etc... int systemInit(){ allegro_init(); install_mouse(); install_keyboard(); set_keyboard_rate(400, 0); set_color_depth(sysBpp); set_gfx_mode( GFX_AUTODETECT_WINDOWED, sysXres, sysYres, 0, 0 ); gbmp = create_bitmap(sysXres, sysYres); //HACK rows should render to their own bitmap, this is just a test } int updateScreen(){ //show_mouse(gbmp); blit(gbmp, screen , 0,0,0,0,sysXres , sysYres); clear_bitmap(gbmp); //removed because it was causing bug with backgrounds }


Instead of scrolling evenly, all the dots go off the screen, and then start back at the edge. It would be super easy to make a structure and use arrays and just track each dot, and have each one wrap around. It feels like I'm missing something, how can i get this thing to scroll without using an array?
added on the 2008-11-14 01:38:28 by b0ib0t b0ib0t
this makes no sense.
scrolling is function of time.

pixel.x += time;

no need for an array
added on the 2008-11-14 02:24:21 by quisten quisten
I don't understand how that has to do with wrapping. Getting the pixels to translate is not my problem.
added on the 2008-11-14 02:36:34 by b0ib0t b0ib0t
unobfuscated
Code://draw dots for(int offset = 0; offset < 1024; offset++) { for(int pixel = offset; pixel < 1024; pixel += 200) { putpixel(gbmp, pixel, 300, makecol(200,200,200)); } ... }

structures and arrays? Not, unless you're going to do dot-particle stuff.
added on the 2008-11-14 02:39:30 by bdk bdk
Code: for(int pixel = 0; pixel < 1024; pixel += 200){ putpixel(gbmp, (pixel + offset)%1024, 300, makecol(200,200,200)); }


... but it's a seriously fucked up way way of doing what you are doing
added on the 2008-11-14 02:42:37 by Jcl Jcl
maybe
Code:for(;;) { for(off=0; off<1024; off+=200) putpixel(gbmp, (pixel + off)&1023, 300, makecol(200,200,200)); pixel++; }
added on the 2008-11-14 02:45:30 by bdk bdk
broderick: That fixed it. Thanks a ton. :)
added on the 2008-11-14 02:45:52 by b0ib0t b0ib0t
huh, ### Telepathy! I go to sleep ^^ ###
added on the 2008-11-14 02:46:41 by bdk bdk
:)
added on the 2008-11-14 02:47:07 by bdk bdk

login

Go to top