![]() ![]() The problem was that I forgot to add fall() to the act class of my actor itself - the jumping and falling is now working, but the actor gets nevertheless teleportet, when he hits a block/obstacle. We can make that sound play every time the crab eats a worm by adding a single line to our crab class that calls aySound after we remove a worm from the world: Give that a try. The folder your scenario is in bears the name of your. The scenario comes with a sound ready for you to use, named 'eating.wav'. Add code that generates a random number and uses that to decide which leaf image to display. Notice that there are 4 possible images for leaves, even though right now, only one image is displayed. Right now, all it does is set a speed for the leaves. That is where you paste the sound files for that project. this is exactly the problem: Take a look at the constructor. Find the sounds folder and open it (it should be there and it should be empty). ![]() If (onGround & Greenfoot.isKeyDown("w")) vSpeed = -jumpStrength Find the folder for the project you are working on and open it. Int dx = 0 //determine direction to move (left=-1, right=1 and none=0) > // code unknown for your project (you decide) Working movement code: setLocation ( getX() - speed, getY() ) If (onGround & Greenfoot.isKeyDown("w")) jump() Working movement code: setLocation ( getX() + speed, getY() ) Private int jumpStrength = 20 //Sprungstärke Private int FallAcceleration = 2 //Fallbeschleunigung Use of started () and stopped () method in World to avoid music that plays forever. Teaches: Use of GreenfootSound API to create and optimize music and sound effects. Private int vSpeed = 0 //speed (Fallend/falling) Not intended for total beginners, though it could certainly be shared with them. Private int speed = 3 //speed (seitlich/sideways) To sum up, the stop statement must be the last statement, or a return statement must follow it (or further statements will execute). * the 'Act' or 'Run' button gets pressed in the environment. So, I put a return statement after the call and now (because the current act cycle of that object has ended) Greenfoot stopped execution of any code and my Pause button became a Run button. * Act - do whatever the PeterP wants to do. * Write a description of class Ojekte here. Import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |