-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[+] add BaseActor [+] import plugin FloatBar [+] import plugin FloatText
- Loading branch information
1 parent
47ee0f8
commit e40520c
Showing
55 changed files
with
1,040 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
2. [简单服务器][13] | ||
3. [基本位置同步][13] | ||
4. 不同步的检测与定位 | ||
5. 逻辑的基本同步技能 | ||
5. 逻辑的基本同步 | ||
6. 碰撞检测库的使用 | ||
7. 添加技能 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using Lockstep.Logging; | ||
using Lockstep.Logic; | ||
using Lockstep.Math; | ||
|
||
namespace LockstepTutorial { | ||
public partial class BaseActor : BaseEntity { | ||
public IActorView actorView; | ||
public LFloat moveSpd = 5; | ||
public LFloat turnSpd = 360; | ||
public int curHealth; | ||
public int maxHealth = 100; | ||
public bool isDead => curHealth <= 0; | ||
|
||
public BaseActor(){ | ||
curHealth = maxHealth; | ||
} | ||
|
||
public virtual void TakeDamage(int amount, LVector3 hitPoint){ | ||
if (isDead) return; | ||
curHealth -= amount; | ||
actorView?.OnTakeDamage(amount, hitPoint); | ||
OnTakeDamage(amount, hitPoint); | ||
if (isDead) { | ||
actorView?.OnDead(); | ||
OnDead(); | ||
} | ||
} | ||
|
||
protected virtual void OnTakeDamage(int amount, LVector3 hitPoint){} | ||
|
||
protected virtual void OnDead(){} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,72 @@ | ||
using Lockstep.Collision2D; | ||
using Lockstep.Logic; | ||
using Lockstep.Math; | ||
using UnityEngine; | ||
using Debug = Lockstep.Logging.Debug; | ||
|
||
namespace LockstepTutorial { | ||
public class Enemy : BaseEntity { | ||
public IEnemyView eventHandler; | ||
public BaseEntity target; | ||
public class Enemy : BaseActor { | ||
public BaseActor target; | ||
|
||
public LFloat stopDistSqr = 1 * 1; | ||
public LFloat atkInterval = 1; | ||
private LFloat atkTimer; | ||
public int damage = 10; | ||
|
||
public Enemy(){ | ||
moveSpd = 2; | ||
turnSpd = 150; | ||
} | ||
|
||
public override void DoUpdate(LFloat deltaTime){ | ||
//find target | ||
var allPlayer = GameManager.allPlayers; | ||
var minDist = LFloat.MaxValue; | ||
BaseActor minTarget = null; | ||
foreach (var player in allPlayer) { | ||
if(player.isDead) continue; | ||
var dist = (player.transform.pos - transform.pos).sqrMagnitude; | ||
if (dist < minDist) { | ||
minTarget = player; | ||
minDist = dist; | ||
} | ||
} | ||
|
||
target = minTarget; | ||
if (minTarget == null) | ||
return; | ||
if (minDist > stopDistSqr) { | ||
// turn to target | ||
var targetPos = minTarget.transform.pos; | ||
var currentPos = transform.pos; | ||
var diff = targetPos - currentPos; | ||
var dir = diff.normalized; | ||
var turnVal = turnSpd * deltaTime; | ||
var targetDeg = CTransform2D.TurnToward(targetPos, currentPos, transform.deg, turnVal, | ||
out var isFinishedTurn); | ||
transform.deg = targetDeg; | ||
//move to target | ||
var distToTarget = (targetPos - currentPos).magnitude; | ||
var movingStep = moveSpd * deltaTime; | ||
if (movingStep > distToTarget) { | ||
movingStep = distToTarget; | ||
} | ||
|
||
var toTarget = (targetPos - currentPos).normalized; | ||
transform.pos = transform.pos + toTarget * movingStep; | ||
} | ||
else { | ||
//atk target | ||
atkTimer -= deltaTime; | ||
if (atkTimer <= 0) { | ||
atkTimer = atkInterval; | ||
//Atk | ||
target.TakeDamage(damage, target.transform.Pos3); | ||
} | ||
} | ||
} | ||
protected override void OnDead(){ | ||
EnemyManager.Instance.RemoveEnemy(this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Lockstep.Logic; | ||
using Lockstep.Math; | ||
|
||
namespace LockstepTutorial { | ||
public interface IActorView : IView { | ||
void OnTakeDamage(int amount, LVector3 hitPoint); | ||
void OnDead(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
using Lockstep.Logging; | ||
|
||
namespace Lockstep.Game { | ||
public class UnityLogHandler { | ||
public static void OnLog(object sender, LogEventArgs args){ | ||
switch (args.LogSeverity) { | ||
case LogSeverity.Info: | ||
UnityEngine.Debug.Log(args.Message); | ||
break; | ||
case LogSeverity.Warn: | ||
UnityEngine.Debug.LogWarning(args.Message); | ||
break; | ||
case LogSeverity.Error: | ||
UnityEngine.Debug.LogError(args.Message); | ||
break; | ||
case LogSeverity.Exception: | ||
UnityEngine.Debug.LogError(args.Message); | ||
break; | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Lockstep.Logic; | ||
using Lockstep.Math; | ||
using UnityEngine; | ||
|
||
namespace LockstepTutorial { | ||
public abstract class BaseActorView : MonoBehaviour, IActorView { | ||
public UIFloatBar uiFloatBar; | ||
public BaseActor baseActor; | ||
protected bool isDead => baseActor?.isDead ?? true; | ||
|
||
public virtual void BindEntity(BaseEntity entity){ | ||
baseActor = entity as BaseActor; | ||
baseActor.actorView = this; | ||
uiFloatBar = FloatBarManager.CreateFloatBar(transform, baseActor.curHealth, baseActor.maxHealth); | ||
transform.position = baseActor.transform.Pos3.ToVector3(); | ||
} | ||
|
||
public virtual void OnTakeDamage(int amount, LVector3 hitPoint){ | ||
uiFloatBar.UpdateHp(baseActor.curHealth, baseActor.maxHealth); | ||
FloatTextManager.CreateFloatText(hitPoint.ToVector3(), -amount); | ||
} | ||
|
||
public virtual void OnDead(){ | ||
if (uiFloatBar != null) FloatBarManager.DestroyText(uiFloatBar); | ||
GameObject.Destroy(gameObject); | ||
} | ||
|
||
private void Update(){ | ||
var pos = baseActor.transform.Pos3.ToVector3(); | ||
transform.position = Vector3.Lerp(transform.position, pos, 0.3f); | ||
var deg = baseActor.transform.deg.ToFloat(); | ||
//deg = Mathf.Lerp(transform.rotation.eulerAngles.y, deg, 0.3f); | ||
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(0, deg, 0), 0.3f); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Collections; | ||
using Lockstep.Logic; | ||
using Lockstep.Math; | ||
using UnityEngine; | ||
|
||
namespace LockstepTutorial { | ||
public class EnemyView : BaseActorView, IEnemyView { | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.