This site requires JavaScript, please enable it in your browser!
Greenfoot back
Brandman73
Brandman73 wrote ...

2020/5/20

Project not working on website

Brandman73 Brandman73

2020/5/20

#
This project was working just perfectly and after uploading, I came to find that the project freezes when the mouse is on the screen, it runs great if the mouse is not on the screen. You will have to see for yourself: Animal Tower Defense It only freezes when a certain actor is called, here is the code that freezes:
MouseInfo m = Greenfoot.getMouseInfo();
            if(m != null)
            {
                setLocation(m.getX(),m.getY());
                
                
                GreenfootImage turtle = new GreenfootImage(me + ".png");
                GreenfootImage outline = new GreenfootImage(me + ".png");
                
                int x=0,y=0;
                while(y < outline.getHeight())
                {
                    while(x < outline.getWidth())
                    {
                        if(!outline.getColorAt(x,y).equals(outline.getColorAt(1,1)))
                        {
                            //outline.setColorAt(x,y,Color.WHITE);
                        }
                        
                        x++;
                    }
                    y++;
                    x=0;
                }
                
                //error should be in this code until the next comment
                
                turtle.scale((int)(turtle.getWidth() * .8),(int)(turtle.getHeight() * .8));
                outline.scale((int)(outline.getWidth() * .9),(int)(outline.getHeight() * .9));
                setImage(turtle);
                GreenfootImage map = new GreenfootImage("TDmap1placing.png");
                Color blue = map.getColorAt(300,1);
                
                if(me == "turtle" || me == "eel")
                {
                }
                else
                {
                    blue = new Color(234,212,135);
                }
                
                boolean place = !isTouching(spacer.class) && map.getColorAt(getX(),getY()).equals(map.getColorAt(100,1));
                if(!place)
                {
                    place = map.getColorAt(getX(),getY()).equals(blue);
                }
                if(me == "eel")
                {
                    place = !isTouching(spacer.class) && map.getColorAt(getX(),getY()).equals(blue);
                }
                
                GreenfootImage img = new GreenfootImage(range * 2,range * 2);
                int r=0,g=0,b=0;
                if(!place)
                {
                    r = 255;
                    g = 0;
                    b = 0;
                }
                else
                {
                    r = 0;
                    g = 255;
                    b = 0;
                }
                img.setColor(new Color(r,g,b,100));
                
                // end of "suspicion"
                
                if(infoOpen)
                {
                    img.fillOval(0,0,range * 2,range * 2);
                    img.setColor(new Color(r,g,b,200));
                    int i=0;
                    while(i < 10)
                    {
                        img.drawOval(i,i,range * 2 - i*2,range * 2 - i*2);
                        i++;
                    }
                }
                
                img.drawImage(turtle,range - (turtle.getWidth() / 2),range - (turtle.getHeight() / 2));
                setImage(img);
                
                // test for open area;
                
                if(Greenfoot.mouseClicked(this) && place)
                {
                    placed = true;
                }
            }
You need to login to post a reply.