![]() ![]() What you probably want here is 'if (getX() = 0 || getX() = getWidth() - 1 || getY() = 0 || getY() = getHeight() - 1)'. = atWorldEdge(): this method, as is, will always return 'false' as getX() will never return 600, not to mention, that the random chance of a match in the y-coordinate is 1 in 400 (or one-quarter of a one percent chance). Will continue on new post (as it would make it easier for me to see what code you had already). This will give the bird a constant speed (for now, we will replace the 2 with a variable that can change later), and give it some random up and down (for now, as this will nearly end up to be a straight line across the screen). What you probably want is something like 'setLocation(getX() + 2, getY() + getRandomNumber(3) - 1) '. Anyway, the 600 is outside the world bounds, and any hard-coded number will have the bird jumping up and down along a line because of the random number choosing of the y-coordinate. (Somehow, it posted right then, not intended). = move(): the setLocation statement says to randomly pick a location one pixel off the right side of the screen We will look at your method (other than the act method) first: You should always fix the code you have before adding more code (or a tangled web you will weave). I do see multiple problems with the code you provided, which should be fixed before moving on. If three make it to the right side, you lose. OK, you add the Bird objects on the left side of the window and (let me guess) they fly across to the right side whilst the player tries to shoot them down (by clicking on them). this is my class i know it may have so many errors. I didn't set anything to the direction yet. ![]() ![]() If(getOneIntersectingObject(Bird.class) != null)Īctor bird = getOneIntersectingObject(Bird.class) * the 'Act' or 'Run' button gets pressed in the environment. * Act - do whatever the Birds wants to do. * Write a description of class Birds here. Import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |