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

2020/4/10

need help with my file dialog

1
2
3
4
Cats123 Cats123

2020/4/13

#
I need there to be one where the colors on the circle meter meet.
danpost danpost

2020/4/13

#
Cats123 wrote...
could i put it in my prepare method because i need it to be there all the time?? How would i use the ArcX and ArcY variables from the CircleMeter class in the world??
You know what, you can put it in the fire method, instead. You will just need to add parameters to the ViralLoad constructor so you can pass the returned getArcX and getArcY values.
Cats123 Cats123

2020/4/13

#
Ok i added it how would i get the variables from the CircleMeter class??
danpost danpost

2020/4/13

#
Cats123 wrote...
Ok i added it how would i get the variables from the CircleMeter class??
What did you add?
Cats123 Cats123

2020/4/13

#
ViralLoad viralload = new ViralLoad(); addObject(viralload, getArcX(), getArcY()); just that is that all i need to add?
danpost danpost

2020/4/13

#
Cats123 wrote...
ViralLoad viralload = new ViralLoad(); addObject(viralload, getArcX(), getArcY()); just that is that all i need to add?
No -- that does not look right. Let me clear something up first. You said:
Cats123 wrote...
I need there to be one where the colors on the circle meter meet.
Do you mean a ViralLoad object? But, isn't that the type of object that is fired when the "space" is pressed?
Cats123 Cats123

2020/4/13

#
Yes, the viraload and i need both of those things, to shoot when the space bar is pressed and for there to be a viralload where the colors meet in the circlemeter at the top of the arc
Cats123 Cats123

2020/4/13

#
also i have a fire method in viralload and in circlemeter
danpost danpost

2020/4/13

#
Cats123 wrote...
Yes, the viraload and i need both of those things, to shoot when the space bar is pressed and for there to be a viralload where the colors meet in the circlemeter at the top of the arc
Okay, I guess. I would actually suggest to use separate object types for the actual shots and the object that remains at the edge of the circle -- but, so be it. First, the ViralLoad objects will need to know their horizontal and vertical speeds (both being zero for the one at the edge of the circle). These objects also need to retain those values. So, add two int fields to ViralLoad class to hold them. Then add a ViralLoad constructor with two int parameters to acquire the values to be stored in those fields. Next, in the CircleMeter class, add a field to reference the one at its perimeter:
private ViralLoad load = new ViralLoad(0, 0);
Then, add an addedToWorld(World) method to place the load into the world. The load will need to be re-positioned any time degFull changes. Work on that. Respond back when done.
danpost danpost

2020/4/13

#
Cats123 wrote...
also i have a fire method in viralload and in circlemeter
You will not need one in ViralLoad.
Cats123 Cats123

2020/4/13

