Animation(String imagePrefix, int count) {
images = new PImage[imageCount];
for (int i = 0; i < imageCount; i++) {
String filename = imagePrefix + "_" + nf(i, 1) + ".png";
images[i] = loadImage(filename);
void display(float xpos, float ypos) {
frame = (frame+1) % imageCount;
image(images[frame], xpos, ypos);
int offsetA, offsetB, yOffset, speed;
ScrollingImage(PImage i, int y, int s) {
image(image, offsetA, yOffset);
image(image, offsetB, yOffset);
if(offsetA == -image.width) {
if(offsetB == -image.width) {
PImage player_standing, path, background, mountains, sign;
Animation player_running, monster;
ScrollingImage scrolling_path, scrolling_background, scrolling_mountains;
int playerOffset, monsterOffset, textOffset, runningBuffer;
text = "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful.";
mrsmonster = loadFont("Mrs.Monster-90.vlw");
player_running = new Animation("Running", 19);
monster = new Animation("Monster", 10);
sign = loadImage("Sign.png");
player_standing = loadImage("Standing.png");
path = loadImage("Path.png");
background = loadImage("Background.jpg");
mountains = loadImage("Mountains.png");
scrolling_background = new ScrollingImage(background, 0, 0);
scrolling_mountains = new ScrollingImage(mountains, 267, 0);
scrolling_path = new ScrollingImage(path, 451, 0);
scrolling_background.draw();
scrolling_mountains.draw();
text(text, textOffset - (int(textWidth(typed_text)) - 300) + textWidth(typed_text), 560);
text(typed_text, textOffset - (int(textWidth(typed_text)) - 300), 560);
player_running.display(playerOffset,370);
monster.display(monsterOffset, 350);
scrolling_background.speed = 4;
scrolling_mountains.speed = 8;
scrolling_path.speed = 16;
image(player_standing, playerOffset, 370);
monster.display(monsterOffset, 350);
scrolling_background.speed = 0;
scrolling_mountains.speed = 0;
scrolling_path.speed = 0;
if(monsterOffset > 280) {
textFont(mrsmonster, 90);
textAlign(CENTER, BOTTOM);
text("Game over!", 400, 300);
textFont(mrsmonster, 90);
textAlign(CENTER, BOTTOM);
text("Congratulations!", 400, 300);
if(!(text.length() == 0)) {
if(key == text.charAt(0)) {
text = text.substring(1);