Files
DNF_DEV/source_game/Scene/Scene_Test.cpp
2025-10-23 15:44:43 +08:00

135 lines
3.9 KiB
C++

#include "Scene_Test.h"
#include <memory>
#include "EngineCore/Game.h"
#include "EngineFrame/Component/AnimationManager.h"
#include "EngineFrame/Component/Text.h"
#include "EngineFrame/Component/Canvas.h"
#include "Global/Global_Game.h"
Scene_Test::Scene_Test()
{
}
Scene_Test::~Scene_Test()
{
SDL_Log("Scene_Test::我的ID是%d --- 我被释放了!", this->MyId);
}
void Scene_Test::Enter()
{
SetScale(VecFPos(1.2f, 1.2f));
map = new GameMap;
map->LoadMap("map/cataclysm/town/elvengard/new_elvengard.map");
map->Enter(this);
RefPtr<CharacterObject> obj = new CharacterObject();
obj->SetPosition({1000, 300, 0});
obj->Construction(0);
RefPtr<MonsterObject> monster = new MonsterObject();
monster->SetPosition({1200, 301, 0});
monster->Construction(1);
monster->SetDirection(1);
map->AddObject(obj);
map->AddObject(monster);
_camera = new GameMapCamera;
_camera->SetFromActor(obj.Get());
return;
// // SDL_Log("Scene_Test::进入测试场景!");
RefPtr<Actor> actor = new Actor;
AddChild(actor);
RefPtr<Sprite> sprite = new Sprite("ImagePacks2/test_white_background.png");
RefPtr<Sprite> chr = new Sprite("sprite/interface2/hud/hud.img", 0);
// chr->SetPos(VecFPos{200, 100});
// chr->SetAlpha(0.5);
// chr->SetShadow();
actor->AddComponent(chr);
// RefPtr<Canvas> canvas = new Canvas(VecSize{1280, 720});
// actor->AddChild(canvas);
// canvas->AddChild(chr);
// RefPtr<AnimationManager> Am = new AnimationManager;
// RefPtr<Animation> ani4 = new Animation("map/cataclysm/town/hendonmyre/animation/object/gateall_02.ani");
// Am->AddAnimation(ani4);
// // Am->SetPos(VecFPos{200, 100});
// actor->AddChild(Am);
// RefPtr<Text> text = new Text();
// text->Init("测试文本", Global_Game::GetInstance().Fonts[0], SDL_Color{255, 255, 255, 255});
// text->SetPos(VecFPos{200, 100});
// actor->AddChild(text);
// // sprite2->UnsetClipRect();
// RefPtr<Actor> actor2 = new Actor;
// actor->AddChild(actor2);
// RefPtr<Animation> ani4 = new Animation("map/cataclysm/town/hendonmyre/animation/object/gateall_02.ani");
// // ani4->SetScale(VecFPos{-1.0, 1.0});
// actor->AddChild(ani4);
// RefPtr<Animation> ani3 = new Animation("map/cataclysm/town/elvengard/animation/obj/serialight01_right.ani");
// actor->AddChild(ani3);
// RefPtr<Animation> ani4 = new Animation("map/cataclysm/town/hendonmyre/animation/object/gateall_02.ani");
// ani4->SetPos(VecPos{300, 500});
// actor->AddChild(ani4);
// for (size_t i = 0; i < 400; i++)
// {
// RefPtr<Actor> actor = new Actor;
// AddChild(actor);
// // RefPtr<Animation> ani3 = new Animation("common/commoneffect/animation/priestslowheal1.ani");
// // actor->AddComponent(ani3);
// // ani3->SetRenderZOrder(1000);
// // RefPtr<Animation> ani = new Animation("common/anton/main.ani");
// // actor->AddComponent(ani);
// // ani->SetRenderZOrder(500);
// RefPtr<Sprite> sprite = new Sprite("sprite/item/avatar/swordman/0sm_acap.img", 0);
// actor->AddComponent(sprite);
// // RefPtr<Animation> ani2 = new Animation("common/anton/face/0/0.ani");
// // actor->AddComponent(ani2);
// // ani2->SetRenderZOrder(1000);
// }
}
void Scene_Test::HandleEvents(SDL_Event *e)
{
Scene::HandleEvents(e);
}
void Scene_Test::Update(float deltaTime)
{
Scene::Update(deltaTime);
// 摄像机中有检测宿主坐标 所以要在场景的update后调用以便读取到本帧最新的坐标
if (_camera)
_camera->Update(deltaTime);
if (map)
map->Update(deltaTime);
}
void Scene_Test::Render()
{
Scene::Render();
}
void Scene_Test::Exit()
{
SDL_Log("Scene_Test::退出测试场景!当前引用计数%d", this->GetRefCount());
}
RefPtr<BaseNode> Scene_Test::GetCamera()
{
return this->_camera;
}