1 package erland.game.tileadventure;
2
3 /*
4 * Copyright (C) 2004 Erland Isaksson (erland_i@hotmail.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 *
20 */
21
22 public class Animation implements AnimationInterface, Cloneable {
23 private int[] imageList;
24 private int current;
25 private int speed;
26 private int animationCounter;
27 public Animation(int speed, int[] imageList) {
28 this.speed= speed;
29 this.imageList = imageList;
30 this.current = 0;
31 this.animationCounter = 0;
32 }
33 public int getNextImage() {
34 animationCounter++;
35 if(speed>0 && animationCounter>=speed) {
36 animationCounter=0;
37 current++;
38 if(current>=imageList.length) {
39 current = 0;
40 }
41 }
42 return imageList[current];
43 }
44
45 public Object clone() {
46 Animation a = null;
47 try {
48 a = (Animation) super.clone();
49 } catch (CloneNotSupportedException e) {
50 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
51 }
52 return a;
53 }
54 }