wrapping w/out an array
category: general [glöplog]
I have some dots scrolling across the screen. The code looks like this.
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?
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?
this makes no sense.
scrolling is function of time.
pixel.x += time;
no need for an array
scrolling is function of time.
pixel.x += time;
no need for an array
I don't understand how that has to do with wrapping. Getting the pixels to translate is not my problem.
unobfuscated
structures and arrays? Not, unless you're going to do dot-particle stuff.
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.
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
maybe
Code:
for(;;)
{
for(off=0; off<1024; off+=200)
putpixel(gbmp, (pixel + off)&1023, 300, makecol(200,200,200));
pixel++;
}
broderick: That fixed it. Thanks a ton. :)
huh, ### Telepathy! I go to sleep ^^ ###
:)