极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 14537|回复: 2

Processing之旅-----【好玩的库之AI_for_2D_Games5】

[复制链接]
发表于 2013-10-14 14:40:55 | 显示全部楼层 |阅读模式
下面说一下,避障的功能,其实避障的功能首先一个条件是什么?有障碍。
[pre lang="processing" line="1"]import game2dai.entities.*;
import game2dai.entityshapes.ps.*;
import game2dai.maths.*;
import game2dai.*;
import game2dai.entityshapes.*;
import game2dai.fsm.*;
import game2dai.steering.*;
import game2dai.utils.*;
import game2dai.graph.*;

// ObstacleAvoid_01.pde
int[] obs = new int[] {
  100, 100, 36,
  200, 200, 32,
  270, 70, 16,
  380, 180, 37,
  510, 110, 27,
  520, 210, 23,
  400, 80, 10,
  90, 240, 6
};
World world;
Domain wd;
Vehicle tank;  
BitmapPic view;

StopWatch sw = new StopWatch();

public void setup() {
  size(600, 300);
  world = new World(width, height);
  wd = new Domain(0, 0, width, height);

  ObstaclePic obView = new ObstaclePic(this, color(0, 96, 0), color(0), 3);
  for (int i = 0; i < obs.length; i += 3) {
    Obstacle obstacle = new Obstacle(
    new Vector2D(obs, obs[i+1]), // position
    obs[i+2] // collision radius
    );
    obstacle.renderer(obView);
    world.add(obstacle);
  }

  // Create the tank
  tank = new Vehicle(
  new Vector2D(width/2, height/2), // position
  16, // collision radius
  new Vector2D(0, 0), // velocity
  60, // maximum speed
  new Vector2D(1, 1), // heading
  7, // mass
  1.5f, // turning rate
  1000 // max force
  );
  view = new BitmapPic(this, "tanks32_4.png", 8, 1, 0);  
  view.showHints(Hints.HINT_HEADING | Hints.HINT_VELOCITY | Hints.HINT_OBS_AVOID);
  tank.renderer(view);
  tank.AP().obstacleAvoidOn().wanderOn();
  tank.AP().wanderFactors(60, 40, 10);
  tank.AP().obstacleAvoidDetectBoxLength(45);
  tank.worldDomain(wd, SBF.WRAP);
  world.add(tank);
}

public void draw() {
  double elapsedTime = sw.getElapsedTime();
  // Animate the tank image
  float speed = (float) tank.speed();
  float maxSpeed = (float) tank.maxSpeed();
  if (speed > 1) {
    int newInterval = (int) map(speed, 0, maxSpeed, 600, 40);
    view.interval(newInterval);
  }
  else {
    view.interval(0);
  }
  world.update(elapsedTime);
  background(220, 255, 220);
  world.draw();
}[/code]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2013-10-14 21:06:43 | 显示全部楼层
这个。。这个。。。都开始避障了。。。厉害
回复 支持 反对

使用道具 举报

发表于 2013-10-15 09:30:07 | 显示全部楼层
niubility!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-19 15:28 , Processed in 0.046682 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表