Results 1 to 2 of 2
  1. #1
    Kerrai is offline Member
    Join Date
    Oct 2010
    Posts
    12
    Rep Power
    0

    Default Java game dev, Basic AI

    Greetings

    I have a project going on and i am responsible for programming the AI for the random monsters that will roam our map.

    I got the monster to bounce between left and right or up and down. What i havnt understood is if its possible for it to check if it can go left/right if its going up/down. I have set it up like

    Java Code:
    if (e1.intersects(b2))
                    ec.eSpeed(-1);
                    //ec.right(!true);
                 if (e1.getY() == 0) {
                	 ec.eSpeed(1);
                	// ec.right(true);
                 }
                 if (e1.getY() == 665) {
                	 ec.eSpeed(-1);
                	// ec.right(true);
                 }
    This part works, it goes down and then up again but i dont see how i could make it a chance it tries to go left or right.

    Java Code:
    if (!e1.intersects(b2)){
                  ec.right(true); 
                  ec.move_right();
                  }
                
                if (e1.intersects(b2)){
                			ec.right(!true);
                			ec.down(true);
                			ec.move_down();
                		
                        }
    This part is what i would like to use, i have set up the booleans for the four directions but as you can see my first If statement is enaged again as soon as the monster stops to intersect the block (b2 is just a made up rectangle). So it goes to the right, intersects, goes down so it doesnt intersect anymore but then continues right. I would like for it to just stop moving right and continue on its path down.

    I dont know if you need more code, its quite heavy, well atleast for me as a new guy.

    Well any thoughts or help is more then welcome

    //Kerrai

  2. #2
    demonick is offline Member
    Join Date
    Dec 2010
    Posts
    27
    Rep Power
    0

    Default

    possibly add boolean values e. g. movingDown, movingRight, then check and change them on intersection, sorry but its hard to understand at first what is needed, so i can just give an hint.

Similar Threads

  1. Basic Java help, AIM?
    By jkswebsite in forum New To Java
    Replies: 4
    Last Post: 07-11-2012, 06:17 PM
  2. Basic Football management game
    By Wakesta in forum Java Gaming
    Replies: 1
    Last Post: 07-05-2010, 10:50 PM
  3. Basic counter timer for a game?
    By Laura in forum New To Java
    Replies: 1
    Last Post: 04-18-2010, 01:46 AM
  4. Beginner at very basic game development
    By codermom in forum New To Java
    Replies: 4
    Last Post: 01-20-2009, 04:22 AM
  5. basic java help
    By adred in forum New To Java
    Replies: 0
    Last Post: 03-08-2008, 12:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •