顶视角射击/角色扮演游戏框架搭建
立即解锁
发布时间: 2025-08-24 01:28:44 阅读量: 2 订阅数: 3 

# 顶视角射击/角色扮演游戏框架搭建
## 1. 框架基础逻辑
首先来看一段基础的逻辑代码,它处理了不同的事件类型:
```lua
local bool retval;
local Actor TempActor;
local Vector HitLocation;
local TraceHitInfo HitInfo;
retval = true;
if (EventType == ZoneEvent_Touch)
{
// Code for Setting Bot WayPoint
TempActor = PickActor(TouchLocation, HitLocation, HitInfo);
ProcessTouch(TempActor, HitLocation);
SetHUDPawn(TempActor);
}
else
if(EventType == ZoneEvent_Update)
{
}
else
if (EventType == ZoneEvent_UnTouch)
{
// Stop Firing Pawn's weapon
StopFire(0);
}
return retval;
```
这个代码块根据不同的事件类型执行不同的操作:
- **ZoneEvent_Touch**:选择一个演员,处理触摸事件,并设置 HUD 角色。
- **ZoneEvent_Update**:当前未做处理。
- **ZoneEvent_UnTouch**:停止角色武器的射击。
## 2. 创建角色
### 2.1 玩家角色
玩家角色的代码如下:
```lua
class PlayerPawnCh12 extends JazzPawnDamage;
var bool bFollowPlayerRotation;
var string CharacterName;
var int Experience;
////////// Top Down View ///////
simulated function bool CalcCamera( float fDeltaTime, out vector out_CamLoc, out rotator
out_CamRot, out float out_FOV )
{
out_CamLoc = Location;
out_CamLoc.Z += CamOffsetDistance;
if(!bFollowPlayerRotation)
{
out_CamRot.Pitch = -16384;
out_CamRot.Yaw = 0;
out_CamRot.Roll = 0;
}
else
{
out_CamRot.Pitch = -16384;
out_CamRot.Yaw = Rotation.Yaw;
out_CamRot.Roll = 0;
}
return true;
}
simulated singular event Rotator GetBaseAimRotation()
{
local rotator POVRot, tempRot;
tempRot = Rotation;
tempRot.Pitch = 0;
SetRotation(tempRot);
POVRot = Rotation;
POVRot.Pitch = 0;
return POVRot;
}
defaultproperties
{
bFollowPlayerRotation = false
CamOffsetDistance= 1500.0
CharacterName = "Player"
Experience = 0
}
```
这里定义了玩家角色的一些属性和方法:
- **属性**:`bFollowPlayerRotation` 决定相机是否跟随玩家旋转,`CharacterName` 是玩家名称,`Experience` 是玩家经验值。
- **方法**:`CalcCamera` 函数用于设置相机视角为顶视角,`GetBaseAimRotation` 函数设置武器射击的瞄准旋转。
### 2.2 盟友机器人角色
盟友机器人角色的代码如下:
```lua
class BotPawnCh12 extends BotPawn;
var string CharacterName;
var int Experience;
event TakeDamage(int Damage, Controller InstigatedBy, vector HitLocation, vector
Momentum, class<DamageType> DamageType, optional TraceHitInfo HitInfo, optional Actor
DamageCauser)
{
PlaySound(JazzHitSound);
Health = Health - Damage;
if (Health <= 0)
{
SetLocation(InitialLocation);
SetPhysics(PHYS_Falling);
Health = 100;
Experience = 0;
}
}
defaultproperties
{
CharacterName = "TeamMember1"
Experience = 0;
}
```
盟友机器人角色有自己的名称和经验值,`TakeDamage` 函数处理受到伤害的情况,当生命值小于等于 0 时,重置位置、物理状态、生命值和经验值。
### 2.3 敌人机器人角色
敌人机器人角色的代码如下:
```lua
class GuardPawn2 extends BotPawnCh10;
var int ExperienceValue;
event TakeDamage(int Damage, Controller InstigatedBy, vector HitLocation, vector
Momentum, class<DamageType> DamageType, optional TraceHitInfo HitInfo, optional Actor
DamageCauser)
{
PlaySound(HurtSound);
Health = Health - Damage;
if (Health <= 0)
{
PlaySound(DeathSound);
/*Add experience points to player or member of player's group
if this pawn is killed by one of them*/
if (InstigatedBy.IsA('ExampleCh12PC'))
{
PlayerPawnCh12(InstigatedBy.Pawn).Experience += ExperienceValue;
}
else
if (InstigatedBy.IsA('BotAllyController'))
{
BotPawnCh12(InstigatedBy.Pawn).Experience += ExperienceValue;
}
//destroy();
SetLocation(InitialLocation);
SetPhysics(PHYS_Falling
```
0
0
复制全文
相关推荐









