1 package ru
.deadsoftware
.cavecraft
.misc
;
3 import com
.badlogic
.gdx
.Gdx
;
4 import com
.badlogic
.gdx
.graphics
.Texture
;
5 import com
.badlogic
.gdx
.graphics
.g2d
.BitmapFont
;
6 import com
.badlogic
.gdx
.graphics
.g2d
.GlyphLayout
;
7 import com
.badlogic
.gdx
.graphics
.g2d
.Sprite
;
8 import com
.badlogic
.gdx
.graphics
.g2d
.TextureRegion
;
9 import ru
.deadsoftware
.cavecraft
.CaveGame
;
13 public static final int BLOCK_TEXTURES
= 48;
15 private static GlyphLayout layout
;
17 public static BitmapFont minecraftFont
;
19 public static Sprite gameLogo
;
21 public static Texture menuButtonTexture
;
22 public static TextureRegion
[] menuButton
= new TextureRegion
[3];
24 public static Texture playerTexture
;
25 public static Sprite
[][] playerSprite
= new Sprite
[2][4];
27 public static Texture pigTexture
;
28 public static Sprite
[][] pigSprite
= new Sprite
[2][2];
30 public static Sprite shade
;
32 public static Texture terrain
;
33 public static TextureRegion
[] blockTextures
= new TextureRegion
[BLOCK_TEXTURES
];
35 public static Texture gui
;
36 public static TextureRegion invBar
;
37 public static TextureRegion invBarCur
;
38 public static TextureRegion guiCur
;
40 public static Texture creativeTexture
;
41 public static TextureRegion creativeInv
;
42 public static TextureRegion creativeScroll
;
44 public static Texture touchGui
;
45 public static TextureRegion
[] touchArrows
= new TextureRegion
[4];
46 public static TextureRegion touchLMB
, touchRMB
;
47 public static TextureRegion touchToggleMode
;
48 public static TextureRegion touchSpace
;
50 private static void loadPlayer() {
51 playerTexture
= new Texture(Gdx
.files
.internal("mobs/char.png"));
54 playerSprite
[0][0] = new Sprite(new TextureRegion(playerTexture
, 0,0,12,12));
55 playerSprite
[0][0].flip(false,true);
57 playerSprite
[0][1] = new Sprite(new TextureRegion(playerTexture
, 0,13,12,12));
58 playerSprite
[0][1].flip(false,true);
60 playerSprite
[0][2] = new Sprite(new TextureRegion(playerTexture
, 25,5,20,20));
61 playerSprite
[0][2].flip(false,true);
63 playerSprite
[0][3] = new Sprite(new TextureRegion(playerTexture
, 25,27,20,20));
64 playerSprite
[0][3].flip(false,true);
67 playerSprite
[1][0] = new Sprite(new TextureRegion(playerTexture
, 13,0,12,12));
68 playerSprite
[1][0].flip(false,true);
70 playerSprite
[1][1] = new Sprite(new TextureRegion(playerTexture
, 13,13,12,12));
71 playerSprite
[1][1].flip(false,true);
73 playerSprite
[1][2] = new Sprite(new TextureRegion(playerTexture
, 37,5,20,20));
74 playerSprite
[1][2].flip(false,true);
76 playerSprite
[1][3] = new Sprite(new TextureRegion(playerTexture
, 37,27,20,20));
77 playerSprite
[1][3].flip(false,true);
80 private static void loadPig() {
81 pigTexture
= new Texture(Gdx
.files
.internal("mobs/pig.png"));
82 pigSprite
[0][0] = new Sprite(new TextureRegion(pigTexture
, 0, 0, 25, 12));
83 pigSprite
[0][0].flip(false,true);
84 pigSprite
[1][0] = new Sprite(new TextureRegion(pigTexture
, 0, 12, 25, 12));
85 pigSprite
[1][0].flip(false,true);
86 pigSprite
[0][1] = new Sprite(new TextureRegion(pigTexture
, 4, 26, 12, 12));
87 pigSprite
[0][1].flip(false,true);
88 pigSprite
[1][1] = new Sprite(new TextureRegion(pigTexture
, 16, 26, 12, 12));
89 pigSprite
[1][1].flip(false,true);
92 public static void load() {
93 minecraftFont
= new BitmapFont(Gdx
.files
.internal("font.fnt"), true);
94 minecraftFont
.getData().setScale(.375f);
96 layout
= new GlyphLayout();
98 gameLogo
= new Sprite(new Texture(Gdx
.files
.internal("gamelogo.png")));
99 gameLogo
.flip(false, true);
101 menuButtonTexture
= new Texture(Gdx
.files
.internal("buttons.png"));
102 for (int i
=0; i
<3; i
++) {
103 menuButton
[i
] = new TextureRegion(menuButtonTexture
, 0, 20*i
, 200, 20);
104 menuButton
[i
].flip(false, true);
110 shade
= new Sprite(new Texture(Gdx
.files
.internal("shade.png")));
112 gui
= new Texture(Gdx
.files
.internal("gui.png"));
113 guiCur
= new TextureRegion(gui
,0,0,16,16);
114 invBar
= new TextureRegion(gui
,0,16,182,22);
115 invBarCur
= new TextureRegion(gui
,0,38,24,24);
117 creativeTexture
= new Texture(Gdx
.files
.internal("allitems.png"));
118 creativeInv
= new TextureRegion(creativeTexture
, 0, 0, 176, 136);
119 creativeInv
.flip(false,true);
120 creativeScroll
= new TextureRegion(creativeTexture
, 3, 137, 12, 15);
121 creativeScroll
.flip(false, true);
123 if (CaveGame
.TOUCH
) {
124 touchGui
= new Texture(Gdx
.files
.internal("touch_gui.png"));
125 for (int i
= 0; i
< 4; i
++) {
126 touchArrows
[i
] = new TextureRegion(touchGui
, i
* 26, 0, 26, 26);
127 touchArrows
[i
].flip(false, true);
129 touchLMB
= new TextureRegion(touchGui
, 0, 26, 26, 26);
130 touchLMB
.flip(false, true);
131 touchRMB
= new TextureRegion(touchGui
, 52, 26, 26, 26);
132 touchRMB
.flip(false, true);
133 touchToggleMode
= new TextureRegion(touchGui
, 26, 26, 26, 26);
134 touchToggleMode
.flip(false, true);
135 touchSpace
= new TextureRegion(touchGui
, 0, 52, 104, 26);
136 touchSpace
.flip(false, true);
139 terrain
= new Texture(Gdx
.files
.internal("terrain.png"));
140 for (int i
=0; i
<BLOCK_TEXTURES
; i
++) {
141 blockTextures
[i
] = new TextureRegion(terrain
,
142 (i
%16)*16, (i
/16)*16, 16,16);
143 blockTextures
[i
].flip(false,true);
147 public static int getStringWidth(String s
){
148 layout
.setText(minecraftFont
,s
);
149 return (int)layout
.width
;
152 public static int getStringHeight(String s
){
153 layout
.setText(minecraftFont
,s
);
154 return (int)layout
.height
;