local ragdogLib = {}; ragdogLib.convertHexToRGB = function(hexCode) assert(#hexCode == 7, "The hex value must be passed in the form of #XXXXXX"); local hexCode = hexCode:gsub("#","") return tonumber("0x"..hexCode:sub(1,2))/255,tonumber("0x"..hexCode:sub(3,4))/255,tonumber("0x"..hexCode:sub(5,6))/255; end return ragdogLib;
local physics = require( "physics" ) physics.start() local ragdogLib = require "ragdogLib"; function randomcolor() local colors = { "#e67e22","#e74c3c" ,"#f1c40f","#1abc9c","#8e44ad" } local finalcolor = colors[math.random(1, 5)] return finalcolor end local function bombTouched(self,event) if ( event.phase == "began" ) then print(unpack(self.fillColor)) Runtime:removeEventListener( "enterFrame", event.self ) event.target:removeSelf() self = nil score = score + 1 -- add new score to current score scoreText.text = score end end local function addnewobject() local startingpoint = math.random(display.contentWidth\*0.1,display.contentWidth\*0.9) local bombstartnew = display.newRect( startingpoint, -340, 50, 50) physics.addBody( bombstartnew ) local color1, color2, color3 = ragdogLib.convertHexToRGB(randomcolor()) bombstartnew:setFillColor(color1, color2, color3); bombstartnew.fillColor = {color1, color2, color3} bombstartnew:addEventListener( "touch", bombstartnew ) Runtime:addEventListener( "enterFrame", bombstartnew ) end timer.performWithDelay(500, addnewobject,0)