/// <summary> /// /// </summary> /// <param name="pText"></param> /// <param name="pSize"></param> /// <param name="pX"></param> /// <param name="pY"></param> /// <param name="pColor"></param> public override void DrawText(string pText, int pSize, int pX, int pY, SMX.Maths.Color4 pColor) { System.Drawing.Font font = new Font("Arial", pSize, FontStyle.Bold); SolidBrush brush = new SolidBrush(pColor.ToGDI()); SMX.Maths.Rectangle r = GetScreenCoords(pX, pY, 0, 0); mGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear; mGraphics.DrawString(pText, font, brush, new PointF(r.X, r.Y)); }
/// <summary> /// Este método es una copia del propio código del PictureBox, mirado en el codigo fuente de .Net /// </summary> /// <param name="pContainerClientRectangleWidth"></param> /// <param name="pContainerClientRectangleHeight"></param> /// <param name="pImageWidth"></param> /// <param name="pImageHeight"></param> /// <returns></returns> public static SMX.Maths.Rectangle CalcZoomRectangle(int pContainerClientRectangleWidth, int pContainerClientRectangleHeight, int pImageWidth, int pImageHeight) { SMX.Maths.Rectangle ret = new SMX.Maths.Rectangle(); float ratio = Math.Min((float)pContainerClientRectangleWidth / (float)pImageWidth, (float)pContainerClientRectangleHeight / (float)pImageHeight); ret.Width = (int)(pImageWidth * ratio); ret.Height = (int)(pImageHeight * ratio); ret.X = (pContainerClientRectangleWidth - ret.Width) / 2; ret.Y = (pContainerClientRectangleHeight - ret.Height) / 2; return(ret); }
/// <summary> /// /// </summary> /// <param name="pGameWidth"></param> /// <param name="pGameHeight"></param> /// <param name="pScreenWidth"></param> /// <param name="pScreenHeight"></param> public virtual void SetGameWindow(int pGameWidth, int pGameHeight, int pScreenWidth, int pScreenHeight) { mGameWidth = pGameWidth; mGameHeight = pGameHeight; mScreenWidth = pScreenWidth; mScreenHeight = pScreenHeight; SMX.Maths.Rectangle dR = CalcZoomRectangle(this.mScreenWidth, this.mScreenHeight, mGameWidth, mGameHeight); mOffsetX = dR.X; mOffsetY = dR.Y; mScaleX = (float)dR.Width / (float)mGameWidth; mScaleY = (float)dR.Height / (float)mGameHeight; }
/// <summary> /// /// </summary> public static SharpDX.RectangleF ToSDXRectangleF(this SMX.Maths.Rectangle pSrc) { return(new SharpDX.RectangleF(pSrc.X, pSrc.Y, pSrc.Width, pSrc.Height)); }
/// <summary> /// /// </summary> public static System.Drawing.Rectangle ToGDI(this SMX.Maths.Rectangle pSrc) { return(new System.Drawing.Rectangle(pSrc.X, pSrc.Y, pSrc.Width, pSrc.Height)); }
public void onFrameMove() { mSpeedPxS += Game.mGravityVel * Game.mDt; mPos += mSpeedPxS * Game.mDt; mState = ePlayerState.Idle; if (Game.mInput.IsActionPressed(eAction.Left)) { mPos.X -= DefaultHorizontalSPeedPxS * Game.mDt; mState = ePlayerState.WalkLeft; } else if (Game.mInput.IsActionPressed(eAction.Right)) { mPos.X += DefaultHorizontalSPeedPxS * Game.mDt; mState = ePlayerState.WalkRight; } //Restricciones para que no se salga de la pantalla mPos.X = Math.Min(mPos.X, Game.DefaultGameWidth - PlayerWidth); mPos.X = Math.Max(mPos.X, 0); mPos.Y = Math.Min(mPos.Y, Game.DefaultGameHeight - PlayerHeight); mPos.Y = Math.Max(mPos.Y, 0); //Animacion del personaje float limitetiempo; switch (mState) { case ePlayerState.Idle: mSpriteSourceRectangle = mWalkAnimationSourceRectangles[mCurrentAnimationIdx]; break; case ePlayerState.WalkLeft: mContadorDeTiempoAnimacion += Game.mDt; limitetiempo = 1f / 12f; if (mContadorDeTiempoAnimacion > limitetiempo) { mContadorDeTiempoAnimacion = 0; mCurrentAnimationIdx++; if (mCurrentAnimationIdx >= mWalkAnimationSourceRectangles.Count) { mCurrentAnimationIdx = 0; } mSpriteSourceRectangle = mWalkAnimationSourceRectangles[mCurrentAnimationIdx]; } break; case ePlayerState.WalkRight: mContadorDeTiempoAnimacion += Game.mDt; limitetiempo = 1f / 12f; if (mContadorDeTiempoAnimacion > limitetiempo) { mContadorDeTiempoAnimacion = 0; mCurrentAnimationIdx++; if (mCurrentAnimationIdx >= mWalkAnimationSourceRectangles.Count) { mCurrentAnimationIdx = 0; } mSpriteSourceRectangle = mWalkAnimationSourceRectangles[mCurrentAnimationIdx]; } break; } }