1 package com.explosion.utilities.Graphics;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 /***
24 * @author Stephen Cowx
25 * @version 1.0
26 */
27
28 import java.awt.Graphics;
29 import java.awt.Image;
30 import java.awt.Rectangle;
31
32 public class AnimatedImage
33 {
34
35 int xpos = 0;
36
37 int ypos = 0;
38
39 int size = 10;
40
41 Image[] images;
42
43 int numImages = 10;
44
45 int currentImageIndex = 0;
46
47 int imageHeight = 22;
48
49 int imageWidth = 22;
50
51 int screenWidth = 10;
52
53 int screenHeight = 10;
54
55 boolean finished = false;
56
57 boolean moving = false;
58
59 boolean loop = false;
60
61 public AnimatedImage(int xpos, int ypos, Image[] images, int imageWidth, int imageHeight, int screenWidth, int screenHeight, boolean moving, boolean loop)
62 {
63 this.xpos = xpos;
64 this.ypos = ypos;
65 this.images = images;
66 this.imageWidth = imageWidth;
67 this.imageHeight = imageHeight;
68 this.numImages = images.length;
69 this.screenWidth = screenWidth;
70 this.screenHeight = screenHeight;
71 this.moving = moving;
72 this.loop = loop;
73 this.currentImageIndex = 0;
74 }
75
76 public void draw(Graphics g)
77 {
78 if (!finished) g.drawImage(images[currentImageIndex], xpos, ypos, null);
79 }
80
81 public void cycle()
82 {
83 if (loop)
84 {
85 if (currentImageIndex < numImages - 1)
86 currentImageIndex++;
87 else
88 currentImageIndex = 0;
89 } else
90 {
91 if (currentImageIndex < numImages - 1)
92 currentImageIndex++;
93 else
94 finished = true;
95 }
96 }
97
98 public void move(int x, int y)
99 {
100 if (xpos + x > 0 && xpos + x < screenWidth)
101 {
102 xpos += x;
103 }
104
105 if (ypos + y > 0 && ypos + y < screenHeight)
106 {
107 ypos += y;
108 }
109 }
110
111 public int getXPos()
112 {
113 return xpos;
114 }
115
116 public int getYPos()
117 {
118 return ypos;
119 }
120
121 public Rectangle getBounds()
122 {
123 return new Rectangle(xpos, ypos, imageWidth, imageHeight);
124 }
125
126 public boolean isFinished()
127 {
128 return finished;
129 }
130
131 public boolean isMoving()
132 {
133 return moving;
134 }
135 }