Conversion of game Moving Pictures

Source: Internet
Author: User

To move a picture's transformation:

Defines a direction that, when moved, determines whether the next move is the current direction, and if not, only changes the picture and does not move.

1  PackageCom.itheima.bean;2 3  Public classTankextendsElement {4     Private intSpeed = 64;5Direction Direction = direction.up;//Initial up6 7      PublicTank (intXinty) {8          This. x =x;9          This. y =y;Ten          This. ImagePath = "Res/img/tank_u.gif"; One  A     } -  -      Public voidMove (Direction dir) { the         if(Direction! = Dir) {//if the direction passed in is not equal to the current direction -Direction =dir;  -             Switch(dir) {//convert pictures by direction -              CaseUp : +                  This. ImagePath = "Res/img/tank_u.gif"; -                  Break; +  A              CaseDown : at                  This. ImagePath = "Res/img/tank_d.gif"; -                  Break; -              CaseLeft : -                  This. ImagePath = "Res/img/tank_l.gif"; -                  Break; -              CaseRight : in                  This. ImagePath = "Res/img/tank_r.gif"; -                  Break; to             } +             return;//do not continue down execution -         } the         Switch(dir) {//Moving *          CaseUp : $Y-=Speed ;Panax Notoginseng              Break; -  the          CaseDown : +Y + =Speed ; A              Break; the          CaseLeft : +X-=Speed ; -              Break; $          CaseRight : $X + =Speed ; -              Break; -         } the     } -}
View Code

Essay says:

The game movement principle is the picture coordinates change displays.

Conversion of game Moving pictures

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.