BrickBreaker/src/brickbreaker/Main.fx

Print this page


   1 package brickbreaker;
   2 
   3 import javafx.scene.*;
   4 import javafx.stage.*;
   5 import javafx.scene.paint.*;

   6 
   7 /**
   8  * @author Pavel Porvatov
   9  */
  10 



  11 // Instance of the MainFrame class
  12 public var mainFrame: MainFrame;



  13 
  14 def IS_MOBILE = FX.getProperty("javafx.me.profiles") != null;
  15 
  16 function run(__ARGS__ : String[]) {

  17     // Initialization should be the first
  18     Config.initialize(IS_MOBILE);
  19 








  20     mainFrame = MainFrame {
  21         title: "Brick Breaker"
  22         resizable: false
  23 
  24         scene: Scene {
  25             fill: Color.BLACK
  26             width: Config.screenWidth
  27             height: Config.screenHeight

  28         }
  29     }
  30 }
  31 
  32 public class MainFrame extends Stage {
  33     // Instance of splash (if exists)
  34     var splash: Splash;
  35 
  36     // Instance of level (if exists)
  37     var level: Level;
  38 
  39     // Number of lifes
  40     public var lifeCount: Integer;
  41 
  42     // Current score
  43     public var score: Integer;
  44 
  45     // Initializes game (lifes, scores etc)
  46     public function startGame() {
  47         lifeCount = 3;
  48         score = 0;
  49         state = 1;
  50     }
  51 
  52     // Current state of the game. The next values are available
  53     // 0 - Splash
  54     // 1..Level.LEVEL_COUNT - Level
  55     public var state: Integer = 0 on replace {
  56         if (state < 1 or state > LevelData.getLevelsCount()) {
  57             splash.stop();
  58             level.stop();
  59             
  60             level = null;
  61             splash = Splash {};
  62 
  63             scene.content = [
  64                 splash
  65             ];
  66 
  67             splash.start();
  68         } else {
  69             splash.stop();
  70             level.stop();
  71             
  72             splash = null;
  73             level = Level {
  74                 levelNumber: state
  75             }
  76 
  77             scene.content = [
  78                 level
  79             ];
  80             
  81             level.start();
  82         }
  83     };
  84 }
   1 package brickbreaker;
   2 
   3 import javafx.scene.*;
   4 import javafx.stage.*;
   5 import javafx.scene.paint.*;
   6 import javafx.scene.transform.Transform;
   7 
   8 /**
   9  * @author Pavel Porvatov
  10  */
  11 
  12 var scaleW:Number = 1.0;
  13 var scaleH:Number = 1.0;
  14 
  15 // Instance of the MainFrame class
  16 public var mainFrame: MainFrame;
  17 public var content : Group = Group {
  18     transforms: bind Transform.scale(scaleW, scaleH)
  19 };
  20 
  21 def IS_MOBILE = FX.getProperty("javafx.me.profiles") != null;
  22 
  23 function run(__ARGS__ : String[]) {
  24     
  25     // Initialization should be the first
  26     Config.initialize(IS_MOBILE);
  27 
  28     // Fit screen for mobile
  29     if("{__PROFILE__}" == "mobile") {
  30         var w = javafx.stage.Screen.primary.bounds.width;
  31         var h = javafx.stage.Screen.primary.bounds.height;
  32         scaleW = w/240.0;
  33         scaleH = h/320.0;
  34     }
  35     
  36     mainFrame = MainFrame {
  37         title: "Brick Breaker"
  38         resizable: false
  39 
  40         scene: Scene {
  41             fill: Color.BLACK
  42             width: Config.screenWidth
  43             height: Config.screenHeight
  44             content: content
  45         }
  46     }
  47 }
  48 
  49 public class MainFrame extends Stage {
  50     // Instance of splash (if exists)
  51     var splash: Splash;
  52 
  53     // Instance of level (if exists)
  54     var level: Level;
  55 
  56     // Number of lifes
  57     public var lifeCount: Integer;
  58 
  59     // Current score
  60     public var score: Integer;
  61 
  62     // Initializes game (lifes, scores etc)
  63     public function startGame() {
  64         lifeCount = 3;
  65         score = 0;
  66         state = 1;
  67     }
  68 
  69     // Current state of the game. The next values are available
  70     // 0 - Splash
  71     // 1..Level.LEVEL_COUNT - Level
  72     public var state: Integer = 0 on replace {
  73         if (state < 1 or state > LevelData.getLevelsCount()) {
  74             splash.stop();
  75             level.stop();
  76             
  77             level = null;
  78             splash = Splash {};
  79 
  80             content.content = [
  81                 splash
  82             ];
  83 
  84             splash.start();
  85         } else {
  86             splash.stop();
  87             level.stop();
  88             
  89             splash = null;
  90             level = Level {
  91                 levelNumber: state
  92             }
  93 
  94             content.content = [
  95                 level
  96             ];
  97             
  98             level.start();
  99         }
 100     };
 101 }