Compare commits

...

16 Commits

20 changed files with 159 additions and 75 deletions

3
.gitignore vendored
View File

@ -2,4 +2,5 @@ ImagePacks2/
SoundPacks/
Yosin_Game_Reloading.Sign
Script.pvf
Yosin_Engine.pdb
Yosin_Engine.pdb
*.pvf

Binary file not shown.

View File

@ -11,10 +11,14 @@ class Animation extends Actor {
//当前帧数
CurrentFrameIndex = 0;
//总帧数
TotalFrameIndex = 0;
//当前帧时间
CurrentIndexT = 0;
//当前帧
CurrentFrame = null;
//下帧延迟
NextFrameDelay = 9999999;
//状态机对象(只有存在时才有KeyFlag)
StateMachine = null;
@ -102,22 +106,25 @@ class Animation extends Actor {
AnimationFlag = Buf.Flag;
FrameArr = Buf.Frame;
foreach(FrameObj in FrameArr) {
//如果有附加处理 格式化
if (AdditionalOptions && AdditionalOptions.rawin("ImgFormat")) FrameObj.Img_Path = AdditionalOptions["ImgFormat"](FrameObj.Img_Path);
local Spritebuf;
//img路径判空
if (FrameObj.Img_Path) {
//如果有附加处理 格式化
if (AdditionalOptions && AdditionalOptions.rawin("ImgFormat")) FrameObj.Img_Path = AdditionalOptions["ImgFormat"](FrameObj.Img_Path);
local SpriteFramebuf = CL_SpriteFrameObject("sprite/" + FrameObj.Img_Path, FrameObj.Img_Index);
local Spritebuf = CL_SpriteObject();
Spritebuf.SetFrame(SpriteFramebuf);
Spritebuf = CL_SpriteObject("sprite/" + FrameObj.Img_Path, FrameObj.Img_Index);
//线性减淡
if ("GRAPHIC_EFFECT_LINEARDODGE" in FrameObj.Flag) {
Spritebuf.SetMode(0);
//线性减淡
if ("GRAPHIC_EFFECT_LINEARDODGE" in FrameObj.Flag) {
Spritebuf.SetMode(0);
}
//坐标
Spritebuf.SetPosition(FrameObj.Pos);
} else {
Spritebuf = CL_SpriteObject();
}
//坐标
Spritebuf.SetPosition(FrameObj.Pos);
SpriteArr.append(Spritebuf);
}
@ -127,10 +134,13 @@ class Animation extends Actor {
//初始化完毕 如果是第一次初始化 而非重新构造 设置大小为第0帧大小否则天空 地板等依靠大小的初始化会有问题
if (CurrentIndexT == 0) SetSize(SpriteArr[0].GetSize());
//记录总帧数
TotalFrameIndex = FrameArr.len();
}
//被添加时 要刷新一下当前帧
function OnAddchild(Parent) {
base.OnAddchild(Parent);
FlushFrame(0);
}
@ -159,7 +169,9 @@ class Animation extends Actor {
CurrentFrame = SpriteArr[CurrentFrameIndex];
Addchild(SpriteArr[CurrentFrameIndex]);
local FlagBuf = FrameArr[CurrentFrameIndex].Flag;
local FrameInfo = FrameArr[CurrentFrameIndex];
local FlagBuf = FrameInfo.Flag;
NextFrameDelay = FrameInfo.Delay;
//关键帧
if ("SET_FLAG" in FlagBuf) {
if (StateMachine && StateMachine.State != -1) StateMachine.ChangeAniKeyFlag(FlagBuf.SET_FLAG);
@ -179,17 +191,16 @@ class Animation extends Actor {
//override
function OnUpdate(dt) {
//可用性检查
if (IsUsability) {
//累加当前帧时间
CurrentIndexT += dt;
//当前帧时间 超过 当前帧延迟就需要切换帧了
if (CurrentIndexT >= FrameArr[CurrentFrameIndex].Delay) {
if (CurrentIndexT >= NextFrameDelay) {
CurrentIndexT = 0;
//如果当前帧小于总帧数就切换
if (CurrentFrameIndex<(FrameArr.len() - 1)) {
if (CurrentFrameIndex<(TotalFrameIndex - 1)) {
FlushFrame(CurrentFrameIndex + 1);
}
//说明播放完毕了
@ -206,10 +217,8 @@ class Animation extends Actor {
}
}
}
}
base.OnUpdate(dt);
//Animation类下只会有精灵 因此不需要对子对象进行更新
// base.OnUpdate(dt);
}
}

View File

@ -20,6 +20,8 @@ class CL_BaseObject {
Var = null;
//销毁状态
DestroyFlag = false;
//不需要Update函数
NoUpdate = false;
constructor(C_Object, ...) {
Children = {};
@ -36,6 +38,7 @@ class CL_BaseObject {
//被调用
function OnUpdate(dt) {
if (NoUpdate) return;
ExistingTime += dt;
//如果CallBack函数存在则调用
@ -64,12 +67,7 @@ class CL_BaseObject {
//添加子对象
function Addchild(Child) {
Children[Child.GetId()] <- Child;
Child.Parent = this.weakref();
//给自己解引用计数
Child.OnAddchild(this);
BaseObject_Addchild(this.C_Object, Child.C_Object);
}
//移除子对象
function Removechild(Child) {
@ -88,8 +86,10 @@ class CL_BaseObject {
}
//被添加
function OnAddchild(Parent) {
function OnAddchild(ParentObj) {
ParentObj.Children[GetId()] <- this;
this.Parent = ParentObj.weakref();
BaseObject_Addchild(ParentObj.C_Object, this.C_Object);
}
//被移除
function OnRemove(Parent) {

View File

@ -19,6 +19,9 @@ class Layer extends Actor {
//设置图层裁剪区域
function SetClipRect(x, y, w, h) {
if (!IsLayer) {
print("SetClipRect:窗口不是图层窗口");
}
LayerActor_SetClipRect(this.C_Object, x, y, w, h);
}

View File

@ -189,12 +189,12 @@ function InitPvfAni(Ro) {
//调用的第几个Img
local Index_Buf = Ro.GetShort();
//如果等于-1说明是img路径为空
if (Index_Buf != 65535) {
if (Index_Buf != -1) {
FrameObject.Img_Path <- AniObject.Img_List[Index_Buf].tolower();
//Img中的PNG下标
FrameObject.Img_Index <- Ro.GetUShort();
} else {
FrameObject.Img_Path <- "";
FrameObject.Img_Path <- null;
FrameObject.Img_Index <- 0;
}

View File

@ -6,12 +6,14 @@
*/
class CL_SpriteFrameObject extends CL_BaseObject {
ImgPath = null;
ImgIndex = null;
constructor(...) {
if (vargv.len() == 2) {
local Path = vargv[0];
local Index = vargv[1];
C_Object = SpriteFrame_Create(Path, Index);
ImgPath = vargv[0];
ImgIndex = vargv[1];
C_Object = SpriteFrame_Create(ImgPath, ImgIndex);
} else {
C_Object = vargv[0];
}

View File

@ -319,20 +319,19 @@ class Math {
}
function sq_GetAccel(sv, ev, currentRate, maxRate, increaseFeature) {
local rate = currentRate.tofloat() / maxRate.tofloat();
local varyValue = ev - sv;
local increaseRate = 1.0;
if (increaseFeature) {
increaseRate = pow(50, rate) / 50; //慢->快
} else {
increaseRate = pow(rate, 0.05);
// 修正后的减速逻辑计算,例如采用线性变换结合幂次运算来实现更合理的减速效果
// 先将rate映射到一个更合适的范围这里从[0,1]映射到[0.1, 1],可调整)
local mappedRate = rate * 0.9 + 0.1;
increaseRate = pow(mappedRate, 2); // 幂次可调整这里取2来让减速更明显可根据实际情况修改
}
return sv + varyValue * increaseRate;
}

View File

@ -184,6 +184,9 @@ class Yosin_Window extends Yosin_BaseWindow {
//是否为独立窗口
IsIndependent = true;
//是否为图层窗口
IsLayer = false;
constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
ObjectId = gObjectId;
//宽度
@ -199,7 +202,7 @@ class Yosin_Window extends Yosin_BaseWindow {
Y = gY;
//调用原生方法
base.constructor(true);
base.constructor(IsLayer);
SetSize(Width, Height);
SyncPos(X, Y);

View File

@ -69,4 +69,5 @@ sqr/User/UI/Window/1_Select_Character.nut
sqr/User/UI/Window/2_create_Character.nut
sqr/User/UI/Window/233_HUD_Message.nut
sqr/User/main.nut

View File

@ -191,6 +191,18 @@ class _AssetManager_ {
Ret = Data.Get();
DataTable.type.index <- Ret.tointeger();
}
//光环效果
else if (Pack == "[aurora graphic effects]") {
DataTable.aurora_effects <- [];
local Count = Data.Get();
for (local i = 0; i< Count; i++) {
local T = {
type = Data.Get(),
path = Data.Get().tolower()
}
DataTable.aurora_effects.push(T);
}
}
//Ani
else if (Pack == "[animation job]") {
local Job = Data.Get().slice(1, -1);

View File

@ -50,6 +50,9 @@ class Character_Animation extends Actor {
//普通攻击Ani
AttackAni = null;
//光环
AuroraAni = null;
constructor() {
base.constructor();
@ -57,7 +60,6 @@ class Character_Animation extends Actor {
//同步单部位动画
function SyncAnimationBySlot(Type, AniObj, Src) {
this[AniObj][Type] <- [];
//如果有时装就初始化Ani
@ -113,8 +115,6 @@ class Character_Animation extends Actor {
}
}
}
return this[AniObj][Type];
}
//读取并设置Ani
@ -275,6 +275,30 @@ class Character_Animation extends Actor {
// ReadAndSetAttackAni();
}
function InitAuroa() {
//光环
local Info = Parent.aurora;
//如果有光环
if (AuroraAni) {
foreach(Ani in AuroraAni) {
Removechild(Ani);
}
}
AuroraAni = [];
foreach(Effect in Info.Aurora_effects) {
local AniBuf = Animation(Effect.path);
AuroraAni.append(AniBuf);
Addchild(AniBuf);
//front
if (Effect.type == 1) {
AniBuf.SetZOrder(100000);
} else {
AniBuf.SetZOrder(-100000);
}
}
}
//设置Ani
function SetAnimation(Ani) {
@ -295,7 +319,7 @@ class Character_Animation extends Actor {
CurrentAni = this[Ani];
}
//重置Ani 并添加子对象
foreach(AniGroup in CurrentAni) {
foreach(Key, AniGroup in CurrentAni) {
foreach(AniObj in AniGroup) {
AniObj.Reset();
Addchild(AniObj);

View File

@ -27,6 +27,8 @@ class GameItem.Equipment extends GameItem.Item {
Description = "";
//文件路径
DirPath = null;
//光环特效
Aurora_effects = null;
//装备属性
Property = null;
@ -51,6 +53,7 @@ class GameItem.Equipment extends GameItem.Item {
if (EquInfo.rawin("icon")) Icon = EquInfo["icon"];
if (EquInfo.rawin("Ani")) Animation_Job = EquInfo["Ani"];
if (EquInfo.rawin("DirPath")) DirPath = EquInfo["DirPath"];
if (EquInfo.rawin("aurora_effects")) Aurora_effects = EquInfo["aurora_effects"];
}
}
}
@ -73,6 +76,7 @@ class GameItem.Equipment extends GameItem.Item {
else if (EType == "shoes avatar") SetRealEquipmentType("shoes", "avatar");
else if (EType == "breast avatar") SetRealEquipmentType("breast", "avatar");
else if (EType == "face avatar") SetRealEquipmentType("face", "avatar");
else if (EType == "aurora avatar") SetRealEquipmentType("aurora", "aurora");
}
//穿戴装备回调

View File

@ -16,6 +16,7 @@ class GameObject.Character extends GameObject.ActiveObject {
pants = null; //下装
shoes = null; //鞋子
weapon = null; //武器
aurora = null; //光环
//动画对象管理器
AnimationManager = null;
@ -100,6 +101,8 @@ class GameObject.Character extends GameObject.ActiveObject {
//如果是武器或者时装则同步动画
if (Equ.SlotType == "weapon" || Equ.Type == "avatar") {
AnimationManager.Init(Equ.SlotType);
} else if (Equ.Type == "aurora") {
AnimationManager.InitAuroa();
}
}
//切换装备列表

View File

@ -53,24 +53,27 @@ function TestStage() {
// local Window = Sq_CreateWindow(_Select_Character_Window, "选择角色界面窗口", 0, 0, 1066, 600, 0);
// local T = {
// Background = 1,
// Charc = [{
// Job = 0,
// Ava = [601500060, 601550060, 601560058, 601570053, 601520052, 601500060, 601510059, 601530051, 601540060, 601580023]
// loginImg = 1,
// charac = [{
// job = 0,
// equip = [601500060, 601550060, 601560058, 601570053, 601520052, 601500060, 601510059, 601530051, 601540060, 601580023]
// }, {
// Job = 0,
// Ava = [601500060, 601550060, 601560058, 601570053, 601520052, 601500060, 601510059, 601530051, 601540060, 601580023]
// job = 0,
// equip = [601500060, 601550060, 601560058, 601570053, 601520052, 601500060, 601510059, 601530051, 601540060, 601580023]
// }, {
// Job = 0,
// Ava = [601500060, 601550060, 601560058, 601570053, 601520052, 601500060, 601510059, 601530051, 601540060, 601580023]
// job = 0,
// equip = [601500060, 601550060, 601560058, 601570053, 601520052, 601500060, 601510059, 601530051, 601540060, 601580023]
// }, {
// Job = 0,
// Ava = [601500060, 601550060, 601560058, 601570053, 601520052, 601500060, 601510059, 601530051, 601540060, 601580023]
// job = 0,
// equip = [601500060, 601550060, 601560058, 601570053, 601520052, 601500060, 601510059, 601530051, 601540060, 601580023]
// }, {
// Job = 0,
// Ava = [601500060, 601550060, 601560058, 601570053, 601520052, 601500060, 601510059, 601530051, 601540060, 601580023]
// job = 0,
// equip = [601500060, 601550060, 601560058, 601570053, 601520052, 601500060, 601510059, 601530051, 601540060, 601580023]
// }]
// };
// Window.Init(T);
// print(ObjectCount);
// Sq_CreateWindow(_CreateCharacter, "创建角色界面窗口", 0, 0, 1066, 600, 0);
}

View File

@ -22,6 +22,9 @@ class _Login_Window extends Yosin_Window {
//信息
PackInfo = null;
//公告框
NoticeBox = null;
constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
base.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH);
@ -36,12 +39,13 @@ class _Login_Window extends Yosin_Window {
//注册登录回调包
MySocket.RegisterHandler(2, function(Jso) {
if (NoticeBox) NoticeBox.CloseWindow();
//登录成功
if (Jso.state) {
HUD_Message(500, 200, "登录成功,正在进入游戏...");
NoticeBox = _Yosin_MessageBox("登录成功,正在进入游戏...");
MySocket.Send(9, null);
} else {
HUD_Message(500, 200, "登录失败");
NoticeBox = _Yosin_MessageBox("登录失败");
}
}.bindenv(this));
@ -59,6 +63,10 @@ class _Login_Window extends Yosin_Window {
info.equip.append(value);
}
}
//关闭登录界面
NoticeBox.CloseWindow();
CloseWindow();
local Window = Sq_CreateWindow(_Select_Character_Window, "选择角色界面窗口", 0, 0, 1066, 600, 0);
Window.Init(PackInfo);
}.bindenv(this));
@ -154,6 +162,7 @@ class _Login_Window extends Yosin_Window {
});
PasswordTextActor.SetPosition(720, 281);
Addchild(PasswordTextActor);
}

View File

@ -58,16 +58,19 @@ class _Select_Character_SettingBackground_Object_Window extends Yosin_CommonUi {
function OnMouseLbClick(MousePos_X, MousePos_Y) {
base.OnMouseLbClick(MousePos_X, MousePos_Y);
if (isInRect) {
//遍历父对象中的所有按钮 还原其他按钮
foreach(Button in Parent.SettingBackgroundButtonList) {
Button.SelectMask.SetVisible(false);
Button.SelectFlag = false;
}
//设置自身选中状态
SelectMask.SetVisible(true);
SelectFlag = true;
//必须是在框的范围内
if (MousePos_Y > Parent.Y && MousePos_Y<(Parent.Y + Parent.Height)) {
//遍历父对象中的所有按钮 还原其他按钮
foreach(Button in Parent.SettingBackgroundButtonList) {
Button.SelectMask.SetVisible(false);
Button.SelectFlag = false;
}
//设置自身选中状态
SelectMask.SetVisible(true);
SelectFlag = true;
Parent.Parent.ChangeBackground(Idx);
Parent.Parent.ChangeBackground(Idx);
}
}
}
}
@ -76,6 +79,9 @@ class _Select_Character_SettingBackground_Window extends Yosin_Window {
//是否为独立窗口
IsIndependent = false;
//是否为图层窗口
IsLayer = true;
//是否可见
Visible = false;
@ -122,7 +128,7 @@ class _Select_Character_SettingBackground_Window extends Yosin_Window {
ScrollObject = Yosin_ScrollBar(Width - 13, 5, Height - 8, 20);
ScrollObject.SetChangeCallBack(function(Value) {
foreach(Pos, Button in SettingBackgroundButtonList) {
Button.SetPosition(5 + (101 * (Pos % 2)), 9 + (61 * (Pos / 2)) - Value * (61 * 12));
Button.SyncPos(5 + (101 * (Pos % 2)), 9 + (61 * (Pos / 2)) - Value * (61 * 12));
}
}.bindenv(this));
AddUIChild(ScrollObject);
@ -142,14 +148,14 @@ class _Select_Character_SettingBackground_Window extends Yosin_Window {
}
//角色
class _Select_Character_Chr extends Yosin_Window {
class _Select_Character_Chr extends Yosin_CommonUi {
//是否为独立窗口
IsIndependent = false;
Info = null;
constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH) {
base.constructor(gObjectId, gX, gY, gWidth, gHeight, gTitleH);
constructor(gX, gY, gWidth, gHeight) {
base.constructor(gX, gY, gWidth, gHeight);
RegisterDraw();
}
@ -168,6 +174,7 @@ class _Select_Character_Chr extends Yosin_Window {
Charc.SetAnimation("RestAni");
Charc.SetPosition(48, 12, 0);
Addchild(Charc);
// print(Charc.AnimationManager.Children.len());
}
}
@ -236,7 +243,7 @@ class _Select_Character_Window extends Yosin_Window {
//角色对象
for (local i = 0; i< 5; i++) {
local Buf = _Select_Character_Chr("选择角色角色对象" + i, 190 + (i * 144), ((i % 2) ? 15 : 0) + 225, 126, 208, 0);
local Buf = _Select_Character_Chr(190 + (i * 144), ((i % 2) ? 15 : 0) + 225, 126, 208);
if (i< Info.charac.len()) Buf.Init(Info.charac[i]);
AddUIChild(Buf);
}

View File

@ -5,7 +5,7 @@
文件用途: 公告或信息弹窗
*/
class HUD_Message extends Yosin_Window {
class _Yosin_MessageBox extends Yosin_Window {
//调试模式
// DeBugMode = true;
@ -23,7 +23,7 @@ class HUD_Message extends Yosin_Window {
titleTextActor = null;
messageTextActor = null;
constructor(gX, gY, message, info = {
constructor(message, gX = 418, gY = 200, info = {
// 标题
title = "公告",
// 水平边距
@ -60,7 +60,7 @@ class HUD_Message extends Yosin_Window {
cacheH = messageTextActor.GetSize().h + verticalMargin;
// 默认构造数据
base.constructor("公告或信息弹窗" + clock().tostring(), gX, gY, cacheW, cacheH, 20);
base.constructor("公告或信息弹窗" + clock().tostring(), gX ? gX : 418, gY ? gY : 200, cacheW, cacheH, 20);
//注册控件

View File

@ -17,6 +17,6 @@ function main(args) {
Game.size = [1066, 600];
Game.v_sync = false;
Game.frame_interval = 10000;
// Game.debug_mode = true;
Game.debug_mode = true;
Game.Run(LoginStage);
}

View File

@ -173,7 +173,11 @@
"User/UI/Window/233_HUD_Message.nut": {
"description": "公告弹窗"
},
"User/UI/Window/1_Select_Character.nut": {
"description": "选择角色界面"
},
"User/UI/Window/2_Create_Character.nut": {
"description": "创建角色"
}
}