Java Game Programming - Checkpoint System

preview_player
Показать описание
In this episode of Java Game Programming episode 22, we create our checkpoint system for the enemies of our tower defense game. This system implementation will span over the course of a few videos, but in this tutorial we cover the first method of our pathfinding AI: Finding Direction.

Java Game Programming Classes:
Рекомендации по теме
Комментарии
Автор

*LEAVING THIS HERE FOR OTHERS WITH THE SAME PROBLEM*
The problem is that I was spawning the wave right next to the edge of the screen, and when it tested the up direction it tried a tile that didn't actually exist (y of -1) so it crashed.

Exception in thread "main" -1
    at
    at
    at Enemy.<init>(Enemy.java:38)
    at Boot.<init>(Boot.java:35)
    at Boot.main(Boot.java:51)

I tried rewatching some parts and randomly bug checking, then I even copy-pasted the TileGrid, Enemy, and Tile classes into my code, and this exact exception still happens.

Ideas?

Trophonix
Автор

hello

the ufo checks for the initial direction but doens't keep checking for different tiles
any ideas

alalko
Автор

I Have a problem:
the method Delta() is undefined for the type Enemy

that is my Enemy class:
package data;

import static helper.Artist.DrawQuadTex;

import java.util.ArrayList;

import

public class Enemy {
private int width, height, health;
private float speed, x, y;
private Texture texture;
private Tile startTile;
private boolean first = true;
private TileGrid grid;

private ArrayList<Checkpoint> checkpoint;
private int[] directions;

public Enemy(Texture texture, Tile startTile, TileGrid grid, int width, int height, float speed) {
this.texture = texture;
this.startTile = startTile;
this.x = startTile.getX();
this.y = startTile.getY();
this.width = width;
this.height = height;
this.speed = speed;
this.grid = grid;

this.checkpoint = new ArrayList<Checkpoint>();
this.directions = new int[2];
//X direction
this.directions[0] = 0;
//Y direction
this.directions[1] = 0;
directions = FindNextD(startTile);
}

public void Update() {
if(first)
first = false;
else {
x += Delta() * directions[0];
y += Delta() * directions[1];
}
}

private int[] FindNextD(Tile s) {
int[] dir = new int[2];
Tile u = grid.GetTile(s.getXPlace(), s.getYPlace() - 1);
Tile r= grid.GetTile(s.getXPlace() + 1, s.getYPlace());
Tile d = grid.GetTile(s.getXPlace(), s.getYPlace() + 1);
Tile l = grid.GetTile(s.getXPlace() - 1, s.getYPlace());

if(s.getType() == u.getType()) {
dir[0] = 0;
dir[1] = -1;
} else if ( s.getType() == r.getType()) {
dir[0] = 0;
dir[1] = 1;
} else if ( s.getType() == d.getType()) {
dir[0] = 1;
dir[1] = 0;
} else if ( s.getType() == l.getType()) {
dir[0] = 0;
dir[1] = -1;
} else {
System.out.println("NO DIRECTION FOUND");
}

return dir;
}

/*
private boolean pathContinues() {
boolean answer = true;

Tile myTile = grid.GetTile((int) (x / 64), (int) (y / 64));
Tile nextTile = grid.GetTile((int) (x / 64) + 1, (int) (y / 64));

if (myTile.getType() != nextTile.getType())

answer = false;

return answer;
}
*/
public void Draw(){
DrawQuadTex(texture, x, y, width, height);
}

public int getWidth() {
return width;
}

public void setWidth(int width) {
this.width = width;
}

public int getHeight() {
return height;
}

public void setHeight(int height) {
this.height = height;
}

public int getHealth() {
return health;
}

public void setHealth(int health) {
this.health = health;
}

public float getSpeed() {
return speed;
}

public void setSpeed(float speed) {
this.speed = speed;
}

public float getX() {
return x;
}

public void setX(float x) {
this.x = x;
}

public float getY() {
return y;
}

public void setY(float y) {
this.y = y;
}

public Texture getTexture() {
return texture;
}

public void setTexture(Texture texture) {
this.texture = texture;
}

public Tile getStartTile() {
return startTile;
}

public void setStartTile(Tile startTile) {
this.startTile = startTile;
}

public boolean isFirst() {
return first;
}

public void setFirst(boolean first) {
this.first = first;
}

public TileGrid getTileGrid() {
return grid;
}

}

fab
Автор

Why does the console say "DIE DIE DIE DIE DIE DIE DIE" over and over again? (I noticed this around 3:50)

elliottwalker
Автор

White girls be all like "FindNextD()"

MicahVance