package core;
import icon.BaseIcon;
import icon.HouseIcon;
import icon.ScvIcon;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.DirectColorModel;
import java.awt.image.MemoryImageSource;
import java.awt.image.PixelGrabber;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.ImageIcon;
import tile.Barrack;
import tile.Headquarter;
import tile.House;
import tile.Marine;
import tile.Mine;
import tile.Scv;
import tile.Sprite;
import tile.Supply;
import tile.Tank;
import tile.Tile;
import tile.Sprite.Animation;
public class ResourceManager {
private GridMap gridMap;
public static ResourceManager resourceManager;
private static Map<String,Image> IMAGE_CACHE = new HashMap<String, Image>();
public static Image loadImage(String fileName) {
if(!IMAGE_CACHE.containsKey(fileName)){
IMAGE_CACHE.put(fileName, new ImageIcon(ResourceManager.class.getResource("/images/"+fileName)).getImage());
}
return IMAGE_CACHE.get(fileName);
}
public static GridMapRender load(int type,List<Integer> types){
resourceManager = new ResourceManager(type,types);
return resourceManager.gridMap.getTileMapRender();
}
public GridMap getGridMap() {
return gridMap;
}
/**
* 初始化缩略图
* @return
*/
private Image initMapBg(){
BufferedImage buffer = new BufferedImage(128,128,BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = (Graphics2D) buffer.getGraphics();
for (int y = 0; y < gridMap.getHeight(); ++y) {
for (int x = 0; x < gridMap.getWidth(); ++x) {
AffineTransform affineTransform = new AffineTransform();
affineTransform.setToTranslation(x*10, y*5);
affineTransform.scale(0.2, 0.2);
g2.drawImage(Constant.IMAGE_BG, affineTransform, null);
}
}
return buffer;
}
private ResourceManager(int type,List<Integer> types) {
Constant.load();
gridMap = loadMap(type,types);
Constant.IMAGE_MAP_BG = initMapBg();
Constant.progress = Constant.TOTAL;
}
private GridMap loadMap(int type,List<Integer> types) {
List<String> list = new ArrayList<String>();
int width = readMap(list, "startmap1.map");
GridMap map = new GridMap(width, list.size());
GridMapRender mapRender = new GridMapRender(map);
mapRender.type = type;
map.setTileMapRender(mapRender);
map.setIconMap(Constant.ICON_MAP);
for (int y = 0; y < list.size(); ++y) {
// 读取每一行
String s = list.get(y);
for (int x = 0; x < s.length(); ++x) {
int code = (int)s.charAt(x)-40;
if(code<0||code>Constant.TILE_TABLE.length)
continue;
if(code<80&&!types.contains((code/20)))
continue;
Tile tile = Constant.TILE_TABLE[code].clone(x, y,map);
tile.setHealth(1.0f);
map.add(tile);
//确定当前视觉范围
if(tile.getType()==type&&tile instanceof Headquarter){
//获取当前基地坐标
int hqX = GridMapRender.tileXToPx(tile.getTileX());
int hqY = GridMapRender.tileYToPx(tile.getTileY());
Point size = tile.getSize();
//获取屏幕中心坐标
int centerX = (800-GridMapRender.tileXToPx(size.x))/2;
int centerY = (600-GridMapRender.tileYToPx(size.y))/2;
mapRender.setOffset(Math.max(hqX-centerX, 0),Math.max(hqY-centerY, 0));
}
}
}
return map;
}
private static int readMap(List list, String fileName) {
BufferedReader br = null;
int width = 0;
try {
br = new BufferedReader(new InputStreamReader(ResourceManager.class.getResourceAsStream("/map/" + fileName)));
String line = null;
while ((line = br.readLine()) != null) {
if (line.startsWith("#"))
continue;
list.add(line);
width = Math.max(width, line.length());
}
return width;
} catch (Exception e) {
e.printStackTrace();
return -1;
} finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static class Constant {
public static String IP;
public static Color GREEN;
public static Color RED=Color.red;
//背景
public static Image IMAGE_BG;
//控制台
public static Image IMAGE_CONTROL;
//光照效果
public static Image SCV_SPARK;
//矿产
public static Image ICON_MINE;
//人口
public static Image ICON_MAN;
//矿产错误信息
public static String MINE_ERROR="没资源咯,还是多去采点矿吧";
//人口错误信息
public static String MAN_ERROR="太挤啦,快造点房子出来吧";
public static String BUILD_ERROR="地基不稳,不能修在这里";
public static Image IMAGE_MAP_BG;
//ICONS
public static final BaseIcon[][] SCV_ICONS = new BaseIcon[2][3];
public static final BaseIcon[][] HQ_ICONS = new BaseIcon[2][3];
public static final BaseIcon[][] BACK_ICONS = new BaseIcon[2][3];
//ICON资源表
public static final Map<Integer,BaseIcon[][]> ICON_TABLE = new HashMap<Integer, BaseIcon[][]>();
//Tile资源表
public static final Tile[] TILE_TABLE = new Tile[82];
private static final int TYPE = 4;
public static final int TYPE_SIZE = 20;
//进度控制
private static float progress;
private static final float TOTAL=19;
static void load(){
IMAGE_BG = loadImage("bg1.gif");
IMAGE_CONTROL = loadImage("panel/main.gif");
SCV_SPARK = loadImage("unit/0_scv_spark.gif");
ICON_MINE = loadImage("panel/mine.gif");
ICON_MAN = loadImage("panel/man.gif");
GREEN = new Color(16, 252, 24);
initTile();
}
private static final Map<String, BaseIcon> ICON_MAP = new HashMap<String, BaseIcon>();
private static int count = 0;
private static BaseIcon createIcon(BaseIcon icon){
ICON_MAP.put("icon"+(++count), icon);
return icon;
}
private static void initTile(){
//加载图片
Image scv = loadImage("unit/0_scv_red.gif");
Image marine = loadImage("unit/0_marine_red.gif");
Image marineFight = loadImage("unit/0_fight_marine_red.png");
Image tank = loadImage("unit/0_tank.gif");
Image supply = loadImage("build/0_supply_red.gif");
Image barrack = loadImage("build/0_barrack_red.gif");
Image base = loadImage("build/0_hq_red.gif");
Image mine = loadImage("block/mine.gif");
//转换成buffer
BufferedImage scv_buffer=imageToBuffer(scv);
BufferedImage marine_buffer=imageToBuffer(marine);
BufferedImage marineFight_buffer=imageToBuffer(marineFight);
BufferedImage supply_buffer=imageToBuffer(supply);
BufferedImage barrack_buffer=imageToBuffer(barrack);
BufferedImage base_buffer=imageToBuffer(base);
BufferedImage tank_buffer=imageToBuffer(tank);
//初始化矿产资源
TILE_TABLE[80] = new Mine(mine,80);
//ICON
HQ_ICONS[0][0] = createIcon(new HouseIcon(loadImage("ico/0_scv.gif")));
SCV_ICONS[0][0] = createIcon(new ScvIcon(loadImage("ico/0_supply.gif")));
SCV_ICONS[0][1] = createIcon(new ScvIcon(loadImage("ico/0_barrack.gif")));
BACK_ICONS[0][0] = createIcon(new HouseIcon(loadImage("ico/0_marine.gif")));
//BACK_ICONS[0][1] = new HouseIcon(loadImage("ico/0_tanke.gif"));
//初始化比较复杂的Tile
for(int i=0;i<TYPE;++i){
//农民
TILE_TABLE[TYPE_SIZE*i] = createScv(scv_buffer,TYPE_SIZE*i);
ICON_TABLE.put(TILE_TABLE[TYPE_SIZE*i].getId(), SCV_ICONS);
scv_buffer = imageToBuffer(createImage(scv, i));
//�
没有合适的资源?快使用搜索试试~ 我知道了~
Swing星际争霸游戏
共418个文件
class:144个
gif:140个
java:90个
2星 需积分: 10 19 下载量 70 浏览量
2011-01-23
01:07:51
上传
评论 1
收藏 1.48MB ZIP 举报
温馨提示
Swing星际争霸游戏,Swing写的游戏,好玩很强大,欢迎广大java爱好者下载,
资源推荐
资源详情
资源评论
收起资源包目录
Swing星际争霸游戏 (418个子文件)
startmap1.map.bak 13KB
startmap1.map.bak 13KB
my_setup1.bat 101B
setup2.bat 54B
setup3.bat 54B
setup1.bat 54B
ResourceManager$Constant.class 11KB
Sprite.class 10KB
GridMapRender.class 9KB
AStarSearch.class 9KB
Scv.class 8KB
Server.class 7KB
MutilPlayerPanel$2.class 6KB
ResourceManager.class 6KB
FocusManager.class 6KB
GridMap.class 5KB
NewGamePanel$LeftPanel.class 5KB
Control.class 5KB
House.class 5KB
Client.class 4KB
DefaultNetWorkManager.class 4KB
MutilPlayerPanel$LeftPanel.class 4KB
ScreenManager.class 4KB
ServerProcessor.class 4KB
FullGameCore.class 4KB
ClientGUI.class 4KB
GameCore.class 3KB
PathSearch.class 3KB
WorkPanel.class 3KB
MapPanel.class 3KB
Player.class 3KB
GameGUI.class 3KB
GamePanel.class 3KB
MockNetWorkManager.class 3KB
PlayerInfo.class 3KB
Mine.class 3KB
PSExplosion.class 3KB
MutilPlayerPanel.class 3KB
AStarNode.class 3KB
MainMenuPanel$MenuItem.class 2KB
SingleGamePanel$LeftPanel.class 2KB
Receiver.class 2KB
StarScrollBarUI.class 2KB
Detector.class 2KB
PlayerContext.class 2KB
NewGamePanel$RightPanel.class 2KB
NewGamePanel.class 2KB
MutilPlayerPanel$RightPanel.class 2KB
SingleGamePanel$RightPanel.class 2KB
Marine.class 2KB
Abstractpanel.class 2KB
StarComboBoxUI.class 2KB
Control$ControlDragListener.class 2KB
MutilPlayerPanel$LeftPanel$2.class 2KB
SingleGamePanel.class 2KB
MainMenuPanel$MenuItem$1.class 2KB
MoveInfo.class 2KB
MutilPlayerPanel$LeftPanel$1.class 2KB
TileList.class 2KB
Sprite$Animation.class 2KB
Vector.class 2KB
AbstractTile.class 2KB
StarNode.class 2KB
StarComboBoxUI.class 2KB
NewGamePanel$RightPanel$2.class 2KB
NewGamePanel$RightPanel$1.class 2KB
NewGamePanel$LeftPanel$4.class 2KB
NewGamePanel$LeftPanel$5.class 2KB
NewGamePanel$LeftPanel$3.class 2KB
Stack.class 2KB
MutilPlayerPanel$RightPanel$1.class 2KB
Tank.class 2KB
Particle.class 2KB
ClientEvent.class 2KB
NewGamePanel$TextPanel.class 2KB
BaseIcon.class 2KB
StarListCellRender.class 2KB
GamePanel$5.class 2KB
SingleGamePanel$RightPanel$1.class 1KB
SingleGamePanel$LeftPanel$2.class 1KB
SingleGamePanel$LeftPanel$1.class 1KB
GamePanel$1.class 1KB
ConsolePanel.class 1KB
Control$ControlMoveListener.class 1KB
IconInfo.class 1KB
NewGamePanel$LeftPanel$1.class 1KB
TestGameCore.class 1KB
Elastic.class 1KB
NetworkPanel$MenuItem.class 1KB
ImageManager.class 1KB
Broadcaster.class 1KB
RandomSequence.class 1KB
Headquarter.class 1KB
MainMenuPanel.class 1KB
MapPanel$MouseListener.class 1KB
Control$ControlKeyListener.class 1KB
RoundBorder.class 1KB
RoundBorder.class 1KB
RoundBorder.class 1KB
NewGamePanel$LeftPanel$GameItemListener.class 1KB
共 418 条
- 1
- 2
- 3
- 4
- 5
资源评论
- 天涯泪小武2014-03-04跑是跑起来了,但是不能操作
chenjie3392593
- 粉丝: 65
- 资源: 30
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功