Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Desperate Need of help

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool Desperate Need of help

    Hi to anyone that is reading this, and thank you for taking the time to do so. I have been trying to get some code figured out and im going out of my mind.
    THE GOAL: Have a playerobject (square) and a enemyobject(square) and get a vector between them to determine if they are in line of sight of each other. (there maybe terrain objects, also square in the way). All of these objects are derived from the same "Entity" super class. (I WISH I WAS BETTER AT MATH FOR THIS) Here is my code so far, it just determines if the player is close enough to the enemy for the enemy to pay attention to him.

    I think the proper way to do this.. is to create a line between the player and enemy, get all the terrainobjects that are in bounds of the rectangle of possibles, then check the objects to see if any of thier boundries are touching the line between the player and enemy. Sadly this is beyond my skills.. can someone please help me get started. AND/Or tell me if it is possible to make a 360 degree projectile but using graphics.Drawline() with the vector line between the player and enemy.

    public void creatureShoot() {
    CreatureEntity creature;
    int xDistance, yDistance;
    int playerX, playerY, creatureX, creatureY, totalDistance;
    for (int j = 0; j < currentCreatureObj.size(); j++) {
    creature = (CreatureEntity) currentCreatureObj.get(j);
    //get coords of the center of the sprites
    playerX = (int) (playerEnt.getX() + (playerEnt.getWidth()) / 2);
    playerY = (int) (playerEnt.getY() + (playerEnt.getHeight()) / 2);
    creatureX = (int) (creature.getX() + (creature.getWidth()) / 2);
    creatureY = (int) (creature.getY() + (creature.getHeight()) / 2);

    xDistance = Math.abs(playerX - creatureX);
    yDistance = Math.abs(playerY - creatureY);
    totalDistance = (int) Math.sqrt(Math.pow(xDistance, 2) + Math.pow(yDistance, 2));

    if (totalDistance <= SHOOTING_RANGE) {
    String ref = "null.jpg";
    //NEED TO CHANGE THIS TO 360 DEGREE SHOOTING
    int direction = (int) creature.getLastMovementDirection();
    if (direction == Entity.NORTH || direction == Entity.SOUTH) { ref = "verticalmissile.gif"; }
    else if (direction == Entity.WEST || direction == Entity.EAST) { ref = "horizontalmissile.gif"; }
    System.out.println(totalDistance + " creature in range of player, should shoot now");
    //CREATE A MISSLE OBJ IN THE LAST DIRECTION THE MONSTER WAS FACING.. NEEDS TO SWITCH TO 360 DEGREE VECTOR TO PLAYER
    currentMissileObj.add(new Missile(ref, creature.getX() + creature.getWidth() / 2, creature.getY() + creature.getHeight() / 2, direction));
    }
    }
    }
    Last edited by mszyndlar; October 15th, 2011 at 12:51 AM.


  2. #2
    Junior Member
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Desperate Need of help

    i figured out that what i need is to use the CohenSutherland method to check if my ArrayList of obstacles touch a line, i just need some help with implementationn

  3. #3
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Desperate Need of help

    1. Use code tags to enclose your tag.
    2. Use some editor to format the code.
    3. Ask about the exact problem. Your problem should be precise, short and descriptive enough to give knowledge about, you are asking.

Similar Threads

  1. programming hw desperate help!
    By midnightdream13 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 16th, 2011, 07:58 AM
  2. What is wrong with this code, please desperate
    By macnasty in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 6th, 2010, 10:26 AM

Tags for this Thread