Hello Guest

getting player coordinates

  • 6 Replies
  • 9010 Views
getting player coordinates
« on: January 03, 2014, 00:20:03 »
I am trying to make my mob chase the player but it seems that i can't get an updated version of my player coordinates cause my players spawn at 100 x and 100 z it keeps printing that value but i have moved already but it stay's 100 and i can't seem to get it updated ii have tried evrything on my mind

Re: getting player coordinates
« Reply #1 on: January 03, 2014, 13:27:54 »
1) Use punctuation! Big pet-peeve of mine. Act (at least a little) professional. :-\
2) We need code to have any hope of figuring out your problem. :P
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Re: getting player coordinates
« Reply #2 on: January 03, 2014, 14:40:37 »
1) Use punctuation! Big pet-peeve of mine. Act (at least a little) professional. :-\
2) We need code to have any hope of figuring out your problem. :P

srry that i am not english and btw i will give you the players class and the mob ai class

Player.class
Code: [Select]

package net.game.entity;

import static org.lwjgl.opengl.GL11.*;

import org.lwjgl.input.*;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.UnicodeFont;
import org.newdawn.slick.font.effects.*;

import net.game.ZombieHouse;
import net.game.util.*;
import net.game.world.World;

public class Player extends Entity{

public float speed = 0.70f;
public float jumpSpeed = 0.40f;

public boolean jumping = false;

public int list;

public UnicodeFont font;
public java.awt.Font awtFont;
public World world;

public CrossHair crossHair;

@SuppressWarnings("unchecked")
public Player(){
position = new Vector3f(100, 60, 100);
rotation = new Vector3f(180, 120, 0);

awtFont = new java.awt.Font("Courier New", java.awt.Font.BOLD, 18);
font = new UnicodeFont(awtFont);
font.getEffects().add(new ColorEffect(java.awt.Color.WHITE));

world = new World(0, 0);

crossHair = new CrossHair();
}

public void useCam() {
glRotatef(rotation.x, 1, 0, 0);
glRotatef(rotation.y, 0, 1, 0);
glRotatef(rotation.z, 0, 0, 1);
glTranslatef(position.x, position.y + -30, position.z);
}

public void checkPhysics(){

if(position.y > 0  && !jumping){
position.y -= gravity;
}

/*//5 pixels offset from the beginning (Possibly changing)
if(position.x + 5 < world.width * world.tileSize || position.y < -2){//size times tilesize = - 32 offset to the back
position.y -= gravity;
}

if(position.z + 5 < world.width * world.tileSize || position.y < -2){
position.y -= gravity;
}

//getWorldSize() gets the size in the world class manually set unfortunantly
if(position.x - 5 > world.getWorldSize() || position.y < -2){
position.y -= gravity;
}

if(position.z + 2 > world.getWorldSize() || position.y < -2){
position.y -= gravity;
}

if(position.y < -300){
position.x = 10;
position.y = 20;
position.z = 10;
}*/
}

//jumping variables
int jumpLimit = 40;
float jumpHeight = 0;

final float currentJumpDelay = 19f;

float jumpDelay = currentJumpDelay;

boolean canJump = false;

public void jump(){

jumpHeight++;
canJump = true;

if(jumpHeight < jumpLimit && jumping && canJump && !(position.y > jumpLimit)){
position.y += jumpSpeed;
}else{
jumping = false;
canJump = false;
}
}

public void update(){
boolean forward = Keyboard.isKeyDown(Keyboard.KEY_W);
boolean back = Keyboard.isKeyDown(Keyboard.KEY_S);
boolean left = Keyboard.isKeyDown(Keyboard.KEY_A);
boolean right = Keyboard.isKeyDown(Keyboard.KEY_D);
boolean space = Keyboard.isKeyDown(Keyboard.KEY_SPACE);
boolean Lshift = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT);
//boolean esc = Keyboard.isKeyDown(Keyboard.KEY_ESCAPE);
//boolean Lctrl = Keyboard.isKeyDown(Keyboard.KEY_LCONTROL);

double mouseDX = Mouse.getEventDX();
double mouseDY = Mouse.getEventDY();

checkPhysics();

System.out.println(position.x + " , " + position.y + " , " + position.z);

//if jumpLimit reached and you stopped moving count down the delay
if(jumpHeight > jumpLimit || !jumping){
jumpDelay -= 0.5f;
}

//the delay between jumping set above the jumping method
if(jumpDelay == 0){
jumpHeight = 0;
jumpDelay = currentJumpDelay;
canJump = true;
}

//the movement features calculations are all working correctly
if(Mouse.isGrabbed() && Mouse.isInsideWindow()){
if(forward){
position.z -= speed * Math.sin(Math.toRadians(rotation.y + 90));
position.x -= speed * Math.cos(Math.toRadians(rotation.y + 90));
}
if(back){
position.z += speed * Math.sin(Math.toRadians(rotation.y + 90));
position.x += speed * Math.cos(Math.toRadians(rotation.y + 90));
}
if(left){
position.x += speed * Math.cos(Math.toRadians(rotation.y));
position.z += speed * Math.sin(Math.toRadians(rotation.y));
}
if(right){
position.x -= speed * Math.cos(Math.toRadians(rotation.y));
position.z -= speed * Math.sin(Math.toRadians(rotation.y));
}

if(space){
jumping = true;
jump();
}else if(!space){
jumping = false;
}

if(Lshift){
speed = 1.50f;
}else if (!Lshift){
speed = 0.70f;
}

while(Mouse.next()){
if(Mouse.isGrabbed()){
rotation.y -= mouseDX;

if(rotation.x < 270 || rotation.x > 90){
rotation.x -= mouseDY;
}

if(rotation.x < 90.1f){
rotation.x = 90f;
}

if(rotation.x > 270.1f){
rotation.x = 270.0f;
}
}
}
}
}

