小编cep*_*tno的帖子

游戏编程ai:缩放墙壁以找到玩家?

我一直在研究这种人工智能方法.int如果一堵墙阻挡了他通往玩家的路径,它基本上可以为敌人提供每个方向.这在大多数情况下不起作用.有时敌人会经历无法穿过的裂缝.其他时候它会被卡在有明显空隙的墙上.我会附上我的代码,但如果它看起来效率太低或者没有解决问题的方法,我并不反对改变我的方法.我只是想知道这些事情是如何正常完成的,这样我就能以更好的(和工作!)方式实现它.

我的代码:

    public void update(ArrayList<Wall> walls, Player p){

    findPlayer(p.getX(), p.getY());

    boolean isCollision = false;
    System.out.println(isCollision);
    //if movement straight towards the player is blocked, move along the walls
    for(Wall w : walls){
        if(Helper.isBoundingBoxCollision((int)(x + vectorToPlayer.getDX() * SPEED), (int)(y + vectorToPlayer.getDY() * SPEED), width, height, w.getX(), w.getY(), w.width, w.height)){
            isCollision = true;

            if(Math.abs(vectorToPlayer.getDX()) > Math.abs(vectorToPlayer.getDY())){
                if(vectorToPlayer.getDX() > 0)
                    WALL_COLLISION = 3;
                else
                    WALL_COLLISION = 1;
            }
            else if(Math.abs(vectorToPlayer.getDX()) <     Math.abs(vectorToPlayer.getDY())){
                if(vectorToPlayer.getDY() > 0)
                    WALL_COLLISION = 0;
                else
                    WALL_COLLISION = 2; …
Run Code Online (Sandbox Code Playgroud)

java game-ai

7
推荐指数
1
解决办法
474
查看次数

与目标'Google API'不兼容的AVD

我正在开发一个Android应用程序并尝试在AVD上启动它.API设置为Android 2.3.3.我有一个2.3.3模拟器(sdk版本10),并且android清单显示:

    <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="10" />
Run Code Online (Sandbox Code Playgroud)

我将目标更改为10以匹配我在项目中包含的api.我该如何解决此错误:

[2013-01-30 23:18:47 - kiloboltandroidframework] Failed to find an AVD compatible with target 'Google APIs'.
[2013-01-30 23:18:48 - kiloboltandroidframework] Still no compatible AVDs with target 'Google APIs': Aborting launch.
Run Code Online (Sandbox Code Playgroud)

android android-virtual-device

4
推荐指数
1
解决办法
2万
查看次数

与Matplotlib和TeX的均匀间距

我正在为数学课绘制一些图表,我无法在情节图例中得到和平定义的间距.我目前正在使用

\,
Run Code Online (Sandbox Code Playgroud)

在TeX的一个空间,但碰到的情况是一个稍微更远了比其它可能是由于等式的左边多少占用.这是我的代码

import matplotlib.pyplot as plt
import numpy as np
import math as math

# 0-1
x = np.linspace(0, 1)
y = np.power(x, 2)
plt.plot(x, y, label=r"$t^2 \,\,\,\,\,\, 0 \leq t \leq 1$")

#1-2
x = [1,2]
y = [1,1]
plt.plot(x, y, label=r"$1 \,\,\,\,\,\,\, 1 < t \leq 2$")

#2-3
x = np.linspace(2, 3)
y = 3-x
plt.plot(x, y, label=r"$3 - t \,\,\,\, 2 < t \leq 3$")


plt.grid()
plt.axis([0,3,0,1.5])
plt.legend(loc='upper right')
plt.show()
Run Code Online (Sandbox Code Playgroud)

这是结果

如何有效地格式化这种方式,无论左边的像素大小如何都能始终有效?

python matplotlib tex

4
推荐指数
1
解决办法
259
查看次数

如何轻松打印阵列?

我目前正在使用数组,每次我需要打印一个我做一个for循环.

System.out.print("[");
for(int i = 0; i < arr.length; i++){
    System.out.print(arr[i] + ", ");
}
System.out.println("]");
Run Code Online (Sandbox Code Playgroud)

这似乎是一个将内置到java中的功能(我正在使用java).是否有内置的方法来打印数组?

java arrays

3
推荐指数
2
解决办法
408
查看次数

如何使用已经使用python脚本导入的包调出python shell?

我想提出一个python窗口(可能是空闲或基于cmd),已经通过双击python脚本导入了一些包.这可能吗?如果是这样,我该怎么办?

python python-3.x

1
推荐指数
1
解决办法
109
查看次数

编写将遵循LayoutManager规范的自定义JPanel

我正在尝试编写一个自定义JPanel,它遵循包含JPanel的布局管理器(我正在使用gridbag).我的自定义JPanel在这里粘贴的时间有点太长了,但是要覆盖所有要覆盖的方法的清单以使其工作.

以下是我的自定义JPanel的摘录:

        public class GridPanel extends JPanel implements MouseMotionListener, MouseListener{
            private Rectangle offdutyRect, sbRect, driveRect, onRect;
            private int delta = 60;
            private int[][] gridArray;
            int draggedStartX = -1;
            int draggedStartY = -1;
            private int dutyStatusSpacing = 60;
            private int totalSpacing = 100;

            public GridPanel(){
            this.setSize(new Dimension(800, 100));
            this.addMouseMotionListener((MouseMotionListener) this);
            this.addMouseListener(this);
            int gridArrayColumns = 24*60/delta;
            gridArray = new int[4][gridArrayColumns];

            int r = 0;
            int rHeight = this.getHeight()/4;
            offdutyRect = new Rectangle(this.getX() + dutyStatusSpacing, this.getY() + r*rHeight, this.getWidth() - totalSpacing, rHeight);
            r++; …
Run Code Online (Sandbox Code Playgroud)

java swing jpanel layout-manager preferredsize

0
推荐指数
1
解决办法
129
查看次数