package edu.wisc.cs.games10.chrononaut;

import processing.core.PApplet;
import processing.core.PImage;

public class RegularLevel extends Level {
	public RegularLevel(String ln, PApplet canvas) {
		levelname = ln;
		
		pasttiles = Level.loadEraFromImage(levelname, "a", canvas);
		presenttiles = Level.loadEraFromImage(levelname, "b", canvas);
		futuretiles = Level.loadEraFromImage(levelname, "c", canvas);
		
		width = pasttiles.length;
		height = pasttiles[0].length;
		
		// get images
		pastforeground = canvas.loadImage("levels/" + levelname + "/a_front.png");
		presentforeground = canvas.loadImage("levels/" + levelname + "/b_front.png");
		futureforeground = canvas.loadImage("levels/" + levelname + "/c_front.png");
		pastbackground = canvas.loadImage("levels/" + levelname + "/a_back.png");
		presentbackground = canvas.loadImage("levels/" + levelname + "/b_back.png");
		futurebackground = canvas.loadImage("levels/" + levelname + "/c_back.png");
		
		reloadLevel(canvas);
	}
	
	@Override
	public Vector2D getStartLocation() {
		// TODO: load this location from file
		return new Vector2D(1, 0);
	}
	
	@Override
	public PImage getBackground(Era era) {
		if (era == Era.PAST) {
			return pastbackground;
		} else if (era == Era.PRESENT) {
			return presentbackground;
		} else {
			return futurebackground;
		}
	}

	@Override
	public PImage getForeground(Era era) {
		if (era == Era.PAST) {
			return pastforeground;
		} else if (era == Era.PRESENT) {
			return presentforeground;
		} else {
			return futureforeground;
		}
	}
	
	@Override
	public int isLevelFinished(Player p) {
		// go to splash screen if we have got all creatures
		//  and player has gone all the way right
		if (creatures.size() == 0 && p.loc.x >= width - 2) {
			return 0;
		}
		return -1;
	}
	
	PImage pastforeground;
	PImage presentforeground;
	PImage futureforeground;
	
	PImage pastbackground;
	PImage presentbackground;
	PImage futurebackground;
}
