Advertisement
lavalevel

scene_play.lua

Oct 6th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.55 KB | None | 0 0
  1. -----------------------------------------------------------------------------------------
  2. --
  3. -- play.lua
  4. --
  5. -----------------------------------------------------------------------------------------
  6.  
  7. local storyboard = require( "storyboard" )
  8. local scene = storyboard.newScene()
  9. local scrollView
  10. local Mask = require ("mask")
  11. local txt_wep
  12. local txt_ppl
  13. local txt_fod
  14. local txt_med
  15.  
  16. local calculate_stats
  17.  
  18. local titleText
  19. local areaImage
  20.  
  21. local areaImage
  22.  
  23.  
  24. local gameGroup
  25.  
  26. -- Chance for Zombies = % of 1 of 3 stages
  27. -- Chance for People type = % of 1 of 3 stages
  28.  
  29.  
  30.  
  31. area = { title = "Convenience store",
  32.          image = "img_cornerStore",
  33.          chanceForZombies = {50, 60, 99 },
  34.          numberOfZombies  = {3, 6, 9},
  35.          cacheFood =        { 80, 40, 20 },
  36.          cacheMedicine =    { 10, 7, 3 },
  37.          cacheWeapons =     { 1, 0, 0 },
  38.          ChancePplType =    { 70, 40, 7},          
  39.          numberOfPeople =   { 5, 3, 1 }
  40.  
  41.         }
  42.  
  43. place_cornerStore = area
  44.  
  45. area = { title = "Gas Station",
  46.          image = "img_gasStation",
  47.          chanceForZombies = { 30, 45, 90},
  48.          numberOfZombies  = { 3, 6, 9},
  49.          cacheFood =        { 80, 40, 20 },
  50.          cacheMedicine =    { 10, 7, 3 },
  51.          cacheWeapons =     { 3, 1, 1 },
  52.          ChancePplType =    { 60, 40, 5},          
  53.          numberOfPeople =   { 6, 3, 2 }
  54.  
  55.          
  56.         }
  57.  
  58. place_gasStation = area
  59.  
  60. area = { title = "Farm",
  61.          image = "img_farm",
  62.          chanceForZombies = { 40, 60, 90},
  63.          numberOfZombies  = { 13, 6, 5},
  64.          cacheFood =        { 180, 90, 40 },
  65.          cacheMedicine =    { 10, 6, 2 },
  66.          cacheWeapons =     { 15, 10, 7 },
  67.          ChancePplType =    { 60, 40, 5},          
  68.          numberOfPeople =   { 6, 3, 1 }
  69.  
  70.         }
  71.  
  72. place_Farm = area
  73.  
  74.  
  75. area = { title = "Field",
  76.          image = "img_field",
  77.          chanceForZombies = { 20, 35, 70},
  78.          numberOfZombies  = { 2, 4, 8},
  79.          cacheFood =        { 2, 1, 1 },
  80.          cacheMedicine =    { 5, 3, 1 },
  81.          cacheWeapons =     { 15, 10, 7 },
  82.          ChancePplType =    { 60, 40, 5},          
  83.          numberOfPeople =   { 6, 3, 1 }
  84.  
  85.         }
  86.  
  87. place_Field = area
  88.  
  89. 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}
  90.  
  91.  
  92.  
  93. -- include Corona's "widget" library
  94. --local widget = require "widget"
  95.  
  96. -- rosetta:getString("A")
  97. --------------------------------------------
  98. -----------------------------------------------------------------------------------------
  99. -- BEGINNING OF YOUR IMPLEMENTATION
  100. --
  101. -- NOTE: Code outside of listener functions (below) will only be executed once,
  102. --       unless storyboard.removeScene() is called.
  103. --
  104. -----------------------------------------------------------------------------------------
  105. --  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)
  106.  
  107. -- Called when the scene's view does not exist:
  108. function scene:createScene( event )
  109.     group = self.view
  110.  
  111.     gameGroup = display.newGroup()
  112.  
  113.     -- display a background image
  114.     local background = display.newImageRect( "res/bk_default.png", display.contentWidth, display.contentHeight )
  115.     background:setReferencePoint( display.TopLeftReferencePoint )
  116.     background.x, background.y = 0, 0
  117.  
  118.     _gameData = _disk.loadTable ("SaveGameData.txt", system.DocumentsDirectory)
  119.  
  120. --[[
  121.     -- Title
  122.     local title = display.newText( rosetta:getString("Touch to go back")  , 0, 0, native.systemFontBold, 16)
  123.     title:setTextColor( 255,255,255)
  124.     title.x = display.contentCenterX
  125.     title.y = display.contentCenterY  
  126.     title.name = "title"
  127.    
  128.     -- Touch to go back
  129.     local function touched ( event )
  130.         if ("ended" == event.phase) then
  131.             storyboard.gotoScene( "scene_play", "fade", 500 )
  132.         end
  133.     end
  134. ]]
  135.     gameGroup:insert(background)
  136.     --group:insert( background )
  137.  
  138.  
  139.     txt_ppl = display.newText( _gameData.People, 0, 30, "Verdana-Bold", 20 )
  140.     txt_ppl.x, txt_ppl.y = _CX *.25 ,40     -- center title
  141.  
  142.     txt_fod = display.newText( _gameData.Food, 0, 30, "Verdana-Bold", 20 )
  143.     txt_fod.x, txt_fod.y = _CX * .75 ,40        -- center title
  144.  
  145.     txt_med = display.newText( _gameData.Medicine, 0, 30, "Verdana-Bold", 20 )
  146.     -- txt_med = display.newText( , 0, 30, "Verdana-Bold", 40 )
  147.  
  148.     txt_med.x, txt_med.y = _CX *1.25 ,40    -- center title
  149.    
  150.  
  151.     txt_wep = display.newText( _gameData.Weapons, 0, 30, "Verdana-Bold", 20 )
  152.     -- txt_wep = display.newText( (math.floor(_gameData.Medicine/_gameData.People)), 0, 30, "Verdana-Bold", 20 ) -- (math.floor(_gameData.Medicine/_gameData.People))
  153.  
  154.     txt_wep.x, txt_wep.y = _CX *1.75 ,40        -- center title
  155.     txt_wep:setTextColor( 255,255,0 )
  156.  
  157.     calculate_stats()
  158.  
  159.     gameGroup:insert ( txt_ppl )
  160.     gameGroup:insert ( txt_fod )
  161.     gameGroup:insert ( txt_med )
  162.     gameGroup:insert ( txt_wep )
  163.  
  164.  
  165.     -- all display objects must be inserted into group
  166.    
  167.     --group:insert( title )
  168.  
  169.    
  170.     -- group:insert( scrollView )
  171.     -- scrollView.isVisible = false
  172.     group:insert (gameGroup)
  173. end
  174.  
  175.  
  176. function calculate_stats()
  177.  
  178.     local find_difference
  179.  
  180.     if _gameData.People <=3 then
  181.             txt_ppl:setTextColor( 255,0,0 )
  182.     elseif _gameData.People >=4 and _gameData.People <= 14 then
  183.             txt_ppl:setTextColor( 255,255,0 )
  184.     else
  185.             txt_ppl:setTextColor( 0,255,0 )
  186.     end
  187.  
  188.     find_difference = (math.floor(_gameData.Food/_gameData.People))
  189.  
  190.     --txt_fod.x, txt_fod.y = _CX * .75 ,40      -- center title
  191.  
  192.     if find_difference <= 3 then
  193.         txt_fod:setTextColor( 255,0,0 )
  194.     elseif find_difference >=4 and find_difference <=9 then
  195.         txt_fod:setTextColor( 255,255,0 )
  196.     else
  197.         txt_fod:setTextColor( 0,255,0 )
  198.     end
  199.  
  200.     find_difference = (math.floor(_gameData.Medicine/_gameData.People))
  201.  
  202.  
  203.     -- txt_med = display.newText( , 0, 30, "Verdana-Bold", 40 )
  204.  
  205.     if find_difference >= 2 then
  206.         txt_med:setTextColor( 0,255,0 )
  207.     elseif find_difference == 1 then
  208.         txt_med:setTextColor( 255, 255, 0)
  209.     else
  210.         txt_med:setTextColor( 255,0,0)
  211.     end
  212.  
  213.     -- txt_med.x, txt_med.y = _CX *1.25 ,40 -- center title
  214.    
  215.     find_difference = (math.floor(_gameData.Weapons/_gameData.People))
  216.  
  217.  
  218.     -- txt_wep = display.newText( (math.floor(_gameData.Medicine/_gameData.People)), 0, 30, "Verdana-Bold", 20 ) -- (math.floor(_gameData.Medicine/_gameData.People))
  219.     if find_difference >= 2 then
  220.         txt_wep:setTextColor( 0,255,0 )
  221.     elseif find_difference == 1 then
  222.         txt_wep:setTextColor( 255, 255, 0)
  223.     else
  224.         txt_wep:setTextColor( 255,0,0)
  225.     end
  226.  
  227.     txt_ppl.text = _gameData.People
  228.     txt_fod.text = _gameData.Food
  229.     txt_med.text = _gameData.Medicine
  230.     txt_wep.text = _gameData.Weapons
  231.  
  232. end
  233.  
  234.  
  235. function  setScrollView()
  236.  
  237. ---  MAKE THE SCROLL Listener
  238.  
  239.     areaImage = display.newImageRect( "res/Story1.png", 190, 130 )
  240.     -- local background = display.newImageRect( "res/bk_default.png", display.contentWidth, display.contentHeight )
  241.     areaImage:setReferencePoint( display.TopLeftReferencePoint )
  242.     areaImage.x, areaImage.y = 10, place_content
  243.  
  244.     gameGroup:insert (areaImage)
  245.  
  246.     -- gameGroup:insert(scrollView)
  247.  
  248.  
  249. end
  250.  
  251.  
  252. -- Called immediately after scene has moved onscreen:
  253. function scene:enterScene( event )
  254.     group = self.view
  255.  
  256.     -- group.scrollView.isVisible = false
  257.  
  258.     -- titleText.text = ( rosetta:getString ("Day ") .. _gameData.Days  )  -- BUGS OUT
  259.  
  260.    
  261.  
  262.  
  263.     -- scrollView.titleText.x = display.contentCenterX
  264.     -- INSERT code here (e.g. start timers, load audio, start listeners, etc.)
  265.  
  266.         local Button_continueReleased = function( event )
  267.             print (" *** HEY !!! *** ")
  268.             --storyboard.gotoScene( "scene_play", "fade", 500 )
  269.             _gameData.People = math.random (1, 4)
  270.             calculate_stats()
  271.         end
  272.  
  273. -- Called immediately after scene has moved onscreen:
  274.  
  275. -- INSERT code here (e.g. start timers, load audio, start listeners, etc.)
  276.    
  277.         Button_scout = widget.newButton
  278.     {
  279.         id = "Button_scout",
  280.         defaultFile = "res/btn_up.png",
  281.         overFile = "res/btn_down.png",
  282.         label =  rosetta:getString("Scout"),
  283.         font = "Tungsten",
  284.         labelYOffset = 3,
  285.         fontSize = _FontSize1,
  286.         emboss = true,
  287.         labelColor =
  288.         {
  289.             default = { 0, 0, 0, 255 },
  290.         },
  291.         onRelease = Button_scoutReleased,
  292.     }
  293.  
  294.         Button_camp = widget.newButton
  295.     {
  296.         id = "Button_camp",
  297.         defaultFile = "res/btn_up.png",
  298.         overFile = "res/btn_down.png",
  299.         label =  rosetta:getString("Camp"),
  300.         font = "Tungsten",
  301.         labelYOffset = 3,
  302.         fontSize = _FontSize1,
  303.         emboss = true,
  304.         labelColor =
  305.         {
  306.             default = { 0, 0, 0, 255 },
  307.         },
  308.         onRelease = Button_campReleased,
  309.     }
  310.  
  311.             Button_moveOn = widget.newButton
  312.     {
  313.         id = "Button_moveOn",
  314.         defaultFile = "res/btn_up.png",
  315.         overFile = "res/btn_down.png",
  316.         label =  rosetta:getString("Move On"),
  317.         font = "Tungsten",
  318.         labelYOffset = 3,
  319.         fontSize = _FontSize1,
  320.         emboss = true,
  321.         labelColor =
  322.         {
  323.             default = { 0, 0, 0, 255 },
  324.         },
  325.         onRelease = Button_moveOnReleased,
  326.     }
  327.  
  328. --  scrollView.isVisible = true
  329.  
  330.     Button_scout.x = _CX *.5
  331.     Button_scout.y = _CY * 2.54
  332.  
  333.     Button_camp.x = _CX *1.5
  334.     Button_camp.y = _CY * 2.54
  335.  
  336.     Button_moveOn.x = _CX *1.5 -- + math.random(1,10) -- 160
  337.     Button_moveOn.y = _CY * 2.8 -- + math.random(1,10)-- 130
  338.    
  339.  
  340.     group:insert (Button_scout)
  341.     group:insert (Button_camp)
  342.     group:insert (Button_moveOn)
  343.  
  344.  
  345.     -- setScrollView()
  346.  
  347.  
  348. end
  349.  
  350. -- Called when scene is about to move offscreen:
  351. function scene:exitScene( event )
  352.     local group = self.view
  353.  
  354.    
  355.     -- INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.)
  356. end
  357.  
  358. -- If scene's view is removed, scene:destroyScene() will be called just prior to:
  359. function scene:destroyScene( event )
  360.     local group = self.view
  361.    
  362. end
  363.  
  364. -----------------------------------------------------------------------------------------
  365. -- END OF YOUR IMPLEMENTATION
  366. -----------------------------------------------------------------------------------------
  367.  
  368. -- "createScene" event is dispatched if scene's view does not exist
  369. scene:addEventListener( "createScene", scene )
  370.  
  371. -- "enterScene" event is dispatched whenever scene transition has finished
  372. scene:addEventListener( "enterScene", scene )
  373.  
  374. -- "exitScene" event is dispatched whenever before next scene's transition begins
  375. scene:addEventListener( "exitScene", scene )
  376.  
  377. -- "destroyScene" event is dispatched before view is unloaded, which can be
  378. -- automatically unloaded in low memory situations, or explicitly via a call to
  379. -- storyboard.purgeScene() or storyboard.removeScene().
  380. scene:addEventListener( "destroyScene", scene )
  381.  
  382. -----------------------------------------------------------------------------------------
  383.  
  384. return scene
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement