Skip to content

Commit

Permalink
更新單挑系列功能
Browse files Browse the repository at this point in the history
  • Loading branch information
lemingcen committed Apr 27, 2019
1 parent 6d1369a commit 3319118
Show file tree
Hide file tree
Showing 30 changed files with 2,012 additions and 130 deletions.
7 changes: 6 additions & 1 deletion Content/Data/TextureRecs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ Content\Textures\Resources\Start\Cloud2:png:Cloud2:586:396:586:396:1:Scene;
Content\Textures\Resources\Start\Cloud3:png:Cloud3:466:351:466:351:1:Scene;
Content\Textures\Resources\Start\Cloud4:png:Cloud4:663:391:663:391:1:Scene;
Content\Textures\Resources\Start\Cloud5:png:Cloud5:586:396:586:396:1:Scene;
Content\Textures\Resources\Start\Cloud6:png:Cloud6:466:351:466:351:1:Scene
Content\Textures\Resources\Start\Cloud6:png:Cloud6:466:351:466:351:1:Scene;
Content\Textures\Resources\Dantiao\Story:png:Story:200:42:100:42:2:Scene;
Content\Textures\Resources\Dantiao\Button:png:Button:200:42:100:42:2:Scene;
Content\Textures\Resources\Dantiao\Page:png:Left,Right:100:24:25:24:2:Scene;
Content\Textures\Resources\Dantiao\General01A:png:WalkLeft,WalkRight,AttackLeft,AttackRight,Failure:1024:384:128:128:4:Scene;
Content\Textures\Resources\Dantiao\General01B:png:WalkLeft,WalkRight,AttackLeft,AttackRight,Failure:1024:384:128:128:4:Scene
Binary file added Content/Textures/Resources/Dantiao/Avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Textures/Resources/Dantiao/Button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Textures/Resources/Dantiao/Cloud.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Textures/Resources/Dantiao/Ground.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Textures/Resources/Dantiao/Land.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Textures/Resources/Dantiao/Page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Textures/Resources/Dantiao/StarLeft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Textures/Resources/Dantiao/StarRight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Textures/Resources/Dantiao/Story.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Content/Textures/Resources/Dantiao/Tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
285 changes: 285 additions & 0 deletions WorldOfTheThreeKingdoms/GameManager/AnimatedTexture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
using Microsoft.Xna.Framework;
using SanguoSeason;
using Microsoft.Xna.Framework.Graphics;
using System.Linq;
using System;

