![]() ![]() ![]() *You can find an example of the former being used in an InDesign like app in Design Patterns by the Gang of Four if you want further reference on how to set that up. I don't make games for a living so I'm sure there are even better ways to do it. If I understand what you are asking properly, I would say that it is possible, provided the declared array types are not violated. When the pivot point is no longer valid (the snake no longer has any parts that cross the pivot) I'd remove it from the array. Whatever is possible in java, as far as arrays are concerned, is possible in greenfoot. If I was implementing it I'd use an array of pivot points that would tell the snake how to turn pieces of the snake as it traverses the board. As the snake moves you can just increment over the array and change the points to take into account the direction of movement and how far to move. The snake object could have an array (or better yet an ArrayList) that stores the coordinates of the blocks that make up a snake. Selection from Introduction to Programming with Greenfoot. It wouldn't be unreasonable to let the snake draw itself on the board* or at least store it's display information for the board to handle. Making music: An on-screen piano topics: sound concepts: abstraction, loops, arrays. If it detects a collision on between the snake and itself, the game would end. If it the game board detects a collision between the snake and food, it would move the food sprite to the next position and invoke Eat() on the snake object in play. Probably a better idea would be to move user input elsewhere and have the game board communicate state changes to the various sprites (snake, food, wall etc) including collision detection. In this game, there is an visual representation of a piano, which can be used to play different notes, and play different music to your choices. That means you are shuffling 9 times, not just once. Also, all following codes will be executed 9 times as it is all within the for loop. It looks like you're trying to put a lot of sprite interaction logic in your snake class. I do not see random values being added to the array. I'm getting the feeling your question is more general than simple array handling. GetWorld().addObject ( new Food(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(400)) * Write a description of class Snake here.Īctor a = getOneIntersectingObject(Food.class) The class Snake: import greenfoot.* // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) * Constructor for objects of class WorldofSnake.ĪddObject ( new Food(), Greenfoot.getRandomNumber(600), Greenfoot.getRandomNumber(400)) ![]() The world: public class WorldofSnake extends World ![]() However, a black key should not be created when an empty string is encountered in the loop within the 'displayKeys' method.Got a new task in School to code the Snake Game from scratch and need to use a array to add a new Snake bodypart when the Snakehead eats food and at the beginning the Snake need to have 1 head and 2 bodyparts.and I have no idea how to do this.can someone out there help me on right direction.how to start? Here is my code so far: Adding blanks in the toggledBlack array will help to even out the arrays. With the blank spaces in the arrays you are creating keys with the keyName not being equal to an existing key in Greenfoot.The blanks (empty strings) are place holders for where there is no black key on the piano keyboard. In the Key class you can't ckeck to see if a key is down if that key ("") doesn't exist. Just like you didn't for all the other keys on the board.Įven if you do add in spaces into the array, you will still get errors, just in a different class. It happens to be that on a computer keyboard, the letter 'R' lies between the letters 'E' and 'T', but that doesn't mean you have to give it a blank index in an array. Instead of adding blanks into the toggledBlack array, the blanks in the other arrays should be removed. Yehuda wrote.I'm not sure what the purpose of all the blank array parts are for. In my computer science class at school, Greenfoot throws weird exceptions that have nothing to do with my code but I am not sure if that is the case this time. I triple checked and I am 99% sure that I did nothing wrong. Key key = new Key(blackKeys, blackNotes + ".wav", "black", toggledBlack) Key key = new Key(whiteKeys, whiteNotes + ".wav", "white", toggledWhite) ĪddObject (key, 54 + (i*key.getImage().getWidth()), 140) It also uses images created by Spritefoot to demonstrate how you can use multiple arrays of images to smoothly manage animation. Public Key(String keyName, String soundFile, String keyType, String toggle) This scenario uses System.nanoTime to produce smooth, time-based movement and animation (rather than act-based). Import greenfoot.* // (World, Actor, GreenfootImage, and Greenfoot) ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |