]>
cvs.zerfleddert.de Git - FreeShisen/blob - src/de/cwde/freeshisen/Tileset.java
1 package de
.cwde
.freeshisen
;
3 import android
.graphics
.Bitmap
;
4 import android
.graphics
.BitmapFactory
;
5 import android
.graphics
.Matrix
;
6 import android
.util
.Log
;
10 public int tileHeight
;
12 private ShisenSho app
;
14 public Tileset(ShisenSho shishenSho
) {
15 this.app
= shishenSho
;
18 private void loadPNGTileset(int tilesetid
, int screenWidth
, int screenHeight
) {
19 BitmapFactory
.Options ops
= new BitmapFactory
.Options();
21 Bitmap tileset
= BitmapFactory
.decodeResource(app
.getResources(), tilesetid
, ops
);
22 tileset
.setDensity(Bitmap
.DENSITY_NONE
);
24 // The tile set has 4 rows x 9 columns
27 int loadedtileWidth
= tileset
.getWidth()/tilesetCols
;
28 int loadedtileHeight
= tileset
.getHeight()/tilesetRows
;
29 tile
= new Bitmap
[tilesetRows
*tilesetCols
];
32 // "large" is 16x6, and we want to have a nice border, so we use 17x7 and
33 // choose the lowest scale so everything fits
34 float scalex
= ((float) (screenWidth
- 2)/17) / loadedtileWidth
;
35 float scaley
= ((float) (screenHeight
- 2)/7) / loadedtileHeight
;
36 if (scaley
< scalex
) {
41 Matrix matrix
= new Matrix();
42 matrix
.setScale(scalex
, scaley
);
45 for (int i
=0; i
<tilesetRows
; i
++) {
46 for (int j
=0; j
<tilesetCols
; j
++) {
47 tile
[k
] = Bitmap
.createBitmap(tileset
, j
*loadedtileWidth
, i
*loadedtileHeight
,
48 loadedtileWidth
, loadedtileHeight
, matrix
, false);
49 tile
[k
].setDensity(Bitmap
.DENSITY_NONE
);
53 tileWidth
= tile
[0].getWidth();
54 tileHeight
= tile
[0].getHeight();
57 private void loadSVGTileset(int tilesetid
, int screenWidth
, int screenHeight
) {
61 public void loadTileset(int screenWidth
, int screenHeight
) {
64 String s
= app
.tilesetid
;
66 if (s
.equals("classic")) {
67 id
= R
.drawable
.classic
;
68 } else if (s
.equals("jade")) {
70 } else if (s
.equals("traditional")) {
71 id
= R
.drawable
.traditional
;
72 } else if (s
.equals("pixel")) {
73 id
= R
.drawable
.pixel
;
74 } else if (s
.equals("original")) {
75 id
= R
.drawable
.original
;
76 } else if (s
.equals("veit")) {
79 // shouldn't be reached...
80 Log
.e("ShisenSho", "somebody managed to set an invalid tileset string");
81 id
= R
.drawable
.classic
;
85 loadSVGTileset(id
, screenWidth
, screenHeight
);
87 loadPNGTileset(id
, screenWidth
, screenHeight
);