public synchronized void removeAll() { if (sprites != null) { sprites.removeAll(); } if (desktop != null) { desktop.getContentPane().clear(); } }
public final void paint(LGraphics g) { if (!running || isClose()) { return; } if (sleep == 0) { if (scrCG == null) { return; } if (scrCG.getBackgroundCG() != null) { if (shakeNumber > 0) { g.drawImage( scrCG.getBackgroundCG(), shakeNumber / 2 - LSystem.random.nextInt(shakeNumber), shakeNumber / 2 - LSystem.random.nextInt(shakeNumber)); } else { g.drawImage(scrCG.getBackgroundCG(), 0, 0); } } int moveCount = 0; for (int i = 0; i < scrCG.getCharas().size(); i++) { Chara chara = (Chara) scrCG.getCharas().get(i); float value = 1.0f; if (chara.next()) { value = chara.getNextAlpha(); moveCount++; } g.setAlpha(value); chara.draw(g); g.setAlpha(1.0F); } drawScreen(g); if (desktop != null) { desktop.createUI(g); } if (sprites != null) { sprites.createUI(g); } } else { sleep--; if (color != null) { double alpha = (double) (sleepMax - sleep) / sleepMax; if (alpha < 1.0) { if (scrCG.getBackgroundCG() != null) { g.drawImage(scrCG.getBackgroundCG(), 0, 0); } g.setAlpha(alpha); g.setColor(color); g.fillRect(0, 0, getCurrentWidth(), getCurrentHeight()); g.setAlpha(1.0f); } } if (sleep <= 0) { sleep = 0; color = null; } } }
/** 创建程序UI */ public synchronized void createUI(final LGraphics g) { draw(g); if (sprites != null) { sprites.createUI(g); } if (desktop != null) { desktop.createUI(g); } }
public void run() { initAVG(); while (running) { repaint(); pause(delay); if (desktop != null) { desktop.update(delay); } if (sprites != null) { sprites.update(delay); } } }
public synchronized void nextScript() { if (command != null && !isClose() && running) { for (; isRunning = command.next(); ) { String result = command.doExecute(); if (result == null) { continue; } if (!nextScript(result)) { break; } List commands = Command.splitToList(result, " "); int size = commands.size(); String cmdFlag = (String) commands.get(0); String mesFlag = null, orderFlag = null, lastFlag = null; if (size == 2) { mesFlag = (String) commands.get(1); } else if (size == 3) { mesFlag = (String) commands.get(1); orderFlag = (String) commands.get(2); } else if (size == 4) { mesFlag = (String) commands.get(1); orderFlag = (String) commands.get(2); lastFlag = (String) commands.get(3); } if (cmdFlag.equalsIgnoreCase(CommandType.L_WAIT)) { scrFlag = true; break; } if (cmdFlag.equalsIgnoreCase(CommandType.L_SNOW) || cmdFlag.equalsIgnoreCase(CommandType.L_RAIN) || cmdFlag.equalsIgnoreCase(CommandType.L_PETAL)) { if (sprites != null) { boolean flag = false; ISprite[] ss = sprites.getSprites(); for (int i = 0; i < ss.length; i++) { ISprite s = ss[i]; if (s instanceof FreedomEffect) { flag = true; break; } } if (!flag) { if (cmdFlag.equalsIgnoreCase(CommandType.L_SNOW)) { sprites.add(FreedomEffect.getSnowEffect()); } else if (cmdFlag.equalsIgnoreCase(CommandType.L_RAIN)) { sprites.add(FreedomEffect.getRainEffect()); } else if (cmdFlag.equalsIgnoreCase(CommandType.L_PETAL)) { sprites.add(FreedomEffect.getPetalEffect()); } } } continue; } if (cmdFlag.equalsIgnoreCase(CommandType.L_SNOWSTOP) || cmdFlag.equalsIgnoreCase(CommandType.L_RAINSTOP) || cmdFlag.equalsIgnoreCase(CommandType.L_PETALSTOP)) { if (sprites != null) { ISprite[] ss = sprites.getSprites(); for (int i = 0; i < ss.length; i++) { ISprite s = ss[i]; if (s instanceof FreedomEffect) { if (cmdFlag.equalsIgnoreCase(CommandType.L_SNOWSTOP)) { if (((FreedomEffect) s).getKernels()[0] instanceof SnowKernel) { sprites.remove(s); } } else if (cmdFlag.equalsIgnoreCase(CommandType.L_RAINSTOP)) { if (((FreedomEffect) s).getKernels()[0] instanceof RainKernel) { sprites.remove(s); } } else if (cmdFlag.equalsIgnoreCase(CommandType.L_PETALSTOP)) { if (((FreedomEffect) s).getKernels()[0] instanceof PetalKernel) { sprites.remove(s); } } } } } continue; } if (cmdFlag.equalsIgnoreCase(CommandType.L_PLAY)) { playSound(mesFlag); continue; } if (cmdFlag.equalsIgnoreCase(CommandType.L_PLAYLOOP)) { // 待替换(J2SE版音频管理组件待完善,目前无法做到所有音频格式皆支持循环播放,预计0.3版完成) playSound(mesFlag); continue; } if (cmdFlag.equalsIgnoreCase(CommandType.L_PLAYSTOP)) { if (NumberUtils.isNumber(mesFlag)) { stopSound(Integer.parseInt(mesFlag)); } else { stopSound(); } continue; } if (cmdFlag.equalsIgnoreCase(CommandType.L_FADEOUT) || cmdFlag.equalsIgnoreCase(CommandType.L_FADEIN)) { scrFlag = true; Color color = Color.black; if (mesFlag.equalsIgnoreCase("red")) { color = Color.red; } else if (mesFlag.equalsIgnoreCase("yellow")) { color = Color.yellow; } else if (mesFlag.equalsIgnoreCase("white")) { color = Color.white; } else if (mesFlag.equalsIgnoreCase("black")) { color = Color.black; } else if (mesFlag.equalsIgnoreCase("cyan")) { color = Color.cyan; } else if (mesFlag.equalsIgnoreCase("green")) { color = Color.green; } else if (mesFlag.equalsIgnoreCase("orange")) { color = Color.orange; } else if (mesFlag.equalsIgnoreCase("pink")) { color = Color.pink; } if (sprites != null) { sprites.removeAll(); if (cmdFlag.equalsIgnoreCase(CommandType.L_FADEIN)) { sprites.add(Fade.getInstance(Fade.TYPE_FADE_IN, color)); } else { sprites.add(Fade.getInstance(Fade.TYPE_FADE_OUT, color)); } } continue; } if (cmdFlag.equalsIgnoreCase(CommandType.L_SELLEN)) { if (mesFlag != null) { if (NumberUtils.isNumber(mesFlag)) { select.setLeftOffset(Integer.parseInt(mesFlag)); } } continue; } if (cmdFlag.equalsIgnoreCase(CommandType.L_SELTOP)) { if (mesFlag != null) { if (NumberUtils.isNumber(mesFlag)) { select.setTopOffset(Integer.parseInt(mesFlag)); } } continue; } if (cmdFlag.equalsIgnoreCase(CommandType.L_MESLEN)) { if (mesFlag != null) { if (NumberUtils.isNumber(mesFlag)) { message.setMessageLength(Integer.parseInt(mesFlag)); } } continue; } if (cmdFlag.equalsIgnoreCase(CommandType.L_MESTOP)) { if (mesFlag != null) { if (NumberUtils.isNumber(mesFlag)) { message.setTopOffset(Integer.parseInt(mesFlag)); } } continue; } if (cmdFlag.equalsIgnoreCase(CommandType.L_MESLEFT)) { if (mesFlag != null) { if (NumberUtils.isNumber(mesFlag)) { message.setLeftOffset(Integer.parseInt(mesFlag)); } } continue; } if (cmdFlag.equalsIgnoreCase(CommandType.L_MESCOLOR)) { if (mesFlag != null) { if (mesFlag.equalsIgnoreCase("red")) { message.setFontColor(Color.red); } else if (mesFlag.equalsIgnoreCase("yellow")) { message.setFontColor(Color.yellow); } else if (mesFlag.equalsIgnoreCase("white")) { message.setFontColor(Color.white); } else if (mesFlag.equalsIgnoreCase("black")) { message.setFontColor(Color.black); } else if (mesFlag.equalsIgnoreCase("cyan")) { message.setFontColor(Color.cyan); } else if (mesFlag.equalsIgnoreCase("green")) { message.setFontColor(Color.green); } else if (mesFlag.equalsIgnoreCase("orange")) { message.setFontColor(Color.orange); } else if (mesFlag.equalsIgnoreCase("pink")) { message.setFontColor(Color.pink); } } continue; } if (cmdFlag.equalsIgnoreCase(CommandType.L_MES)) { if (select.isVisible()) { select.setVisible(false); } scrFlag = true; String nMessage = mesFlag; message.setMessage(StringUtils.replace(nMessage, "&", " ")); message.setVisible(true); break; } if (cmdFlag.equalsIgnoreCase(CommandType.L_MESSTOP)) { scrFlag = true; message.setVisible(false); select.setVisible(false); continue; } if (cmdFlag.equalsIgnoreCase(CommandType.L_SELECT)) { selectMessage = mesFlag; continue; } if (cmdFlag.equalsIgnoreCase(CommandType.L_SELECTS)) { if (message.isVisible()) { message.setVisible(false); } select.setVisible(true); scrFlag = true; isSelectMessage = true; String[] selects = command.getReads(); select.setMessage(selectMessage, selects); break; } if (cmdFlag.equalsIgnoreCase(CommandType.L_SHAKE)) { shakeNumber = Integer.valueOf(mesFlag).intValue(); continue; } if (cmdFlag.equalsIgnoreCase(CommandType.L_CGWAIT)) { scrFlag = false; break; } if (cmdFlag.equalsIgnoreCase(CommandType.L_SLEEP)) { sleep = Integer.valueOf(mesFlag).intValue(); sleepMax = Integer.valueOf(mesFlag).intValue(); scrFlag = false; break; } if (cmdFlag.equalsIgnoreCase(CommandType.L_FLASH)) { scrFlag = true; String[] colors = mesFlag.split(","); if (color == null && colors != null && colors.length == 3) { color = new Color( Integer.valueOf(colors[0]).intValue(), Integer.valueOf(colors[1]).intValue(), Integer.valueOf(colors[2]).intValue()); sleep = 20; sleepMax = sleep; scrFlag = false; } else { color = null; } continue; } if (cmdFlag.equalsIgnoreCase(CommandType.L_GB)) { if (mesFlag == null) { return; } if (mesFlag.equalsIgnoreCase("none")) { scrCG.noneBackgroundCG(); } else { scrCG.setBackgroundCG(mesFlag); } continue; } if (cmdFlag.equalsIgnoreCase(CommandType.L_CG)) { if (mesFlag == null) { return; } if (mesFlag.equalsIgnoreCase(CommandType.L_DEL)) { if (orderFlag != null) { scrCG.removeImage(orderFlag); } else { scrCG.clear(); } } else if (lastFlag != null && CommandType.L_TO.equalsIgnoreCase(orderFlag)) { Chara chara = scrCG.removeImage(mesFlag); if (chara != null) { int x = chara.getX(); int y = chara.getY(); chara = new Chara(lastFlag, 0, 0, getCurrentWidth()); chara.setMove(false); chara.setX(x); chara.setY(y); scrCG.addChara(lastFlag, chara); } } else { int x = 0, y = 0; if (orderFlag != null) { x = Integer.parseInt(orderFlag); } if (size >= 4) { y = Integer.parseInt((String) commands.get(3)); } scrCG.addImage(mesFlag, x, y, getCurrentWidth()); } continue; } if (cmdFlag.equalsIgnoreCase(CommandType.L_EXIT)) { scrFlag = true; setFPS(LSystem.DEFAULT_MAX_FPS); running = false; onExit(); break; } } } }
public void removeAll() { sprites.removeAll(); desktop.getContentPane().clear(); }
public void remove(ISprite sprite) { sprites.remove(sprite); }
public void add(ISprite s) { if (sprites == null) { initDesktop(); } sprites.add(s); }
public synchronized void remove(ISprite sprite) { if (sprites != null) { sprites.remove(sprite); } }
/** * 添加游戏精灵 * * @param sprite */ public void add(ISprite sprite) { if (sprites != null) { sprites.add(sprite); } }
/** * 监听Screen中精灵 * * @param sprListerner */ public void setSprListerner(ISpriteListener sprListerner) { if (sprites == null) { return; } sprites.setSprListerner(sprListerner); }
/** * 返回精灵监听 * * @return */ public ISpriteListener getSprListerner() { if (sprites == null) { return null; } return sprites.getSprListerner(); }
/** * 设定指定精灵到图层最后 * * @param sprite */ public void sendSpriteToBack(ISprite sprite) { sprites.sendToBack(sprite); }
/** * 设定指定精灵到图层最前 * * @param sprite */ public void sendSpriteToFront(ISprite sprite) { sprites.sendToFront(sprite); }
/** 检查窗体默认对象中是否包含指定精灵 */ public boolean contains(ISprite sprite) { return sprites.contains(sprite); }