#include "Engine.h"
/**
<summary>
Creates an instance of the KeyEventArgs class.
</summary>
<param name="key">The key that is the focus of this event.</param>
<param name="pressed">Indicates if the specified key is pressed or not.</param>
*/
HgeNet::KeyEventArgs::KeyEventArgs(HgeNet::VirtualKey key, bool pressed)
{
_key = key;
_pressed = pressed;
}
/**
<value>
The key that is the focus of this event.
</value>
*/
HgeNet::VirtualKey HgeNet::KeyEventArgs::Key::get()
{
return _key;
}
/**
<value>
Indicates if the specified key is pressed or not.
</value>
*/
bool HgeNet::KeyEventArgs::Pressed::get()
{
return _pressed;
}
/**
<value>
Indicates if the Exit event should be terminated.
</value>
*/
bool HgeNet::ExitEventArgs::CancelExit::get()
{
return _cancelExit;
}
/**
<value>
Indicates if the Exit event should be terminated.
</value>
*/
void HgeNet::ExitEventArgs::CancelExit::set(bool value)
{
_cancelExit = value;
}
/**
<summary>
Adds a key to the list of keys for which an event will be raised if there is a state change in the specified key.
</summary>
<param name="key">The key to monitor.</param>
*/
void HgeNet::Engine::RegisterKey(HgeNet::VirtualKey key)
{
KeyMonitor^ monitor;
int counter;
for (counter = 0; counter < _keys->Count; counter++ )
{
if (_keys[counter]->Key == key)
{
return;
}
}
monitor = gcnew KeyMonitor();
monitor->Key = key;
_keys->Add(monitor);
}
/**
<summary>
Removes the key from the list of keys to monitor.
</summary>
<param name="key">The key to no longer monitor.</param>
*/
void HgeNet::Engine::UnregisterKey(HgeNet::VirtualKey key)
{
int counter;
for (counter = 0; counter < _keys->Count; counter++ )
{
if (_keys[counter]->Key == key)
{
_keys->RemoveAt(counter);
return;
}
}
}
/**
<summary>
Registers an array of keys for event notification.
</summary>
<param name="keys">An array of keys to register.</param>
*/
void HgeNet::Engine::RegisterKeys(array<HgeNet::VirtualKey>^ keys) {
int counter;
int keyCounter;
HgeNet::VirtualKey key;
KeyMonitor^ monitor;
bool found;
for (keyCounter = 0; keyCounter < keys->Length-1; keyCounter++) {
key = keys[keyCounter];
found = false;
for (counter = 0; counter < _keys->Count; counter++ )
{
if (_keys[counter]->Key == key)
{
found = true;
}
}
if (found == false) {
monitor = gcnew KeyMonitor();
monitor->Key = key;
_keys->Add(monitor);
}
}
}
/**
<summary>
Removes registrations of an array of keys for event notification.
</summary>
<param name="keys">An array of keys to unregister.</param>
*/
void HgeNet::Engine::UnregisterKeys(array<HgeNet::VirtualKey>^ keys) {
int counter;
int keyCounter;
HgeNet::VirtualKey key;
for (keyCounter = 0; keyCounter < keys->Length-1; keyCounter++) {
key = keys[keyCounter];
for (counter = 0; counter < _keys->Count; counter++ )
{
if (_keys[counter]->Key == key)
{
_keys->RemoveAt(counter);
}
}
}
}
/**
<summary>
Called by the HGE engine, this method calls the HGE.Net RenderFrame method.
</summary>
*/
bool HgeNet::Engine::RenderHandler()
{
_graphics->RenderFrame();
return false;
}
/**
<summary>
Called by the HGE engine, this method performs all of the necessary work to process one frame of the display.
</summary>
*/
bool HgeNet::Engine::FrameHandler()
{
int counter;
bool state;
float x;
float y;
// This checks each key that is to be monitored to see if it has changed state.
// If it has, it calls the OnKey method for that key.
for (counter = 0; counter < _keys->Count; counter++)
{
state = this->GetKeyPressed(_keys[counter]->Key);
if (state != _keys[counter]->LastState)
{
OnKey(_keys[counter]->Key, state);
_keys[counter]->LastState = state;
}
}
// If the HGE window contains the display we need to handle the mouse.
if (_hge->Input_IsMouseOver())
{
// If the engine thinks it doesn't have the mouse then the mouse was moved over the engine since
// the last frame and we need to raise the DoMouseEnter event.
if (_containsMouse == false)
{
_containsMouse = true;
_graphics->DoMouseEnter();
}
// If the mouse isn't in the last known position, raise the DoMouseMove event.
_hge->Input_GetMousePos(&x, &y);
if ((x != _lastX) || (y != _lastY))
{
_graphics->DoMouseMove(x, y);
_lastX = x;
_lastY = y;
}
// If the left mouse button has changed state, raise the DoMouseButton event.
state = this->GetKeyPressed(VirtualKey::LeftButton);
if (state != _lastLeft)
{
_graphics->DoMouseButton(x, y, VirtualKey::LeftButton, state);
_lastLeft = state;
}
// If the middle mouse button has changed state, raise the DoMouseButton event.
state = this->GetKeyPressed(VirtualKey::MiddleButton);
if (state != _lastRight)
{
_graphics->DoMouseButton(x, y, VirtualKey::MiddleButton, state);
_lastLeft = state;
}
// If the right mouse button has changed state, raise the DoMouseButton event.
state = this->GetKeyPressed(VirtualKey::RightButton);
if (state != _lastRight)
{
_graphics->DoMouseButton(x, y, VirtualKey::RightButton, state);
_lastRight = state;
}
}
else
{
// If the HGE window does not contian the mouse and the engine thinks it does have the mouse then the
// mouse left the window since the last frame so we need to raise the DoMouseLeave event.
if (_containsMouse)
{
_containsMouse = false;
_graphics->DoMouseLeave();
}
}
// Indicate to the HGE engine if the frame was successful or not.
return _graphics->UpdateFrame();
}
/**
<summary>
This method is called whenever a monitored key has changed state.
</summary>
<param name="key">The key that has changed state.</param>
<param name="pressed">The new state of the key.</param>
*/
void HgeNet::Engine::OnKey(HgeNet::VirtualKey key, bool pressed)
{
KeyEventArgs^ e;
if (pressed)
{
e = gcnew KeyEventArgs(key, pressed);
KeyPressed(this, e);
} else {
e = gcnew KeyEventArgs(key, pressed);
KeyReleased(this, e);
}
}
/**
<summary>
Called by the HGE engine, this method will raise the FocusLost event.
</summary>
*/
bool HgeNet::Engine::LostFocusHandler()
{
EventArgs^ e;
e = gcnew EventArgs;
FocusLost(this, e);
return false;
}
/**
<summary>
Called by the HGE engine, this method will raise the FocusGained event.
</summary>
*/
bool HgeNet::Engine::GainFocusHandler()
{
EventArgs^ e;
e = gcnew EventArgs;
FocusGained(this, e);
return false;
}
/**
<summary>
Called by the HGE engine, this method will raise the Exiting event.
</summary>
*/
bool HgeNet::Engine::ExitHandler()
{
ExitEventArgs^ e;
e = gcnew ExitEventArgs;
Exiting(this, e);
return !e->CancelExit;
}
/**
<summary>
All necessary event handlers are attached here.
</summary>
*/
void HgeNet::Engine::WireUpEvents()
{
hgeCallback callback;
_hgeFrameEvent = gcnew HgeEventHandler(this, &Engine::FrameHandler);
_hgeLostFocusEvent = gcnew HgeEventHandler(this, &Engine::LostFocusHandler);
_hgeGainFocusEvent = gcnew HgeEventHandler(this, &Engine::GainFocusHandler);
_hgeExitEvent = gcnew HgeEventHandler(this, &Engine::ExitHandler);
_hgeRenderEvent = gcnew HgeEventHandler(this, &Engine::RenderHandler);
callback = (hgeCallback)(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(_hgeFrameEvent).ToPointer());
_hge->System_SetState(HGE_FRAMEFUNC, callback);
callback = (hgeCallback)(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(_hgeLostFocusEvent).ToPointer());
_hge->System_SetState(HGE_FOCUSLOSTFUNC, callback);
callback = (hgeCallback)(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(_hgeGainFocusEvent).ToPointer());
_hge->System_SetState(HGE_FOCUSGAINFU
没有合适的资源?快使用搜索试试~ 我知道了~
2D游戏的引擎Hge适合.NET开发工具
共30个文件
h:15个
cpp:13个
sln:1个
5星 · 超过95%的资源 需积分: 15 19 下载量 38 浏览量
2011-05-13
22:25:43
上传
评论
收藏 33KB RAR 举报
温馨提示
一款优秀的2d游戏开发引擎,可以加载很多种图片格式,文件很小,很适合开发2d小游戏
资源推荐
资源详情
资源评论
收起资源包目录
HgeNet_Source.rar (30个子文件)
HgeNet
Particles.cpp 18KB
AssemblyInfo.cpp 1KB
Texture.h 1017B
HgeNet.vcproj 7KB
Gui.cpp 7KB
Font.h 2KB
Target.cpp 2KB
ResourceManager.h 1KB
EngineManaged.h 156B
HgeNet.cpp 58B
Primitives.cpp 872B
Primitives.h 792B
Distortion.cpp 12KB
Graphics.h 4KB
HgeNet.h 692B
ResourceManager.cpp 4KB
Particles.h 7KB
Texture.cpp 2KB
StringConversion.h 642B
Gui.h 3KB
Distortion.h 2KB
Graphics.cpp 17KB
HgeNet.sln 2KB
Font.cpp 8KB
Sprite.cpp 11KB
Sprite.h 4KB
Enums.h 4KB
Target.h 969B
Engine.cpp 19KB
Engine.h 4KB
共 30 条
- 1
资源评论
- helpmsg2014-01-02打算重新用C++ 写一遍!
wulie513
- 粉丝: 9
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功