Results 1 to 7 of 7
  1. #1
    Jressing is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default Impossible error

    Hey Guys,
    Im working on a game im writing but i have encountered an error i cant solve on my own. Can you guys take a look pls? Any help/suggestions are appreciated. (error message is at bottom)

    Main
    Java Code:
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class FCApplet extends Applet implements ActionListener
    {
    
      static Rectangle r = new Rectangle(275, 175, 16, 16);
      
       // classes & thread
      private Thread th;
      private Player player;
      private Shot [] shots;
      private AI Ai = AI3(AI2);
    
       // movement/looking
      private final int shotSpeed = 5;
      private final int playerLeftSpeed = -2;
      private final int playerRightSpeed = 2;
      private final int playerUpSpeed = -2;
      private final int playerDownSpeed = 2;
      private boolean playerMoveLeft;
      private boolean playerMoveRight;
      private boolean playerMoveUp;
      private boolean playerMoveDown;
      private boolean mouseMove;
    
       // Images
      private Image dbImage;
      private Graphics dbg;
      private Image background;
      private Image mist;
      private Image mist1;
      private Image mist2;
      Image speler;
      Image zombie;
    
       // Buttons
      JButton play;
      private JRadioButton Makkelijk, Gemiddeld, Moeilijk;
      private JRadioButton Box, Maze;
      private ButtonGroup group1, group2;
    
       // Stuff
      AudioClip soundFile1;
      AudioClip soundFile2;
    
    
      public void init()
      {
        background = null;
        
        JButton play = new JButton(new ImageIcon(getClass().getResource("play.png")));
        play.setMnemonic('C');
    
        //play = new Button("Play");
        //  play.setFont(new Font("Arial", Font.ITALIC, 20));
    
        Makkelijk = new JRadioButton("Makkelijk", false);
        Gemiddeld = new JRadioButton("Gemiddeld", true);
        Moeilijk = new JRadioButton("Moeilijk", false);
        Box = new JRadioButton("Box", false);
        Maze = new JRadioButton("Maze", false);
        add(Makkelijk);
        add(Gemiddeld);
        add(Moeilijk);
        add(Box);
        add(Maze);
        
        group1 = new ButtonGroup();
        group1.add(Makkelijk);
        group1.add(Gemiddeld);
        group1.add(Moeilijk);
        group2 = new ButtonGroup();
        group2.add(Box);
        group2.add(Maze);
        
        JPanel moeilijkheidsgraad2 = new JPanel();
        moeilijkheidsgraad2.add(Makkelijk);
        moeilijkheidsgraad2.add(Gemiddeld);
        moeilijkheidsgraad2.add(Moeilijk);
        JPanel mapkeuze2 = new JPanel();
        mapkeuze2.add(Box);
        mapkeuze2.add(Maze);
        add(moeilijkheidsgraad2);
        add(mapkeuze2);
        
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        player = new Player(d.width / 2, d.height / 2);
        shots = new Shot[100];
        
        add(play);
        play.addActionListener(this);
        
        soundFile2 = getAudioClip(getDocumentBase(), "memento.wav");
        soundFile2.loop();
      }
    
      public void loadImages()
      {
        try
        {
          background = getImage(getDocumentBase(), "background.jpg");
          mist = getImage(getDocumentBase(), "mist.jpg");
          mist1 = getImage(getDocumentBase(), "mist1.jpg");
          mist2 = getImage(getDocumentBase(), "mist2.jpg");
          speler = getImage(getDocumentBase(), "spelertje.png");
          zombie = getImage(getDocumentBase(), "zombie.png");
        }
        catch(Exception e) { }
      }
    
      public void paint(Graphics g)
      {
        Dimension d = getSize();
        if (background == null)
        loadImages();
        g.drawImage(background, 0, 0, d.width, d.height, this);
      }
    
      public void actionPerformed(ActionEvent e)
      {
        CsFrame cs = new CsFrame("Spelvenster");
        cs.addKeyListener(new KeyAdapter()
        {
          //@Override
          public void keyReleased(KeyEvent e)
          {
            switch (e.getKeyCode())
            {
              case KeyEvent.VK_LEFT:
                playerMoveLeft = false;
                break;
              case KeyEvent.VK_RIGHT:
                playerMoveRight = false;
                break;
              case KeyEvent.VK_UP:
                playerMoveUp = false;
                break;
              case KeyEvent.VK_DOWN:
                playerMoveDown = false;
                break;
            }
          }
          
          //@Override
          public void keyPressed(KeyEvent e)
          {
            switch (e.getKeyCode())
            {
              case KeyEvent.VK_LEFT:
                playerMoveLeft = true;
                break;
              case KeyEvent.VK_RIGHT:
                playerMoveRight = true;
                break;
              case KeyEvent.VK_UP:
                playerMoveUp = true;
                break;
              case KeyEvent.VK_DOWN:
                playerMoveDown = true;
                break;
            }
          }
        });
      }
    
      class CsFrame extends Frame
      {
        public CsFrame(String s)
        { super(s);
          addWindowListener(new WindowAdapter()
          {  public void windowClosing(WindowEvent e)
             {
               dispose();
             }
          });
          setLayout(new BorderLayout());
          MijnCanvas cv = new MijnCanvas();
          add("Center", cv);
          Dimension sd = getToolkit().getScreenSize();
          setSize(sd.width, sd.height);
          setLocation(0, 0);
          setVisible(true);
          setResizable(false);
          cv.setFocusable(false);
        }
      }
    
      class MijnCanvas extends Canvas implements Runnable, MouseListener, MouseMotionListener
      {
        double mousex, mousey;
        double playerx, playery;
        double dx, dy;
        double angle;
      
        public MijnCanvas()
        {
          super();
          init();
        }
      
        public void init()
        {
          soundFile1 = getAudioClip(getDocumentBase(), "dryfire_pistol.au");
          addMouseListener(this);
          addMouseMotionListener(this);
          th = new Thread(this);
          th.start ();
        }
      
        public void run()
        {
          Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
    
          while (true)
          {
            // do operations on shots in shots array
            for(int i=0; i < shots.length; i++)
            {
              if(shots[i] != null)
              {
                Dimension d = getSize();
                // move shot
                shots[i].moveShot(shotSpeed);
    
                // test if shot is out
                if(shots[i].getYPos() < 0 || shots[i].getYPos() > d.height || shots[i].getXPos() < 0 || shots[i].getXPos() > d.width)
                {
                  // remove shot from array
                  shots[i] = null;
                }
              }
            }
    
            if(playerMoveLeft && playerMoveUp)
            {
              player.moveX(playerLeftSpeed);
              player.moveY(playerUpSpeed);
            }
            else if(playerMoveUp && playerMoveRight)
            {
              player.moveX(playerRightSpeed);
              player.moveY(playerUpSpeed);
            }
            else if(playerMoveRight && playerMoveDown)
            {
              player.moveX(playerRightSpeed);
              player.moveY(playerDownSpeed);
            }
            else if(playerMoveLeft && playerMoveDown)
            {
              player.moveX(playerLeftSpeed);
              player.moveY(playerDownSpeed);
            }
            else if(playerMoveLeft)
            {
              player.moveX(playerLeftSpeed);
            }
            else if(playerMoveRight)
            {
              player.moveX(playerRightSpeed);
            }
            else if(playerMoveUp)
            {
              player.moveY(playerUpSpeed);
            }
            else if(playerMoveDown)
            {
              player.moveY(playerDownSpeed);
            }
            
            repaint();
    
            try
            {
              Thread.sleep(10);
            }
            catch (InterruptedException ex)
            {
              // do nothing
            }
    
            Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
          }
        }
    
        public void update (Graphics g)
        {
          if (dbImage == null)
          {
            dbImage = createImage (this.getSize().width, this.getSize().height);
            dbg = dbImage.getGraphics ();
          }
    
          dbg.setColor (getBackground ());
          dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
    
          dbg.setColor (getForeground());
          paint (dbg);
    
          g.drawImage (dbImage, 0, 0, this);
        }
    
        public void paint(Graphics g)
        {
          Dimension d = getSize();
          loadImages();
          
          if (Box.isSelected())
          {
            g.drawImage(mist1, 0, 0, d.width, d.height, this);
            g.drawImage(speler, player.x_pos, player.y_pos, d.width / 24 , d.height / 24, null);
            Ai.draw(g);
            for(int i=0; i < shots.length; i++)
            {
              if(shots[i] != null)
              {
                shots[i].drawShot(g);
              }
            }
          } else if (Maze.isSelected())
          {
            g.drawImage(mist2, 0, 0, d.width, d.height, this);
            g.drawImage(speler, player.x_pos, player.y_pos, d.width / 24 , d.height / 24, null);
            for(int i=0; i < shots.length; i++)
            {
              if(shots[i] != null)
              {
                shots[i].drawShot(g);
              }
            }
          } else
          {
            g.drawImage(mist, 0, 0, d.width, d.height, this);
            g.setFont(new Font("Arial", Font.BOLD, 20));
            g.drawString("To play, select a level before pressing 'play'.", d.width / 2 - 230, d.height / 2 - 5);
          }
        }
        
        public void mouseClicked(MouseEvent evt)
        {
          soundFile1.play();
        }
    
        public void mousePressed(MouseEvent evt)
        {
          soundFile1.play();
        }
        
        public void mouseMoved(MouseEvent e)
        {
          mousex = e.getX();
          mousey = e.getY();
          playerx = player.x_pos;
          playery = player.y_pos;
          dx = mousex - playerx;
          dy = mousey - playery;
          
          angle = Math.atan(dy/dx);
          if (dx < 0)
            angle += Math.PI;
    
          if (angle < 0)
            angle += 2 * Math.PI;
    
          double degrees = Math.toDegrees(angle);
    
          //System.out.println(angle);
        }
    
        public void mouseDragged(MouseEvent e) {}
        public void mouseReleased(MouseEvent evt) {}
        public void mouseEntered(MouseEvent evt) {}
        public void mouseExited(MouseEvent evt) {}
      }
    }
    
    //http://stackoverflow.com/questions/2198303/java-2d-drag-mouse-to-rotate-image-smoothly

    AI class
    Java Code:
    import java.awt.*;
    import javax.swing.ImageIcon;
    public class AI implements Runnable
    {
      Rectangle AI2, target;
     // naam AI2 ipv AI (AI gebruik je al voor hoogste klasse/applet)
      int xDirection, yDirection;
      static Image zombie;
    // naam zombie ipv enemy (in tekengedeelte gebruik je ook zombie)
      public int x_pos, y_pos;
    
    
      public void AI3(Rectangle r)
      // naam AI3 ipv AI (AI gebruik je al voor hoogste klasse/applet)
      {
        AI2 = r;
        // naam AI2 ipv AI (AI gebruik je al voor hoogste klasse/applet)
      }
      
      public void AI4 (Rectangle t, int x, int y)
      {
        target = t;
        x_pos = 800; //800 = x
        y_pos = 450; //450 = y
      }
    
      public void draw(Graphics g)
      {
        g.setColor(Color.LIGHT_GRAY);
        if(AI2 != null)
          g.drawRect(x_pos, y_pos, 40, 40);
        g.drawImage(zombie, x_pos, y_pos, null);
      }
    
      public void findPathToPlayer()
      {
        if(x_pos < target.x)
          xDirection = 1;
        if(x_pos > target.x)
          xDirection = -1;
        if(x_pos == target.x)
          xDirection = 0;
        if(y_pos < target.y)
          yDirection = 1;
        if(y_pos > target.y)
          yDirection = -1;
        if(y_pos == target.y)
          yDirection = 0;
      }
    
      public void move()
      {
        x_pos += xDirection;
        y_pos += yDirection;
      }
      
      //@Override
      public void run()
      {
        try
        {
          while(true)
          {
            findPathToPlayer();
            move();
            //Thread.sleep(10);
          }
        }
        catch(Exception ex)
        {
          System.err.println(ex.getMessage());
        }
      }
    
      // main toegevoegd
      public static void main(String[] args) {
        //new AI("ai");
      }
    }
    Error message:
    Compileer E:\PWS\Juist\FCApplet.java met Java-Compiler
    FCApplet.java:15:23: cannot resolve symbol
    symbol : variable AI2
    location: class FCApplet
    private AI Ai = AI3(AI2);
    ^
    1 error



    Thx

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,957
    Rep Power
    19

    Default Re: Impossible error

    What does that line do?
    There's no "new" so it's not creating an AI3 object.
    There's no AI3 method, so it's not calling that.
    Even if either of the above two things were true, there is no AI2 object to pass into the constructor/method as a parameter.

  3. #3
    Jressing is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default Re: Impossible error

    At the bottom somewhere is the line:

    AI.draw(g)

    Without the line you referred to thats not possible I think.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Impossible error

    the compiler is correct as that line of code makes no sense whatsoever. I'm not sure what you're trying to tell us in your post just above this one.

  5. #5
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: Impossible error

    Is it wrong to tell the OP to stop using Applets, I feel it's like using a big huge rock to open a coconut at this stage. Nobody uses it anymore, try HTML5 intead. Applets never took off and certainly not for game dev. Everything important that you would have learned can be transferred to HTML5. Happy Coding...

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Impossible error

    No, I don't see any problem with that. They may be forced to do this though due to the requirements of a course.

  7. #7
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

Similar Threads

  1. Replies: 3
    Last Post: 12-03-2011, 01:38 PM
  2. Impossible or not? restart router through java
    By Questionmark in forum Advanced Java
    Replies: 5
    Last Post: 08-07-2010, 12:22 PM
  3. Replies: 1
    Last Post: 03-10-2010, 01:53 PM
  4. Replies: 1
    Last Post: 12-05-2009, 07:28 AM
  5. Replies: 1
    Last Post: 10-26-2009, 04:38 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
  •