|
@ -0,0 +1,45 @@ |
|
|
|
|
|
import hxd.Key; |
|
|
|
|
|
|
|
|
|
|
|
class Main extends hxd.App { |
|
|
|
|
|
var bmp:h2d.Bitmap; |
|
|
|
|
|
var deplacement = 5; |
|
|
|
|
|
|
|
|
|
|
|
override function init() { |
|
|
|
|
|
var tile = h2d.Tile.fromColor(0x0085ff, 100, 100); |
|
|
|
|
|
bmp = new h2d.Bitmap(tile, s2d); |
|
|
|
|
|
bmp.x = s2d.width * 0.5; |
|
|
|
|
|
bmp.y = s2d.height * 0.5; |
|
|
|
|
|
hxd.Window.getInstance().addEventTarget(onEvent); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function onEvent(event:hxd.Event) { |
|
|
|
|
|
switch (event.kind) { |
|
|
|
|
|
case EKeyDown: |
|
|
|
|
|
switch (event.keyCode) { |
|
|
|
|
|
case 37: // LEFT |
|
|
|
|
|
bmp.x -= deplacement; |
|
|
|
|
|
if (bmp.x < bmp.width) bmp.x = bmp.width; |
|
|
|
|
|
case 38: // UP |
|
|
|
|
|
bmp.y -= deplacement; |
|
|
|
|
|
if (bmp.y < bmp.height) bmp.y = bmp.height; |
|
|
|
|
|
case 39: // RIGHT |
|
|
|
|
|
bmp.x += deplacement; |
|
|
|
|
|
if (bmp.x > s2d.width - bmp.width) bmp.x = s2d.width - bmp.width; |
|
|
|
|
|
case 40: // DOWN |
|
|
|
|
|
bmp.y += deplacement; |
|
|
|
|
|
if (bmp.y > s2d.height - bmp.height) bmp.y = s2d.height - bmp.height; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
case _: |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override function update(dt:Float) { |
|
|
|
|
|
bmp.rotation += 0.3; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static function main() { |
|
|
|
|
|
new Main(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
// faire une tuile de 100sur100 et de la faire deplacer grace aux fleches |