Advertisement
faneron

Flixel overlap

Jun 8th, 2021 (edited)
1,745
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 2.14 KB | None | 0 0
  1. /// PLAYSTATE ////
  2. class PlayState extends FlxState
  3. {
  4.     var _testPice: Pice;
  5.     var _testPice2: Pice;
  6.     var _testPice3: Pice;
  7.    
  8.     override public function create()
  9.     {
  10.         super.create();
  11.        
  12.         _testPice = new Pice(0, 0, 1);
  13.         _testPice2 = new Pice(0, 1, 2);
  14.         _testPice3 = new Pice(1, 0, 1);
  15.        
  16.         add(_board);
  17.         add(_testPice3);
  18.         add(_testPice2);
  19.         add(_testPice);
  20.        
  21.         Reg.boardData.add(_testPice);
  22.         Reg.boardData.add(_testPice2);
  23.         Reg.boardData.add(_testPice3);
  24.     }
  25.  
  26.     override public function update(elapsed:Float)
  27.     {
  28.         super.update(elapsed);
  29.     }
  30.    
  31. }
  32.  
  33. //////// PICE Class ////
  34. class Pice extends FlxSpriteGroup
  35. {
  36.     ////// THIS IS THE PROPERTY AND IS PUBLIC
  37.     public var player: Int;
  38.    
  39.     // Elements of the full pice
  40.     public var pice: FlxExtendedSprite;
  41.  
  42.     public function new(?X:Int = 0, ?Y:Int = 0, ?Player:Int = 1)
  43.     {
  44.         super(X, Y, 0);
  45.        
  46.         // Sets pice position on board
  47.         super(X * Config.PICE_SIZE, Y * Config.PICE_SIZE);
  48.        
  49.         // Identifier, player and type of pice
  50.         player = Player; ///////HERE ITs
  51.        
  52.         // Load sprite for the pice
  53.         pice = new FlxExtendedSprite(0, 0);
  54.         pice.loadGraphic('assets/images/pice__f.jpg', false, Config.PICE_SIZE, Config.PICE_SIZE);
  55.        
  56.         /// Colors the pice depending on the player
  57.         if (player == 1) {
  58.             pice.color = FlxColor.fromRGB(184, 111, 60, 0);
  59.         } else if (player == 2) {
  60.             pice.color = FlxColor.fromRGB(235, 202, 163, 0);
  61.         }
  62.  
  63.         //Adds objets to the group
  64.         add(pice);
  65.     }
  66.  
  67.  
  68. //////// PiceMove Classs WHERE THE OVERLAP IS CHECKED ////
  69. class PiceMove extends FlxExtendedSprite
  70. {
  71.     var pice:Pice;
  72.     var isOverlaping:Bool;
  73.  
  74.     public function new(X:Float = 0, Y:Float = 0, Face: String,  ParentPice: Pice)
  75.     {
  76.         super(X * Config.PICE_SIZE, Y * Config.PICE_SIZE);
  77.  
  78.         pice = ParentPice;
  79.  
  80.         loadGraphic(AssetPaths.move__png, false, Config.PICE_SIZE, Config.PICE_SIZE);
  81.     }
  82.    
  83.     override public function update(elapsed:Float)
  84.     {
  85.         super.update(elapsed);
  86.         isOverlaping = FlxG.overlap(this, Reg.boardData, onOverlap);
  87.     }
  88.    
  89.     private function onOverlap(object1, object2:Pice) {
  90.         FlxG.log.add(object1.pice.player);
  91.         FlxG.log.add(object2.player);
  92.  
  93.         object2.kill();
  94.     }  
  95.    
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement