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

2014/9/1

Minigame Code Assistance Needed

pokemunn pokemunn

2014/9/1

#
Hello, I'm a bit new to Greenfoot and I'm required to make 'something fun' for returning to school on the 4th (cutting it a bit close I know), so far I've managed to get all the sprites for the actors and world classes, but I can't seem to get the hang of the new code. Previously we were learning Pascal and so this sudden change is a bid disorientating, I've been looking at tutorials from places like Mik's Blog if anyone else knows of that, but I thought I'd ask on here to see if anyone can help. The minigame is one of those fake duck shooting ranges you find at carnivals and places like that, you have a row of ducks, and about 10 seconds to shoot as many as you can. For this I basically need help with three 'steps'. Step 1: I need the ducks to move up and down (out of sync with each other so its not really easy to preempt their movement) In my sort of pascal pseudo-code: (I'll try and make it as 'Java' as I know) While TimeLimit > 0 Do { For 'Counter' 1 to 8 do { Move Up (1); } Wait (2); For 'Counter' 1 to 8 do { Move Down (8); } Wait (2); } Something like that if it at all makes sense. Step 2: There's a crosshair that I want to follow the cursor so you're aiming with the mouse. Unfortunately I haven't the faintest clue how to do this, I'm hoping that's possible, if not then I have a backup plan that I should be able to do using the code from step 1 once/if I get help with that. Step 3: When a duck is shot I need it to firstly change sprite and secondly to add to a scoreboard. Once again I have no idea how to do this, I believe there's a scoreboard function or something similar in Greenfoot as I saw it mentioned in Mik's Blog. As for this I shall also be looking at his video on that but some help from you guys would be just as appreciated such as with the changing of the sprite. Thank you to anyone who can/wants to help. ~Okemian (Pokemunn)
pokemunn pokemunn

2014/9/1

#
Just noticed a typo in step 1, MoveDown should be (1), not (8). Otherwise that'd be moving it by 8, 8 times.
danpost danpost

2014/9/1

#
First, you need to understand that each object created and added to the world will have their 'act' methods run individually. The 'act' method of one will be completed before the next one to act is started. What this means is that using 'wait' in the act method of an object will cause everything to wait. Also, just to make it clear, without the wait statements, the act method will be executed within a single frame -- that is, the end result of the actions performed in the act method is what will be shown on the screen. No intermediate state will be apparent. So, if you say (in pseudo-code) 'moveUp(8); moveDown(16);', you will never actually see it move up -- it will only appear to move down 8 each act cycle. 'Act' methods should be programmed to describe what the actor will do at each instance of time depending on the current states of it and its environment. If you want your actors to move between two points, there are a few values that these actors will need to store and/or track: * the direction of movement (horizontal or vertical); this could also be saved as an angle value; * the speed of movement; this could also be stored as individual horizontal and vertical speeds; * the range of movement; this could be the coordinates at which to reverse direction or as the number of moves before reversing; Randomness can be applied to any of those values listed above. For initial random location within the range of movement, create a loop that runs the act method of the actors a random number of times. For the crosshairs, you can easily have an object follow the mouse; but, the normal arrow cursor will still be present. There is a way to actually change the mouse cursor image; but, you should probably work on that when refining your project (get it working first by using an actor that follows the mouse). Finally, people seem to find working with scores difficult; where all it is, is an actor with an image that displays changing text (or really, a changing image). All that needs done is to change the image each time the score changes. The score itself should be in your subclass of world as well as a reference to the actor that displays the score. A reference to the crosshairs actor would also be helpful in that class.
pokemunn pokemunn

2014/9/1

#
Thank you danpost, this helps me out a lot. :)
You need to login to post a reply.