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

danpost's Comments

Back to danpost's profile

@jabirfatah91, (1) 'private' is not neccessary, but will restrict access from other classes; 'double' is used for more precise movement. (2) with 'first' initially set to 'true', the code block that is executed on the condition 'if (first)' will execute. (3a) Since 'first' is changed within the block to 'false' (by 'first = !first;'), the block is destined to only run once (the first time the act method is executed). (3b) 'System.currentTimeMillis()' is a system command to return the 'long' value of the current system time. Each unit of time returned is equivalent to 1/1000th of a second.
Just need to put, in the Seal class, something like (this is pseudo-code) move forward if in water, move back and turn some to make sure the seals to not go into the water.
Sorry again, CRAB.
That will show the seals above the water, but will not resolve the issue of the lobster being eaten while totally in the water area. I placed the lobster, stuck to the left wall, right in the middle of the upper water image (vertically). A seal went into the water area (hidden under the water image) and ate the lobster. So it is not a matter of the lobster being 'partially in the field the seals can still eat you'.
Yes. The code is open source to view; and it is fairly well documented.
I forgot to mention, in the first 'if' block in the 'hyper' method, set 'spaceDown' to 'true'; and in the other one, set it back to 'false'.
In the Space class, I saw two things that could be done to make the code look better. (1) line 8, the int 's' is not used anywhere, so it can be removed (2) lines 7, 9 and 10: these are only used in the 'createStars' method and should be local to it. Move line 7 to the beginning of the 'createStars' method (you may have to assign zero to it) and remove 9 and 10 (there are already local variables for these, so those declared in lines 9 and 10 are not being used). In the Star class: the constructor uses 'if (size == 2)...if(size == 3)...if(size == 4)'. Better would be a 'switch' statement. Also 'size' has a range from one to five; you are not doing anything for when it is one or five. Actually those with sizes of one and five are invisible (black on a black background) since the default drawing color for them was never changed. In the Spaceship class: You are calling the 'hyper' method every act cycle (which is OK), but the method is updating the image each time it is called, whether the image needs changed or not. You can add a boolean field to the class, 'private boolean spaceDown;' and change the 'if's in the method to: if (!spaceDown && Greenfoot.isKeyDown("space")) and if (spaceDown && !Greenfoot.isKeyDown("space")) With that, the image will only be updated when there is a change in state of the "space" key.
In their trajectories, none. In the way the movement is calculated, a lot.
@hkrhassleholm, the 800 and 600 were supposed to be 600 and 400 for the width and height of the world; that is why the move code sets x back to 600.