#
viral load public class ViralLoad extends Actor { /** * Act - do whatever the Person wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { if(isTouching(Bird.class)) //|| this.isAtEdge()) { removeTouching(ViralLoad.class); } } public ViralLoad(int xspeed,int yspeed) { xspeed=0; yspeed=0; } } circle meter public class CircleMeter extends Actor { private ViralLoad load = new ViralLoad(0, 0); private int degFull; // how full is the meter? from 0 to maxDegree private int radius; // how big is the "sweeping" radius of this meter? private int maxDegree; // what is the maximum number of degrees in this meter? /** * constructs a 180 degree (half circle) meter with specified radius * * @param radius the size of the semicircle's radius */ public CircleMeter(int radius) { degFull=0; // starts out empty this.radius=radius; // use specified radius maxDegree=180; // by default, a half circle redraw(); // redraws the circle image, based on above. } /** * constructs a semicircle meter with specified radius and maximum degree. WARNING: this is really * intended to work with only multiples of 90 degrees. * * @param radius the size of the semicircle's radius * @param the sweeping range of the meter. Intended to work in multiples of 90 degrees. */ public CircleMeter(int radius, int maxDegree) { degFull=0; // starts out empty this.radius=radius; // use specifed radius // use specifed sweeping range (carefully) this.maxDegree=Math.min(180, Math.max(maxDegree, 10)); redraw(); // redraws the meter, based on above } // // redraw is a private method that will rebuild the image for a CircleMeter private void redraw() { // get a new (empty) image of the needed size. int imgWidth = radius + (maxDegree>90?radius:0); imgWidth = Math.max(imgWidth, radius); GreenfootImage img = new GreenfootImage( imgWidth , radius); // get underlying java awt image (need direct java awt rendering) java.awt.image.BufferedImage awtVersion = img.getAwtImage(); java.awt.Graphics2D g = (java.awt.Graphics2D) awtVersion.getGraphics(); // draw the blue filled backgound, indicating "unfilled" portion Shape arc = new Arc2D.Float(-(180-maxDegree)/90*radius, 0, 2*radius-1, 2*radius-1, 0, maxDegree, Arc2D.PIE); g.setPaint(java.awt.Color.BLUE); g.fill(arc); // draw the orange filled foregound, indicating "filled" portion arc = new Arc2D.Float(-(180-maxDegree)/90*radius, 0, 2*radius-1, 2*radius-1, 0, degFull, Arc2D.PIE); g.setPaint(java.awt.Color.ORANGE); g.fill(arc); // now that we have built the image, use it as this Actor's image. setImage(img); } /** * getAngle specifies (in radians) the current fill value of the meter * * @return the angle value in radians of the meter. */ public double getAngle() {return Math.toRadians(degFull);} /** * getDegrees specifies the current fill value of the meter in degrees * @return the angle value in degrees */ public int getDegrees() {return degFull;} /** * getArcX gives the x value of the perimeter of the circle where the meter is currently filled to * * @return the x location of the filled portion of the meter */ public int getArcX() { // find the "origin" x value of the meter int originX = getX() - (maxDegree<=90?radius/2:0); //we'll be an appropriate offset from that origin. return (int) (originX+Math.cos(Math.toRadians(degFull))*radius); } /** * getArcY gives the y value of the perimeter of the circle where the meter is currently filled to * * @return the y location of the filled portion of the meter */ public int getArcY() { // find the "origin" y value of the meter int originY = getY()+getImage().getHeight()/2; //we'll be an appropriate offset from that origin. return (int) (originY-Math.sin(Math.toRadians(degFull))*radius); } /** * Act - do whatever the CircleMeter wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { RectangleMeter rectangle = (RectangleMeter)getWorld().getObjects(RectangleMeter.class).get(0); double rectRatio = rectangle.getFilledRatio(); // if the left arrow key is being pressed and we can still grow, if (Greenfoot.isKeyDown("Left") && degFull<maxDegree) { degFull++; // a bit more is full redraw(); // rebuild image to note the updates fill amount ViralLoad viralload = new ViralLoad(0,0); getWorld().addObject(viralload, getArcX(), getArcY()); } // if the right arrow key is being pressed and we could still shrink our fill ... if (Greenfoot.isKeyDown("Right") && degFull>0) { degFull--; // a bit less is fulll redraw(); // rebuild image to reflect the new fill amount ViralLoad viralload = new ViralLoad(0,0); getWorld().addObject(viralload, getArcX(), getArcY()); } if(Greenfoot.isKeyDown("space")) { fire(); } } private void fire() { ViralLoad viralload = new ViralLoad(0,0); getWorld().addObject(viralload,getArcX(), getArcY()); viralload.setRotation(-degFull); viralload.move(radius); } public void addedToWorld(World pasteVirus) { ViralLoad viralload = new ViralLoad(0,0); ((MyWorld)getWorld()).addObject(viralload,getArcX(),getArcY()); } } not sure if i did that 100% correct but this is what i got
danpost danpost

2020/4/13

#
viral load
danpost wrote...
add two int fields to ViralLoad class
circle meter
protected void addedToWorld(World world)
{
    world.addObject(load, 0, 0);
    updateLoadPosition();
}

private void updateLoadPosition()
{
    load.setLocation(getX(), getY());
    load.setRotation(-degFull);
    load.move(75);
}
Cats123 Cats123

2020/4/13

#
ok i did that and it does pretty much the same thing
danpost danpost

2020/4/13

#
Cats123 wrote...
ok i did that and it does pretty much the same thing
Now, the fire method in CircleMeter class needs a ref to the rectangle (as shown above), so that, when it creates a new ViralLoad shooting object, it can supply the appropriate axial speeds.
Cats123 Cats123

2020/4/13

#
whenever i press the arrow keys it just posts a ton of them
There are more replies on the next page.
1
2
3
4