Lan Yi iOS to write small games to achieve new features

Source: Internet
Author: User

Today is the practice day, through a few days of systematic learning, I have a basic knowledge of a simple understanding, today with a day of time by sorting out a few days to learn something, successfully wrote a simple small game.  In the game, almost all the control functions learned, Label,text,uiimageview,uibutton,nstimer and so on. Today I write my own game is to implement a character picture by setting the four button buttons to control its movement, there are three obstacles in the middle of the picture, hit the barrier will reduce the amount of blood, and back to the starting point. Detects the collision place uses the Nstimer knowledge, among them also has a minefield, mined the area through asks Li Guobin teacher to learn the new knowledge, [image Removefromsubview]; The realization of the previous production image erasure. Although it is a very simple small game, although it is a lot of bug games, but I am still very happy, after all, it is self-written by the following is one of the code:

Implement the arrangement of the border around

for (int j=0; J<<span style= "font-variant-ligatures:no-common-ligatures; color: #272ad8" >700; j=j+367) {

for (int i=0; I<<span style= "font-variant-ligatures:no-common-ligatures; color: #272ad8" >500; i++) {

Uilabel*biankuang2=[[uilabel Alloc]initwithframe:cgrectmake (J, i*10, 8, 8)];

if (i%3==0) {

Biankuang2. Backgroundcolor=[uicolor Redcolor];

}else if (i%3==1) {

Biankuang2. Backgroundcolor=[uicolor Bluecolor];

}else{

Biankuang2. Backgroundcolor=[uicolor Blackcolor];

}

[Self.view Addsubview:biankuang2];

}

}

////////////////////////////////////////////////////////////////////////

Below the _time1 is the control three obstacle picture movement

_time1=[nstimer scheduledtimerwithtimeinterval:.1 target:self selector: @selector (move1) UserInfo:nilrepeats:YES];

The following _time2 when the mine is in control of mined areas

_time2=[nstimer scheduledtimerwithtimeinterval:3.0 target:self selector: @selector (Dilei) Userinfo:nil Repeats:YES];

Judging if it collided.

_time3=[nstimer scheduledtimerwithtimeinterval:.02 target:self selector: @selector (crash) Userinfo:nil Repeats:yes];

}

Jump out of the page program

Collision detection

-(void) fly{

_snowflake.center=cgpointmake (_SNOWFLAKE.CENTER.X-_QQ, _SNOWFLAKE.CENTER.Y+_QQ);

if (_snowflake.center.x<<span style= "font-variant-ligatures:no-common-ligatures; color: #272ad8" >5) {

_snowflake.center=cgpointmake (388, _SNOWFLAKE.CENTER.Y);

}else if (_snowflake.center.y>666) {

_snowflake.center=cgpointmake (_snowflake.center.x, 66);

}

}

-(void) crash{

if (Cgrectintersectsrect (_iv4.frame, _iv3.frame) | | Cgrectintersectsrect (_iv4.frame,_iv2.frame) | | Cgrectintersectsrect (_iv4.frame, _iv.frame) | | Cgrectintersectsrect (_iv4.frame, _iv5.frame)) {

_iv4.center=cgpointmake (120, 650);

To achieve a collision once the remaining blood volume is reduced by one

_blood--;

Here's the text must be put here to write. Shows the remaining amount of blood left.

[Email protected] (_blood). StringValue;

if (_blood<<span style= "font-variant-ligatures:no-common-ligatures; color: #272ad8" >1) {

Uilabel*over=[[uilabel alloc]initwithframe:cgrectmake (0, 0, 400, 666)];

[Email protected] "meal, do it again!" ";

Over.font=[uifont systemfontofsize:50 weight:33];

Over.textcolor=[uicolor Redcolor];

Over.backgroundcolor=[uicolor Bluecolor]

;

[Self.view Addsubview:over];

}

_level++;

[Email protected] (_level). StringValue;

Each _KK value is negative when it controls the motion of the picture, so add it here

If the judgement is positive, if it is positive, then minus

if (_kk>0) {

_kk+=10;

}else{

_kk+=-10;

}

if (_kk2>0) {

_kk2+=10;

}else{

_kk2+=-10;

}

if (_kk3>0) {

_kk3+=10;

}else{

_kk3+=-10;

}

////////

if (_level>=2) {

Uiimageview*good=[[uiimageview alloc]initwithframe:cgrectmake (0, 0, 380, 666)];

Good.image=[uiimage imagenamed:@ "08.jpg"];

[Self.view Addsubview:good];

}

Lan Yi iOS to write small games to implement new features

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.