
-----------------------------------
xzecution2
Mon Jan 19, 2009 9:39 pm

Urgent!
-----------------------------------
Hi, so I'm creating a program that needs a ship to have AI and all i need it to do is to be able to move randomly across the x-axis and shoot downwards randomly.  
here's an excerpt from my code that makes the ship.

import java.awt.Graphics;
import java.awt.Color;
import java.awt.Image; 

public class Player2
{
        // Declaring integral variables
        private int x_pos=150;
        private int y_pos=150;
        private Image xwing;
        private int minx = 1, maxx=900;
        private int x_speed = 3;
   
        

        public Player2(int x, int y)
        {
                x_pos = x;
                y_pos = y;
        }
        
        
             
        public Shot generateShot()
        {
                Shot shot = new Shot(x_pos, y_pos);

                return shot;
        }

        public void drawPlayer2(Graphics g)
        {
                g.setColor(Color.blue);
                int 


Mod Edit: Remember to use syntax tags! Thanks :) [syntax="java"]Code Here[/syntax]

-----------------------------------
Insectoid
Mon Jan 19, 2009 9:41 pm

RE:Urgent!
-----------------------------------
First, use code tags. Second, title your thread descriptively; 'urgent' tells us nothing of your problem.

-----------------------------------
xzecution2
Mon Jan 19, 2009 9:45 pm

RE:Urgent!
-----------------------------------
sorry about that, I don't think i'll be able to edit it now though since you can't edit posts that have been replied to.

-----------------------------------
DemonWasp
Tue Jan 20, 2009 1:02 am

RE:Urgent!
-----------------------------------
I'm assuming that you have:

Player (basic player, not used on its own)
HumanPlayer extends Player (the human, controlled by the keyboard)
AIPlayer extends Player (the computer)

Then you need to add a method (let's call it "update") to Player, overridden by AIPlayer, which runs the AI to determine what to do. In HumanPlayer, update() checks the keyboard for input and moves that player.

Then your main game loop looks like this:

loop
    for ( Player player : Players ) {
        player.update();
    }
    for ( Player player : Players ) {
        player.draw ( g );
    }
end loop
