1. stqn
  2. rwkc

Commits

lanael  committed 2a832fd

* travail sur l'éditeur
- gameobjectfactory : pour déporter la
construction des objets de map ( besoin pour l'éditeur )
- editoractions.d : communication entre les outils et l'éditeur
- gui : ajout des méthodes pour modifier le bitmap du pointeur
- redesign de l'éditeur en 3 modes ( edit, tools et move )
- ajout des bitmaps spéciaux pour l'éditeur ( manipulations
de lignes et colonnes et monstres avec orientation initiale
de leur déplacement )

  • Participants
  • Parent commits 785f58f
  • Branches default

Comments (0)

Files changed (16)

File RWKC_linux.cbp

View file
 		<Unit filename="src/chrono.d" />
 		<Unit filename="src/configfile.d" />
 		<Unit filename="src/editor.d" />
+		<Unit filename="src/editoractions.d" />
 		<Unit filename="src/editortools.d" />
 		<Unit filename="src/game.d" />
 		<Unit filename="src/gameconstants.d" />
 		<Unit filename="src/gamemanager.d" />
 		<Unit filename="src/gameobject.d" />
+		<Unit filename="src/gameobjectfactory.d" />
 		<Unit filename="src/gameobjectmanager.d" />
 		<Unit filename="src/gameobjects/boss.d" />
 		<Unit filename="src/gameobjects/brick.d" />

File data/boss_icon.png

Added
New image

File data/column_add.png

Added
New image

File data/column_delete.png

Added
New image

File data/editor_ennemi_h_left.png

Added
New image

File data/editor_ennemi_h_right.png

Added
New image

File data/editor_ennemi_v_down.png

Added
New image

File data/editor_ennemi_v_up.png

Added
New image

File data/row_add.png

Added
New image

File data/row_delete.png

Added
New image

File src/editor.d

View file
 import screen;
 import editortools;
 import gui;
