Achieve vertical columns turntable game with lua

Under combing wheel flow of the game, click, open turn, stop, the results, so focus on the process simulation turn!

Given data structure! Suppose there is a turntable rows 4, 5, to a coherent visual effects, we need to design a board five rows and five columns (hidden line above the first board) so a total of 5 * 5 = 25 item, the width of each item high consistent state of each column wheel control with int, 1, 2, representing the turn, stop and stop soon

When the start switch, each column of status changes to 1, starting from the first column, the entire column of each row is moved down, the item is moved to a height, return to the starting height of the entire column, while the remaining columns except for the first row from Alternatively to the next image, i.e. the image is replaced on the Bank line image, the first image line transducer in FIG random, this process cycle rotation

To stop in time, each column 3 becomes a state, when the last cycle of the above procedure, when the height of the column can return to the initial state becomes 2, the rotation is stopped

Codes come!

 
    1 Game{ 
 
2      Row = . 5 
. 3      COL = . 5 
. 4      startPos = 300  - starting position of the column 
. 5      endpos = 150   - end position of the column, the default FIG high 150 
. 6      Item = {}         - photos 
. 7      itemcol = {}     - All column node 
. 8      colstate = {}    - nematic state, a rotation stop 2, 3 will stop    
. 9      speed = 30       - the moving speed of each frame 
10      stopdelay = 30  - delay parameter dial is stopped, the table can also be used stop delay settings for each column 
. 11  }
 12 is  
13 is  functionGame: the Init ()
 14      for I = 0 , self.col - . 1  do 
15          self.item [I] = {}
 16          self.colstate [I] = 2 
. 17          for J = 0 , self.row- . 1  do 
18 is              Self .Item [I] [J] .image = randomimage - to all nodes image assignments 
. 19          End 
20 is      End 
21 is  End 
22 is  
23 is  function Game: the Update ()
 24      for I = 0 , self.col - . 1  do 
25          IF self.colstate[i] == 1 then
26             self.itemcol[i].pos.y = self.itemcol[i].pos.y - vector3(0,speed,0) --列的位置向下移动
27             if self.itemcol[i].pos.y <= self.endpos then
28                 self.itemcol[i].pos.y = self.startpos
29                 for j = self.row -1, 1, -1 do
30                     self.item[i][j].image = self.item[i][j-1].image
31                 end
32                 self.item[i][0].image = randomimage
33                 if self.stopdelay >= 0 then
34                     self.stopdelay = self.stopdelay -1
35                     if self.stopdelay <= 0 then
36                         self.colstate[i] = 3
37                     end
38                 end
39             end
40         else if if self.colstate[i] == 3 then
41             self.itemcol[i].pos.y = self.itemcol[i].pos.y - vector3(0,speed,0) --列的位置向下移动
42             if self.itemcol[i].pos.y <= self.endpos then
43                 self.itemcol[i].pos.y = self.startpos
44                 for j = self.row -1, 1, -1 do
45                     self.item[i][j].image = self.item[i][j-1].image
46                 end
47                 self.item[i][0].image = randomimage
48                 self.colstate[i] = 2
49             end
50        end
    end
51 end

 

Guess you like

Origin www.cnblogs.com/dongmianbaozi/p/11688448.html