namespace GameManager
{
public class AnimatedTexture
{
//public Texture2D myTexture;
public Rectangle[] Recs;
private float TimePerFrame;
public int Frame { get; set; }
public float TotalElapsed;
public bool Paused = false, Visible = true;

public int CircleNumber = 0;
public int CircleNumberMax { get; set; }

//private bool MultiPicture = false;
//public float Rotation, Scale, Depth;
//public Vector2 Origin;
public bool MouseOver;
public Vector2 Position;

public float Depth = 0f;

private int width, height;

public string Asset;
private string Name;

public string Text;
public int[] TextHigh;
public Vector2 TextPos;

public bool OrderAsc;

public float Scale = 1f;

//public bool IsPaused
//{
// get { return Paused; }
//}

public int FrameCount;

public int LimiteWidth = 0;

public bool LimiteOrder = true;

public AnimatedTexture(string asset, string name, string extension, bool orderAsc, int framesPerSec)
: this(asset, name, extension, Session.TextureRecs[asset + "#" + name], orderAsc, framesPerSec)
{
}

public AnimatedTexture(string asset, string name, string extension, TextureRecs textureRecs, bool orderAsc, int framesPerSec)
{
Asset = asset;
Name = name;
//MultiPicture = false;
width = textureRecs.Recs[0].Width; height = textureRecs.Recs[0].Height;

OrderAsc = orderAsc;
//myTexture = CacheManager.Load(asset); //, extension, textureRecs.IsLive ? CacheLiveType.Live : CacheLiveType.Scene, false);

if (OrderAsc)
{
Recs = textureRecs.Recs;
}
else
{
//Recs = textureRecs.Recs.Select(re => new Rectangle(myTexture.Width - re.X - re.Width, re.Y, re.Width, re.Height)).ToArray();
Recs = textureRecs.Recs.Select(re => new Rectangle(textureRecs.Width - re.X - re.Width, re.Y, re.Width, re.Height)).ToArray();
}
FrameCount = Recs.Length;
//width = (myTextures[0].Width * assets.Length) / frameCount;
TimePerFrame = (float)1 / framesPerSec;
Frame = 0;
TotalElapsed = 0;
Paused = false;
}

public void ChangeFrame(int framesPerSec)
{
TimePerFrame = (float)1 / framesPerSec;
}

public void ClearCache()
{
//FontCharacter.RemoveSceneCache(myTexture);
}

public bool IsInTexture(int poX, int poY)
{
MouseOver = this.Position.X <= poX && poX <= this.Position.X + width && this.Position.Y <= poY && poY <= this.Position.Y + height;
return MouseOver;
}

public void UpdateFrame(float elapsed, int start, int end)
{
if (!Visible || Paused || CircleNumberMax != 0 && CircleNumber >= CircleNumberMax) return;
TotalElapsed += elapsed;
if (TotalElapsed > TimePerFrame)
{
//if (OrderAsc)
//{
if (Frame < start || Frame > end) Frame = start;
else if (Frame == end) Frame = start;
else Frame++;
//}
//else
//{
// if (Frame < start || Frame > end) Frame = end;
// else if (Frame == start) Frame = end;
// else Frame--;
//}
TotalElapsed -= TimePerFrame;
}
}

public void UpdateFrame(float elapsed)
{
if (!Visible || Paused || CircleNumberMax != 0 && CircleNumber >= CircleNumberMax) return;
TotalElapsed += elapsed;
if (TotalElapsed > TimePerFrame)
{
Frame = NextFrame(Frame, true);
//if (OrderAsc)
//{
// if (Frame != FrameCount - 1) { Frame++; }
// else { Frame = 0; CircleNumber++; }
// //Frame++;
// // Keep the Frame between 0 and the total frames, minus one.
// //if (Frame == FrameCount) Frame = 0;
// //Frame = Frame % FrameCount;
// //if (Frame == 0) CircleNumber++;
// ////if (Frame == 0 && CircleNumber != null) CircleNumber++;
//}
//else
//{
// if (Frame != 0) { Frame--; }
// else { Frame = FrameCount - 1; CircleNumber++; }
//}
TotalElapsed -= TimePerFrame;
}
}

public int NextFrame(int frame, bool circle)
{
if (OrderAsc)
{
if (frame != FrameCount - 1) { return frame + 1; }
else
{
if (circle) CircleNumber++;
return 0;
}
//Frame++;
// Keep the Frame between 0 and the total frames, minus one.
//if (Frame == FrameCount) Frame = 0;
//Frame = Frame % FrameCount;
//if (Frame == 0) CircleNumber++;
////if (Frame == 0 && CircleNumber != null) CircleNumber++;
}
else
{
if (frame != 0) { return frame - 1; }
else
{
if (circle) CircleNumber++;
return FrameCount - 1;
}
}
}

public void DrawFrame(int? frame)
{
DrawFrame(frame == null ? Frame : (int)frame, Position, Color.White);
}

public void DrawFrame(Vector2 screenPos)
{
DrawFrame(Frame, screenPos, Color.White);
}

public void DrawFrame(int? frame, Vector2 screenPos)
{
DrawFrame(frame == null ? Frame : (int)frame, screenPos, Color.White);
}

public void DrawFrame(Vector2 screenPos, Color alpha)
{
DrawFrame(Frame, screenPos, alpha);
}

public void DrawFrame(Color alpha)
{
DrawFrame(Frame, Position, alpha);
}

public void DrawFrame(int frame, Vector2 screenPos, Color alpha)
{
if (Visible && (CircleNumberMax == 0 || CircleNumberMax != 0 && CircleNumber < CircleNumberMax))
{
SpriteEffects effect = SpriteEffects.None;
Vector2 pos = screenPos;
if (!OrderAsc)
{
effect = SpriteEffects.FlipHorizontally;
if (Recs.Length > frame)
{
pos.X = pos.X - (Recs[frame].Width - 83) + 34;
}
}
if (Recs.Length > frame)
{
var rec = Recs[frame];

Vector2 viewVec = pos;

var viewRec = new Rectangle(rec.X, rec.Y, rec.Width, rec.Height);

if (LimiteWidth > 0)
{
if (LimiteOrder)
{
viewVec = pos + new Vector2(rec.Width - LimiteWidth, 0);

viewRec = new Rectangle(rec.X + (rec.Width - LimiteWidth), rec.Y, LimiteWidth, rec.Height);
}
else
{
viewRec = new Rectangle(rec.X, rec.Y, LimiteWidth, rec.Height);
}
}

CacheManager.Draw(Asset, viewVec, viewRec, alpha, effect, Scale, Depth);
}
if (!String.IsNullOrEmpty(Text))
{
int framePlus = frame % FrameCount;
if (TextHigh != null && TextHigh.Length > 0 && TextHigh.Length > framePlus)
{
CacheManager.DrawString(null, Text, pos + TextPos * Scale + new Vector2(0, TextHigh[framePlus]), Color.White, 0f, Vector2.Zero, Scale, SpriteEffects.None, Depth);
}
}
//myTexture = CacheManager.Load(asset);
//CoreGame.Current.spriteBatch.Draw(myTexture, pos, Recs[frame], alpha, 0f, Vector2.Zero, 1f, effect, 1f);
//if (!MultiPicture)
//{
// //int FrameWidth = myWidth / framecount;
// int num = width * frame / myTextures[0].Width;
// int plus = (width * frame % myTextures[0].Width) / width;
// Rectangle sourcerect = new Rectangle(width * plus, 0, width, myTextures[0].Height);
// batch.Draw(myTextures[num].Texture, sourcerect, null, screenPos, Color.White);
//}
//else if (myTextures != null)
//{
// batch.Draw(myTextures[frame].Texture, null, screenPos, Color.White);
//}
}
}
public void Reset()
{
Frame = 0;
TotalElapsed = 0f;
}
public void Stop()
{
Paused = true;
Reset();
}
public void Play()
{
Paused = false;
}
//public void Pause()
//{
// Paused = true;
//}

}
}
Loading

0 comments on commit 3319118

Please sign in to comment.