+import editoractions;
 
 class Editor: public GamePart {
 
 	GAMEPART_STATE mState;
 	SDL_Surface* mBg;
 	SDL_Surface* mPointer;
-	float mPx = 0;
-	float mPy = 0;
 	float mVx = 0;
 	float mVy = 0;
 
 	EditorTools mTools;
+	ActionType mAction;
+	string mPointerIcon;
+	char mTileCode;
+
+	void delegate() fMode;
+	void delegate() fPreviousMode;
 
 	this() {
-
 		SDL_WM_GrabInput(SDL_GRAB_ON);
-//		SDL_WarpMouse(0,0);
-//		SDL_ShowCursor(SDL_ENABLE);
 
 		gView.setTarget( null );
 
 
 		mBg = gTextureManager.get( "background.png" );
 		mPointer = gTextureManager.get("pointer.png");
+		mAction = ActionType.NOTHING;
+
+		fMode = &editMode;
 	}
 
 	~this() {
-//		SDL_ShowCursor(SDL_DISABLE);
 		SDL_WM_GrabInput(SDL_GRAB_OFF);
+		if( mTools !is null ) delete( mTools );
 	}
 
 	void update() {
 
 		gView.update();
 		gView.draw();
-		processInput();
+		fMode();
+		checkQuit();
+	}
+
+	void editMode() {
+		int x,y;
+		gInputManager.getMousePositionRelative( x,y );
+		GUI.instance.update( x,y, gInputManager.isMouseButtonUp(SDL_BUTTON_LEFT) );
+
+		if( gInputManager.isMouseButtonUp(SDL_BUTTON_MIDDLE) ) {
+			mTools = new EditorTools;
+			GUI.instance.changePointer( "pointer.png" );
+			fMode = &toolsMode;
+			return;
+		}
+
+		if ( gInputManager.isMouseButtonPressed(SDL_BUTTON_RIGHT) ) {
+			GUI.instance.hidePointer();
+			fPreviousMode = &editMode;
+			fMode = &moveMode;
+			return;
+		}
+
+		if( gInputManager.isMouseButtonUp(SDL_BUTTON_LEFT) ) {
+			// switch( action ) ...
+		}
 
 	}
 
-    void processInput() {
-
-        if( gInputManager.isReleased(IMA_TOGGLE_EDITOR)
-         || gInputManager.isReleased(IMA_BACK))
-			mState = GAMEPART_STATE.CONTINUE;
-
+	void moveMode() {
 		int x,y;
-		//ubyte button = SDL_GetRelativeMouseState( &x, &y );
 		gInputManager.getMousePositionRelative( x,y );
 
-		if( mTools is null) {
-
-			if( gInputManager.isMouseButtonUp(SDL_BUTTON_MIDDLE) ) {
-				mTools = new EditorTools;
-			}
-			else {
-
-				if ( gInputManager.isMouseButtonPressed(SDL_BUTTON_RIGHT) ) {
-		//			SDL_WM_GrabInput(SDL_GRAB_ON);
-					GUI.instance.hidePointer();
-					mVx += x;
-					mVy += y;
-					gView.setPosition( mVx, mVy );
-				}
-				else {
-					GUI.instance.showPointer();
-					mPx += x;
-					mPy += y;
-					if( mPx < 0 ) mPx = 0;
-					if( mPy < 0 ) mPy = 0;
-					if( mPx > 640 ) mPx = 640;
-					if( mPy > 480 ) mPy = 480;
-		//			SDL_WM_GrabInput(SDL_GRAB_OFF);
-				}
-			}
+		if ( gInputManager.isMouseButtonPressed(SDL_BUTTON_RIGHT) ) {
+			mVx += x;
+			mVy += y;
+			gView.setPosition( mVx, mVy );
 		}
 		else {
-			if( mTools.done() || gInputManager.isMouseButtonUp(SDL_BUTTON_MIDDLE) )
-				delete( mTools );
+			GUI.instance.showPointer();
+			fMode = fPreviousMode;
+		}
+	}
+
+	void toolsMode() {
+		int x,y;
+		gInputManager.getMousePositionRelative( x,y );
+
+		if ( gInputManager.isMouseButtonPressed(SDL_BUTTON_RIGHT) ) {
+			GUI.instance.hidePointer();
+			fPreviousMode = &toolsMode;
+			fMode = &moveMode;
+			return;
 		}
 
 		GUI.instance.update( x,y, gInputManager.isMouseButtonUp(SDL_BUTTON_LEFT) );
 
-    }
+		if( mTools.done() ) {
+			mAction = mTools.getAction();
+			mPointerIcon = mTools.getBitmap();
+			mTileCode = mTools.getCode();
+			GUI.instance.changePointer( mPointerIcon );
+		}
+
+		if( mTools.done() || gInputManager.isMouseButtonUp(SDL_BUTTON_MIDDLE) ) {
+			delete( mTools );
+			fMode = &editMode;
+		}
+
+	}
+
+	void checkQuit() {
+		if( gInputManager.isReleased(IMA_TOGGLE_EDITOR)
+			|| gInputManager.isReleased(IMA_BACK))
+			mState = GAMEPART_STATE.CONTINUE;
+	}
+
 
 	GAMEPART_STATE getState() {
 		return( mState );
 	}
 
+
 }

File src/editoractions.d

View file
+module editoractions;
+
+enum ActionType {
+	NOTHING,
+	INSERT_LINE,
+	DELETE_LINE,
+	INSERT_COLUMN,
+	DELETE_COLUMN,
+	ADD_TILE,
+	DELETE_TILE
+};

File src/editortools.d

View file
 import gui;
 import gameobject;
 import std.stdio;
+import gameobjectfactory;
 
+import editoractions;
 
 class EditorTools: public GUI.ButtonListener {
 
 
 	struct Action {
 		string caption;
+		string bitmap;
+		ActionType type;
 		GUI.Button button;
-		//void opCall( string c ) { caption = c; };
 	};
 
 	Action[] mActions;
 
 	struct Tile{
 		string bitmap;
+		char mapCode;
 		GUI.Button button;
-		GameObject.Type type;
 	};
 
 	Tile[] mTiles;
 
+	ActionType mSelectedAction;
+	char mSelectedCode;
+	string mSelectedBitmap;
 	bool mDone = false;
 
 	this() {
 		initActions();
 
 		mActionsPanel = GUI.instance.addPanel( 0,0 );
-		foreach( action; mActions ) {
+		foreach( inout action; mActions ) {
 			action.button = mActionsPanel.addTextButton( action.caption, "", this );
-			mActionsPanel.nl();
+			//mActionsPanel.nl();
 		}
 
 		initTiles();
 
-		mTilesPanel = GUI.instance.addPanel( 320, 0 );
-		foreach( int i, tile; mTiles ) {
+		mTilesPanel = GUI.instance.addPanel( 0, 50 );
+		foreach( int i, inout tile; mTiles ) {
 			tile.button = mTilesPanel.addIconButton( tile.bitmap, this );
-			if( i%10 == 0) mTilesPanel.nl();
+			if( (i+1)%17 == 0) mTilesPanel.nl();
 		}
+
+		mSelectedAction = ActionType.NOTHING;
 	}
 
 	~this() {
 	}
 
 	void initActions() {
-		mActions ~= Action( "Insert Column");
-		mActions ~= Action( "Insert Line");
-		mActions ~= Action( "Delete Column");
-		mActions ~= Action( "Delete Line");
+		mActions ~= Action( "Insert Column", "column_add.png", ActionType.INSERT_COLUMN );
+		mActions ~= Action( "Insert Line", "row_add.png", ActionType.INSERT_LINE );
+		mActions ~= Action( "Delete Column", "column_delete.png", ActionType.DELETE_COLUMN );
+		mActions ~= Action( "Delete Line", "row_delete.png", ActionType.DELETE_LINE );
 	}
 
 	void initTiles() {
-		mTiles ~= Tile( "brick.png" );
-		mTiles ~= Tile( "wall1.png" );
-		mTiles ~= Tile( "wall2.png" );
+
+		mTiles ~= Tile( "wall1.png", '=' );
+		mTiles ~= Tile( "wall2.png", '#' );
+		mTiles ~= Tile( "bigwall1_1.png", '1' );
+		mTiles ~= Tile( "bigwall1_2.png", '2' );
+		mTiles ~= Tile( "bigwall1_3.png", '3');
+		mTiles ~= Tile( "bigwall1_4.png", '4' );
+		mTiles ~= Tile( "brick.png", '*' );
+		mTiles ~= Tile( "bluedoor.png", 'b' );
+		mTiles ~= Tile( "greendoor.png", 'g' );
+		mTiles ~= Tile( "reddoor.png", 'r' );
+		mTiles ~= Tile( "boss_icon.png", '&' );
+		mTiles ~= Tile( "editor_ennemi_h_left.png", '<' );
+		mTiles ~= Tile( "editor_ennemi_h_right.png", '>' );
+		mTiles ~= Tile( "hero_right_000002.png", '@' );
+		mTiles ~= Tile( "fluid_top_full_000001.png", ',' );
+		mTiles ~= Tile( "fluid_000001.png", '~' );
+		mTiles ~= Tile( "editor_ennemi_v_up.png", '^' );
+		mTiles ~= Tile( "editor_ennemi_v_down.png", 'v' );
+		mTiles ~= Tile( "ennemy_c_000001.png", 'u' );
+		mTiles ~= Tile( "princess_000001.png", 'X' );
+		mTiles ~= Tile( "jump.png", 'j' );
+		mTiles ~= Tile( "doublejump.png", 'J' );
+		mTiles ~= Tile( "shot.png", 's' );
+		mTiles ~= Tile( "super_shot.png", 'S' );
+		mTiles ~= Tile( "powerup_missile.png", 'm' );
+		mTiles ~= Tile( "horizontal_speed.png", 'H' );
+		mTiles ~= Tile( "vertical_speed.png", 'V' );
+		mTiles ~= Tile( "bluekey.png", 'B' );
+		mTiles ~= Tile( "greenkey.png", 'G' );
+		mTiles ~= Tile( "redkey.png", 'R' );
+		mTiles ~= Tile( "save_0.png", 'c' );
+
 	}
 
 	void onButtonPressed( GUI.Button b ) {
+
 		mDone = true;
+
+		foreach( tile; mTiles ) {
+			if( tile.button == b ) {
+				mSelectedBitmap = tile.bitmap;
+				mSelectedCode = tile.mapCode;
+				mSelectedAction = ActionType.ADD_TILE;
+				return;
+			}
+		}
+
+		foreach( action; mActions ) {
+			if( action.button == b ) {
+				mSelectedAction = action.type;
+				mSelectedBitmap = action.bitmap;
+				return;
+			}
+		}
+
+	}
+
+	ActionType getAction() {
+		return( mSelectedAction );
+	}
+
+	string getBitmap() {
+		return( mSelectedBitmap );
+	}
+
+	char getCode() {
+		return( mSelectedCode );
 	}
 
 	bool done() {

File src/gameobjectfactory.d

View file
+module gameobjectfactory;
+
+import gameobject;
+import gameobjectmanager;
+import gameobjects.boss;
+import gameobjects.brick;
+import gameobjects.checkpoint;
+import gameobjects.door;
+import gameobjects.enemy1;
+import gameobjects.enemy2;
+import gameobjects.enemy3;
+import gameobjects.fluid;
+import gameobjects.goal;
+import gameobjects.hero;
+import gameobjects.powerup;
+import gameobjects.updatedgameobject;
+import gameobjects.wall;
+
+import std.stdio;
+
+
+class GameObjectFactory {
+/*
+	static GameObject build( GameObject.Type type, GameObject.Subtype subtype ) {
+	}
+*/
+	static void create( char mapCode, int xpix, int ypix ) {
+
+		switch( mapCode ) {
+
+			case '#': new Wall( xpix, ypix, "wall1.png" );	break;
+			case '=': new Wall( xpix, ypix, "wall2.png" );	break;
+			case '1': new Wall( xpix, ypix, "bigwall1_1.png" );	break;
+			case '2': new Wall( xpix, ypix, "bigwall1_2.png" );	break;
+			case '3': new Wall( xpix, ypix, "bigwall1_3.png" );	break;
+			case '4': new Wall( xpix, ypix, "bigwall1_4.png" );	break;
+			case '*': new Brick( xpix, ypix );	break;
+			case 'b': new Door( xpix, ypix, "bluedoor.png", GameObject.Type.DOOR_BLUE ); break;
+			case 'g': new Door( xpix, ypix, "greendoor.png", GameObject.Type.DOOR_GREEN );	break;
+			case 'r': new Door( xpix, ypix, "reddoor.png", GameObject.Type.DOOR_RED );	break;
+			case '&': new Boss( xpix, ypix, -1 ); break;
+			case '<': new Enemy1( xpix, ypix, -1 );	break;
+			case '>': new Enemy1( xpix, ypix, +1 );	break;
+			case '@': new Hero( xpix, ypix ); break;
+			case ',': new Fluid( xpix, ypix, Fluid.FluidType.SURFACE );	break;
+			case '~': new Fluid( xpix, ypix, Fluid.FluidType.BOTTOM );	break;
+			case '^': new Enemy2( xpix, ypix, -1 );	break;
+			case 'v': new Enemy2( xpix, ypix, 1 );	break;
+			case 'u': new Enemy3( xpix, ypix );	break;
+			case 'X': new Goal( xpix, ypix ); break;
+			case 'j': new Powerup( xpix, ypix, GameObject.Type.POWERUP_JUMP, "jump.png" );	break;
+			case 'J': new Powerup( xpix, ypix, GameObject.Type.POWERUP_JUMP_DOUBLE, "doublejump.png" );	break;
+			case 's': new Powerup( xpix, ypix, GameObject.Type.POWERUP_SHOOT, "shot.png" );	break;
+			case 'S': new Powerup( xpix, ypix, GameObject.Type.POWERUP_SHOOT_FAST, "super_shot.png" ); break;
+			case 'm': new Powerup( xpix, ypix, GameObject.Type.POWERUP_MISSILE, "powerup_missile.png" ); break;
+			case 'H': new Powerup( xpix, ypix, GameObject.Type.POWERUP_ROCKET_HORIZONTAL, "horizontal_speed.png" ); break;
+			case 'V': new Powerup( xpix, ypix, GameObject.Type.POWERUP_ROCKET_VERTICAL, "vertical_speed.png" );	break;
+			case 'B': new Powerup( xpix, ypix, GameObject.Type.POWERUP_KEY_BLUE, "bluekey.png" ); break;
+			case 'G': new Powerup( xpix, ypix, GameObject.Type.POWERUP_KEY_GREEN, "greenkey.png" );	break;
+			case 'R': new Powerup( xpix, ypix, GameObject.Type.POWERUP_KEY_RED, "redkey.png" );	break;
+			case 'c': new Checkpoint( xpix, ypix );	break;
+			case ' ': break;
+			default:
+				writefln( "Unknown char in map '", mapCode,"'" );
+				assert(0);
+			//break;
+		}
+	}
+
+}

File src/gui.d

View file
 		//Panel[] mPanels;
 		Button[] mButtons;
 
-		int mMargin = 3;
+		int mMargin = 8;
 		int mLineHeight;
 		int mLineGap = 3;
 		int mElementGap = 3;
 			foreach( b; mButtons ) {
 				delete(b);
 			}
+
+			if( mBg != null ) SDL_FreeSurface( mBg );
 		}
 
 		TextButton addTextButton( string caption, string fontid, ButtonListener listener=null ) {
 
 			adjustLineHeight( h );
 
-			mXInsert += w + mElementGap;
+			mXInsert += ( w + mElementGap );
 			//mYInsert += h;
 			bool updateBg = false;
-			if( mXInsert+w > mW ) { mW = mXInsert; updateBg = true; }
-			if( mYInsert+h > mH ) { mH = mYInsert + h + mMargin; updateBg = true; }
+			if( mXInsert+w > mW-mMargin ) { mW = mXInsert + mMargin; updateBg = true; }
+			if( mYInsert+h > mH-mMargin ) { mH = mYInsert + h + mMargin; updateBg = true; }
 
 			if( updateBg ) {
 				if( mBg != null ) SDL_FreeSurface( mBg );
 	SDL_Surface* mPointer;
 	bool mPointerHidden;
 	int mPx, mPy;
+	SDL_Rect mPointerRect;
 
 	alias SList!(Panel) PanelList;
 	PanelList mPanels;
 
 	private this() {
 		mPointerHidden = false;
-		mPointer = gTextureManager.get("pointer.png");
+		changePointer( "pointer.png" );
 		mPanels = new PanelList;
 	}
 
 	}
 
 	void drawPointer() {
-		SDL_Rect rect;
-		rect.x = cast(short)mPx;
-		rect.y = cast(short)mPy;
-		rect.w = 32;
-		rect.h = 32;
-		SDL_BlitSurface( mPointer, null, gScreen.mSurface, &rect);
+		with( mPointerRect ) {
+			x = cast(short)mPx;
+			y = cast(short)mPy;
+		}
+		SDL_BlitSurface( mPointer, null, gScreen.mSurface, &mPointerRect );
 	}
 
+	void changePointer( string bitmap ) {
+		mPointer = gTextureManager.get(bitmap);
+		with( mPointerRect ) {
+			w = cast(ushort)mPointer.w;
+			h = cast(ushort)mPointer.h;
+		}
+	}
 
 	void update( int relx, int rely, bool click ) {
 

File src/map.d

View file
 import std.math;
 import std.regexp;
 import std.stdio;
-import std.string;
-
-import gameobject;
-import gameobjectmanager;
-import gameobjects.boss;
-import gameobjects.brick;
-import gameobjects.checkpoint;
-import gameobjects.door;
-import gameobjects.enemy1;
-import gameobjects.enemy2;
-import gameobjects.enemy3;
-import gameobjects.fluid;
-import gameobjects.goal;
-import gameobjects.hero;
-import gameobjects.powerup;
-import gameobjects.updatedgameobject;
-import gameobjects.wall;
+import std.string;
+
+
+import gameobjectfactory;
+import gameobject;
 import objectlist;
 
 public static Map gMap;
 
 				assert( x < mWidth );
 
-				GameObject obj;
 				auto xpix = x*TILE_WIDTH;
 				auto ypix = y*TILE_HEIGHT;
 
-				switch(c) {
-
-					case '#':
-						obj = new Wall( xpix, ypix, "wall1.png" );
-					break;
-
-					case '=':
-						obj = new Wall( xpix, ypix, "wall2.png" );
-					break;
-
-					case '1':
-						obj = new Wall( xpix, ypix, "bigwall1_1.png" );
-					break;
-
-					case '2':
-						obj = new Wall( xpix, ypix, "bigwall1_2.png" );
-					break;
-
-					case '3':
-						obj = new Wall( xpix, ypix, "bigwall1_3.png" );
-					break;
-
-					case '4':
-						obj = new Wall( xpix, ypix, "bigwall1_4.png" );
-					break;
-
-					case '*':
-						obj = new Brick( xpix, ypix );
-					break;
-
-					case 'b':
-						obj = new Door( xpix, ypix, "bluedoor.png", GameObject.Type.DOOR_BLUE );
-					break;
-
-					case 'g':
-						obj = new Door( xpix, ypix, "greendoor.png", GameObject.Type.DOOR_GREEN );
-					break;
-
-					case 'r':
-						obj = new Door( xpix, ypix, "reddoor.png", GameObject.Type.DOOR_RED );
-					break;
-
-					case '&':
-						obj = new Boss( xpix, ypix, -1 );
-					break;
-
-					case '<':
-						obj = new Enemy1( xpix, ypix, -1 );
-					break;
-
-					case '>':
-						obj = new Enemy1( xpix, ypix, +1 );
-					break;
-
-					case '@':
-						obj = new Hero( xpix, ypix );
-					break;
-
-					case ',':
-						obj = new Fluid( xpix, ypix, Fluid.FluidType.SURFACE );
-					break;
-
-					case '~':
-						obj = new Fluid( xpix, ypix, Fluid.FluidType.BOTTOM );
-					break;
-
-					case '^':
-						obj = new Enemy2( xpix, ypix, -1 );
-					break;
-
-					case 'v':
-						obj = new Enemy2( xpix, ypix, 1 );
-					break;
-
-					case 'u':
-						obj = new Enemy3( xpix, ypix );
-					break;
-
-					case 'X':
-						obj = new Goal( xpix, ypix );
-					break;
-
-					case 'j':
-						obj = new Powerup( xpix, ypix, GameObject.Type.POWERUP_JUMP, "jump.png" );
-					break;
-
-					case 'J':
-						obj = new Powerup( xpix, ypix, GameObject.Type.POWERUP_JUMP_DOUBLE, "doublejump.png" );
-					break;
-
-					case 's':
-						obj = new Powerup( xpix, ypix, GameObject.Type.POWERUP_SHOOT, "shot.png" );
-					break;
-
-					case 'S':
-						obj = new Powerup( xpix, ypix, GameObject.Type.POWERUP_SHOOT_FAST, "super_shot.png" );
-					break;
-
-					case 'm':
-						obj = new Powerup( xpix, ypix, GameObject.Type.POWERUP_MISSILE, "powerup_missile.png" );
-					break;
-
-					case 'H':
-						obj = new Powerup( xpix, ypix, GameObject.Type.POWERUP_ROCKET_HORIZONTAL, "horizontal_speed.png" );
-					break;
-
-					case 'V':
-						obj = new Powerup( xpix, ypix, GameObject.Type.POWERUP_ROCKET_VERTICAL, "vertical_speed.png" );
-					break;
-
-					case 'B':
-						obj = new Powerup( xpix, ypix, GameObject.Type.POWERUP_KEY_BLUE, "bluekey.png" );
-					break;
-
-					case 'G':
-						obj = new Powerup( xpix, ypix, GameObject.Type.POWERUP_KEY_GREEN, "greenkey.png" );
-					break;
-
-					case 'R':
-						obj = new Powerup( xpix, ypix, GameObject.Type.POWERUP_KEY_RED, "redkey.png" );
-					break;
-
-					case 'c':
-						obj = new Checkpoint( xpix, ypix );
-					break;
-
-					case ' ':
-						obj = null;
-					break;
-
-					default:
-						writefln( "Unknown char in map: '%c' (x=%d, y=%d).", c, x, y );
-						assert(0);
-					//break;
-
-				}
+				GameObjectFactory.create( c, xpix, ypix );
 
 			}