Flash AS3 play balloon Small game code

Source: Internet
Author: User
Tags addchild anonymous

The effect is as follows

The first is the source code, saved as a main.as file, and associated with the FLA to run.

The code is as follows Copy Code

Package {
Import flash.display.*;
Import flash.events.*;
Import flash.text.*;
Import Flash.utils.Timer;
Import Flash.geom.Matrix;
[SWF (width=800, HEIGHT=465,BACKGROUNDCOLOR=0XFFFFFF, framerate=24)]
public class Main extends Sprite {
private Var pointnum:number=0;
private var Ptxt:textfield = AddChild (New TextField ()) as TextField;
private var Matrix:matrix = new Matrix ();
Public Function main () {
var t:timer = new Timer (500);
var tfun=function () {Matrix.creategradientbox (800,465,math.pi/2,0,0), Graphics.begingradientfill ( Gradienttype.linear,[0x00ccff,0xffffff],[0.3,1],[0,255],matrix), Graphics.drawrect (0,0,800,465), T.addeventlistener (Timerevent.timer,function (e) {var mc;
var mcfun = function () {Mc=addchild (New Balloon (Math.random () *10 + 1)), Mc.x=math.round (Math.random () * (700-30)) +30, Mc.y=465}.apply ();
Mc.addeventlistener (Mouseevent.mouse_down, function (e) {removechild (e.target.parent), ptxt.htmltext= ' <font size = "color=" #ff0000 ">score: ' + (++pointnum). toString () + ' </font> '}), T.start ()}.apply ();
}
}
}
Import Flash.display.Sprite;
Import flash.events.Event;
Class Balloon extends sprite{
private Var Speed:number;
private var s:sprite =addchild (New Sprite ()) as Sprite;
Public Function Balloon (_t) {
var sfun=function () {s.graphics.linestyle (1, 0), S.graphics.curveto ( -10, 0,), S.graphics.beginfill (Math.random ( ) * 0XFFFFFF + 0xff000000), s.graphics.drawcircle (0,0,20), Speed=math.round (_t)}.apply ();
S.addeventlistener (Event.enter_frame,function (e) {s.y-= speed;});
}
}

This code, with a line, with a semicolon, the statement of a line, I do not have a line to write n sentence of the smart.

This code, some places are not standardized, such as the use of anonymous functions, but not to optimize efficiency (object pool), but as a complete game, it can run up, remove import those, the core code is 20 lines.

Although only a short line of 30 lines of code, but we use the class of knowledge, objects, gradients, matrices, event processing, anonymous functions, random operations, as well as graphic graphics, such as though small spite wow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.