J2ME 2D Game Getting Started Tour (5) Realize the explosion effect, join the props missile

xiaoxiao2021-03-06  117

5. Implement the explosion effect, and join the props missile

Most games have a rich effect, once in the elf mobile game, this is an important selling point. Light is some rich effects that cannot produce a good game, but a good game is not a good effect.

Many people think that the game's effect layer is sometimes not too much relationship with game logic itself, often in the final screen, then draws a layer of effect layer. However, communication between game logic and effect layers is important. This communication is often reflected in the latency and waiting. For example, when the aircraft explodes, does not accept any user input, and the explosion effect will continue to follow the plane fall, and even the scope of the explosion will affect the surrounding objects, waiting for the explosion result to continue the game. Communication between game logic and effect layers is a complicated issue. Here I suddenly had a sammy, we didn't start any analysis on the game, the game is completely hard-coded, I think there is, everyone follows it. The aircraft class is just a Sprite, not designed as a state machine, which makes our effect layer and logical communication in some cartoon. Perhaps this article gives you the joy of your first game, and brings you a worry about game scales and complexity. Maybe this is more meaningful than a hard-coded game? Who is good, now I think that the promotion of the extension is the masterpiece of the great game division, I believe that you will redesign this game after you have one or two good ideas, so that there is some like a little system". However, good technology does not necessarily have a good game ... huh,

There is a long, will go to reality, BOYS AND GIRLS! Goon.

Describe our explosion effect, after the bullet hits the plane, the bullet should disappear quickly, the aircraft image remains unchanged. At this time, the explosion effect is above the aircraft image, and then begins to show the boom animation. During this period, the aircraft does not accept any Move indication because he lose control. The plane disappeared after the explosion effect.

Our explosion effect class:

GameObject Explosion; //

Initialization overce:

IMG = imageTools.getimage ("/ pic / expend.png"); //

Explosion = New GameObject (IMG, 32, 32);

initialization:

Explosion.reset ();

Explosion.lifetime = 3; // Life cycle positioning three

Logic processing:

if (GameOver) {// If the game is over, the effect class is displayed

Explosion.paint (g);

Explosion.Update ();

if (! "@Alive) {// When the life cycle is over

Plane.Alive = false; // Turn off PLANE

G.SetColor (255, 255, 255); // Output a review, down-return decomposition

g.drawstring (StringTools.Timeopinion (Gametime), 5, 22, G.LEFT | G.TOP);

g.drawstring ("Fly 0.1 Ver By Favo Yang", 2,100, G.LEFT | G.TOP);

g.drawstring ("e-mail: favoyang@yahoo.com", 2,115, g.left | g.top);

g.drawstring ("Simulate from:", 2, 130, G.LEFT | G.TOP);

g.drawstring ("Mr. Tony 'S ", 2,145, g.left | g.top);

G. DrawString ("Hello Tony, Just Funny.", 2, 160, G.LEFT | G.TOP);

}

Now you see how I solve the communication between the effect layer and the logic layer, I use the global variable GameOver, using a large number of global state variables in simple games is also a common method, which can avoid brainning. However, the disadvantage is obvious, the game hard coding, the structure is neither clear and not beautiful, almost no scalability. So it is best to design aircraft based on state machine, and design the effect class into an abstract class with a callback function, and then inherit the effect class to implement the callback function to implement communication. As for the overall level, you can use the stack to bring the drawing unit. There is also a layered handling, etc. ... give you a starting point for you ...

The missile is achievable, is there any idea, actually use Bullets.killBullets.

Logic processing

IF (Bomb.Alive) {

Bomb.moveto (Plane.Sprite.getx () - 20, Plane.SPRITE.GETY () - 20);

Bomb.Paint (g);

Bomb.UPDATE ();

Bullets.killBullets (Plane.Sprite, 32);

}

Here I have to mention a sentence, and the concept of life is very good in GameObject (in fact, we just use it as a keyword), but the life cycle is arranged in GameObject, and the life cycle is not necessarily. Based on, sometimes time based, sometimes there is something else. I mean that she is more complex to hand over another independent class, which actually needs an sufficiently powerful display method, which supports the number of parameters.

In fact, I feel more, maybe you are also confused. For the section on the directory, we lack the game's reward and punishment system, and I will make up.

转载请注明原文地址:https://www.9cbs.com/read-98262.html

New Post(0)