Flash games: men play the next layer

Source: Internet
Author: User

 

I recently bought Android, which is boring on the tram. I made a small game for Android and made a flash version by the way.

The game screen is as follows:

The game test URL is as follows:

Http://fsanguo.comoj.com/flash/jump/index.php

This game is easy to implement and has few code. First, we need several broken diagrams:

Because the game is simple, it is faster to directly make the corresponding graph into MC.

A total of the following MC

Game Genie, regular floor, revolving floor, left floor, right floor, bounce floor, HP floor

Add several lines of code to each MC

 

**************/

// Whether the game genie can stand. If the Game Genie exists, the player starts to play the game. If the fifth day is set to false, and the game begins to flip, the player cannot stand.

VaR ST: Boolean = true;

VaR fun: function;

Stop ();

**************/

Import flash. display. Sprite;

 

VaR ST: Boolean = true;

VaR charaismove: Boolean = true;

// Game Genie

VaR chara: SPRITE;

Onmove ();

Function onmove (): void {

If (chara! = NULL ){

// When the game genie is not empty, move the Game Genie to the left

If (chara. x <this. x | chara. x> This. x + this. width ){

Chara = NULL;

St = false;

} Else {

Chara. X-= 2;

}

}

}

/********* Right shift floor **************/

Import flash. display. Sprite;

 

VaR ST: Boolean = true;

VaR charaismove: Boolean = true;

// Game Genie

VaR chara: SPRITE;

Onmove ();

Function onmove (): void {

If (chara! = NULL ){

// If the game genie is not empty, move the genie to the right.

If (chara. x <this. x | chara. x> This. x + this. width ){

Chara = NULL;

St = false;

} Else {

Chara. x + = 2;

}

}

}

**************/

Import flash. display. Sprite;

 

VaR ST: Boolean = true;

VaR charaismove: Boolean = true;

VaR chara: object;

Stop ();

Function onjump (): void {

If (chara! = NULL ){

// Bounce if the game genie is not empty

Chara. jumpspeed =-15;

Chara. Jump = true;

Chara = NULL;

}

}

**************/

// Stands

VaR ST: Boolean = true;

// Reduce HP

VaR minshp: Boolean = true;

 

In the game implementation part, only one class main is required. below is all the code

