Animation
package;
import gecko.Screen;
import gecko.Assets;
import gecko.Gecko;
import gecko.systems.draw.DrawSystem;
import gecko.components.draw.TextComponent;
import gecko.components.draw.AnimationComponent;
import gecko.input.KeyCode;
import gecko.input.Keyboard;
class Game {
public function new(){
Gecko.currentScene.addSystem(DrawSystem.create());
Assets.load([
"images/kenney/pixelExplosion00.png",
"images/kenney/pixelExplosion01.png",
"images/kenney/pixelExplosion02.png",
"images/kenney/pixelExplosion03.png",
"images/kenney/pixelExplosion04.png",
"images/kenney/pixelExplosion05.png",
"images/kenney/pixelExplosion06.png",
"images/kenney/pixelExplosion07.png",
"images/kenney/pixelExplosion08.png",
"images/kenney/wingMan1.png",
"images/kenney/wingMan2.png",
"images/kenney/wingMan3.png",
"images/kenney/wingMan4.png",
"images/kenney/wingMan5.png",
"images/kenney/wingMan4.png",
"images/kenney/wingMan3.png",
"images/kenney/wingMan2.png",
"images/opengameart/golem-walk.png",
"images/opengameart/golem-atk.png",
"images/opengameart/golem-die.png",
"Ubuntu-B.ttf"
], _onLoadAssets).start();
}
private function _createAnimatedEntity(x:Float, y:Float, sx:Float = 1, sy:Float = 1) : AnimationComponent {
var entity = Gecko.currentScene.createEntity();
entity.transform.position.set(x, y);
entity.transform.scale.set(sx, sy);
return entity.addComponent(AnimationComponent.create());
}
private function _onLoadAssets() {
var anim1Frames = [
"images/kenney/pixelExplosion00.png",
"images/kenney/pixelExplosion01.png",
"images/kenney/pixelExplosion02.png",
"images/kenney/pixelExplosion03.png",
"images/kenney/pixelExplosion04.png",
"images/kenney/pixelExplosion05.png",
"images/kenney/pixelExplosion06.png",
"images/kenney/pixelExplosion07.png",
"images/kenney/pixelExplosion08.png",
];
var animComponent1 =_createAnimatedEntity(Screen.width/4, 150);
animComponent1.addAnimFromAssets("explosion", 0.9, anim1Frames);
animComponent1.play("explosion", true);
var anim2Frames = [
"images/kenney/wingMan1.png",
"images/kenney/wingMan2.png",
"images/kenney/wingMan3.png",
"images/kenney/wingMan4.png",
"images/kenney/wingMan5.png",
"images/kenney/wingMan4.png",
"images/kenney/wingMan3.png",
"images/kenney/wingMan2.png",
];
var animComponent2 =_createAnimatedEntity(Screen.width/4*3, 150);
animComponent2.addAnimFromAssets("wings", 0.5, anim2Frames);
animComponent2.play("wings", true);
var golem = _createAnimatedEntity(Screen.centerX, Screen.height - 100, 3, 3);
golem.entity.transform.anchor.set(0.5,1);
golem.addAnimFromGridAssets("walk", 0.5, "images/opengameart/golem-walk.png", 4, 7, [14, 15, 16, 17, 18, 19, 20]);
golem.addAnimFromGridAssets("attack", 0.8, "images/opengameart/golem-atk.png", 4, 7, [14, 15, 16, 17, 18, 19, 20]);
golem.addAnimFromGridAssets("die", 0.9, "images/opengameart/golem-die.png", 2, 7, null, 7);
golem.play("walk", true);
var text = Gecko.currentScene.createEntity();
text.addComponent(TextComponent.create("Press 'z' to walk, 'x' to attack, 'c' to die", "Ubuntu-B.ttf", 30));
text.transform.position.set(Screen.centerX, Screen.height - 60);
text.transform.fixedToCamera = true;
Keyboard.enable();
Keyboard.onPressed += function(key:KeyCode) {
if(golem != null){
switch(key){
case KeyCode.Z: golem.play("walk", true);
case KeyCode.X: golem.play("attack", true);
case KeyCode.C: golem.play("die", true);
default:
}
}
};
}
}
Source Code