Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----------------------------------------------------------------------------------------
- --
- -- play.lua
- --
- -----------------------------------------------------------------------------------------
- local storyboard = require( "storyboard" )
- local scene = storyboard.newScene()
- local scrollView
- local Mask = require ("mask")
- local txt_wep
- local txt_ppl
- local txt_fod
- local txt_med
- local calculate_stats
- local titleText
- local areaImage
- local areaImage
- local gameGroup
- -- Chance for Zombies = % of 1 of 3 stages
- -- Chance for People type = % of 1 of 3 stages
- area = { title = "Convenience store",
- image = "img_cornerStore",
- chanceForZombies = {50, 60, 99 },
- numberOfZombies = {3, 6, 9},
- cacheFood = { 80, 40, 20 },
- cacheMedicine = { 10, 7, 3 },
- cacheWeapons = { 1, 0, 0 },
- ChancePplType = { 70, 40, 7},
- numberOfPeople = { 5, 3, 1 }
- }
- place_cornerStore = area
- area = { title = "Gas Station",
- image = "img_gasStation",
- chanceForZombies = { 30, 45, 90},
- numberOfZombies = { 3, 6, 9},
- cacheFood = { 80, 40, 20 },
- cacheMedicine = { 10, 7, 3 },
- cacheWeapons = { 3, 1, 1 },
- ChancePplType = { 60, 40, 5},
- numberOfPeople = { 6, 3, 2 }
- }
- place_gasStation = area
- area = { title = "Farm",
- image = "img_farm",
- chanceForZombies = { 40, 60, 90},
- numberOfZombies = { 13, 6, 5},
- cacheFood = { 180, 90, 40 },
- cacheMedicine = { 10, 6, 2 },
- cacheWeapons = { 15, 10, 7 },
- ChancePplType = { 60, 40, 5},
- numberOfPeople = { 6, 3, 1 }
- }
- place_Farm = area
- area = { title = "Field",
- image = "img_field",
- chanceForZombies = { 20, 35, 70},
- numberOfZombies = { 2, 4, 8},
- cacheFood = { 2, 1, 1 },
- cacheMedicine = { 5, 3, 1 },
- cacheWeapons = { 15, 10, 7 },
- ChancePplType = { 60, 40, 5},
- numberOfPeople = { 6, 3, 1 }
- }
- place_Field = area
- road_stage = { place_Field, place_Field, place_Field, place_Field, place_Field, place_Farm, place_Farm, place_Farm, place_Farm, place_Farm, place_Field, place_Field, place_Field, place_Field, place_Field, place_Farm, place_gasStation, place_gasStation, place_cornerStore, place_cornerStore}
- -- include Corona's "widget" library
- --local widget = require "widget"
- -- rosetta:getString("A")
- --------------------------------------------
- -----------------------------------------------------------------------------------------
- -- BEGINNING OF YOUR IMPLEMENTATION
- --
- -- NOTE: Code outside of listener functions (below) will only be executed once,
- -- unless storyboard.removeScene() is called.
- --
- -----------------------------------------------------------------------------------------
- -- local new_gamedata = { Days = 2, Score = 0, enemiesKilled= enemiesKilled, enemy = enemy, enemies= enemies, People = People, Food = Food, Medicine = Medicine, Weapons = Weapons } _disk.saveTable( new_gamedata, "SaveGameData.txt", system.DocumentsDirectory)
- -- Called when the scene's view does not exist:
- function scene:createScene( event )
- group = self.view
- gameGroup = display.newGroup()
- -- display a background image
- local background = display.newImageRect( "res/bk_default.png", display.contentWidth, display.contentHeight )
- background:setReferencePoint( display.TopLeftReferencePoint )
- background.x, background.y = 0, 0
- _gameData = _disk.loadTable ("SaveGameData.txt", system.DocumentsDirectory)
- --[[
- -- Title
- local title = display.newText( rosetta:getString("Touch to go back") , 0, 0, native.systemFontBold, 16)
- title:setTextColor( 255,255,255)
- title.x = display.contentCenterX
- title.y = display.contentCenterY
- title.name = "title"
- -- Touch to go back
- local function touched ( event )
- if ("ended" == event.phase) then
- storyboard.gotoScene( "scene_play", "fade", 500 )
- end
- end
- ]]
- gameGroup:insert(background)
- --group:insert( background )
- txt_ppl = display.newText( _gameData.People, 0, 30, "Verdana-Bold", 20 )
- txt_ppl.x, txt_ppl.y = _CX *.25 ,40 -- center title
- txt_fod = display.newText( _gameData.Food, 0, 30, "Verdana-Bold", 20 )
- txt_fod.x, txt_fod.y = _CX * .75 ,40 -- center title
- txt_med = display.newText( _gameData.Medicine, 0, 30, "Verdana-Bold", 20 )
- -- txt_med = display.newText( , 0, 30, "Verdana-Bold", 40 )
- txt_med.x, txt_med.y = _CX *1.25 ,40 -- center title
- txt_wep = display.newText( _gameData.Weapons, 0, 30, "Verdana-Bold", 20 )
- -- txt_wep = display.newText( (math.floor(_gameData.Medicine/_gameData.People)), 0, 30, "Verdana-Bold", 20 ) -- (math.floor(_gameData.Medicine/_gameData.People))
- txt_wep.x, txt_wep.y = _CX *1.75 ,40 -- center title
- txt_wep:setTextColor( 255,255,0 )
- calculate_stats()
- gameGroup:insert ( txt_ppl )
- gameGroup:insert ( txt_fod )
- gameGroup:insert ( txt_med )
- gameGroup:insert ( txt_wep )
- -- all display objects must be inserted into group
- --group:insert( title )
- -- group:insert( scrollView )
- -- scrollView.isVisible = false
- group:insert (gameGroup)
- end
- function calculate_stats()
- local find_difference
- if _gameData.People <=3 then
- txt_ppl:setTextColor( 255,0,0 )
- elseif _gameData.People >=4 and _gameData.People <= 14 then
- txt_ppl:setTextColor( 255,255,0 )
- else
- txt_ppl:setTextColor( 0,255,0 )
- end
- find_difference = (math.floor(_gameData.Food/_gameData.People))
- --txt_fod.x, txt_fod.y = _CX * .75 ,40 -- center title
- if find_difference <= 3 then
- txt_fod:setTextColor( 255,0,0 )
- elseif find_difference >=4 and find_difference <=9 then
- txt_fod:setTextColor( 255,255,0 )
- else
- txt_fod:setTextColor( 0,255,0 )
- end
- find_difference = (math.floor(_gameData.Medicine/_gameData.People))
- -- txt_med = display.newText( , 0, 30, "Verdana-Bold", 40 )
- if find_difference >= 2 then
- txt_med:setTextColor( 0,255,0 )
- elseif find_difference == 1 then
- txt_med:setTextColor( 255, 255, 0)
- else
- txt_med:setTextColor( 255,0,0)
- end
- -- txt_med.x, txt_med.y = _CX *1.25 ,40 -- center title
- find_difference = (math.floor(_gameData.Weapons/_gameData.People))
- -- txt_wep = display.newText( (math.floor(_gameData.Medicine/_gameData.People)), 0, 30, "Verdana-Bold", 20 ) -- (math.floor(_gameData.Medicine/_gameData.People))
- if find_difference >= 2 then
- txt_wep:setTextColor( 0,255,0 )
- elseif find_difference == 1 then
- txt_wep:setTextColor( 255, 255, 0)
- else
- txt_wep:setTextColor( 255,0,0)
- end
- txt_ppl.text = _gameData.People
- txt_fod.text = _gameData.Food
- txt_med.text = _gameData.Medicine
- txt_wep.text = _gameData.Weapons
- end
- function setScrollView()
- --- MAKE THE SCROLL Listener
- areaImage = display.newImageRect( "res/Story1.png", 190, 130 )
- -- local background = display.newImageRect( "res/bk_default.png", display.contentWidth, display.contentHeight )
- areaImage:setReferencePoint( display.TopLeftReferencePoint )
- areaImage.x, areaImage.y = 10, place_content
- gameGroup:insert (areaImage)
- -- gameGroup:insert(scrollView)
- end
- -- Called immediately after scene has moved onscreen:
- function scene:enterScene( event )
- group = self.view
- -- group.scrollView.isVisible = false
- -- titleText.text = ( rosetta:getString ("Day ") .. _gameData.Days ) -- BUGS OUT
- -- scrollView.titleText.x = display.contentCenterX
- -- INSERT code here (e.g. start timers, load audio, start listeners, etc.)
- local Button_continueReleased = function( event )
- print (" *** HEY !!! *** ")
- --storyboard.gotoScene( "scene_play", "fade", 500 )
- _gameData.People = math.random (1, 4)
- calculate_stats()
- end
- -- Called immediately after scene has moved onscreen:
- -- INSERT code here (e.g. start timers, load audio, start listeners, etc.)
- Button_scout = widget.newButton
- {
- id = "Button_scout",
- defaultFile = "res/btn_up.png",
- overFile = "res/btn_down.png",
- label = rosetta:getString("Scout"),
- font = "Tungsten",
- labelYOffset = 3,
- fontSize = _FontSize1,
- emboss = true,
- labelColor =
- {
- default = { 0, 0, 0, 255 },
- },
- onRelease = Button_scoutReleased,
- }
- Button_camp = widget.newButton
- {
- id = "Button_camp",
- defaultFile = "res/btn_up.png",
- overFile = "res/btn_down.png",
- label = rosetta:getString("Camp"),
- font = "Tungsten",
- labelYOffset = 3,
- fontSize = _FontSize1,
- emboss = true,
- labelColor =
- {
- default = { 0, 0, 0, 255 },
- },
- onRelease = Button_campReleased,
- }
- Button_moveOn = widget.newButton
- {
- id = "Button_moveOn",
- defaultFile = "res/btn_up.png",
- overFile = "res/btn_down.png",
- label = rosetta:getString("Move On"),
- font = "Tungsten",
- labelYOffset = 3,
- fontSize = _FontSize1,
- emboss = true,
- labelColor =
- {
- default = { 0, 0, 0, 255 },
- },
- onRelease = Button_moveOnReleased,
- }
- -- scrollView.isVisible = true
- Button_scout.x = _CX *.5
- Button_scout.y = _CY * 2.54
- Button_camp.x = _CX *1.5
- Button_camp.y = _CY * 2.54
- Button_moveOn.x = _CX *1.5 -- + math.random(1,10) -- 160
- Button_moveOn.y = _CY * 2.8 -- + math.random(1,10)-- 130
- group:insert (Button_scout)
- group:insert (Button_camp)
- group:insert (Button_moveOn)
- -- setScrollView()
- end
- -- Called when scene is about to move offscreen:
- function scene:exitScene( event )
- local group = self.view
- -- INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.)
- end
- -- If scene's view is removed, scene:destroyScene() will be called just prior to:
- function scene:destroyScene( event )
- local group = self.view
- end
- -----------------------------------------------------------------------------------------
- -- END OF YOUR IMPLEMENTATION
- -----------------------------------------------------------------------------------------
- -- "createScene" event is dispatched if scene's view does not exist
- scene:addEventListener( "createScene", scene )
- -- "enterScene" event is dispatched whenever scene transition has finished
- scene:addEventListener( "enterScene", scene )
- -- "exitScene" event is dispatched whenever before next scene's transition begins
- scene:addEventListener( "exitScene", scene )
- -- "destroyScene" event is dispatched before view is unloaded, which can be
- -- automatically unloaded in low memory situations, or explicitly via a call to
- -- storyboard.purgeScene() or storyboard.removeScene().
- scene:addEventListener( "destroyScene", scene )
- -----------------------------------------------------------------------------------------
- return scene
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement