- This wiki is out of date, use the continuation of this wiki instead
Scroll window
From FenixWiki
(Difference between revisions)
| Revision as of 00:29, 28 July 2008 (edit) Sandman (Talk | contribs) (not done yet!) ← Previous diff |
Current revision (00:40, 28 July 2008) (edit) (undo) Sandman (Talk | contribs) (done; now ctype should be done) |
||
| Line 11: | Line 11: | ||
| You can control scrolls in multiple ways. | You can control scrolls in multiple ways. | ||
| - | * | + | * Change the scroll coordinates directly using <code>x0</code>, <code>y0</code>, <code>x1</code>, <code>y1</code> in the [[global variable]] [[scroll]]. Be sure to alter the correct scroll. |
| + | * Tell the scroll to 'follow' another scroll, by using <code>[[scroll]].follow</code>. | ||
| + | * Use a 'camera' process, which the scroll try to follow, by using <code>[[scroll]].camera</code>. | ||
| More about scrolls: | More about scrolls: | ||
| Line 18: | Line 20: | ||
| == Example == | == Example == | ||
| + | <pre> | ||
| + | Const | ||
| + | SCREEN_WIDTH = 320; | ||
| + | SCREEN_HEIGHT = 200; | ||
| + | SCREEN_DEPTH = 8; | ||
| + | MAP_WIDTH = 500; | ||
| + | MAP_HEIGHT = 400; | ||
| + | SHIP_WIDTH = 30; | ||
| + | SHIP_HEIGHT = 30; | ||
| + | SHIP_SPEED = 6; | ||
| + | End | ||
| - | + | Declare Process playership(int x, int y) | |
| + | End | ||
| + | Declare Function int makeMap(int width, int height, int depth) | ||
| + | End | ||
| + | Declare Function int makeShipGfx(int width, int height, int depth) | ||
| + | End | ||
| + | |||
| + | Process Main() | ||
| + | Private | ||
| + | int map; | ||
| + | Begin | ||
| + | // Setup the screen | ||
| + | set_mode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_DEPTH); | ||
| + | |||
| + | // Create the background graphic | ||
| + | map = makeMap(MAP_WIDTH,MAP_HEIGHT,SCREEN_DEPTH); | ||
| + | |||
| + | // Start a new scroll | ||
| + | // scrollNumber = 0 | ||
| + | // fileID = 0 | ||
| + | // foregroundGraphID = map | ||
| + | // backgroundGraphID = 0: no background | ||
| + | // region = 0: use entire screen | ||
| + | // lockindicator = 0: don't repeat graphics | ||
| + | start_scroll(0,0,map,0,0,0); | ||
| + | |||
| + | // Start a controllable object on the scroll | ||
| + | playership(320,200); | ||
| + | |||
| + | // Wait till the key ESC is pressed | ||
| + | Repeat | ||
| + | frame; | ||
| + | Until(key(_esc)) | ||
| + | |||
| + | OnExit | ||
| + | // Kill all other processes | ||
| + | let_me_alone(); | ||
| + | |||
| + | // Clean up memory used for map | ||
| + | unload_map(0,map); | ||
| + | End | ||
| + | |||
| + | |||
| + | Process playership(int x, int y) | ||
| + | Private | ||
| + | int sp = SHIP_SPEED; | ||
| + | int halfWidth; | ||
| + | int halfHeight; | ||
| + | Begin | ||
| + | |||
| + | // This process should be displayed on a scroll only | ||
| + | ctype = c_scroll; | ||
| + | |||
| + | // This process should be tracked by the scroll | ||
| + | Scroll.camera = id; | ||
| + | |||
| + | // Create a graph for this process | ||
| + | graph = makeShipGfx(SHIP_WIDTH,SHIP_HEIGHT,SCREEN_DEPTH); | ||
| + | |||
| + | // Obtain the value of half the width of the graphic | ||
| + | halfWidth = graphic_info(0,graph,G_WIDTH )/2; | ||
| + | halfHeight = graphic_info(0,graph,G_HEIGHT)/2; | ||
| + | |||
| + | // React on keys LEFT and RIGHT | ||
| + | Loop | ||
| + | |||
| + | // Adjust x,y on input | ||
| + | x+=(key(_right)-key(_left))*sp; | ||
| + | y+=(key(_down)-key(_up))*sp; | ||
| + | |||
| + | // Make sure the ship stays on the scroll | ||
| + | if(x > MAP_WIDTH-halfWidth) | ||
| + | x = MAP_WIDTH-halfWidth; | ||
| + | elseif(x < halfWidth) | ||
| + | x = halfWidth; | ||
| + | end | ||
| + | if(y > MAP_HEIGHT-halfHeight) | ||
| + | y = MAP_HEIGHT-halfHeight; | ||
| + | elseif(y < halfHeight) | ||
| + | y = halfHeight; | ||
| + | end | ||
| + | |||
| + | frame; | ||
| + | |||
| + | End | ||
| + | |||
| + | OnExit | ||
| + | // Clean up used memory for graph | ||
| + | unload_map(0,graph); | ||
| + | End | ||
| + | |||
| + | Function int makeMap(int width, int height, int depth) | ||
| + | Private | ||
| + | int n; | ||
| + | int x1,y1; | ||
| + | int m; | ||
| + | Begin | ||
| + | |||
| + | // New map | ||
| + | m = new_map(width,height,depth); | ||
| + | |||
| + | // Put on some pretty stars | ||
| + | rand_seed(100); | ||
| + | for(n=0;n<1000;n++) | ||
| + | map_put_pixel(0,m,rand(0,width),rand(0,height),rgb(150,170,200)); | ||
| + | end | ||
| + | |||
| + | // Return it | ||
| + | return m; | ||
| + | |||
| + | End | ||
| + | |||
| + | Function int makeShipGfx(int width, int height, int depth) | ||
| + | Private | ||
| + | int g; | ||
| + | Begin | ||
| + | |||
| + | // Return a map of one color (RGB(150,200,170)) | ||
| + | g=new_map(width,height,depth); | ||
| + | map_clear(0,g,rgb(200,100,170)); | ||
| + | return g; | ||
| + | |||
| + | End | ||
| + | </pre> | ||
| + | Used in example: [[set_mode]](), [[start_scroll]](), [[key]](), [[let_me_alone]](), [[unload_map]](), [[graphic_info]](), [[new_map]](), [[rand_seed]](), [[rand]](), [[rgb]](), [[map_put_pixel]](), [[map_clear]](), [[ctype]], [[scroll]] | ||
Current revision
[edit] Definition
A scroll window is a region in which a scroll has been started by start_scroll() and setup with the global variable [[scroll]. This scroll window provides a view window into the scroll that has been setup there, with certain background and foreground graphics. The view window can be 'scrolled' over the scroll (and the graphics).
Processes can also be added to a scroll (see the global variable ctype), in which case a lot of things related to that process change.
- The graphic of the process is not drawn to the screen, but to the scroll window, using the region of the scroll.
- The z of an added process only has a meaning to the scroll window and compared to other processes added to the same scroll, meaning from a user perspective, the process is drawn at the z value of the scroll. If two processes are added to the same scroll, the one with the lower z value will be drawn over the other one.
- The x- and y-coordinates are not relative to the upper left corner of the screen, but relative to the upper left corner of the scroll.
You can control scrolls in multiple ways.
- Change the scroll coordinates directly using
x0,y0,x1,y1in the global variable scroll. Be sure to alter the correct scroll. - Tell the scroll to 'follow' another scroll, by using
scroll.follow. - Use a 'camera' process, which the scroll try to follow, by using
scroll.camera.
More about scrolls:
- A scroll with a lower z value will be drawn over a scroll with a lower z value.
- The foreground is the plane to be controlled and the background moves relative to the foreground.
[edit] Example
Const
SCREEN_WIDTH = 320;
SCREEN_HEIGHT = 200;
SCREEN_DEPTH = 8;
MAP_WIDTH = 500;
MAP_HEIGHT = 400;
SHIP_WIDTH = 30;
SHIP_HEIGHT = 30;
SHIP_SPEED = 6;
End
Declare Process playership(int x, int y)
End
Declare Function int makeMap(int width, int height, int depth)
End
Declare Function int makeShipGfx(int width, int height, int depth)
End
Process Main()
Private
int map;
Begin
// Setup the screen
set_mode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_DEPTH);
// Create the background graphic
map = makeMap(MAP_WIDTH,MAP_HEIGHT,SCREEN_DEPTH);
// Start a new scroll
// scrollNumber = 0
// fileID = 0
// foregroundGraphID = map
// backgroundGraphID = 0: no background
// region = 0: use entire screen
// lockindicator = 0: don't repeat graphics
start_scroll(0,0,map,0,0,0);
// Start a controllable object on the scroll
playership(320,200);
// Wait till the key ESC is pressed
Repeat
frame;
Until(key(_esc))
OnExit
// Kill all other processes
let_me_alone();
// Clean up memory used for map
unload_map(0,map);
End
Process playership(int x, int y)
Private
int sp = SHIP_SPEED;
int halfWidth;
int halfHeight;
Begin
// This process should be displayed on a scroll only
ctype = c_scroll;
// This process should be tracked by the scroll
Scroll.camera = id;
// Create a graph for this process
graph = makeShipGfx(SHIP_WIDTH,SHIP_HEIGHT,SCREEN_DEPTH);
// Obtain the value of half the width of the graphic
halfWidth = graphic_info(0,graph,G_WIDTH )/2;
halfHeight = graphic_info(0,graph,G_HEIGHT)/2;
// React on keys LEFT and RIGHT
Loop
// Adjust x,y on input
x+=(key(_right)-key(_left))*sp;
y+=(key(_down)-key(_up))*sp;
// Make sure the ship stays on the scroll
if(x > MAP_WIDTH-halfWidth)
x = MAP_WIDTH-halfWidth;
elseif(x < halfWidth)
x = halfWidth;
end
if(y > MAP_HEIGHT-halfHeight)
y = MAP_HEIGHT-halfHeight;
elseif(y < halfHeight)
y = halfHeight;
end
frame;
End
OnExit
// Clean up used memory for graph
unload_map(0,graph);
End
Function int makeMap(int width, int height, int depth)
Private
int n;
int x1,y1;
int m;
Begin
// New map
m = new_map(width,height,depth);
// Put on some pretty stars
rand_seed(100);
for(n=0;n<1000;n++)
map_put_pixel(0,m,rand(0,width),rand(0,height),rgb(150,170,200));
end
// Return it
return m;
End
Function int makeShipGfx(int width, int height, int depth)
Private
int g;
Begin
// Return a map of one color (RGB(150,200,170))
g=new_map(width,height,depth);
map_clear(0,g,rgb(200,100,170));
return g;
End
Used in example: set_mode(), start_scroll(), key(), let_me_alone(), unload_map(), graphic_info(), new_map(), rand_seed(), rand(), rgb(), map_put_pixel(), map_clear(), ctype, scroll
