PDA

View Full Version : Something complex (not a request)



Majora
03-10-2009, 06:57 PM
I want to somehow simulate an animated background in a side-view area without wasting eleventy billion pages of tiles. Is it possible with scripting at all to make images from scratch? As in, without using tiles. This is for my Final Destination/Master Hand battle, and I'm wondering if any easy way exists to make an animated background for it.

EDIT: wait, I have another question *is typing it*
EDIT: crap forgot it

pkmnfrk
03-10-2009, 10:51 PM
Why, yes, you can!

...

Oh, you want an example? Well, that depends what you want. Take, for example, this script:


const int screenHeight = 176;
const int screenWidth = 256;
const int screenMidX = 128;
const int screenMidY = 88;

ffc script ScrollingBG {
void run(int layer, int cset, int firstTile, int scrollX, int scrollY, int frames, int animspeed) {
int drawX = 0;
int drawY = 0;
int drawF = 0;
int drawT = 0;

while(true) {
drawX += scrollX;
drawY += scrollY;

if(drawX > screenWidth) drawX -= screenWidth;
if(drawX < -screenWidth) drawX += screenWidth;

if(drawY > screenHeight) drawY -= screenHeight;
if(drawY < -screenHeight) drawY += screenHeight;

for(int j = 0; j < 2; j++) {
if(frames > 0) {
drawT += 1;
if(drawT > animspeed) {
drawT = 0;
drawF += 1;
if(drawF >= frames) drawF = 0;
}
}
for(int x = Floor(drawX) - screenWidth; x < Floor(drawX) + screenWidth; x+= screenWidth) {
for(int y = Floor(drawY) - screenHeight; y < Floor(drawY) + screenHeight; y += screenHeight) {
Screen->DrawTile(layer, x, y, firstTile + drawF * 220, 16, 11, cset, 1, 0, 0, 0, 0, false, 128);
}
}
Waitframe();
}
}
}
}

ffc script Starfield {
//stars -- MAX 150!!
//speed -- NO FRACTIONS, WHOLE NUMBERS ONLY!!!
//speedadj -- update every X frames (but, draw every frame)
void run(int stars, int speed, int layer, int col, int speedadj) {

if(stars > 150) stars = 150;
if(speedadj < 1) speedadj = 1;

float field[150];

//each star is formated as such:
// distance . angle
// eg:
// 56 . 0023
// 23 degrees, 56 pixels away from centre.
// godspeed ;)

//initialize the field:
for(int i = 0; i < stars; i++) {
field[i] = Rand(150) + (Rand(359) / 1000);
}

while(true) {
int dist;
int ang;
int x;
int y;

for(int j = 0; j < speedadj; j++) {
for(int i = 0; i < stars; i++) {
dist = Floor(field[i]);
ang = 1000 * (field[i] - dist);

x = Sin(ang) * dist + screenMidX;
y = Cos(ang) * dist + screenMidY;

if(dist > 150 && (x >= screenWidth || x < 0 || y >= screenWidth || y < 0)) {
field[i] = 2 + (Rand(359) / 1000);
dist = 2;
ang = 1000 * (field[i] - dist);
x = Sin(ang) * dist + screenMidX;
y = Cos(ang) * dist + screenMidY;
}

Screen->PutPixel(layer, x, y, col, 0, 0, 0, 128);
}
Waitframe();
}

for(int i = 0; i < stars; i++) {
field[i] = field[i] + speed;
}
}
}
}


You get two FFCs from this.

The first one will take a 16x11 "page" of tiles, and draw it each frame. It will scroll it as you wish, and can animate it too (using successive "pages").

If you want to go entirely dynamic, and not use tiles at all... Well, it might be tricky, but by no means impossible. You just need to specify what you want. But, you could look at the second FFC, which gives you a starfield shooting out from the middle of the screen.

It's entirely possible to put more stars in, but I'm not sure how many. You would just need to increase the size of the array (and, change the sanity check at the top). But, I kept it relatively small just in case.

Edit: I integrated a second script into the above text.