Download zip: click here
Initially I wanted to to animate a sequence from The Matrix but then decided for Naruto.
The scene uses animated Sprites.
class Animation
{
int tick, frame, fps;
int repeated, repeatCount;
int posX, posY;
boolean sequenceFinished;
PImage sequenceRAW = new PImage();
PImage []sequence;
public Animation(String name, int numFrames, int offsetX, int addX, int sizeX, int sizeY, int fps, int repeatCount, int posX, int posY)
{
tick = 0;
frame = 0;
repeated = 0;
sequenceFinished = false;
this.fps = fps;
this.repeatCount = repeatCount;
this.posX = posX;
this.posY = posY;
sequence = new PImage[numFrames];
sequenceRAW = loadImage(name+".png");
for(int i=0; i<sequence.length; i++)
{
sequence[i] = sequenceRAW.get(i*offsetX+addX, 0, sizeX, sizeY);
}
}
public void animate()
{
pushStyle();
image(sequence[frame], posX,posY);
if( !sequenceFinished )
{
if (millis() - tick >= 1000/fps)
{
frame++;
if( frame == sequence.length-1 )
{
frame = 0;
repeated++;
}
if( repeatCount == repeated )
{
sequenceFinished = true;
frame = sequence.length-2;
}
tick = millis();
}
}
popStyle();
}
}
float scale, circleSize, circleAlpha, shadowAlpha;
int anim001X, anim001Y;
Animation anim001;
Animation anim002;
int anim003X, anim003Y;
Animation anim003;
Animation anim004;
PImage bg, shadow, charShadow;
boolean locked;
void setup()
{
size(500,250);
scale = 1;
circleSize = 10;
circleAlpha = 10;
shadowAlpha = 180;
anim001X = 50;
anim001Y = 100;
anim003X = 450;
anim003Y = 93;
locked = true;
//name, numFrames, offsetX, addX, sizeX, sizeY, fps, repeatCount, posX, posY
anim001 = new Animation("sequenz001",4, 104,14, 100,72, 10,3, 0,0);
anim002 = new Animation("sequenz001",3, 104,470, 100,72, 5,1, 0,0);
anim003 = new Animation("sequenz002",4, 104,14, 100,72, 10,3, 0,0);
anim004 = new Animation("sequenz002",3, 104,556, 100,72, 5,1, 0,0);
bg = loadImage("background.png");
shadow = loadImage("shadow.png");
charShadow = loadImage("charShadow.png");
}
void draw()
{
background(121);
if(millis() > 1400)
{
locked = false;
}
if (!locked)
{
image(bg,0,-110);
pushStyle();
tint(255, 190);
image(charShadow,anim001X+30,anim001Y+46);
image(charShadow,anim003X-90,anim003Y+53);
popStyle();
//Draw Sasuke
pushMatrix();
translate( anim001X,anim001Y );
if( !anim001.sequenceFinished )
{
anim001X += 2;
anim001.animate();
}
if( anim001.sequenceFinished )
{
anim002.animate();
}
popMatrix();
//Draw Naruto
pushMatrix();
translate( anim003X,anim003Y );
scale(-1,1);
if( !anim003.sequenceFinished )
{
anim003X -= 2;
anim003.animate();
}
if( anim003.sequenceFinished )
{
anim004.animate();
}
popMatrix();
//Draw Explosion
if( anim001.sequenceFinished )
{
pushStyle();
fill(255,255,255,circleAlpha);
noStroke();
circleSize+=5;
circleAlpha+= 2;
ellipse(width/2, height/2, circleSize, circleSize);
popStyle();
pushStyle();
tint(255, shadowAlpha);
shadowAlpha -= 3;
image(shadow,0,0);
popStyle();
}
if( circleAlpha > 270 )
{
pushMatrix();
pushStyle();
fill(0);
textAlign(CENTER);
text("Martin Hanusch \n-\n Interactive Art Homework 2",250,height/2-20);
popStyle();
popMatrix();
}
}
}

Keine Kommentare:
Kommentar veröffentlichen