Package game {<br/> Import flash. display. sprite; <br/> Import flash. utils. getdefinitionbyname; <br/> Import flash. events. event; <br/> Import flash. events. mouseevent; <br/> Import flash. text. textfield; <br/> Import flash. events. keyboardevent; <br/> Import flash. display. shape; <br/> Import flash. display. displayobjectcontainer; <br/> Import flash. system. fscommand; <br/> // import flash. desktop. nativeapplicatio N; </P> <p> public class main extends sprite {<br/> private VaR _ chara: chara = new chara (); <br/> private VaR _ wall: sprite = new sprite (); <br/> private VaR _ Bak: SPRITE = new sprite (); <br/> private VaR _ bakimg: Bak = new Bak (); <br/> private VaR _ Mai: Mai = New Mai (); <br/> private VaR _ ue: ue = new UE (); <br/> private VaR _ HP: HP = new HP (); <br/> private VaR _ chara_ctrl: Boolean = false; <br/> private VaR _ sect End: Int = 0; <br/> private VaR _ speed: Int = 2; <br/> private VaR _ mclist: array = new array (); <br/> private VaR _ leftctrl: Boolean = false; <br/> private VaR _ rightctrl: Boolean = false; <br/> private VaR _ mcindex: Int = 0; <br/> private VaR _ mcarray: array = new array (); <br/> private VaR _ TXT: textfield = new textfield (); <br/> private VaR _ hpindex: Int = 1; <br/> private VaR _ charaold: Int = 1; <br/> private va R _ shape: Shape = new shape (); <br/> private VaR _ showtext: SPRITE = new sprite (); <br/> private VaR _ gamestart: Boolean = false; <br/> private VaR _ sound: Jiao = new Jiao (); <br/> private VaR _ hpadd: Int = 0; <br/> // Add floor <br/> private function getmc (My: Int = 480, mx: Int =-1): void {<br/> var I: int = math. floor (math. random () * _ mcarray. length); <br/> var classreference: Class; <br/> classreference = getdefinitionb Yname (_ mcarray [I]) as class; <br/> var NMC: SPRITE = new classreference as sprite; <br/> NMC. y = My-this. _ wall. y; <br/> If (MX <0) {<br/> NMC. X = math. floor (math. random () * 270)-50; <br/>} else {<br/> NMC. X = Mx; <br/>}< br/> This. _ mclist. push (NMC); <br/> This. _ Bak. addchild (NMC); </P> <p >}< br/> public function main () {<br/> // Add various floors to an array <br/> // common floor <br/> _ mcarray. push ("MC"); <br/> // rotatable floor <br/> _ mcarray. push (" Toumc "); <br/> // left move floor <br/> _ mcarray. push ("leftmc"); <br/> // right shift floor <br/> _ mcarray. push ("rightmc"); <br/> // bounce floor <br/> _ mcarray. push ("Tan"); <br/> // remove HP floor <br/> _ mcarray. push ("SMC"); </P> <p> // Add each canvas layer <br/> This. _ Bak. addchild (_ bakimg); <br/> This. _ wall. addchild (this. _ BAK); <br/> This. _ wall. addchild (this. _ chara); <br/> This. _ chara. X = 160; <br/> This. _ chara. y = 100; <br/> This. addchild (this. _ wall); </P> <p> This. addchi LD (_ Mai); <br/> This. addchild (_ UE); <br/> _ HP. X = 20; <br/> _ HP. y = 460; <br/> This. addchild (_ HP); </P> <p> This. addchild (_ shape); <br/> _ TXT. selectable = false; <br/> _ TXT. X = 20; <br/> _ TXT. y = 430; <br/> _ TXT. width = 200; <br/> _ TXT. height = 200; <br/> This. addchild (_ txt); <br/> This. addchild (_ showtext); <br/> This. addeventlistener (mouseevent. mouse_down, ondown); <br/> This. addeventlistener (mouseevent. mouse_up, Onup); </P> <p> stage. addeventlistener (keyboardevent. key_down, iskeydown, false, 0, true); <br/> stage. addeventlistener (keyboardevent. key_up, iskeyup, false, 0, true); <br/> stage. showdefaconcontextmenu = false </P> <p> // fscommand ("showmenu", "false"); <br/> Init (); <br/>}< br/> // game initialization <br/> private function Init (): void {<br/> This. _ Bak. y = 0; <br/> This. _ wall. y = 0; <br/> var I: int; <br/> for (I = 0; I <_ mclist. length; I ++) {<Br/> This. _ Bak. removechild (_ mclist [I]); <br/>}< br/> _ mclist. splice (0, _ mclist. length); </P> <p> This. _ chara. X = 160; <br/> This. _ chara. y = 100; <br/> // Add a Game Description box <br/> _ shape. graphics. linestyle (5, 0x000000, 0.8); <br/> _ shape. graphics. beginfill (0x999999, 0.6); <br/> _ shape. graphics. drawroundrect (50,100,220,300, 20, 20); </P> <p> _ shape. graphics. linestyle (5, 0x000000, 0.8); <br/> _ shape. graphics. beginfill (0x999999, (0.6); <br/> _ shape. graphics. drawroundrect (70,300,180, 40, 10, 10); </P> <p> _ shape. graphics. linestyle (5, 0x000000, 0.8); <br/> _ shape. graphics. beginfill (0x999999, 0.6); <br/> _ shape. graphics. drawroundrect (70,350,180, 10, 10); </P> <p> var TXT: textfield = new textfield (); <br/> TXT. selectable = false; <br/> TXT. width = 200; <br/> TXT. height = 400; <br/> TXT. X = 60; <br/> TXT. y = 110; <br/> txt.html text = "<font color = '# Ffff' size = '20'> <B> "+" 100 when there are too many other than available?/n when there are too many other than available? /N "+ <br/>" Operation: /n </B> </font> "+ <br/>" <font color = '# ffffff' size = '15'> <B> "invalid" cannot exceed limit when there are too many threads: /n Bytes left-side motion shifting/N "+ <br/>" <font color = '# ffff' size = '15'> <B> "→" too many bytes delayed too many labels: /n ← right margin shift/N "+ <br/>" </B> </font> "; <br/> _ showtext. addchild (txt); <br/> TXT = new textfield (); <br/> TXT. selectable = false; <br/> TXT. X = 120; <br/> TXT. y = 305; <br/> txt.html text = "<font color = '# ffffff' size = '20'> <B>" + "too many rows" + "</B> </font> "; <br/> _ show Text. addchild (txt); <br/> TXT = new textfield (); <br/> TXT. selectable = false; <br/> TXT. X = 120; <br/> TXT. y = 355; <br/> txt.html text = "<font color = '# ffffff' size = '20'> <B>" + "too many characters" + "</B> </ font> "; <br/> _ showtext. addchild (txt); <br/> // gamestart (); </P> <p >}< br/> // game end <br/> private function gameover (): void {<br/> This. _ chara. jump = false; <br/> _ leftctrl = false; <br/> _ rightctrl = false; <br/> _ sound. PLA Y (); <br/> _ hpindex = 1; <br/> _ HP. gotoandstop (_ hpindex); <br/> _ gamestart = false; <br/> _ sectend = 0; <br/> This. removeeventlistener (event. enter_frame, onframe); <br/> This. _ Bak. y = 0; <br/> This. _ wall. y = 0; <br/> This. _ bakimg. y = 0; <br/> var I: int; <br/> for (I = 0; I <_ mclist. length; I ++) {<br/> This. _ Bak. removechild (_ mclist [I]); <br/>}< br/> _ mclist. splice (0, _ mclist. length); </P> <p> This. _ chara. X = 160; <br/> th Is. _ chara. y = 100; </P> <p> _ shape. graphics. linestyle (5, 0x000000, 0.8); <br/> _ shape. graphics. beginfill (0x999999, 0.6); <br/> _ shape. graphics. drawroundrect (50,100,220,300, 20, 20); </P> <p> _ shape. graphics. linestyle (5, 0x000000, 0.8); <br/> _ shape. graphics. beginfill (0x999999, 0.6); <br/> _ shape. graphics. drawroundrect (70,300,180, 40, 10, 10); </P> <p> _ shape. graphics. linestyle (5, 0x000000, 0.8); <br/> _ shape. graphics. beg Infill (0x999999, 0.6); <br/> _ shape. graphics. drawroundrect (70,350,180, 10, 10); <br/> var TXT: textfield = new textfield (); <br/> TXT. selectable = false; <br/> TXT. width = 200; <br/> TXT. height = 400; <br/> TXT. X = 60; <br/> TXT. y = 110; <br/> txt.html text = "<font color = '# ffffff' size = '20'> <B>" + "game over/n" + <br/> "Number of shards: "+ _ TXT. text + <br/> "/n title:" + getname (INT (_ TXT. text) + <br/> "/n </B> </font>"; <br/> _ Showtext. addchild (txt); <br/> TXT = new textfield (); <br/> TXT. selectable = false; <br/> TXT. X = 120; <br/> TXT. y = 305; <br/> txt.html text = "<font color = '# ffffff' size = '20'> <B>" + "too many rows" + "</B> </font> "; <br/> _ showtext. addchild (txt); <br/> TXT = new textfield (); <br/> TXT. selectable = false; <br/> TXT. X = 120; <br/> TXT. y = 355; <br/> txt.html text = "<font color = '# ffffff' size = '20'> <B>" + "too many characters" + "</B> </ Font> "; <br/> _ showtext. addchild (txt); <br/>}< br/> // game title <br/> private function getname (CNT: INT ): string {<br/> If (CNT <10) {<br/> return "ちゃ"; <br/>} else if (CNT <20) {<br/> return "subsupply"; <br/>} else if (CNT <30) {<br/> return "pupils "; <br/>} else if (CNT <40) {<br/> return "middle school student"; <br/>} else if (CNT <50) {<br/> return "college student"; <br/>} else if (CNT <60) {<br/> return "college student "; <br/>} else if (CNT <70) {<br/> return" College student "; <br/>}else if (CNT <80) {<br/> return" Jia "; <br/>} else if (CNT <90) {<br/> return ""; <br/>} else {<br/> return "shen "; <br/>}< br/> // game start <br/> private function gamestart (): void {<br/> // Add three floors to the canvas <br/> getmc (300,160); <br/> getmc (350 ); <br/> getmc (400); </P> <p> This. addeventlistener (event. enter_frame, onframe, false, 0, true); <br/>}< br/> // press the keyboard <br/> private function iskeydown (Event: keyboarde Vent): void {<br/> If (! _ Gamestart) {<br/> return; <br/>}< br/> If (event. keycode = 37) {<br/> If (_ leftctrl) {<br/> return; <br/>}< br/> _ leftctrl = true; <br/> _ rightctrl = false; <br/> This. _ chara. gotoandplay ("Left"); <br/>} else if (event. keycode = 39) {<br/> If (_ rightctrl) {<br/> return; <br/>}< br/> _ rightctrl = true; <br/> _ leftctrl = false; <br/> This. _ chara. gotoandplay ("right"); <br/>}< br/> // pop-up on the keyboard <br/> private function Iskeyup (Event: keyboardevent): void {<br/> If (event. keycode = 37) {<br/> _ leftctrl = false; <br/>} else if (event. keycode = 39) {<br/> _ rightctrl = false; <br/>}< br/> // press the mouse <br/> private function ondown (Event: mouseevent): void {<br/> var intx: number = event. currenttarget. mousex; <br/> var inty: Number = event. currenttarget. mousey; <br/> If (_ gamestart) {<br/> If (intx <= 160) {<br/> If (_ leftctrl) {<br/> r Eturn; <br/>}< br/> _ leftctrl = true; <br/> _ rightctrl = false; <br/> This. _ chara. gotoandplay ("Left"); <br/>}else {<br/> If (_ rightctrl) {<br/> return; <br/>}< br/> _ rightctrl = true; <br/> _ leftctrl = false; <br/> This. _ chara. gotoandplay ("right"); <br/>}< br/>} else if (intx> 70 & intx <250 & inty> 300 & inty <340) {<br/> _ gamestart = true; <br/> _ shape. graphics. clear (); <br/> This. removeallchildren (_ SH Owtext); <br/> gamestart (); <br/>}else if (intx> 70 & intx <250 & inty> 350 & inty <390) {</P> <p> fscommand ("quit"); <br/> // stage. nativewindow. close (); <br/> // nativeapplication. nativeapplication. exit (); <br/>}< br/> stage. focus = This; <br/>}< br/> // Method for deleting the floor <br/> Public Function removeallchildren (<br/> container: displayobjectcontainer ): void {<br/> var count: Int = container. numchildren; <br/> (VaR I: Int = 0; I <count; I ++) {<br/> container. removechildat (0); <br/>}< br/> // The cursor is displayed. <br/> private function onup (Event: mouseevent ): void {<br/> var intx: Number = event. currenttarget. mousex; <br/> If (intx <= 160) {<br/> _ leftctrl = false; <br/>} else {<br/> _ rightctrl = false; <br/>}</P> <p >}< br/> // logical part <br/> private function onframe (Event: Event ): void {<br/> var speednum: Number = 0.03; <br/> var d Ownlength: Number; <br/> VaR _ child: object; <br/> // you can delete the floor from the outside of the screen. <br/> If (_ mclist. length> 0 & _ mclist [0]. y-this. _ wall. Y <40) {<br/> _ child = _ mclist [0] as object; <br/> If (_ child. charaismove! = NULL & _ child. chara! = NULL) {<br/> _ child. chara = NULL; <br/>}< br/> This. _ Bak. removechild (_ mclist [0]); <br/> _ mclist. splice (0, 1); <br/>}< br/> var I: int; <br/> This. _ wall. y-= _ speed; <br/> // control the increase and decrease of the Game Genie and the increase and decrease <br/> If (! _ Chara_ctrl) {<br/> This. _ chara. Y + = _ speed; <br/> downlength = speednum * _ sectend; <br/> If (downlength> 37) {<br/> downlength = 37; <br/>}< br/> This. _ chara. Y + = downlength; <br/> _ sectend ++; <br/>} else if (this. _ chara. jump) {<br/> This. _ chara. Y + = _ speed; <br/> This. _ chara. y-= 0.06 * This. _ chara. jumpspeed * This. _ chara. jumpspeed; <br/> // charaold = This. _ chara. y; <br/> This. _ chara. jumpspeed ++; <br/> If (This. _ chara. jumpspeed> = 0) {<br/> This. _ chara. jump = false; <br/>}< br/> // whether it is in the bounce stage <br/> If (! This. _ chara. jump) {<br/> _ chara_ctrl = false; <br/>}else {<br/> If (this. _ chara. jumpspeed> = 0) {<br/> This. _ chara. jump = false; <br/>}</P> <p >}< br/> // array of floor loops <br/> for (I = 0 ;! This. _ chara. jump & I <this. _ mclist. length; I ++) {<br/> _ child = _ mclist [I] as object; </P> <p> // locate the floor in contact with the genie, here we can also use hittestobject to determine <br/> If (this. _ chara. y> = _ child. Y & <br/> This. _ chara. x> = _ child. X & _ child. st & <br/> This. _ chara. x <= _ child. X + _ child. width & _ charaold <= _ child. Y + 1) {<br/> If (_ hpadd> 0 & _ charaold! = This. _ chara. y) {<br/> _ hpadd --; <br/> If (_ hpadd = 0 & _ hpindex> 1) {<br/> _ hpindex --; <br/> _ HP. gotoandstop (_ hpindex); <br/>}< br/> If (_ child. charaismove! = NULL & _ child. charaismove) {<br/> _ child. chara = This. _ chara; <br/>}< br/> If (_ child. minshp! = NULL & _ child. minshp) {<br/> _ child. minshp = false; <br/> _ hpindex ++; <br/> _ hpadd = 5; <br/> _ HP. gotoandstop (_ hpindex); <br/>}< br/> This. _ chara. y = _ child. Y + 1; <br/> _ sectend = 1; <br/> _ chara_ctrl = true; <br/> _ child. play (); <br/> break; <br/>}< br/> // whether the needle above is exposed <br/> If (this. _ chara. hittestobject (_ UE) {<br/> _ chara_ctrl = false; <br/> This. _ chara. jump = false; <br/> This. _ chara. Y + = 30; <br/> _ sectend = 3; <br/> _ hpindex ++; <br/> _ hpadd = 5; <br/> _ HP. gotoandstop (_ hpindex); </P> <p >}< br/> // loop background image to achieve consistent display <br/> If (this. _ wall. Y % 130 = 0) {<br/> _ bakimg. Y + = 130; <br/>}< br/> // genie mobile <br/> If (_ leftctrl) {<br/> This. _ chara. x-= _ speed * 2; <br/>}< br/> If (_ rightctrl) {<br/> This. _ chara. X + = _ speed * 2; <br/>}< br/> If (this. _ chara. x <25) {<br/> This. _ chara. X = 25; <br/>}< br/> If (this. _ chara. x> 295) {<br/> This. _ chara. X = 295; <br/>}< br/> If (_ mcindex <= 0) {<br/> This. getmc (); <br/> _ mcindex = math. floor (math. random () * 60) + 30; <br/>}< br/> _ mcindex --; <br/> // display the floor <br/> _txt.html text = "<font color = '# ffffff 'size = '20'>" + math. floor (-this. _ wall. y)/480) + "</font>"; <br/> _ charaold = This. _ chara. y; <br/> // determines whether the game is over. <br/> If (_ hpindex> = 4) {<br/> gameover (); <br/>} else if (this. _ chara. Y + this. _ wall. y> 540) {<br/> gameover (); <br/>}</P> <p>} 

 

The mini-game is complete. Is it easy? This is flash, a development game, and has an absolute advantage.

Source code is released, images are added, and sound effects are added.

Http://fsanguo.comoj.com/download.php? I =jump.rar

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.