-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadSave.java
103 lines (87 loc) · 3.46 KB
/
LoadSave.java
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
package utilz;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
import javax.imageio.ImageIO;
/**
* Uma classe utilitária para carregar e salvar imagens no jogo.
*/
public class LoadSave {
// Constantes representando nomes de arquivos para várias imagens
public static final String PLAYER_LILITH = "Lilith_player.png";
public static final String LEVEL_ATLAS = "outside_sprites.png";
public static final String MENU_BUTTONS = "button_atlas.png";
public static final String MENU_BACKGROUND = "menu_background.png";
public static final String PAUSE_BACKGROUND = "pause_menu.png";
public static final String SOUND_BUTTONS = "sound_button.png";
public static final String URM_BUTTONS = "urm_buttons.png";
public static final String VOLUME_BUTTONS = "volume_buttons.png";
public static final String MENU_BACKGROUND_IMG = "background_menu.png";
public static final String PLAYING_BG_IMG = "playing_bg_img.png";
public static final String BIG_CLOUDS = "big_clouds.png";
public static final String SMALL_CLOUDS = "small_clouds.png";
public static final String CRABBY_SPRITE = "crabby_sprite.png";
public static final String STATUS_BAR = "health_power_bar.png";
public static final String COMPLETED_IMG = "completed_sprite.png";
public static final String POTION_ATLAS = "potions_sprites.png";
public static final String CONTAINER_ATLAS = "objects_sprites.png";
public static final String TRAP_ATLAS = "trap_atlas.png";
/**
* Carrega um atlas de sprites (imagem) da pasta de recursos.
*
* @param fileName O nome do arquivo a ser carregado.
* @return O BufferedImage carregado.
*/
public static BufferedImage GetSpriteAtlas(String fileName) {
BufferedImage img = null;
InputStream is = LoadSave.class.getResourceAsStream("/" + fileName);
try {
img = ImageIO.read(is);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return img;
}
/**
* Recupera todas as imagens de níveis da pasta "lvls" nos recursos.
*
* @return Uma matriz de BufferedImages representando todos os níveis.
*/
public static BufferedImage[] GetAllLevels() {
URL url = LoadSave.class.getResource("/lvls");
File file = null;
try {
file = new File(url.toURI());
} catch (URISyntaxException e) {
e.printStackTrace();
}
File[] files = file.listFiles();
File[] filesSorted = new File[files.length];
// Ordenando arquivos com base em seus nomes (supondo que sejam nomeados como "1.png", "2.png", etc.)
for (int i = 0; i < filesSorted.length; i++) {
for (int j = 0; j < files.length; j++) {
if (files[j].getName().equals((i + 1) + ".png")) {
filesSorted[i] = files[j];
}
}
}
BufferedImage[] imgs = new BufferedImage[filesSorted.length];
// Lendo imagens dos arquivos ordenados
for (int i = 0; i < imgs.length; i++)
try {
imgs[i] = ImageIO.read(filesSorted[i]);
} catch (IOException e) {
e.printStackTrace();
}
return imgs;
}
}