Advertisement
Guest User

game.lua

a guest
Jun 28th, 2011
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.84 KB | None | 0 0
  1. module(..., package.seeall);
  2.  
  3. -- Determined to see if we are in the real device and not in a simulator
  4. local isAndroid = "Android" == system.getInfo("platformName")
  5.  
  6. -----------------------------------------
  7. -- Game Groups --------------------------
  8. -----------------------------------------
  9.  
  10. local gameGroup = display.newGroup();
  11. local gui = display.newGroup();
  12.  
  13. -----------------------------------------
  14. -- Constants ----------------------------
  15. -----------------------------------------
  16.  
  17. -----------------------------------------
  18. -- Fields -------------------------------
  19. -----------------------------------------
  20.  
  21. local done = false;
  22.  
  23. local backgroundX;
  24. local backgroundY;
  25.  
  26. local pauseButtonX;
  27. local pauseButtonY;
  28.  
  29. local gameSpriteBalloonX;
  30. local gameSpriteBalloonY;
  31.  
  32. -----------------------------------------
  33. -- Images -------------------------------
  34. -----------------------------------------
  35.  
  36. local clearScreen = display.newImage("clear_screen.png");
  37. local pauseButton = display.newImage("pause_button.png");
  38. local gameBackground = display.newImage("game_background.png");
  39. local fadeBackground = display.newImage("fade_background.png");
  40. local gameSpriteDude = display.newImage("game_sprite_dude.png");
  41. local gameSpriteChick = display.newImage("game_sprite_chick.png");
  42. local gameSpriteBrick = display.newImage("game_sprite_brick.png");
  43. local gameSpriteBalloon = display.newImage("game_sprite_balloon.png");
  44.  
  45.  
  46. -----------------------------------------
  47. -- Functions ----------------------------
  48. -----------------------------------------
  49.  
  50. local function initialize()
  51.     -----------------------------------------
  52.     -- Inserts ------------------------------
  53.     -----------------------------------------
  54.     gameGroup:insert(gameBackground);
  55.     gameGroup:insert(pauseButton);
  56.     gameGroup:insert(gameSpriteBalloon);
  57.    
  58.     gameGroup:insert(clearScreen);
  59.    
  60.     -----------------------------------------
  61.     -- Positions ----------------------------
  62.     -----------------------------------------
  63.    
  64.     gameBackground.x = backgroundX;
  65.     gameBackground.y = backgroundY;
  66.    
  67.     pauseButton.x = pauseButtonX;
  68.     pauseButton.y = pauseButtonY;
  69.    
  70.     gameSpriteBalloon.x = gameSpriteBalloonX;
  71.     gameSpriteBalloon.y = gameSpriteBalloonY;
  72.     gui:insert(gameGroup);
  73. end
  74.  
  75.  
  76. local function isDirection(direction)
  77.    
  78.     return false;
  79. end
  80.  
  81.  
  82. local function onAccelerate(event)
  83.     gameSpriteBalloonX = gameSpriteBalloonX + event.xGravity / 2000;
  84.     gameSpriteBalloonY = gameSpriteBalloonY + event.yGravity / 2000;
  85.    
  86. end
  87.  
  88.  
  89. local function gameLoop()
  90.     if isAndroid then
  91.         while done == false do
  92.             initialize();
  93.         end
  94.     end
  95. end
  96.  
  97.    
  98. function new()
  99.     initialize();
  100.     gameLoop();
  101.     return gui;
  102. end
  103.  
  104. -----------------------------------------
  105. -- Other stuff --------------------------
  106. -----------------------------------------
  107.  
  108. Runtime:addEventListener("accelerometer", onAccelerate);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement