IceMx.Mvc my JS MVC framework six, improve Plants vs. Zombies (sunflower debut)

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

The picture is truth, nonsense not say above


See the garden friend support was inspired, more think we should do it, although he was a rookie, but should also share their experiences, as long as there is a benefit that is worth.

I need to download 1 integral CSDN forum, is not completely free to go out because I think one thing if you get too easily tend not to cherish, even a little bit cost only symbolic, I also hope to be able to pay a little more.

If you don't have the CSDN integral, give comments or recommendations, or contact me, can get the code, as long as pay 1 little effort, thank you for your support.


ok, Access point

The long-awaited sunflower will finally debut, welcome.


Sunflower is actually very simple, his role is to produce the sun, as long as a timer set, at a specified time to generate the sun OK.

 1     function XiangRiKui(config) {
 2         this.body = config.body.clone();
 3         this.id = 1;
 4         this.x = config.x;
 5         this.y = config.y;
 6         var _self = this;
 7      
 8         //The sunlight
 9         setInterval(function () {
10             //Registered several events to the sun
11             var myYangGuang = $yangGuang.clone();
12             myYangGuang.mouseover(function () {
13                 $(this).find("img").attr("src", "/img/game/yangGuang2.png");
14             })
15             myYangGuang.mouseout(function () {
16                 $(this).find("img").attr("src", "/img/game/yangGuang.png");
17             })
18 
19             myYangGuang.click(function () {
20                 $i.Ui.tip("The sun +1");
21                 myYangGuang.remove();
22             })
23             
24             myYangGuang.appendTo($zhanChang).css({ "left": _self.x * 100, "top": _self.y * 100 }).animate({ top: "+=20", "left": "+=80" }, 500);
25         },10000)
26         
27     }

Here the sun registered a click event, recovery of sunshine increase integral time click, is it right? It's very simple.

Previously only one plant, now more than one, it's a factory production plant, factory, in the JavaScript mode is very simple.

 1 //Plant factory 
 2 function MakeZhiWu(id, config) {
 3         switch (id) {
 4             case 0:
 5                 //Pea shooter
 6                 config.body = $wanDou;
 7                 return new WanDou(config);
 8                 break;
 9             case 1:
10                 //Sunflower
11                 config.body = $xiangRiKui;
12                 return new XiangRiKui(config);
13                 break;
14             default:
15                 break;
16         }
17     }

The interface on the left side of the part which I called icons, each icon corresponding to a ID, click on the icon to when the ID icon to the factory, so there is a plant.


The bullet is a bullet type, function is to attack, collision detection, display hit animation, notify the zombie you hit. The following code.

 1 function ZiDan(config) {
 2         this.body = $ziDan.clone();
 3         this.speed = 10;
 4         this.y = config.gameY;
 5         this.timer = 0;
 6         var _self = this;
 7         var nowLine = _self.y + 1;
 8         //var p = $i.Game.IntPointToWebPoint(config.x, config.y, $stemp, $body);
 9 
10         this.body.css({ "left": config.x, "top": config.y });
11 
12         this.Run = function () {
13             this.timer = setInterval(function () {
14                 var left = $i.Game.MoveRight(_self.body, 4);
15                 var line = [];
16                 switch (nowLine) {
17                     case 1:
18                         line = $listJiangShi1;
19                         break;
20                     case 2:
21                         line = $listJiangShi2;
22                         break;
23                     case 3:
24                         line = $listJiangShi3;
25                         break;
26                     case 4:
27                         line = $listJiangShi4;
28                         break;
29                     case 5:
30                         line = $listJiangShi5;
31                         break;
32                     case 6:
33                         line = $listJiangShi6;
34                         break;
35                 }
36                 
37               
38                 //Collision detection
39                 for (var i = 0; i <line.length; i++) {
40                     if (left >= line[i].body.position().left) {
41                         //var nowLine = i + 1;
42 
43                         //Hit the processing
44                         clearInterval(_self.timer);
45                         //The bullet hit the animation
46                         $i.Game.Play(_self.body.find("img"), ["/img/game/zidan2.png", "/img/game/zidan3.png"], 60, function () {
47                             _self.body.remove();
48                             delete _self;
49                         });
50 
51                         //Zombie oligemia
52                         line[i].OnFire(function () {
53                             line.splice(i, 1);
54                         });
55                      
56                         if (line.length == 0) {
57                             $i.Event.FireEvent("Line" + nowLine + "Clear");
58                         }
59 
60                         break;
61                     }
62                 }
63                 //Boundary detection
64                 if (left > 800) {
65                     clearInterval(_self.timer);
66                     _self.body.remove();
67                     delete _self;
68                 }
69 
70             }, this.speed);
71         }
72     }

I haven't written for the factory, the next increase when other plants may have to write the factory, because the bullet properties of some plants are not the same. Look at these don't know what you feel, do you want to find fault with it, come on please comment.


Summary

If you feel this is to help you, please support me. If you have a good idea, please enlighten.

If the three layer structure of the Js are interested, please pay attention to the classification of other articles.

Download address

This download requires 1 points in CSDN integration, not to pay 1 costs is not something to cherish, so and click download.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Cassandra at November 15, 2013 - 11:33 AM