

Here is an example of code used in world class: This third array would need to be created when needed and could be filled with index values from the image array, one for each fish in the water. Now, you can easily get the total number of fish in the water and, by use of another array, choose exactly one at random. Then, you could have a second array that has a one-to-one correspondence with the image list, giving the number of each type fish in the water. You could list the different types of fish using their images (in an image array). you don't have to give me all the code if its really complicated I just wanna know how i would add something like this in my gameThis is one way to approach it. How would I implement something like this? i want the fisherman to catch a fish at the end of the casting animation and have the image of the fish caught displayed in the middle of the screen for a few seconds. Each fish will have an assigned rarity and ill use "Greenfoot.getRandomNumber" to choose which fish gets caught. KCee wrote.thank you! another question so i want to make my fisherman catch different types of fish. You will need to replace that code to load your images there. }My for loop from line 17 to line 23 loads mock images into the arrays. GreenfootImage walkR, walkL, castR, castL, currAnim įor (int i=0 i 0 & currAnim != walkR) setAnimation(walkR) Static final Color TRANS = new Color(0, 0, 0, 0) I wrote a simple test scenario to illustrate. I also noticed that the private int speed field is not used anywhere so, it can be removed as well. The currentFrame and imageIndex fields can probably be removed as well because the act counter value can be used to determine the current frame and image. With this field, you can probably remove the String facing field. The field needs to also indication which casting animation is running so, the best thing to do is have the field hold the currently running animation. Finally, you will need a field to indicate whether the casting animation is running or not. This is not a necessity, but it also adds consistency to the game. It would also be better to use an act counter field instead of a SimpleTimer object, to control the speed of the animation that way the action performed stays in time with other actors in the world. It would be best to load all the images of the animations up front - in the constructor (just as you have with the walk animations). For the casting animation to continue even after the 'f' key is released, it must be known that the animation is running to begin with. In fact, that is exactly what your castIt method does ( cast only if 'f' is down). It is probably reverting back to walking once the 'f' key is released. >You need more control over the animations.
#Remove object greenfoot full#
I have to press the key several times for the full animation to play out. KCee wrote.I want to make an animation for casting a fishing rod, but when I click the key to cast ("f"), it only plays 1 frame of the animation. ImageIndex = (imageIndex + 1) % castLeft.length ImageIndex = (imageIndex + 1) % castRight.length ImageIndex = (imageIndex + 1) % walkLeft.length įor (int i = 0 i < castRight.length i++)ĬastRight = new GreenfootImage("images/castAni/cast" + i + ".png") įor (int i = 0 i < castLeft.length i++)ĬastLeft = new GreenfootImage("images/castAni/cast" + i + ".png") ImageIndex = (imageIndex + 1) % walkRight.length WalkLeft = new GreenfootImage("images/walkingAni/walking" + i + ".png") WalkRight = new GreenfootImage("images/walkingAni/walking" + i + ".png") įor (int i = 0 i < walkLeft.length i++) SimpleTimer animationTimer = new SimpleTimer() įor (int i = 0 i < walkRight.length i++) GreenfootImage castLeft = new GreenfootImage GreenfootImage castRight = new GreenfootImage GreenfootImage walkLeft = new GreenfootImage If (x >= myWorld.getWidth() || y >= myWorld.GreenfootImage walkRight = new GreenfootImage ("Number of steps from move() method " + numberOfStepsTaken) * Move one cell forward in the current direction.

Check whether there is a leaf in the same cell as we are.Īctor leaf = getOneObjectAtOffset(0, 0, Leaf.class) A Wombat moves forward until it can't do so anymore, at Import greenfoot.* // (World, Actor, GreenfootImage, and Greenfoot) Then put a new wombat on the stage and run the program. Copy all of the code from the text area below into your Wombat class.

In the text area below is all of the code for the "modified" Wombat Class. Here is some code that I added to the move() method. You then see code similar to the picture below.įind the move() method in your wombat class. Right-click over the Wombat Icon and choose "Open editor". Part II A closer look at the Wombat Class's Code Below is the code for the Wombat class.
