Commits

Anonymous committed 69773c7

oubli d'ajout du source editor.d
et du bitmap pour le pointeur

Comments (0)

Files changed (2)

+
+module editor;
+
+import derelict.sdl.sdl;
+import view;
+import gamepart;
+import inputmanager;
+import gameconstants;
+import texturemanager;
+import screen;
+
+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;
+
+	this() {
+
+		SDL_WM_GrabInput(SDL_GRAB_ON);
+//		SDL_WarpMouse(0,0);
+//		SDL_ShowCursor(SDL_ENABLE);
+
+		gView.setTarget( null );
+
+		gView.setPosition( mVx,mVy );
+
+		mBg = gTextureManager.get( "background.png" );
+		mPointer = gTextureManager.get("pointer.png");
+	}
+
+	~this() {
+//		SDL_ShowCursor(SDL_DISABLE);
+		SDL_WM_GrabInput(SDL_GRAB_OFF);
+	}
+
+	void update() {
+		processInput();
+
+		SDL_BlitSurface( mBg, null, gScreen.mSurface, null );
+		gView.update();
+		gView.draw();
+
+		drawPointer();
+
+	}
+
+	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);
+	}
+
+
+    void processInput() {
+
+        if( gInputManager.isReleased(IMA_TOGGLE_EDITOR)
+         || gInputManager.isReleased(IMA_BACK))
+			mState = GAMEPART_STATE.CONTINUE;
+
+		int x,y;
+		ubyte button = SDL_GetRelativeMouseState( &x, &y );
+
+		if ( button & SDL_BUTTON_RMASK ) {
+			mVx += x;
+			mVy += y;
+			gView.setPosition( mVx, mVy );
+		}
+		else {
+			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_WarpMouse(320,240);
+		}
+    }
+
+	GAMEPART_STATE getState() {
+		return( mState );
+	}
+
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.