Created
          April 27, 2012 01:54 
        
      - 
      
 - 
        
Save devilstower/2505005 to your computer and use it in GitHub Desktop.  
    Battle Chips 0.30 (part 2)
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Socket = class() | |
| function Socket:init(code, x, y) | |
| self.code = code | |
| self.x = x | |
| self.y = y | |
| self.frame = Frame(x, y, x + 145, y + 32) | |
| self.value = 1 | |
| end | |
| function Socket:draw() | |
| pushStyle() | |
| if self.code == nil then | |
| fill(209, 205, 192, 255) | |
| stroke(73, 73, 73, 255) | |
| strokeWidth(2) | |
| self.frame:draw() | |
| for i = 0,4 do | |
| rect(self.frame.left + i * 30, self.frame.bottom + 2, | |
| self.frame.left + i * 30, self.frame.bottom + 6) | |
| rect(self.frame.left + i * 30, self.frame.top - 6 , | |
| self.frame.left + i * 30, self.frame.top - 2) | |
| end | |
| else | |
| fill(self.code.color) | |
| stroke(0, 0, 0, 255) | |
| strokeWidth(1) | |
| self.frame:draw() | |
| font("Futura-Medium") | |
| fontSize(16) | |
| fill(255, 255, 255, 255) | |
| text(self.code.long, | |
| self.frame.left + 10, self.frame.bottom + 6) | |
| if self.code.hasValue then | |
| noStroke() | |
| fill(231, 227, 227, 255) | |
| ellipse(self.x + 110, self.y + 16, 20) | |
| ellipse(self.x + 125, self.y + 16, 20) | |
| rect(self.x + 110, self.y + 6, self.x + 125, self.y + 26) | |
| fill(47, 47, 47, 255) | |
| textMode(CENTER) | |
| text(self.value, self.x + 120, self.y + 15) | |
| end | |
| end | |
| popStyle() | |
| end | |
| function Socket:touched(touch) | |
| if self.frame:touched(touch) then | |
| return true | |
| end | |
| return false | |
| end | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | TextBox = class() | |
| -- TextBox | |
| -- ver. 1.0 | |
| -- a control for basic string editing | |
| -- ==================== | |
| function TextBox:init(x, y, w, s) | |
| self.x = x | |
| self.y = y | |
| self.w = w | |
| self.text = s | |
| self.blink = ElapsedTime | |
| self.blinkstate = true | |
| end | |
| function TextBox:draw() | |
| local x, w, h | |
| pushStyle() | |
| pushMatrix() | |
| font("Futura-Medium") | |
| textMode(CENTER) | |
| fontSize(18) | |
| rectMode(CORNER) | |
| strokeWidth(1) | |
| stroke(0, 0, 0, 255) | |
| fill(228, 228, 228, 255) | |
| translate(self.x, self.y) | |
| rect(0, 0, self.w, 24) | |
| stroke(255, 255, 255, 255) | |
| --noFill() | |
| rect(2, 2, self.w - 4, 20) | |
| fill(22, 22, 22, 255) | |
| text(self.text, self.w / 2, 12) | |
| w, h = textSize(self.text) | |
| if self.blink < ElapsedTime - 0.3 then | |
| self.blink = ElapsedTime | |
| self.blinkstate = not self.blinkstate | |
| end | |
| if self.blinkstate then | |
| strokeWidth(2) | |
| stroke(45, 45, 45, 255) | |
| x = self.w / 2 + w / 2 + 2 | |
| line(x, 3, x, 21) | |
| end | |
| popMatrix() | |
| popStyle() | |
| end | |
| function TextBox:touched(touch) | |
| -- move cursor? For the moment, touching a textbox has no function | |
| end | |
| function TextBox:acceptKey(k) | |
| if k ~= nil then | |
| if string.byte(k) == nil then | |
| if string.len(self.text) > 0 then | |
| self.text = string.sub(self.text, | |
| 1, string.len(self.text) - 1) | |
| end | |
| end | |
| self.text = self.text..k | |
| end | |
| end | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Token = class() | |
| function Token:init(code, x, y, clr) | |
| -- you can accept and set parameters here | |
| self.x = x | |
| self.y = y | |
| self.code = code | |
| end | |
| function Token:draw() | |
| pushStyle() | |
| stroke(0, 0, 0, 255) | |
| strokeWidth(2) | |
| fill(self.code.color) | |
| rect(self.x, self.y, self.x + 130, self.y + 32) | |
| fill(127, 127, 127, 255) | |
| rect(self.x, self.y, self.x + 8, self.y - 8) | |
| rect(self.x + 30, self.y, self.x + 38, self.y - 8) | |
| rect(self.x + 60, self.y, self.x + 68, self.y - 8) | |
| rect(self.x + 90, self.y, self.x + 98, self.y - 8) | |
| rect(self.x + 122, self.y, self.x + 130, self.y - 8) | |
| rect(self.x, self.y + 32, self.x + 8, self.y + 38) | |
| rect(self.x + 30, self.y + 32, self.x + 38, self.y + 38) | |
| rect(self.x + 60, self.y + 32, self.x + 68, self.y + 38) | |
| rect(self.x + 90, self.y + 32, self.x + 98, self.y + 38) | |
| rect(self.x + 122, self.y + 32, self.x + 130, self.y + 38) | |
| noStroke() | |
| fill(230, 230, 230, 255) | |
| font("Futura-Medium") | |
| fontSize(16) | |
| text(self.code.long, self.x + 4, self.y + 6) | |
| if self.code.hasValue then | |
| fill(231, 227, 227, 255) | |
| ellipse(self.x + 100, self.y + 16, 20) | |
| ellipse(self.x + 115, self.y + 16, 20) | |
| rect(self.x + 100, self.y + 6, self.x + 115, self.y + 26) | |
| fill(47, 47, 47, 255) | |
| text("1", self.x + 110, self.y + 4) | |
| end | |
| end | |
| function Token:touched(touch) | |
| if touch.x >= self.x and touch.x <= self.x + 130 and | |
| touch.y >= self.y and touch.y <= self.y + 30 then | |
| return true | |
| end | |
| return false | |
| end | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | TokenTray = class() | |
| function TokenTray:init(x, y) | |
| -- you can accept and set parameters here | |
| self.x = x | |
| self.y = y | |
| self.frame = Frame(x, y, x + 200, y + 850) | |
| self.selected = 0 | |
| self.tokens = {} | |
| self.tokens[1] = Token(codes[1], 30, 0) | |
| self.tokens[2] = Token(codes[2], 30, 0) | |
| self.tokens[3] = Token(codes[3], 30, 0) | |
| self.tokens[4] = Token(codes[4], 30, 0) | |
| self.tokens[5] = Token(codes[5], 30, 0) | |
| self.tokens[6] = Token(codes[6], 30, 0) | |
| self.tokens[7] = Token(codes[7], 30, 0) | |
| self.tokens[8] = Token(codes[8], 30, 0) | |
| self.tokens[9] = Token(codes[9], 30, 0) | |
| self.tokens[10] = Token(codes[10], 30, 0) | |
| for i = 1,10 do | |
| self.tokens[i].y = self.frame:height() - i * 80 - 10 | |
| end | |
| end | |
| function TokenTray:draw() | |
| pushStyle() | |
| pushMatrix() | |
| fill(177, 144, 60, 142) | |
| stroke(135, 122, 36, 245) | |
| strokeWidth(5) | |
| self.frame:draw() | |
| fill(127, 127, 127, 208) | |
| noStroke() | |
| translate(self.x, self.y) | |
| rect(4, self.frame:height() - 40, | |
| self.frame:width() - 4, self.frame:height() - 4) | |
| fill(252, 252, 252, 255) | |
| font("Futura-Medium") | |
| fontSize(16) | |
| text("CHIPS", 10, self.frame:height() - 30) | |
| for i = 1, table.maxn(self.tokens) do | |
| self.tokens[i]:draw() | |
| end | |
| popMatrix() | |
| popStyle() | |
| end | |
| function TokenTray:touched(touch) | |
| t = Ttouch(touch) | |
| self.selected = 0 | |
| t:translate(self.x, self.y) | |
| for i = 1,10 do | |
| if self.tokens[i]:touched(t) then | |
| self.selected = i | |
| return true | |
| --sound(SOUND_SHOOT, 773) | |
| end | |
| end | |
| return false | |
| end | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Ttouch = class() | |
| -- Translatable Touch | |
| -- ver. 1.0 | |
| -- maps fields of a touch but is easily modified. | |
| -- ====================. | |
| function Ttouch:init(touch) | |
| self.x = touch.x | |
| self.y = touch.y | |
| self.state = touch.state | |
| self.prevX = touch.prevX | |
| self.prevY = touch.prevY | |
| self.deltaX = touch.deltaX | |
| self.deltaY = touch.deltaY | |
| self.id = touch.id | |
| self.tapCount = touch.tapCount | |
| self.timer = 0 | |
| end | |
| function Ttouch:translate(x, y) | |
| self.x = self.x - x | |
| self.y = self.y - y | |
| end | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | VColorSlider = class() | |
| function VColorSlider:init(x, y) | |
| self.frame = Frame(x - 30, y - 328, x + 60, y + 56) | |
| self.previousY = 0 | |
| self.pots = {} | |
| for i = 0, 15 do | |
| self.pots[i + 1] = Frame(self.frame.left, | |
| self.frame.top - i * 24 - 24, | |
| self.frame.right, self.frame.top - i * 24) | |
| end | |
| self.selected = 0 | |
| end | |
| function VColorSlider:draw() | |
| pushStyle() | |
| fill(143, 158, 166, 255) | |
| stroke(25, 25, 25, 255) | |
| strokeWidth(1) | |
| self.frame:draw() | |
| for i = 1, 16 do | |
| fill(colors[i]) | |
| self.pots[i]:draw() | |
| end | |
| popStyle() | |
| end | |
| function VColorSlider:touched(touch) | |
| if self.frame:touched(touch) then | |
| for i = 1, 16 do | |
| self.selected = 0 | |
| if self.pots[i]:touched(touch) then | |
| strokeWidth(3) | |
| stroke(106, 130, 155, 255) | |
| self.selected = i | |
| fill(colors[i]) | |
| self.pots[i]:draw() | |
| return true | |
| end | |
| end | |
| end | |
| return false | |
| end | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | VRobotSlider = class() | |
| function VRobotSlider:init(x, y) | |
| self.frame = Frame(x - 25, y - 640, x + 35, y + 210) | |
| self.previousY = 0 | |
| self.pots = {} | |
| for i = 1, 21 do | |
| self.pots[i] = Frame(self.frame.left + 2, | |
| self.frame.top - (i) * 40, | |
| self.frame.right - 2, self.frame.top - (i) * 40 + 40) | |
| end | |
| self.selected = 0 | |
| end | |
| function VRobotSlider:draw(robots) | |
| pushStyle() | |
| textMode(CENTER) | |
| font("Futura-CondensedExtraBold") | |
| fontSize(32) | |
| fill(208, 206, 202, 255) | |
| stroke(90, 87, 87, 155) | |
| strokeWidth(1) | |
| self.frame:draw() | |
| fontSize(32) | |
| for i = 1, 21 do | |
| if i == 1 then | |
| fill(92, 92, 92, 183) | |
| text("?", self.pots[1]:midX(), self.pots[1]:midY()) | |
| end | |
| if i > 1 then | |
| noStroke() | |
| --self.pots[i]:draw() | |
| pushMatrix() | |
| translate(self.pots[i]:midX(), | |
| self.pots[i]:midY()) | |
| scale(0.5) | |
| if i > 1 then | |
| robots[i - 1]:drawBase() | |
| end | |
| popMatrix() | |
| end | |
| end | |
| popStyle() | |
| end | |
| function VRobotSlider:touched(touch) | |
| if self.frame:touched(touch) then | |
| for i = 1, 21 do | |
| self.selected = 0 | |
| if self.pots[i]:touched(touch) then | |
| strokeWidth(3) | |
| noFill() | |
| stroke(106, 130, 155, 255) | |
| self.pots[i]:draw() | |
| self.selected = i - 1 | |
| print(i, self.selected, self.pots[1].left) | |
| return true | |
| end | |
| end | |
| end | |
| return false | |
| end | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | Vslider = class() | |
| function Vslider:init(x, y, v) | |
| self.frame = Frame(x - 30, y - 200, x + 30, y + 60) | |
| self.value = v | |
| self.previousY = 0 | |
| end | |
| function Vslider:draw() | |
| pushStyle() | |
| fill(143, 158, 166, 255) | |
| stroke(25, 25, 25, 255) | |
| strokeWidth(1) | |
| self.frame:draw() | |
| fill(231, 227, 227, 255) | |
| noStroke() | |
| ellipse(self.frame.left + 20, self.frame.top - 15, 25) | |
| ellipse(self.frame.right - 20, self.frame.top - 15, 25) | |
| rect(self.frame.left + 20, self.frame.top - 3, | |
| self.frame.right - 20, self.frame.top - 27) | |
| fill(23, 23, 23, 255) | |
| textMode(CENTER) | |
| fontSize(18) | |
| text(self.value, self.frame.left + 30, self.frame.top - 15) | |
| strokeWidth(2) | |
| line(self.frame:midX(), self.frame.bottom + 10, | |
| self.frame:midX(), self.frame.top - 50) | |
| stroke(207, 207, 207, 255) | |
| line(self.frame:midX() + 4, self.frame.bottom + 10, | |
| self.frame:midX() + 4, self.frame.top - 50) | |
| line(self.frame:midX() - 4, self.frame.bottom + 10, | |
| self.frame:midX() - 4, self.frame.top - 50) | |
| popStyle() | |
| end | |
| function Vslider:touched(touch) | |
| if self.frame:touched(touch) then | |
| self.value = math.floor((self.frame.top - 50 - touch.y) / 6) | |
| if self.value < 1 then self.value = 1 end | |
| if self.value > 30 then self.value = 30 end | |
| return true | |
| end | |
| return false | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment