我有一个学校项目,为2D赛车游戏建立一个AI,它将与其他几个AI竞争.
我们获得了赛道的黑白位图图像,我们可以在收到地图后选择我们的汽车的基本属性(操控,加速,最大速度和制动).AI连接到游戏的服务器,并为当前加速和转向提供几次秒数.顺便说一句,我选择的语言是C++.问题是
所以,我正在研究AndEngine PhysicsExample代码.我想知道这种方法的含义是什么(http://pastebin.com/Day2hciB):
private void addFace(final float pX, final float pY) {
this.mFaceCount++;
Debug.d("Faces: " + this.mFaceCount);
final AnimatedSprite face;
final Body body;
if(this.mFaceCount % 4 == 0) {
face = new AnimatedSprite(pX, pY, this.mBoxFaceTextureRegion, this.getVertexBufferObjectManager());
body = PhysicsFactory.createBoxBody(this.mPhysicsWorld, face, BodyType.DynamicBody, FIXTURE_DEF);
} else if (this.mFaceCount % 4 == 1) {
face = new AnimatedSprite(pX, pY, this.mCircleFaceTextureRegion, this.getVertexBufferObjectManager());
body = PhysicsFactory.createCircleBody(this.mPhysicsWorld, face, BodyType.DynamicBody, FIXTURE_DEF);
} else if (this.mFaceCount % 4 == 2) {
face = new AnimatedSprite(pX, pY, this.mTriangleFaceTextureRegion, …Run Code Online (Sandbox Code Playgroud) 我正在制作一个蛇游戏。每当我按箭头键向一个方向移动然后向另一个方向按一个键时,蛇就会对角移动。(例如,如果我先按向右然后向上按。)即使释放了前一个键,也会发生这种情况。我怎么能阻止这个?
# x and y marks the player's position
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
x_change = -10
if event.key == pygame.K_RIGHT:
x_change = 10
if event.key == pygame.K_UP:
y_change = -10
if event.key == pygame.K_DOWN:
y_change = 10
x += x_change
y += y_change
Run Code Online (Sandbox Code Playgroud) 我是编程新手.目前,我正在努力使事情变得简单,所以我正在重新创建经典游戏Pong来学习.但是,我遇到了这个问题.播放器控制器工作正常,但按W和SI时不希望播放器移动.请帮忙!
if(Input.GetKey(KeyCode.W)) & Input.GetKey(KeyCode.S){
player_one.GetComponent<Rigidbody2D>().velocity = new Vector2(0f, 0f);
}
Run Code Online (Sandbox Code Playgroud) 我正在创建一个游戏,我想在玩家死亡时显示一个面板
我尝试了不同的方法,但似乎没有一个能做我想做的
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DeadOrAlive : MonoBehaviour
{
public GameObject Player;
public GameObject deadPanel;
void Update()
{
if (!GameObject.FindWithTag("Player"))
{
deadPanel.SetActive(true);
}
}
}
Run Code Online (Sandbox Code Playgroud) 嘿,我只是想让我的子弹在接触地面时自行摧毁,
我试图在 2 秒后摧毁它,但它有同样的问题,
这就是我的代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyBullet : MonoBehaviour
{
GameObject target;
public float speed;
Rigidbody2D bulletRB;
void Start()
{
bulletRB = GetComponent<Rigidbody2D>();
target = GameObject.FindGameObjectWithTag("Player");
Vector2 moveDir = (target.transform.position - transform.position).normalized * speed;
bulletRB.velocity = new Vector2(moveDir.x, moveDir.y);
Destroy(this.gameObject, 2);
}
}
Run Code Online (Sandbox Code Playgroud) 这是我的代码.我有对应设置为20,我得到警告可能错误空语句与这些行.我的目标是提高速度,让你越努力.当我输入数字20时会发生同样的问题.到目前为止,它每次只增加0.75.
if(speed < counterpart);
{
speed += 0.25F;
}
if(speed > counterpart);
{
speed += 0.5F;
}
Run Code Online (Sandbox Code Playgroud)