public void renderHUD(){
glPushMatrix();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, ZombieHouse.width, ZombieHouse.height, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
crossHair.render();
glPopMatrix();
glDisable(GL_TEXTURE_2D);
try {
font.loadGlyphs();
} catch (SlickException e) {
e.printStackTrace();
}
glEnable(GL_TEXTURE_2D);
glPushMatrix();
glLoadIdentity();
glDisable(GL_COLOR_MATERIAL);
glDisable(GL_DEPTH_TEST);
//glDisable(GL_FOG);
font.drawString(15, 10, "FPS: " + ZombieHouse.fps);
font.drawString(15, 30, "UPS: " + ZombieHouse.ups);
font.drawString(15, 50, "X:" + position.x);
font.drawString(15, 70, "Y:" + position.y);
font.drawString(15, 90, "Z:" + position.z);
font.drawString(25, 680, ZombieHouse.version);
font.addGlyphs(".:-+0123456789");
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_DEPTH_TEST);
//glEnable(GL_FOG);
glPopMatrix();
}

public void render(){
super.render();
}
}



and

AIZombieMovement.class
Code: [Select]

package net.game.entity.ai;

import java.util.Random;
import net.game.entity.*;
import net.game.util.Vector3f;
import net.game.world.World;

public class AIZombieMovement extends Entity{

public World world;
public Player player;

public AIZombieMovement(){
position = new Vector3f(300, 0, 300);

world = new World(0, 0);
player = new Player();
}

int time = 0;
int xa = 0;
int za = 0;

public void walk(Random random){
time++;
if (time % 180 == 0) {
xa = random.nextInt(3) - 1;
za = random.nextInt(3) - 1;
if(random.nextInt(3) == 0){
xa = 0;
za = 0;
}
}

if(position.x + 5 > world.width * world.tileSize || position.x - 5 < world.getWorldSize()){
move(xa, 0);
}else{
xa++;
}

if(position.z + 5 > world.width * world.tileSize || position.z + 2 < world.getWorldSize()){
move(0, za);
}else{
za++;
}

if(player.getX() < this.position.x - 50){
}

System.out.println(player.getX());
}
}



Re: getting player coordinates
« Reply #3 on: January 06, 2014, 15:00:34 »
Looks like we need the code for the Entity class (since that is where all the moving and storing of information is done).
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Re: getting player coordinates
« Reply #4 on: January 10, 2014, 21:47:27 »
sure didn't think of that oops

Entity.class
Code: [Select]

package net.game.entity;

import org.lwjgl.util.vector.Vector3f;

import net.game.world.*;
import static org.lwjgl.opengl.GL11.*;

public class Entity {

protected Vector3f position;
protected Vector3f rotation;
protected World world;

protected float gravity = 1.10f;

public Entity(){
position = new Vector3f(0, 0, 0);
rotation = new Vector3f(0, 0, 0);
world = new World(0, 0);
}

public void init(World world){
this.world = world;
}

protected void setPosition(float x, float y, float z){
position.x = x;
position.y = y;
position.z = z;
}

protected void setRotation(float rx, float ry, float rz){
rotation.x = rx;
rotation.y = ry;
rotation.z = rz;
}

public void translate(float x, float y, float z) {
position.x += x;
position.y += y;
position.z += z;
}

public void rotate(float x, float y, float z) {
rotation.x += x;
rotation.y += y;
rotation.z += z;
}

public void move(float xa, float za) {
position.x -= xa;
position.z -= za;
}

public Vector3f getPosition() {
return position;
}

public void update(){
}

public void render(){
glTranslatef(-position.x, world.y - 28.0f, -position.z);
glRotatef(rotation.x, 1, 0, 0);
glRotatef(rotation.y, 0, 1, 0);
glRotatef(rotation.z, 0, 0, 1);
}
}



Re: getting player coordinates
« Reply #5 on: January 17, 2014, 13:34:31 »
I think the problem is that you are creating a new Player instance inside the constructor of AIZombieMovement. You are then using that player for your calculations instead of whatever Player you actually have moving. Maybe try passing in the real Player to the AIZombieMovement constructor?
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Re: getting player coordinates
« Reply #6 on: January 18, 2014, 18:05:56 »
i actualy fixed it with a setter but yiur tip actually is something i could btw i did think of this