Added:
/branches/nm8/data/xml/fonts.xml
/branches/nm8/data/xml/game_main.xml
/branches/nm8/src/cx/it/nullpo/nm8/game/component/package-info.java
/branches/nm8/src/cx/it/nullpo/nm8/game/package-info.java
/branches/nm8/src/cx/it/nullpo/nm8/game/play/package-info.java
/branches/nm8/src/cx/it/nullpo/nm8/game/subsystem/mode/package-info.java
/branches/nm8/src/cx/it/nullpo/nm8/game/subsystem/package-info.java
/branches/nm8/src/cx/it/nullpo/nm8/game/subsystem/randomizer/package-info.java
/branches/nm8/src/cx/it/nullpo/nm8/game/subsystem/wallkick/package-info.java
/branches/nm8/src/cx/it/nullpo/nm8/gui/game/GameFieldController.java
/branches/nm8/src/cx/it/nullpo/nm8/gui/game/GameFieldRenderer.java
/branches/nm8/src/cx/it/nullpo/nm8/gui/game/MainScreenController.java
/branches/nm8/src/cx/it/nullpo/nm8/gui/game/NullpoMinoNiftyGUI.java
/branches/nm8/src/overview.html
Modified:
/branches/nm8/data/properties/log.cfg
/branches/nm8/src/cx/it/nullpo/nm8/game/play/GameManager.java
/branches/nm8/src/cx/it/nullpo/nm8/gui/slick/NullpoMinoSlick.java
/branches/nm8/src/cx/it/nullpo/nm8/gui/swing/NullpoMinoSwing.java
/branches/nm8/src/cx/it/nullpo/nm8/gui/swing/framework/SwingNFGameWrapper.java
/branches/nm8/src/cx/it/nullpo/nm8/neuro/core/NEUROBase.java
/branches/nm8/src/cx/it/nullpo/nm8/util/CustomProperties.java
=======================================
--- /dev/null
+++ /branches/nm8/data/xml/fonts.xml Thu Nov 10 01:23:35 2011
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<nifty-styles>
+ <style id="button-font">
+ <attributes font="data/res/font/font.ttf" />
+ </style>
+
+ <style id="base-font">
+ <attributes font="data/res/font/font.ttf" />
+ </style>
+</nifty-styles>
=======================================
--- /dev/null
+++ /branches/nm8/data/xml/game_main.xml Thu Nov 10 01:23:35 2011
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<nifty xmlns="http://nifty-gui.sourceforge.net/nifty.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://nifty-gui.sourceforge.net/nifty.xsd
http://nifty-gui.sourceforge.net/nifty.xsd">
+ <useStyles filename="nifty-default-styles.xml" />
+ <useControls filename="nifty-default-controls.xml" />
+ <useStyles filename="data/xml/fonts.xml" />
+
+ <controlDefinition name="gamefield"
controller="cx.it.nullpo.nm8.gui.game.GameFieldController">
+ <panel childLayout="center">
+ <panel id="panel-field" backgroundColor="#000000"
childLayout="absolute">
+ </panel>
+ </panel>
+ </controlDefinition>
+
+ <screen id="start"
controller="cx.it.nullpo.nm8.gui.game.MainScreenController">
+ <layer childLayout="vertical" backgroundColor="#202020">
+ <panel childLayout="horizontal" width="100%" height="10%" />
+
+ <panel backgroundColor="#FF0000" childLayout="center" width="162"
height="326" align="center" valign="center">
+ <panel childLayout="center" width="160" height="324" align="center"
valign="center">
+ <control id="field-0" name="gamefield" blocksize="16" />
+ </panel>
+ </panel>
+
+ <panel childLayout="horizontal" width="100%" height="20%">
+ <control id="buttonStart" name="button" label="Start"
focusable="false" />
+ <control id="buttonQuit" name="button" label="Quit" focusable="false"
/>
+ </panel>
+ </layer>
+ </screen>
+</nifty>
=======================================
--- /dev/null
+++ /branches/nm8/src/cx/it/nullpo/nm8/game/component/package-info.java Thu
Nov 10 01:23:35 2011
@@ -0,0 +1,4 @@
+/**
+ * This package contains several components used by the main game logic.
+ */
+package cx.it.nullpo.nm8.game.component;
=======================================
--- /dev/null
+++ /branches/nm8/src/cx/it/nullpo/nm8/game/package-info.java Thu Nov 10
01:23:35 2011
@@ -0,0 +1,5 @@
+/**
+ * This package contains main game codes of NullpoMino.
+ * This package should not contain any rendering codes to make it device
independent.
+ */
+package cx.it.nullpo.nm8.game;
=======================================
--- /dev/null
+++ /branches/nm8/src/cx/it/nullpo/nm8/game/play/package-info.java Thu Nov
10 01:23:35 2011
@@ -0,0 +1,7 @@
+/**
+ * This package contains main game logics.<br>
+ * GameManager: The top most game object.<br>
+ * GameEngine: Handles each "Game Field", but doesn't handle most actions.
This is done to support multiplayer co-op.<br>
+ * GamePlay: Handles most actions of each player.<br>
+ */
+package cx.it.nullpo.nm8.game.play;
=======================================
--- /dev/null
+++
/branches/nm8/src/cx/it/nullpo/nm8/game/subsystem/mode/package-info.java
Thu Nov 10 01:23:35 2011
@@ -0,0 +1,4 @@
+/**
+ * This package contains the game modes.
+ */
+package cx.it.nullpo.nm8.game.subsystem.mode;
=======================================
--- /dev/null
+++ /branches/nm8/src/cx/it/nullpo/nm8/game/subsystem/package-info.java Thu
Nov 10 01:23:35 2011
@@ -0,0 +1,4 @@
+/**
+ * This package contains the sub-packages of Game mode, Randomizer, and
Wallkick systems.
+ */
+package cx.it.nullpo.nm8.game.subsystem;
=======================================
--- /dev/null
+++
/branches/nm8/src/cx/it/nullpo/nm8/game/subsystem/randomizer/package-info.java
Thu Nov 10 01:23:35 2011
@@ -0,0 +1,4 @@
+/**
+ * This package contains the Randomizers that will generate the sequence
of pieces.
+ */
+package cx.it.nullpo.nm8.game.subsystem.randomizer;
=======================================
--- /dev/null
+++
/branches/nm8/src/cx/it/nullpo/nm8/game/subsystem/wallkick/package-info.java
Thu Nov 10 01:23:35 2011
@@ -0,0 +1,4 @@
+/**
+ * This package contains the wallkick systems.
+ */
+package cx.it.nullpo.nm8.game.subsystem.wallkick;
=======================================
--- /dev/null
+++ /branches/nm8/src/cx/it/nullpo/nm8/gui/game/GameFieldController.java
Thu Nov 10 01:23:35 2011
@@ -0,0 +1,56 @@
+package cx.it.nullpo.nm8.gui.game;
+
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import cx.it.nullpo.nm8.util.CustomProperties;
+import de.lessvoid.nifty.Nifty;
+import de.lessvoid.nifty.controls.AbstractController;
+import de.lessvoid.nifty.elements.Element;
+import de.lessvoid.nifty.input.NiftyInputEvent;
+import de.lessvoid.nifty.screen.Screen;
+import de.lessvoid.xml.xpp3.Attributes;
+
+public class GameFieldController extends AbstractController {
+ private Log log = LogFactory.getLog(GameFieldController.class);
+
+ protected Element elementMain;
+ protected Element elementPanelField;
+
+ protected int blocksize;
+
+ public void bind(Nifty nifty, Screen screen, Element element, Properties
parameter, Attributes controlDefinitionAttributes) {
+ log.debug("bind");
+
+ elementMain = element;
+ if(elementMain == null) log.warn("elementMain == null!");
+ elementPanelField = element.findElementByName("panel-field");
+ if(elementPanelField == null) log.warn("elementPanelField == null!");
+
+ CustomProperties params = new CustomProperties(parameter);
+ blocksize = params.getProperty("blksize", 16);
+ log.trace("blocksize:" + blocksize);
+ }
+
+ public void onStartScreen() {
+ log.debug("onStartScreen");
+ }
+
+ public boolean inputEvent(NiftyInputEvent inputEvent) {
+ return false;
+ }
+
+ public Element getElementMain() {
+ return elementMain;
+ }
+
+ public Element getElementPanelField() {
+ return elementPanelField;
+ }
+
+ public int getBlockSize() {
+ return blocksize;
+ }
+}
=======================================
--- /dev/null
+++ /branches/nm8/src/cx/it/nullpo/nm8/gui/game/GameFieldRenderer.java Thu
Nov 10 01:23:35 2011
@@ -0,0 +1,204 @@
+package cx.it.nullpo.nm8.gui.game;
+
+import cx.it.nullpo.nm8.game.component.Block;
+import cx.it.nullpo.nm8.game.component.Field;
+import cx.it.nullpo.nm8.game.component.Piece;
+import cx.it.nullpo.nm8.game.play.GameEngine;
+import cx.it.nullpo.nm8.game.play.GamePlay;
+import cx.it.nullpo.nm8.gui.framework.NFColor;
+import cx.it.nullpo.nm8.gui.framework.NFGraphics;
+import cx.it.nullpo.nm8.gui.framework.NFImage;
+
+/**
+ * This class will draw the game screen
+ */
+public class GameFieldRenderer {
+ /**
+ * Draw the game field
+ * @param fld Field
+ * @param g NFGraphics
+ * @param x X
+ * @param y Y
+ * @param width Width
+ * @param height Height
+ * @param blksize Block Size
+ */
+ public static void drawField(Field fld, NFGraphics g, int x, int y, int
width, int height, int blksize) {
+ g.setClip(x, y, width, height);
+ g.translate(x, y);
+
+ int yOffset = height % blksize;
+ int fldHeight = fld.getHeight();
+ int fldHighestBlockY = fld.getHighestBlockY();
+ int fldWidth = fld.getWidth();
+
+ for(int i = fldHeight - 1; i >= fldHighestBlockY; i--) {
+ if(i * blksize > -blksize - yOffset) {
+ for(int j = 0; j < fldWidth; j++) {
+ Block blk = fld.getBlock(j, i);
+ drawBlock(blk, g, j * blksize, yOffset + (i * blksize), blksize);
+ }
+ } else {
+ break;
+ }
+ }
+
+ g.translate(-x, -y);
+ g.clearClip();
+ }
+
+ /**
+ * Draw the game field
+ * @param engine GameEngine
+ * @param g NFGraphics
+ * @param x X
+ * @param y Y
+ * @param width Width
+ * @param height Height
+ * @param blksize Block Size
+ */
+ public static void drawField(GameEngine engine, NFGraphics g, int x, int
y, int width, int height, int blksize) {
+ drawField(engine.field, g, x, y, width, height, blksize);
+ }
+
+ /**
+ * Draw the game field
+ * @param gamePlay GamePlay
+ * @param g NFGraphics
+ * @param x X
+ * @param y Y
+ * @param width Width
+ * @param height Height
+ * @param blksize Block Size
+ */
+ public static void drawField(GamePlay gamePlay, NFGraphics g, int x, int
y, int width, int height, int blksize) {
+ drawField(gamePlay.engine, g, x, y, width, height, blksize);
+ }
+
+ /**
+ * Draw the current piece
+ * @param gamePlay GamePlay
+ * @param g NFGraphics
+ * @param x X
+ * @param y Y
+ * @param width Width
+ * @param height Height
+ * @param blksize Block Size
+ */
+ public static void drawCurrentPiece(GamePlay gamePlay, NFGraphics g, int
x, int y, int width, int height, int blksize) {
+ g.setClip(x, y, width, height);
+ g.translate(x, y);
+
+ int yOffset = height % blksize;
+
+ Piece piece = gamePlay.nowPieceObject;
+ if(piece != null) {
+ int pieceX = gamePlay.nowPieceX * blksize;
+ int pieceY = gamePlay.nowPieceY * blksize;
+ drawPiece(piece, g, pieceX, yOffset + pieceY, blksize);
+ }
+
+ g.translate(-x, -y);
+ g.clearClip();
+ }
+
+ /**
+ * Draw the current piece
+ * @param engine GameEngine
+ * @param g NFGraphics
+ * @param x X
+ * @param y Y
+ * @param width Width
+ * @param height Height
+ * @param blksize Block Size
+ */
+ public static void drawCurrentPiece(GameEngine engine, NFGraphics g, int
x, int y, int width, int height, int blksize) {
+ for(int player = 0; player <
engine.owner.getNumberOfPlayersForEachEngine(); player++) {
+ GamePlay play = engine.getGamePlay(player);
+ drawCurrentPiece(play, g, x, y, width, height, blksize);
+ }
+ }
+
+ public static void drawGhostPiece(GamePlay gamePlay, NFGraphics g, int x,
int y, int width, int height, int blksize) {
+ g.setClip(x, y, width, height);
+ g.translate(x, y);
+
+ int yOffset = height % blksize;
+
+ Piece piece = gamePlay.nowPieceObject;
+ if(piece != null) {
+ piece = new Piece(piece);
+ piece.setAlpha(0.5f);
+ int pieceX = gamePlay.nowPieceX * blksize;
+ int bottomY = piece.getBottom(gamePlay.nowPieceX, gamePlay.nowPieceY,
gamePlay.engine.field);
+ int pieceY = bottomY * blksize;
+ drawPiece(piece, g, pieceX, yOffset + pieceY, blksize);
+ }
+
+ g.translate(-x, -y);
+ g.clearClip();
+ }
+
+ public static void drawGhostPiece(GameEngine engine, NFGraphics g, int x,
int y, int width, int height, int blksize) {
+ for(int player = 0; player <
engine.owner.getNumberOfPlayersForEachEngine(); player++) {
+ GamePlay play = engine.getGamePlay(player);
+ drawGhostPiece(play, g, x, y, width, height, blksize);
+ }
+ }
+
+ /**
+ * Draw a piece to somewhere on the screen
+ * @param piece Piece
+ * @param direction Direction
+ * @param g NFGraphics
+ * @param x X
+ * @param y Y
+ * @param blksize Block Size
+ */
+ public static void drawPiece(Piece piece, int direction, NFGraphics g,
int x, int y, int blksize) {
+ for(int i = 0; i < piece.getMaxBlock(); i++) {
+ int x2 = x + (piece.getDataX(i, direction) * blksize);
+ int y2 = y + (piece.getDataY(i, direction) * blksize);
+ Block blk = piece.block[i];
+ drawBlock(blk, g, x2, y2, blksize);
+ }
+ }
+
+ /**
+ * Draw a piece to somewhere on the screen
+ * @param piece Piece
+ * @param g NFGraphics
+ * @param x X
+ * @param y Y
+ * @param blksize Block Size
+ */
+ public static void drawPiece(Piece piece, NFGraphics g, int x, int y, int
blksize) {
+ drawPiece(piece, piece.direction, g, x, y, blksize);
+ }
+
+ /**
+ * Draw a Block to somewhere on the screen
+ * @param blk Block
+ * @param g NFGraphics
+ * @param x X
+ * @param y Y
+ * @param blksize Block Size
+ */
+ public static void drawBlock(Block blk, NFGraphics g, int x, int y, int
blksize) {
+ if(blk == null) return;
+ if(blk.isEmpty()) return;
+
+ if(ResourceHolder.blockSkin != null) {
+ // TODO: Add support of multiple block skin
+ NFImage img = ResourceHolder.blockSkin.mapImageNormal.get(16);
+
+ if(img != null) {
+ NFColor col = new NFColor(255,255,255,(int)(blk.alpha * 255));
+ g.drawImage(img, x, y, x+blksize, y+blksize, blk.color * blksize, 0,
(blk.color * blksize) + blksize, blksize, col);
+ }
+ } else {
+ g.setColor(NFColor.green);
+ g.fillRect(x, y, blksize, blksize);
+ }
+ }
+}
=======================================
--- /dev/null
+++ /branches/nm8/src/cx/it/nullpo/nm8/gui/game/MainScreenController.java
Thu Nov 10 01:23:35 2011
@@ -0,0 +1,53 @@
+package cx.it.nullpo.nm8.gui.game;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import de.lessvoid.nifty.Nifty;
+import de.lessvoid.nifty.NiftyEventSubscriber;
+import de.lessvoid.nifty.controls.ButtonClickedEvent;
+import de.lessvoid.nifty.screen.Screen;
+import de.lessvoid.nifty.screen.ScreenController;
+
+public class MainScreenController implements ScreenController {
+ /** Log */
+ private Log log = LogFactory.getLog(MainScreenController.class);
+
+ /** Owner class */
+ protected NullpoMinoNiftyGUI owner;
+
+ public MainScreenController() {
+ log.warn("Parameter-less constractor is called");
+ }
+
+ public MainScreenController(NullpoMinoNiftyGUI owner) {
+ this.owner = owner;
+ log.trace("Constractor MainScreenController(NullpoMinoNiftyGUI owner) is
called");
+ }
+
+ public void bind(Nifty nifty, Screen screen) {
+ log.trace("bind");
+ }
+
+ public void onStartScreen() {
+ log.trace("onStartScreen");
+ }
+
+ public void onEndScreen() {
+ log.trace("onEndScreen");
+ }
+
+ @NiftyEventSubscriber(id="buttonStart")
+ public void onButtonStartClickEvent(final String id, final
ButtonClickedEvent e) {
+ if(owner == null) {
+ log.error("owner == null! Maybe parameter-less constractor was used?");
+ } else {
+ owner.gameStart();
+ }
+ }
+
+ @NiftyEventSubscriber(id="buttonQuit")
+ public void onButtonQuitClickEvent(final String id, final
ButtonClickedEvent e) {
+ owner.sys.exit();
+ }
+}
=======================================
--- /dev/null
+++ /branches/nm8/src/cx/it/nullpo/nm8/gui/game/NullpoMinoNiftyGUI.java Thu
Nov 10 01:23:35 2011
@@ -0,0 +1,253 @@
+package cx.it.nullpo.nm8.gui.game;
+
+import java.awt.event.KeyEvent;
+import java.util.Iterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jdom.Document;
+import org.jdom.input.SAXBuilder;
+
+import cx.it.nullpo.nm8.game.component.Controller;
+import cx.it.nullpo.nm8.game.play.GameEngine;
+import cx.it.nullpo.nm8.game.play.GameManager;
+import cx.it.nullpo.nm8.game.play.GamePlay;
+import cx.it.nullpo.nm8.gui.framework.NFColor;
+import cx.it.nullpo.nm8.gui.framework.NFGame;
+import cx.it.nullpo.nm8.gui.framework.NFGraphics;
+import cx.it.nullpo.nm8.gui.framework.NFKeyListener;
+import cx.it.nullpo.nm8.gui.framework.NFKeyboard;
+import cx.it.nullpo.nm8.gui.framework.NFSystem;
+import cx.it.nullpo.nm8.gui.niftygui.NFInputSystem;
+import cx.it.nullpo.nm8.gui.niftygui.NFRenderDevice;
+import cx.it.nullpo.nm8.gui.niftygui.NFSoundDevice;
+import cx.it.nullpo.nm8.neuro.core.NEURO;
+import cx.it.nullpo.nm8.neuro.error.PluginInitializationException;
+import cx.it.nullpo.nm8.util.NGlobalConfig;
+import cx.it.nullpo.nm8.util.NUtil;
+import de.lessvoid.nifty.Nifty;
+import de.lessvoid.nifty.elements.Element;
+import de.lessvoid.nifty.screen.Screen;
+import de.lessvoid.nifty.tools.TimeProvider;
+
+/**
+ * NFGame implementation of NullpoMino (WIP)
+ */
+public class NullpoMinoNiftyGUI implements NFGame, NFKeyListener {
+ private static final long serialVersionUID = 612498635208267339L;
+
+ /** Log */
+ private Log log = LogFactory.getLog(NullpoMinoNiftyGUI.class);
+
+ /** NFSystem */
+ public NFSystem sys;
+
+ /** NiftyGUI */
+ protected Nifty nifty;
+
+ /** true if NiftyGUI is inited */
+ protected boolean niftyInited;
+
+ /** true if various resource has loaded */
+ protected boolean isResourceLoaded;
+
+ /** GameManager */
+ protected GameManager gameManager;
+
+ // Constants for key config
+ protected static final int MAX_PLAYERS = 2;
+ protected static final int MAX_RULE_KIND = 2;
+ protected static final int MAX_KEY_SLOTS = 4;
+ protected static final int MAX_KEY_KINDS = 9;
+
+ public String getName() {
+ return "NullpoMino";
+ }
+
+ public float getVersion() {
+ return GameManager.getVersionMajor();
+ }
+
+ public String getAuthor() {
+ return "The NullpoMino Dev Team";
+ }
+
+ public void init(NEURO parent) throws PluginInitializationException {
+ }
+
+ public void draw(NFGraphics g) {
+ }
+
+ public void stop() {
+ }
+
+ public boolean isEnableNEURO() {
+ return false;
+ }
+
+ public void init(NFSystem sys) {
+ log.trace("init");
+
+ this.sys = sys;
+ sys.getKeyboard().addKeyListener(this);
+
+ sys.setWindowTitle("NullpoMino8 (NiftyGUI)");
+ }
+
+ public void update(NFSystem sys, long delta) {
+ if(!isResourceLoaded) {
+ isResourceLoaded = true;
+
+ try {
+ String strBlockSkinPathName = "nullpoworld";
+ SAXBuilder builder = new SAXBuilder();
+ Document doc = null;
+ doc = builder.build(NUtil.getURL("data/res/graphics/block/" +
strBlockSkinPathName + "/blockindex.xml"));
+ ResourceHolder.blockSkin = BlockSkin.loadByXML(sys,
strBlockSkinPathName, doc); // TODO: Load multiple block skin
+ } catch (Exception e) {
+ log.error("Failed to load block skin", e);
+ }
+
+ try {
+ if(sys.isSoundSupported() &&
NGlobalConfig.getConfig().getProperty("sys.enablesound", true)) {
+ log.debug("Loading sound effects");
+ ResourceHolder.loadSoundEffects(sys, "default");
+ }
+ } catch (Exception e) {
+ log.error("Failed to load sound effects", e);
+ }
+ }
+
+ if(niftyInited && (nifty != null)) {
+ nifty.update();
+ }
+
+ if((gameManager != null) && gameManager.isGameActive()) {
+ gameManager.update(delta);
+
+ // Play sound effects
+ if(gameManager.getGamePlay(0,0) != null) {
+ synchronized (gameManager.getGamePlay(0,0).seQueue) {
+ Iterator<String> it = gameManager.getGamePlay(0,0).seQueue.iterator();
+ while(it.hasNext()) {
+ ResourceHolder.playSE(it.next());
+ it.remove();
+ }
+ }
+ }
+ }
+ }
+
+ public void render(NFSystem sys, NFGraphics g) {
+ if(!niftyInited && (nifty == null)) {
+ try {
+ nifty = new Nifty(new NFRenderDevice(sys),
+ new NFSoundDevice(sys),
+ new NFInputSystem(sys.getKeyboard(),
sys.getMouse()),
+ new TimeProvider());
+ log.trace("NiftyGUI created");
+
+ nifty.fromXml("data/xml/game_main.xml", "start", new
MainScreenController(this));
+ niftyInited = true;
+ } catch (Exception e) {
+ log.error("NiftyGUI init failed", e);
+ }
+ }
+
+ if(niftyInited && (nifty != null)) {
+ nifty.render(true);
+
+ if((gameManager != null) && gameManager.isGameStarted()) {
+ Screen curScreen = nifty.getCurrentScreen();
+ if(curScreen != null) {
+ for(int engineID = 0; engineID < gameManager.getNumberOfEngines();
engineID++) {
+ GameFieldController fldctl = curScreen.findControl("field-" +
engineID, GameFieldController.class);
+
+ if((fldctl != null) && (fldctl.getElementPanelField() != null)) {
+ Element e = fldctl.getElementPanelField();
+ GameEngine engine = gameManager.getGameEngine(engineID);
+
+ if(engine.gameStarted) {
+ GameFieldRenderer.drawField(engine, g, e.getX(), e.getY(),
e.getWidth(), e.getHeight(), fldctl.getBlockSize());
+ GameFieldRenderer.drawGhostPiece(engine, g, e.getX(), e.getY(),
e.getWidth(), e.getHeight(), fldctl.getBlockSize());
+ GameFieldRenderer.drawCurrentPiece(engine, g, e.getX(), e.getY(),
e.getWidth(), e.getHeight(), fldctl.getBlockSize());
+ }
+ }
+ }
+ }
+ }
+ }
+
+ g.setColor(NFColor.white);
+ g.resetFont();
+ g.drawString("FPS:" + sys.getFPS(), 0, 0);
+ }
+
+ public void onExit(NFSystem sys) {
+ try {
+ ResourceHolder.unloadSoundEffects();
+ nifty.exit();
+ } catch (Throwable e) {}
+ }
+
+ public void keyPressed(NFKeyboard keyboard, int key, char c) {
+ handleKeyEvent(keyboard, key, c, true);
+ }
+ public void keyReleased(NFKeyboard keyboard, int key, char c) {
+ handleKeyEvent(keyboard, key, c, false);
+ }
+
+ public void gameStart() {
+ log.trace("Starting a new game...");
+
+ try {
+ if(gameManager == null) {
+ gameManager = new GameManager();
+ } else {
+ gameManager.stop();
+ }
+ gameManager.init();
+ gameManager.start();
+ } catch (Exception e) {
+ log.fatal("Start new game failed", e);
+ }
+
+ log.trace("Started a new game");
+ }
+
+ public void handleKeyEvent(NFKeyboard keyboard, int key, char c, boolean
pressed) {
+ if(gameManager != null && gameManager.isGameActive()) {
+ for(int engineID = 0; engineID < gameManager.getNumberOfEngines();
engineID++) {
+ if(gameManager.getGameEngine(engineID).gameActive) {
+ for(int playerID = 0; playerID <
gameManager.getNumberOfPlayersForEachEngine(); playerID++) {
+ GamePlay play = gameManager.getGamePlay(engineID, playerID);
+ Controller ctrl = play.ctrl;
+ int ctrlSchemeID = play.ruleopt.ctrlSchemeID;
+
+ for(int slot = 0; slot < MAX_KEY_SLOTS; slot++) {
+ for(int keyKind = 0; keyKind < MAX_KEY_KINDS; keyKind++) {
+ String strID = "key_" + playerID + "_" + ctrlSchemeID + "_" + slot
+ "_" + keyKind;
+ int tempKeyCode = NGlobalConfig.getConfig().getProperty(strID,
KeyEvent.VK_UNDEFINED);
+
+ if(key == tempKeyCode) {
+ ctrl.setButtonState(keyKind, pressed);
+ }
+ }
+ }
+
+ if(key == KeyEvent.VK_ESCAPE) {
+ sys.exit();
+ }
+ }
+ }
+ }
+ }
+ }
+
+ public void initGUI(Nifty n) {
+ }
+
+ public Nifty getGUI() {
+ return null;
+ }
+}
=======================================
--- /dev/null
+++ /branches/nm8/src/overview.html Thu Nov 10 01:23:35 2011
@@ -0,0 +1,6 @@
+<html>
+<body>
+<b>NullpoMino</b> is an open-source action puzzle game that works on the
Java platform.<br>
+Version 8 will feature entirely rewritten codes with better GUI
(hopefully).
+</body>
+</html>
=======================================
--- /branches/nm8/data/properties/log.cfg Tue Oct 25 00:33:37 2011
+++ /branches/nm8/data/properties/log.cfg Thu Nov 10 01:23:35 2011
@@ -20,5 +20,11 @@
# We don't want huge EventService debug log.
log4j.logger.org.bushe.swing=INFO
+
+# Suppress NiftyGUI logs
+log4j.logger.de.lessvoid.nifty.NiftyStopwatch=WARN
+log4j.logger.de.lessvoid.nifty.effects.Effect=WARN
+log4j.logger.de.lessvoid.nifty.effects.EffectProcessor=WARN
+
# To limit the messages from Slick, uncomment below.
#log4j.logger.org.newdawn.slick.Slick=WARN
=======================================
--- /branches/nm8/src/cx/it/nullpo/nm8/game/play/GameManager.java Sun Jul
24 04:50:14 2011
+++ /branches/nm8/src/cx/it/nullpo/nm8/game/play/GameManager.java Thu Nov
10 01:23:35 2011
@@ -124,12 +124,18 @@
* Start game
*/
public void start() {
+ if(engine == null) {
+ init();
+ }
+
for(int i = 0; i < engine.length; i++) {
engine[i].start();
}
}
public void stop() {
+ if(engine == null) return;
+
for (int i = 0; i < engine.length; i++) {
// TODO stop engines
}
@@ -140,6 +146,8 @@
* @param runMsec Nanoseconds elapsed from the last execution
*/
public void update(long runMsec) {
+ if(engine == null) return;
+
gameLoopTime += runMsec;
while(gameLoopTime >= frameBasedLoopTime) {
@@ -193,4 +201,30 @@
public GamePlay getGamePlay(int engineID, int playerID) {
return engine[engineID].gamePlay[playerID];
}
-}
+
+ /**
+ * @return true if at least 1 engine is active
+ */
+ public boolean isGameActive() {
+ if(engine == null) return false;
+ for(int i = 0; i < engine.length; i++) {
+ if(engine[i].gameActive) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @return true if at least 1 engine has started the game (It will not
change back to false until the game is reset)
+ */
+ public boolean isGameStarted() {
+ if(engine == null) return false;
+ for(int i = 0; i < engine.length; i++) {
+ if(engine[i].gameStarted) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
=======================================
--- /branches/nm8/src/cx/it/nullpo/nm8/gui/slick/NullpoMinoSlick.java Thu
Nov 3 22:46:43 2011
+++ /branches/nm8/src/cx/it/nullpo/nm8/gui/slick/NullpoMinoSlick.java Thu
Nov 10 01:23:35 2011
@@ -5,7 +5,7 @@
import cx.it.nullpo.nm8.gui.framework.NFGame;
import cx.it.nullpo.nm8.gui.game.NullpoMino;
-import cx.it.nullpo.nm8.gui.niftygui.NiftyGUITest;
+import cx.it.nullpo.nm8.gui.game.NullpoMinoNiftyGUI;
import cx.it.nullpo.nm8.gui.slick.framework.SlickNFSystem;
import cx.it.nullpo.nm8.util.CustomProperties;
import cx.it.nullpo.nm8.util.NGlobalConfig;
@@ -31,7 +31,7 @@
NFGame game = null;
SlickNFSystem sys = null;
if(args.length > 0 && args[0].equals("--guitest")) {
- game = new NiftyGUITest();
+ game = new NullpoMinoNiftyGUI();
sys = new SlickNFSystem(game, fullscreen, screenWidth, screenHeight,
screenWidth, screenHeight, true, args);
} else {
game = new NullpoMino();
=======================================
--- /branches/nm8/src/cx/it/nullpo/nm8/gui/swing/NullpoMinoSwing.java Thu
Nov 3 22:46:43 2011
+++ /branches/nm8/src/cx/it/nullpo/nm8/gui/swing/NullpoMinoSwing.java Thu
Nov 10 01:23:35 2011
@@ -5,7 +5,7 @@
import cx.it.nullpo.nm8.gui.framework.NFGame;
import cx.it.nullpo.nm8.gui.game.NullpoMino;
-import cx.it.nullpo.nm8.gui.niftygui.NiftyGUITest;
+import cx.it.nullpo.nm8.gui.game.NullpoMinoNiftyGUI;
import cx.it.nullpo.nm8.gui.swing.framework.SwingNFSystem;
import cx.it.nullpo.nm8.util.CustomProperties;
import cx.it.nullpo.nm8.util.NGlobalConfig;
@@ -29,7 +29,7 @@
NFGame game = null;
SwingNFSystem sys = null;
if(args.length > 0 && args[0].equals("--guitest")) {
- game = new NiftyGUITest();
+ game = new NullpoMinoNiftyGUI();
sys = new SwingNFSystem(game, fullscreen, screenWidth, screenHeight,
screenWidth, screenHeight, true, args);
} else {
game = new NullpoMino();
=======================================
---
/branches/nm8/src/cx/it/nullpo/nm8/gui/swing/framework/SwingNFGameWrapper.java
Thu Nov 3 22:46:43 2011
+++
/branches/nm8/src/cx/it/nullpo/nm8/gui/swing/framework/SwingNFGameWrapper.java
Thu Nov 10 01:23:35 2011
@@ -112,7 +112,7 @@
beforeTime = System.nanoTime();
prevCalcTime = beforeTime;
- sys.getNFGame().init(sys);
+ if(sys.getNFGame().isEnableNEURO()) sys.getNFGame().init(sys);
while(!shutdownRequested) {
// Poll the keyboard input
=======================================
--- /branches/nm8/src/cx/it/nullpo/nm8/neuro/core/NEUROBase.java Wed Nov 9
13:49:46 2011
+++ /branches/nm8/src/cx/it/nullpo/nm8/neuro/core/NEUROBase.java Thu Nov 10
01:23:35 2011
@@ -15,7 +15,7 @@
/**
* NEUROBase implements the event-passing functionality of NEURO along
with some basic plugin loading and stopping
- * functions.
+ * functions.
* @author Zircean
*
*/
@@ -25,7 +25,7 @@
protected Set<NEUROPlugin> plugins;
/** The map containing mappings of event types to the plugin listeners
registered for that event type. */
protected Map<Class<? extends NEUROEvent>,Set<PluginListener>> listeners;
-
+
/**
* Constructor for NEUROBase.
*/
@@ -34,11 +34,11 @@
plugins = new HashSet<NEUROPlugin>();
listeners = new HashMap<Class<? extends
NEUROEvent>,Set<PluginListener>>();
}
-
+
public void addPlugin(NEUROPlugin p) {
plugins.add(p);
}
-
+
public void addListener(NEUROPlugin p, Class<? extends NEUROEvent> type) {
PluginListener pl = PluginListener.create(p,type);
if (pl != null) {
@@ -59,15 +59,18 @@
return;
}
// Dispatch the event
- for (PluginListener p : listeners.get(e.getClass())) {
- p.invoke(e);
- }
- }
-
+ try {
+ for (PluginListener p : listeners.get(e.getClass())) {
+ if(p != null)
+ p.invoke(e);
+ }
+ } catch (NullPointerException e2) {}
+ }
+
public void update(long delta) { }
public void draw(NFGraphics g) { }
-
+
/**
* Loads the plugin at the given classpath.
*/
@@ -92,7 +95,7 @@
it.remove();
}
}
-
+
// Remove the listeners attached to this plugin.
PluginListener pl = null;
@@ -114,7 +117,7 @@
/**
* Stops all plugins
*/
- protected void stopAll() {
+ protected void stopAll() {
Set<NEUROPlugin> bPlugins = new HashSet<NEUROPlugin>(plugins);
for (NEUROPlugin p : bPlugins) {
=======================================
--- /branches/nm8/src/cx/it/nullpo/nm8/util/CustomProperties.java Wed Sep
7 06:41:37 2011
+++ /branches/nm8/src/cx/it/nullpo/nm8/util/CustomProperties.java Thu Nov
10 01:23:35 2011
@@ -16,6 +16,21 @@
public class CustomProperties extends Properties {
/** Serial version */
private static final long serialVersionUID = 3L;
+
+ /**
+ * Create a new, empty CustomProperties.
+ */
+ public CustomProperties() {
+ super();
+ }
+
+ /**
+ * Create a CustomProperties from an existing Properties.
+ * @param defaults Properties to copy from
+ */
+ public CustomProperties(Properties defaults) {
+ super(defaults);
+ }
/**
* Set byte property