示例#1
0
static void tickAI(pent c){
    //TODO implement in lua
    if(c != controlledEntity && c->ai != NULL){

switch(c->ai->currentMethod){
case AI_NONE: break;
case AI_WANDER: {
    c->facing += (-1 + ((angle) (rand() % 16) * .5)) * frameTime;
    moveEntityAng(c,
        c->facing,
        getEntityMovespeed(c) * frameTime
    );
} break;
case AI_CHASE: {
    pent closestPlayer = findClosestEntity(c, 0);
    if(!closestPlayer) break;

    c->facing = atan2(closestPlayer->y - c->y, closestPlayer->x - c->x) + PI/2;

    moveEntityAng(c,
        c->facing,
        getEntityMovespeed(c) * frameTime
    );
} break;
}

    }
}
示例#2
0
void MapEditor::mouseReleaseEvent(QMouseEvent *event)
{
    if(event->button() == 2)
        return;
    if(event->button() == 4)
    {
        move = false;
        return;
    }
    if(isClicked)
    {
        isClicked = false;

        if( objType == MapEntityType::SPAWN_POINT || objType == MapEntityType::LIGHT_POINT || objType < 100 || objType == MapEntityType::MODEL )
            return;
        if( startX == convertCoordinate(event->pos().x(),0) || startY == convertCoordinate(event->pos().y(),1) )
            return;

        entity4.type = objType;
        entity4.entityPosition.startX = startX;
        entity4.entityPosition.startZ = startY;

        float x1 = convertCoordinate( event->pos().x(),0);
        float y1 = convertCoordinate( event->pos().y(),1);
        findClosestEntity(&x1,&y1);
        if(!space)
        {
            if( fabs(startX-convertCoordinate(event->pos().x(),0)) > fabs(startY-convertCoordinate(event->pos().y(),1)) )
            {
                entity4.entityPosition.endZ = entity4.entityPosition.startZ;
                entity4.entityPosition.endX = x1;
            }
            else
            {
                entity4.entityPosition.endX = entity4.entityPosition.startX;
                entity4.entityPosition.endZ = y1;
            }
        }
        else
        {
            entity4.entityPosition.endX = x1;
            entity4.entityPosition.endZ = y1;
        }
        addEntity4(entity4);
    }
    ((MainWindow*)main)->setWindowModified(true);
}
示例#3
0
void MapEditor::mousePressEvent(QMouseEvent *event)
{
    startX = convertCoordinate(event->pos().x(),0);
    startY = convertCoordinate(event->pos().y(),1);
    
    if(event->button() == 4)
    {
        move = true;
        return;
    }
    if( objType >= 100 && objType <= 102)
    {
      findClosestEntity(&startX,&startY);
    }
    if(event->button()==2)
    {
        discoverAndDelete(startX,startY);
        return;
    }
    isClicked = true;
    if( objType == MapEntityType::MODEL )
    {
        strcpy(modelEntity.modelName,modelName.data());
        modelEntity.type = objType;
        modelEntity.entityPosition.startX = startX;
        modelEntity.entityPosition.startZ = startY;
        modelEntity.direction = degree;
        addModelEntity(modelEntity);
        ((MainWindow*)main)->setWindowModified(true);
    }
    if( objType == MapEntityType::SPAWN_POINT || objType == MapEntityType::LIGHT_POINT || objType < 100  )
    {
        entity2.type = objType;
        entity2.entityPosition.startX = startX;
        entity2.entityPosition.startZ = startY;
        entity2.direction = degree;
        std::cout<<degree<<std::endl;
        addEntity2(entity2);
        ((MainWindow*)main)->setWindowModified(true);
    }

}