Created
August 12, 2011 23:53
-
-
Save Draknek/1143292 to your computer and use it in GitHub Desktop.
Grid-grid collision bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import net.flashpunk.*; | |
import net.flashpunk.graphics.*; | |
import net.flashpunk.masks.*; | |
import flash.display.*; | |
[SWF(width = "640", height = "480", backgroundColor="#000000")] | |
public class Main extends Engine | |
{ | |
public var e1:Entity; | |
public var e2:Entity; | |
public var g1:Grid; | |
public var g2:Grid; | |
public function Main () | |
{ | |
super(640, 480, 60, true); | |
createEntity(120, 120, 40); | |
e1 = createEntity(110, 165, 30); | |
createEntity(320, 120, 40); | |
e2 = createEntity(325, 165, 30); | |
FP.console.enable(); | |
} | |
private function createEntity (x:Number, y:Number, gridSize:Number):Entity | |
{ | |
var e:Entity = new Entity; | |
e.x = x; | |
e.y = y; | |
e.type = "solid"; | |
var g:Grid = new Grid(gridSize*2, gridSize*2, gridSize, gridSize); | |
g.setTile(0, 0); | |
g.setTile(1, 1); | |
e.mask = g; | |
var t:Tilemap = new Tilemap(new BitmapData(gridSize, gridSize, true, 0xFFFFFFFF), gridSize*2, gridSize*2, gridSize, gridSize); | |
t.setTile(0, 0, 0); | |
t.setTile(1, 1, 0); | |
t.alpha = 0.5; | |
e.graphic = t; | |
FP.world.add(e); | |
return e; | |
} | |
public override function update ():void | |
{ | |
super.update(); | |
//e1.x = FP.world.mouseX; | |
//e1.y = FP.world.mouseY; | |
Tilemap(e1.graphic).color = (e1.collide("solid", e1.x, e1.y)) ? 0xFF0000 : 0x00FF00; | |
Tilemap(e2.graphic).color = (e2.collide("solid", e2.x, e2.y)) ? 0xFF0000 : 0x00FF00; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment