藍懿iOS編寫小遊戲實現新功能

來源:互聯網
上載者:User

標籤:

今天是練習日,通過幾天的系統學習,我對基礎的一些知識有了簡單的瞭解,今天用了一天的時間通過整理幾天所學到的東西,成功編寫了一個簡單的小遊戲。遊戲中幾乎用到了學到的所有控制項功能,Label,text,UiImageView,UiButton,NsTimer等。  今天我自己編寫的遊戲是實現一個角色圖片通過設定好的四個button 按鈕點擊控制它的移動,中間有三個障礙圖片,碰到障礙會減少血量,並且回到起始點。檢測碰撞的地方用到了NsTimer的知識,其中還有一個雷區,雷區裡通過問李國斌老師學會了新知識,[Image removeFromSubview];實現了把之前的產生圖片抹除。雖然是一個很簡單的小遊戲,雖然是一個很多BUG的遊戲,但是我還是很高興,畢竟是自己獨立編寫的下面是其中一段代碼:

//實現邊框左右的排布

    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];

            

        }

        

    }

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

    

    //    下面的_time1是控制三個障礙圖片運動

    

    _time1=[NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(move1) userInfo:nilrepeats:YES];

    //   下面的_time2時控制雷區出現地雷

    _time2=[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(diLei)userInfo:nil repeats:YES];

    

    //判斷是否相撞

    _time3=[NSTimer scheduledTimerWithTimeInterval:.02 target:self selector:@selector(crash)userInfo:nil repeats:YES];

}

///////////////////////////////////////跳出頁面程式

//        碰撞檢測

 

-(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);

        //實現了發生碰撞一次剩餘血量就減一

        _blood--;

        //這裡的text一定要放在這裡寫。顯示剩餘剩餘血量。

        

        

        [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]"大菜逼,重來吧!";

            over.font=[UIFont systemFontOfSize:50 weight:33];

            over.textColor=[UIColor redColor];

            over.backgroundColor=[UIColor blueColor]

            ;

            [self.view addSubview:over];

        }

        

        _level++;

        [email protected](_level).stringValue;

        // ********每個_kk的值在控製圖片運動的時候有負值,所以在這裡加上

        //         if判斷是否為正數,如果是正數就加,負的就減

        

        

        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];

        }

        

藍懿iOS編寫小遊戲實現新功能

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.