/* My first test with using scroll. Things achieved: -a scrolling background (luckily :p ) -the background isn't tiled, it'll stop scrolling when it's at it's limits -something moving around, and the scroll following it if it moves around -a collision test with what's scrolling (well, a copy of that map in fact, rather a collision map kind of thing, doesn't have to be the same image as what's visible :),but it is in this demo ) remarks: -perhaps the block and blockgraphic setup is a bit too complicated, i could as well have just made a block process that moves around in the scroll, and a simple cam process which x and y values get altered by the blockprocess, but the current solution is more customisable i think :) -i'm new to using scrolling, so this might be inaccurate. -haven't tested the gp32 performance yet */ program scrolltest; const global local begin SET_MODE(320,240,8);//setting the graphics mode LOAD_FPG("scroll.fpg");//loading an fpg :) scroller();//calling the process that starts the scroll (utterly useless process :p) end //starts the scroll process scroller() begin START_SCROLL(0,0,3,0,0,3);//starts the scroll, variables: /* 0: number of scroll, 0-9 are possible, this is the first one, so 0 :) 0: fpg library you use, i only laoded 1 fpg, so it's 0 (the first library) in this case :) 3: the map in the library chosen 0: a background for the scroll you can choose (kind of second image scrolling with the same parameters, but not necessarily the same way, and in behind the previously selected image 0:is the part of the screen the scroll is shown in, 0 is default region, the entire screen you can use this if you want to limit the size of the scrol (not in behind a menu or so) for performance issues i guess, thigns on the scroll also won't show outside the region. make sure you give your new regiona number other than 0 or it won't work ;) 3:the flags: 1:horizontal scroll of the map 2:vertical scroll of the map 4:horizontal scroll of the background 8:vertical scroll of the background use: these are powers of two, it's like 4 bits,1=0001;2=0010,4=0100,8=1000 add the together to get all the scrolls you cant, so 1+2=3 is the map scrolling both ways 1+2+4=7 is map scrolling both ways, the background only scrolling horizontal 1+8=9= the map scrolling hotizontal, the background scrolling vertical etc... */ scroll[0].camera=block(160,120);//the scroll process will follow the block process //it'll use it's x and y values as its own track(320,240);//this is the collision map process, for more info read its comments end /* this process is something that moves around in the scroll, acting as camera, so the scroll will follow it it has however been limited so that the scroll won't tile, it limit's the scroll x and y values the object itself (a seperate process) will thus move to the sides of the screen when you reach the edge of the scroll */ process block(realx,realy)//realx and y are the coordinates of the object, not necessarily the scroll! private graphic;//the visualisation of the block begin graphic=blockgraphic(160,120);//creating the graphic loop frame; if(key(_right)and realx<640)realx+=5;end//moving around :) if(key(_left) and realx>0)realx-=5;end//the moving is limited so you can't get of the if(key(_down) and realy<480)realy+=5;end//screen if(key(_up) and realy>0)realy-=5;end x=realx;//we make the coordinates equal to the real ones y=realy; if(x<160)x=160;end//and make sure they're not beyond limits if(y<120)y=120;end//and change them if necessary if(x>480)x=480;end if(y>360)y=360;end graphic.x=realx;//the graphic will be on the actual place :) graphic.y=realy; end end /* the visual part of the scroll */ process blockgraphic(x,y) begin graph=2;//choosing it's file ctype=c_scroll;/*important!!, this says this graphic is moving around on a SCROLL, not on the screen, with cnumber = c_# you choose which scroll, default is 0 so i didn't have to type cnumber=c_0*/ loop//obvious frame; end end /* a collision checking object, cause i don't think you can check collision with a scroll explanation: this object is positioned in the scroll, so that it's map is on the same location as the scroll, (since the image's center is it's center, the coords will be 320,240, since the scroll is 640x480) every loop we make it visible (not to the user, no frame is done after choosing it's actual graph) and check for collisions, and set the graph to 0 (no graph) again. this way we can collide with it without it having to be visible (but you can only check for collisions in this object) important things t know: the collision map is only active in the region 0,0-640x640, outside that it doesn't exist that's good for this example where you don't tile the maps, but isn't otherwise! */ process track(x,y); private col;//id of object we collided with begin ctype=c_scroll;//also moves along with the scroll write_int(0,160,120,0,&col);//writing out the collision check loop graph=3;//we make it "visible" (so we can check for collisions col=COLLISION(type blockgraphic);//checking collision /* little notice: suppose you want to check collision with a lot of items, or want items to know if they collided with this, a bit of handy things that i can think of to make it possible: -remember that collision can give back all items something collides with, every time you call it you get the next item you collide with, if you get 0 the previous one was the last one SO, you can make a little while loop that checks collisions, and puts them in a global array the objects something collides with are reset every frame :) (in case you didn't know) -remember that priorities are supported, give this little process highest priority, and it'll execute before all others do, so you can have it fill the array of collisions, and then other objects can check the array if their ID is in it, if it is, they're colliding! this is untested, but should be a fairly simple method of overcoming the problem that only this process knows what's colliding with it :) */ graph=0;//and make it invisible again, since we got all the info we need, and //probably don't want to draw our collision map frame; end end