Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --ButtonsBirds.lua
- Bird = {}
- Bird.pathForBehaviours = "Assets/Birds/Behaviour/"
- Bird.group = display.newGroup( )
- Bird.group.x = 20
- Bird.group.y = display.contentHeight
- --group = group
- local imgW, imgH = 48, 48
- local behaviourCounter = 0
- --BIRDS TABLE
- Bird.buttons = {}
- --BEHAVIOURS TABLE
- Bird.buttons.behaviours = {
- [1] = {
- name = "behaviour",
- sound = "behaviour.mp3" or nil,
- imageObj = display.newImageRect( Bird.pathForBehaviours .. "behaviour.png", imgW, imgH ),
- sql = "SELECT * FROM birds WHERE PATTERN = 'Spettete'", -- WICH FUNCTION TO LISTEN TO
- },
- [2] = {
- name = "birdHouse",
- sound = "birdHouse.mp3" or nil,
- imageObj = display.newImageRect( Bird.pathForBehaviours .. "birdHouse.png", imgW, imgH ),
- sql = "SELECT * FROM birds WHERE PATTERN = 'Stripete'", -- WICH FUNCTION TO LISTEN TO
- },
- [3] = {
- name = "catchingInsectsInFlight",
- sound = "catchingInsectsInFlight.mp3" or nil,
- imageObj = display.newImageRect( Bird.pathForBehaviours .. "catchingInsectsInFlight.png", imgW, imgH ),
- listnerFunctionName = "playButton", -- WICH FUNCTION TO LISTEN TO
- },
- [4] = {
- name = "climbingTree",
- sound = "climbingTree.mp3" or nil,
- imageObj = display.newImageRect( Bird.pathForBehaviours .. "climbingTree.png", imgW, imgH ),
- listnerFunctionName = "playButton", -- WICH FUNCTION TO LISTEN TO
- },
- }
- function Bird:test(event)
- if ( event.phase == "began" ) then
- print( "Touch started")
- print(self.id)
- -- sql = "SELECT * FROM birds WHERE PATTERN = 'self.id'"
- -- sql = "SELECT * FROM birds WHERE PATTERN = 'Stripete'"
- elseif ( event.phase == "ended" ) then
- print( "Touch ended" )
- end
- updateSql()
- return true
- end
- function Bird:initButtons()
- for k,v in ipairs (Bird.buttons.behaviours) do
- behaviourCounter = behaviourCounter + 1
- local img = v["name"] .. k
- img = v["imageObj"]
- img.x = (imgW + 5) * behaviourCounter --.. behaviourCounter = v["imageObj"]
- img.anchorX = 0.5
- img.anchorY = 0.15
- img:addEventListener( "touch", img )
- img.id = v["name"]
- sql = v["sql"]
- img.touch = Bird.test
- Bird.group:insert(img)
- print(v["name"])
- end
- print( "Bird.group has "..Bird.group.numChildren.." children")
- return true
- end
- function Bird:playButton(self) -- FUNCTION FOR THE BUTTONS
- print("My name is " .. self.name)
- return true
- end
- function playButton(self) -- FUNCTION FOR THE BUTTONS
- print("im a button")
- return true
- end
- function Bird:setupButtons()
- for i = 1, 4 do
- behaviourCounter = behaviourCounter + 1
- -- Bird.buttons.behaviours.imageObj[i].x = imgW * behaviourCounter
- print(Bird.buttons.behaviours[3][2])
- end
- return true
- end
- Bird:initButtons()
- --Bird:setupButtons()
- return Bird
- ----------------------
- ----------------------
- --playGame.lua file
- display.setStatusBar(display.HiddenStatusBar)
- require( "sqlite3" )
- birds = require("Classes.ButtonsBirds")
- --LOCALS FWD
- local composer = require "composer"
- local scene = composer.newScene()
- local path = system.pathForFile( "Birds.sqlite", system.ResourceDirectory )
- local imagePath = "Images/Birds/"
- local text, t, counter, bgItem, bg, colorConverter
- local rowBg = {}
- local rowName = {}
- local rowLatin = {}
- local rowImage = {}
- local playButton = {}
- removeGroup = {}
- updateSql = {}
- local _W, _H = display.contentWidth, display.contentHeight
- local group = {}
- local containerGroup = display.newGroup( )
- local dashboardGroup = display.newGroup( )
- --GLOBALS FWD
- _G.msgFont = "Cheboygan"
- _G.db = sqlite3.open( path )
- -- FUNCTIONS
- local function onSystemEvent( event )
- if ( event.type == "applicationExit" ) then
- db:close()
- end
- end
- function colorConverter(r, g, b)
- local colorR, colorG, colorB
- colorR = r/256; colorG = g/256; colorB = b/256
- return colorR, colorG, colorB
- end
- function removeGroup()
- for i = 1, #group do
- print(#group)
- end
- return true
- end
- -- "scene:create()"
- function scene:create( event )
- local sceneGroup = self.view
- Bird.group = Bird.group
- end
- -- "scene:show()"
- function scene:show( event )
- local sceneGroup = self.view
- local phase = event.phase
- if ( phase == "will" ) then
- elseif ( phase == "did" ) then
- -- sql = "SELECT * FROM birds WHERE PATTERN = 'Spettete'"
- sql = "SELECT * FROM birds"
- function updateSql()
- counter = 0
- if #group > 1 then removeGroup() return true end
- -- sql = "SELECT * FROM birds LIMIT 10"
- for row in db:nrows( sql ) do
- counter = counter + 1
- group[counter] = display.newGroup()
- group[counter].x = 5
- group[counter].y = 50 * counter
- rowBg[counter] = display.newRoundedRect( 0, 0, _W-10, 50, 5 )
- rowBg[counter].anchorX = 0
- rowBg[counter]:setFillColor( colorConverter(2, 121, 22))
- rowName[counter] = display.newText( row.NAME, 5, 5, native.systemFontBold, 24 )
- rowName[counter].anchorX = 0; rowName[counter].anchorY = 1
- rowName[counter]:setFillColor( colorConverter(255, 228, 0) )
- rowLatin[counter] = display.newText( row.LATIN, 5, rowName[counter].height-18, native.systemFontBold, 14 )
- rowLatin[counter].anchorX = 0; rowName[counter].anchorY = 1
- rowLatin[counter]:setFillColor( 1,1,1 )
- rowImage[counter] = display.newImageRect(tostring(imagePath .. row.NAME) .. ".jpg", 45,45 )
- rowImage[counter].anchorX = 1
- rowImage[counter].x = rowBg[counter].width - 10
- sceneGroup:insert(group[counter])
- group[counter]:insert(rowBg[counter])
- group[counter]:insert(rowName[counter])
- group[counter]:insert(rowLatin[counter])
- group[counter]:insert(rowImage[counter])
- end
- return true
- end
- -- Runtime:addEventListener( "enterFrame", updateSql )
- Runtime:addEventListener( "system", onSystemEvent )
- end
- sceneGroup:insert(dashboardGroup)
- dashboardGroup:insert(birds.group)
- print( "dashboardGroup has "..birds.group.numChildren.." children")
- end
- -- "scene:hide()"
- function scene:hide( event )
- local sceneGroup = self.view
- local phase = event.phase
- if ( phase == "will" ) then
- elseif ( phase == "did" ) then
- end
- end
- function scene:destroy( event )
- local sceneGroup = self.view
- -- Runtime:removeEventListener( "system", onSystemEvent )
- end
- -- Listener setup
- scene:addEventListener( "create", scene )
- scene:addEventListener( "show", scene )
- scene:addEventListener( "hide", scene )
- scene:addEventListener( "destroy", scene )
- return scene
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement