-
Meteor Game
I am trying to make a game in which you have to defend the city against a bombardment of meteors, pretty simple, however, if a meteor hits the city then i want the screen to shake, how would i do something like this? Also, I am using the mouse to destroy the meteors, so what would i do to leave a simple trail following the mouse for like 100 pixels (or somehting like that), but not stay there forever?
-
Re: Meteor Game
This is probably more of a general MMF question, rather than one for HWA - but the same solution applies to both MMF2 regular and the HWA beta.
For screen shake you need to do one simple thing (with a number of steps and clicks).
1) If your game window is 640x480, set your frame size to 650x490 for example. This leaves a 5 pixel border around all four edges that can be 'off-screen'
2) Make sure you place all your objects starting 5 pixels from the left and top - ie: take into account that 5 pixel border.
3) This can be done a little more elegantly but for simplicity the duplication of actions will not hurt...Add an ALWAYS event and set the X scroll position and Y scroll position to 5 and 5 respectively via a two actions. This will make sure that the portion of the frame you want to be visible is on screen and that you have a 5 pixel border as defined above while the game plays.
4) Finally, when you want the screen to shake, add two more actions to set the X scroll position and Y scroll position to RND(10) and RND(10) respectively. This will pick a random number for each between 0 and 9 and set the X and Y scroll position of the screen in different places. repeat this every frame for some time and the screen will shake.
That's the principle, to make it better, you could limit the shake to only the X axis, you could use a global or alterable value to specify the amount of shake and reduce this to 'fade' out the shake, eg: set X scroll pos to 5+(rnd( MyValue ) -10) --- where you change MyValue to be the value passed from an alterable value.
For trails, one easy solution I regularly use is to create an active object with only the Appearing animation category populated (make sure Stopped or any other animation category is NOT populated). Set the animation frames to make the trail effect of a single 'particle' (this may be a lump or a large object - not talking literally a spec of dust ;)) and set the animation playback speed as required.
Then add an ALWAYS event (or a timed event for less frequent) and then a CREATE object action to create your trail active object at the position of your meteor. The trick MMF2 will do is it will
1) Create a trail object at the position of EVERY meteor in play, not just one. This is because you have not referenced any single instance and MMF2 will therefore run the CREATE action for every Meteor.
2) Because the trail active object only has the appearing animation, this will play as the object is created and when done it will automatically destroy itself as there are no animation categories to go to when it has finished playing. You therefore do not have to delete the object yourself.
3) As long as your meteors are moving, every frame they will create a trail object at each position they move to, leaving a long trail behind them that will disappear as the appearing animations come to an end.
Hope that gives you a head start to do what you need.
-
Re: Meteor Game
Ooops, I misread the trails part - for the mouse you can do the same, just set the trail active object to the X pos and the Y pos of the mouse. But maybe the meteor trails will give you some ideas too :)
Oh, I don't know how familiar you are with MMF yet, but you'll need to use Expressions (not complicated) as well as Actions and Conditions to build your events. It's not hard to do but the help will show you how to construct an event using these three elements if you get stuck.