aboutsummaryrefslogtreecommitdiff
path: root/src/org/happysanta/gd/Game/Bitmap.java
blob: 087a86501d2ca118c4cb3874176ac3935b461b40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package org.happysanta.gd.Game;

import org.happysanta.gd.Global;
import org.happysanta.gd.R;

import java.io.IOException;

import static org.happysanta.gd.Helpers.*;

public class Bitmap {

	public final static int HELMET = 0;
	public final static int CODEBREW_LOGO = 1;
	public final static int GD_LOGO = 2;
	public final static int STEERING = 3;
	public final static int WHEELS = 4;
	public final static int ARROWS = 5;
	public final static int FLAGS = 6;
	public final static int LOCKS = 7;
	public final static int MEDALS = 8;
	public final static int LEVELS_WHEELS = 9;
	public final static int FENDER = 10;
	public final static int ENGINE = 11;
	public final static int BIKER = 12;

	public final static int BLUEARM = 100;
	public final static int BLUELEG = 101;
	public final static int BLUEBODY = 102;

	public android.graphics.Bitmap bitmap;
	protected static GDBitmapHolder holders[];
	protected static Bitmap empty = null;

	Bitmap(android.graphics.Bitmap b) {
		bitmap = b;
	}

	static {
		holders = new GDBitmapHolder[]{
				// 0
				new GDBitmapHolder(Bitmap.fromDrawable(R.drawable.s_helmet)),

				// 1
				new GDBitmapHolder(Bitmap.fromDrawable(R.drawable.codebrew)),

				// 2
				new GDBitmapHolder(Bitmap.fromDrawable(R.drawable.gd)),

				// 3
				new GDBitmapHolder(Bitmap.fromDrawable(R.drawable.s_steering)),

				// 4
				new GDBitmapHolder(new Bitmap[]{
						Bitmap.fromDrawable(R.drawable.s_wheel1),
						Bitmap.fromDrawable(R.drawable.s_wheel2)
				}),

				// 5
				new GDBitmapHolder(new Bitmap[]{
						Bitmap.fromDrawable(R.drawable.s_arrow_up),
						Bitmap.fromDrawable(R.drawable.s_arrow_down)
				}),

				// 6
				new GDBitmapHolder(new Bitmap[]{
						Bitmap.fromDrawable(R.drawable.s_flag_start0),
						Bitmap.fromDrawable(R.drawable.s_flag_start1),
						Bitmap.fromDrawable(R.drawable.s_flag_start2),
						Bitmap.fromDrawable(R.drawable.s_flag_finish0),
						Bitmap.fromDrawable(R.drawable.s_flag_finish1),
						Bitmap.fromDrawable(R.drawable.s_flag_finish2)
				}),

				// 7
				new GDBitmapHolder(new Bitmap[]{
						Bitmap.fromDrawable(R.drawable.s_lock0),
						Bitmap.fromDrawable(R.drawable.s_lock1),
						Bitmap.fromDrawable(R.drawable.s_lock2)
				}),

				// 8
				new GDBitmapHolder(new Bitmap[]{
						Bitmap.fromDrawable(R.drawable.s_medal_gold),
						Bitmap.fromDrawable(R.drawable.s_medal_silver),
						Bitmap.fromDrawable(R.drawable.s_medal_bronze)
				}),

				// 9
				new GDBitmapHolder(new Bitmap[]{
						Bitmap.fromDrawable(R.drawable.levels_wheel0),
						Bitmap.fromDrawable(R.drawable.levels_wheel1),
						Bitmap.fromDrawable(R.drawable.levels_wheel2)
				}),

				// 10
				new GDBitmapHolder(Bitmap.fromDrawable(R.drawable.s_fender)),

				// 11
				new GDBitmapHolder(Bitmap.fromDrawable(R.drawable.s_engine)),

				// 12
				new GDBitmapHolder(new Bitmap[]{
						Bitmap.fromDrawable(R.drawable.s_bluearm),
						Bitmap.fromDrawable(R.drawable.s_blueleg),
						Bitmap.fromDrawable(R.drawable.s_bluebody)
				})
		};
		empty = new Bitmap(android.graphics.Bitmap.createBitmap(1, 1, android.graphics.Bitmap.Config.ARGB_8888));
	}

	public static Bitmap get(int index) {
		if (index >= BLUEARM && index <= BLUEBODY) {
			return get(BIKER, index - 100);
		}

		if (holders.length >= index - 1) {
			GDBitmapHolder holder = holders[index];

			if (holder != null && !holder.isArray && holder.bitmap != null) {
				return holder.bitmap;
			}
		}

		return empty;
	}

	public static Bitmap get(int index, int arrayIndex) {
		if (holders.length >= index - 1) {
			GDBitmapHolder holder = holders[index];
			if (holder != null && holder.isArray && holder.bitmaps != null && holder.bitmaps.length >= arrayIndex - 1) {
				return holder.bitmaps[arrayIndex];
			}
		}

		return empty;
	}

	public static Bitmap getEmpty() {
		return empty;
	}

	public static Bitmap fromDrawable(int id) {
		return new Bitmap(loadBitmapFromDrawable(id));
	}

	public static Bitmap fromAsset(String s) throws IOException {
		return new Bitmap(loadBitmapFromAsset(s));
	}

	public int getWidth() {
		return bitmap.getWidth();
	}

	public int getHeight() {
		return bitmap.getHeight();
	}

	public int getWidthDp() {
		return Math.round(getWidth() / Global.density);
	}

	public int getHeightDp() {
		return Math.round(getHeight() / Global.density);
	}

	private static class GDBitmapHolder {

		public Bitmap bitmap = null;
		public Bitmap bitmaps[] = null;
		public boolean isArray = false;

		GDBitmapHolder(Bitmap bitmap) {
			this.bitmap = bitmap;
		}

		GDBitmapHolder(Bitmap bitmaps[]) {
			this.bitmaps = new Bitmap[bitmaps.length];
			System.arraycopy(bitmaps, 0, this.bitmaps, 0, bitmaps.length);
			isArray = true;
		}

	}

}