Created
July 6, 2013 05:21
-
-
Save bobobo1618/5938756 to your computer and use it in GitHub Desktop.
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 entities; | |
import com.haxepunk.Entity; | |
import com.haxepunk.graphics.Image; | |
import com.haxepunk.utils.Input; | |
import com.haxepunk.utils.Key; | |
import nape.phys.BodyType; | |
class Block extends Entity { | |
public var moveSpeed:Float; | |
public var napeBody:nape.phys.Body; | |
public var napeShape:nape.shape.Polygon; | |
var image:Image; | |
public inline static function radToDeg(rad:Float):Float | |
{ | |
return 180 / Math.PI * rad; | |
} | |
public function new(x:Int, y:Int) { | |
moveSpeed = 1; | |
image = new Image("gfx/block.png"); | |
graphic = image; | |
napeBody = new nape.phys.Body(BodyType.DYNAMIC); | |
napeShape = new nape.shape.Polygon(nape.shape.Polygon.box(image.scaledWidth, image.scaledHeight)); | |
napeShape.material.density = 4; | |
napeBody.shapes.add(napeShape); | |
napeBody.position.setxy(x, y); | |
centerOrigin(); | |
super(x,y); | |
} | |
public override function update() { | |
x = napeBody.position.x - (0.5*image.scaledWidth); | |
y = napeBody.position.y - (0.5*image.scaledHeight); | |
image.angle = radToDeg(napeBody.rotation); | |
if (Input.check(Key.LEFT)){ | |
moveBy(-2, 0); | |
} | |
if (Input.check(Key.RIGHT)){ | |
moveBy(2, 0); | |
} | |
if (Input.check(Key.UP)){ | |
moveBy(0, -2); | |
} | |
if (Input.check(Key.DOWN)){ | |
moveBy(0, 2); | |
} | |
super.update(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment