Beginner's corner |
Top Previous Next |
Feature of the month: remote cameras This month I want to show you a "pro" feature that is extremely useful in action games, sport games, adventure games, strategy games... in fact, I think that any game could use a remote camera. Practical use: display your football game on a big screen, keep an eye on your fortress' entrance, create rear view mirrors for your car and so much more! First of all, we define a view: view remote We must set its size on x and y to the size of the sprite (128 x 64 pixels in my example). I chose layer = 5 but you can choose any small value. This will be our virtual "screen" but we also need a camera to watch what's happening: action camera1 You can use any model for the camera: place it in Wed, set its position and angles and they will be transmitted to the remote view. This should be all... oh, wait, we need to show the image captured by the "screen" using a sprite: action monitor I am using an oriented sprite; the view will be rendered on "my" bitmap = the bitmap used for the sprite with this action attached to it. Blood pool This snippet will teach you make your enemies bleed as soon as they die. I have kept the code as simple as possible: define number_of_hits skill1; action enemy_blood I have defined a local var named blood_coords. I know that you are too shy to ask but I will explain right here, right now what's with these local and global variables. A global variable is defined outside any action or function - it isn't enclosed by curly brackets. A global variable can be accessed from any other function or action. It is good to know that you can type ammo1 += 100 at the console and get 100 extra bullets for the weapon that uses ammo1, isn't it? A local variable is defined exactly like a global var, but its definition is placed inside the action or function, like the one in action enemy_blood. A local var is known only inside the action / function that has its definition inside it. If you would want to type blood_coords.x = 100; at the console it wouldn't work, get it? Local vars are just like entity skills: you can use them only within the action or function that has defined them. Let's get back to work now... The local var named blood_coords will be set to the origin of the blood spot. I could have used a global var but if you would have attached the same action to several models, every model could have changed blood_coords because this var would have been known to all the actions and functions. A local blood_coords var is recognized only inside its own action or function so the blood_coords value for one of the enemies can't interfere with other blood_coords value, used by another enemy. The enemy is sensitive to impact; shoot it with a rocket to trigger its enemy_hit event. I have used number_of_hits as a name for skill1; as long as number_of_hits is zero, the enemy will play its "stand" animation in a loop // the enemy was hit by a rocket - it must die function create_blood() The blood sprite is passable, oriented and has its flare and bright flags set. The sprite will increase its size on x and y five times. The function that triggers all this scary stuff is: function enemy_hit() If the enemy has collided with an entity, it checks to see if that entity is the player. If the enemy was hit by a rocket, number_of_hits will be increased and the enemy will die.
|