├── examples
├── basic
│ ├── Assets
│ │ ├── .gitkeep
│ │ └── shipYellow_manned.png
│ ├── Libraries
│ │ └── .gitkeep
│ ├── README.md
│ ├── Sources
│ │ ├── Main.hx
│ │ └── Game.hx
│ └── dev.gecko.toml
├── demo
│ ├── Assets
│ │ ├── .gitkeep
│ │ ├── audio
│ │ │ ├── readme.md
│ │ │ └── Retro-Beat.wav
│ │ ├── images
│ │ │ ├── kenney
│ │ │ │ ├── readme.md
│ │ │ │ ├── pig.png
│ │ │ │ ├── giraffe.png
│ │ │ │ ├── hippo.png
│ │ │ │ ├── monkey.png
│ │ │ │ ├── panda.png
│ │ │ │ ├── parrot.png
│ │ │ │ ├── penguin.png
│ │ │ │ ├── rabbit.png
│ │ │ │ ├── snake.png
│ │ │ │ ├── elephant.png
│ │ │ │ ├── enemyUFO.png
│ │ │ │ ├── red_cross.png
│ │ │ │ ├── wingMan1.png
│ │ │ │ ├── wingMan2.png
│ │ │ │ ├── wingMan3.png
│ │ │ │ ├── wingMan4.png
│ │ │ │ ├── wingMan5.png
│ │ │ │ ├── green_panel.png
│ │ │ │ ├── grey_button08.png
│ │ │ │ ├── starBackground.png
│ │ │ │ ├── pixelExplosion00.png
│ │ │ │ ├── pixelExplosion01.png
│ │ │ │ ├── pixelExplosion02.png
│ │ │ │ ├── pixelExplosion03.png
│ │ │ │ ├── pixelExplosion04.png
│ │ │ │ ├── pixelExplosion05.png
│ │ │ │ ├── pixelExplosion06.png
│ │ │ │ ├── pixelExplosion07.png
│ │ │ │ └── pixelExplosion08.png
│ │ │ └── opengameart
│ │ │ │ ├── golem-atk.png
│ │ │ │ ├── golem-die.png
│ │ │ │ ├── mountain.png
│ │ │ │ ├── carbon_fiber.png
│ │ │ │ ├── golem-walk.png
│ │ │ │ └── readme.md
│ │ └── Ubuntu-B.ttf
│ ├── Libraries
│ │ └── .gitkeep
│ ├── Sources
│ │ ├── Main.hx
│ │ └── scenes
│ │ │ ├── DrawScrollingSpriteScene.hx
│ │ │ ├── DrawSpriteScene.hx
│ │ │ ├── DrawNineSliceScene.hx
│ │ │ ├── CustomScene.hx
│ │ │ ├── DrawShapeScene.hx
│ │ │ └── Camera1Scene.hx
│ └── dev.gecko.toml
├── flappy
│ ├── Assets
│ │ ├── .gitkeep
│ │ ├── Ubuntu-B.ttf
│ │ ├── readme.md
│ │ ├── images
│ │ │ ├── flappydoge_bg1.png
│ │ │ ├── flappydoge_bg2.png
│ │ │ ├── flappydoge_anim01.png
│ │ │ ├── flappydoge_anim02.png
│ │ │ ├── flappydoge_anim03.png
│ │ │ ├── flappydoge_anim04.png
│ │ │ ├── flappydoge_floor.png
│ │ │ └── flappydoge_pipe.png
│ │ └── kenpixel_mini_square.ttf
│ ├── Libraries
│ │ └── .gitkeep
│ ├── Sources
│ │ ├── GameState.hx
│ │ ├── Config.hx
│ │ ├── Main.hx
│ │ └── Game.hx
│ ├── readme.md
│ └── dev.gecko.toml
├── khashmup
│ ├── Assets
│ │ ├── .gitkeep
│ │ ├── bullet.png
│ │ ├── Ubuntu-B.ttf
│ │ ├── enemyShip.png
│ │ ├── bulletShoot.wav
│ │ ├── playerShip.png
│ │ ├── smokeOrange0.png
│ │ ├── smokeOrange1.png
│ │ ├── smokeOrange2.png
│ │ ├── smokeOrange3.png
│ │ ├── enemyExplosion.wav
│ │ ├── playerExplosion.wav
│ │ └── kenpixel_mini_square.ttf
│ ├── Libraries
│ │ └── .gitkeep
│ ├── Sources
│ │ ├── components
│ │ │ ├── OutBoundsComponent.hx
│ │ │ ├── PlayerComponent.hx
│ │ │ └── ShootComponent.hx
│ │ ├── Main.hx
│ │ ├── systems
│ │ │ ├── OutBoundsSystem.hx
│ │ │ ├── ShootSystem.hx
│ │ │ └── PlayerSystem.hx
│ │ ├── scenes
│ │ │ └── MainScene.hx
│ │ └── Game.hx
│ ├── readme.md
│ └── dev.gecko.toml
├── shapes
│ ├── Assets
│ │ └── .gitkeep
│ ├── Libraries
│ │ └── .gitkeep
│ ├── README.md
│ ├── Sources
│ │ ├── Main.hx
│ │ └── Game.hx
│ └── dev.gecko.toml
├── sprites
│ ├── Assets
│ │ ├── .gitkeep
│ │ └── kenney
│ │ │ ├── readme.md
│ │ │ ├── pig.png
│ │ │ ├── hippo.png
│ │ │ ├── monkey.png
│ │ │ ├── panda.png
│ │ │ ├── parrot.png
│ │ │ ├── snake.png
│ │ │ ├── elephant.png
│ │ │ ├── giraffe.png
│ │ │ └── penguin.png
│ ├── Libraries
│ │ └── .gitkeep
│ ├── README.md
│ ├── Sources
│ │ ├── Main.hx
│ │ └── Game.hx
│ └── dev.gecko.toml
├── text
│ ├── Assets
│ │ ├── .gitkeep
│ │ ├── Ubuntu-B.ttf
│ │ └── kenpixel_mini_square.ttf
│ ├── Libraries
│ │ └── .gitkeep
│ ├── README.md
│ ├── Sources
│ │ └── Main.hx
│ └── dev.gecko.toml
├── animation
│ ├── Assets
│ │ ├── .gitkeep
│ │ ├── Ubuntu-B.ttf
│ │ └── images
│ │ │ ├── kenney
│ │ │ ├── wingMan1.png
│ │ │ ├── wingMan2.png
│ │ │ ├── wingMan3.png
│ │ │ ├── wingMan4.png
│ │ │ ├── wingMan5.png
│ │ │ ├── pixelExplosion00.png
│ │ │ ├── pixelExplosion01.png
│ │ │ ├── pixelExplosion02.png
│ │ │ ├── pixelExplosion03.png
│ │ │ ├── pixelExplosion04.png
│ │ │ ├── pixelExplosion05.png
│ │ │ ├── pixelExplosion06.png
│ │ │ ├── pixelExplosion07.png
│ │ │ └── pixelExplosion08.png
│ │ │ └── opengameart
│ │ │ ├── golem-atk.png
│ │ │ ├── golem-die.png
│ │ │ ├── golem-walk.png
│ │ │ └── readme.md
│ ├── Libraries
│ │ └── .gitkeep
│ ├── README.md
│ ├── Sources
│ │ └── Main.hx
│ └── dev.gecko.toml
├── bunnyrender
│ ├── Assets
│ │ ├── .gitkeep
│ │ ├── rabbit.png
│ │ └── Ubuntu-B.ttf
│ ├── Libraries
│ │ └── .gitkeep
│ ├── Sources
│ │ ├── Shaders
│ │ │ └── .gitkeep
│ │ └── Main.hx
│ └── dev.gecko.toml
├── nineslice
│ ├── Assets
│ │ ├── .gitkeep
│ │ └── images
│ │ │ └── kenney
│ │ │ ├── green_panel.png
│ │ │ └── grey_button08.png
│ ├── Libraries
│ │ └── .gitkeep
│ ├── README.md
│ ├── Sources
│ │ ├── Main.hx
│ │ └── Game.hx
│ └── dev.gecko.toml
├── parenttransform
│ ├── Assets
│ │ ├── .gitkeep
│ │ └── car_green_small_1.png
│ ├── Libraries
│ │ └── .gitkeep
│ ├── README.md
│ ├── Sources
│ │ ├── Main.hx
│ │ └── Game.hx
│ └── dev.gecko.toml
├── scrollingsprite
│ ├── Assets
│ │ ├── .gitkeep
│ │ └── images
│ │ │ └── opengameart
│ │ │ ├── mountain.png
│ │ │ ├── carbon_fiber.png
│ │ │ └── readme.md
│ ├── Libraries
│ │ └── .gitkeep
│ ├── README.md
│ ├── Sources
│ │ ├── Main.hx
│ │ └── Game.hx
│ └── dev.gecko.toml
└── bunnyentities
│ ├── Assets
│ ├── readme.txt
│ ├── rabbit.png
│ └── Ubuntu-B.ttf
│ ├── Libraries
│ └── readme.txt
│ ├── Sources
│ ├── Main.hx
│ ├── BounceComponent.hx
│ ├── BounceSystem.hx
│ └── Game.hx
│ └── dev.gecko.toml
├── templates
├── basic
│ ├── Assets
│ │ ├── .gitkeep
│ │ └── Ubuntu-B.ttf
│ ├── Libraries
│ │ └── .gitkeep
│ └── Sources
│ │ ├── Main.hx
│ │ ├── scenes
│ │ └── MainScene.hx
│ │ └── Game.hx
├── empty
│ ├── Assets
│ │ └── .gitkeep
│ ├── Libraries
│ │ └── .gitkeep
│ └── Sources
│ │ ├── Game.hx
│ │ └── Main.hx
└── sample
│ ├── Assets
│ ├── .gitkeep
│ └── Ubuntu-B.ttf
│ ├── Libraries
│ └── .gitkeep
│ ├── Sources
│ ├── Game.hx
│ └── Main.hx
│ └── README.md
├── main.js
├── Sources
└── gecko
│ ├── utils
│ ├── Storage.hx
│ ├── ArrayHelper.hx
│ ├── PoolOptions.hx
│ ├── FPSCounter.hx
│ ├── Event.hx
│ ├── MathHelper.hx
│ ├── Chain.hx
│ └── EventEmitter.hx
│ ├── resources
│ ├── Blob.hx
│ ├── Font.hx
│ ├── Image.hx
│ ├── Sound.hx
│ └── Video.hx
│ ├── input
│ ├── KeyCode.hx
│ ├── MouseButton.hx
│ └── HotKey.hx
│ ├── math
│ ├── Matrix.hx
│ ├── Random.hx
│ ├── Vector2i.hx
│ └── Vector2g.hx
│ ├── tween
│ ├── Ease.hx
│ └── TweenManager.hx
│ ├── render
│ ├── Framebuffer.hx
│ ├── BlendingFactor.hx
│ ├── BlendingOperation.hx
│ ├── VerticalTextAlign.hx
│ ├── HorizontalTextAlign.hx
│ └── BlendMode.hx
│ ├── IDrawable.hx
│ ├── IUpdatable.hx
│ ├── ScreenMode.hx
│ ├── components
│ ├── draw
│ │ ├── MovieComponent.hx
│ │ ├── CameraComponent.hx
│ │ ├── ProgressBarComponent.hx
│ │ ├── SpriteComponent.hx
│ │ ├── CircleComponent.hx
│ │ ├── RectangleComponent.hx
│ │ └── PolygonComponent.hx
│ ├── input
│ │ ├── TouchComponent.hx
│ │ └── DraggableComponent.hx
│ ├── misc
│ │ └── BehaviorComponent.hx
│ └── motion
│ │ ├── RotationComponent.hx
│ │ └── MovementComponent.hx
│ ├── Float32.hx
│ ├── ScreenOptions.hx
│ ├── macros
│ ├── IAutoPool.hx
│ ├── GeckoBuilder.hx
│ └── KeyboardBuilder.hx
│ ├── BaseObject.hx
│ ├── GeckoOptions.hx
│ ├── systems
│ ├── misc
│ │ └── BehaviorSystem.hx
│ ├── collision
│ │ └── aabb
│ │ │ └── AABBSystem.hx
│ └── motion
│ │ └── MotionSystem.hx
│ ├── Storage.hx
│ ├── World.hx
│ ├── ConfigFile.hx
│ ├── Time.hx
│ └── timer
│ └── TimerManager.hx
├── .gitmodules
├── docs
├── examples
│ ├── README.md
│ ├── flappy.md
│ ├── khashmup.md
│ ├── test.md
│ ├── basic.md
│ ├── drawsprites.md
│ ├── sprites.md
│ ├── scrollingsprite.md
│ ├── parenttransform.md
│ ├── nineslice.md
│ ├── drawshapes.md
│ └── shapes.md
├── guide
│ ├── screen.md
│ ├── ecs.md
│ └── README.md
├── faq.md
├── .vuepress
│ ├── override.styl
│ ├── examples.json
│ └── config.js
├── api.md
└── readme.md
├── tsconfig.json
├── scripts
├── devkhamake.js
├── koremake.js
├── khamake.js
└── api.js
├── .gitignore
├── cli
├── main.ts
├── cmd
│ ├── version.ts
│ ├── help.ts
│ ├── dir.ts
│ ├── docs.ts
│ └── khafile.ts
├── commands.ts
├── const.ts
├── cli.ts
└── utils.ts
├── webpack.config.js
├── readme.md
├── LICENSE
└── package.json
/examples/basic/Assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/basic/Libraries/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/demo/Assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/demo/Libraries/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/flappy/Assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/khashmup/Assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/shapes/Assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/sprites/Assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/text/Assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/text/Libraries/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/templates/basic/Assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/templates/empty/Assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/templates/sample/Assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/animation/Assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/animation/Libraries/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/bunnyrender/Assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/flappy/Libraries/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/khashmup/Libraries/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/nineslice/Assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/nineslice/Libraries/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/shapes/Libraries/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/sprites/Libraries/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/templates/basic/Libraries/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/templates/empty/Libraries/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/templates/sample/Libraries/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/bunnyrender/Libraries/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/parenttransform/Assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/parenttransform/Libraries/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/scrollingsprite/Assets/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/scrollingsprite/Libraries/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/bunnyrender/Sources/Shaders/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/bunnyentities/Assets/readme.txt:
--------------------------------------------------------------------------------
1 | Put your assets here.
--------------------------------------------------------------------------------
/examples/bunnyentities/Libraries/readme.txt:
--------------------------------------------------------------------------------
1 | Vendor libraries.
--------------------------------------------------------------------------------
/examples/demo/Assets/audio/readme.md:
--------------------------------------------------------------------------------
1 | - Retro-Beat from kenney pack
--------------------------------------------------------------------------------
/main.js:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env node
2 | const cli = require("./cli/bin/cli.js");
--------------------------------------------------------------------------------
/Sources/gecko/utils/Storage.hx:
--------------------------------------------------------------------------------
1 | package gecko.utils;
2 |
3 | //todo storage system
--------------------------------------------------------------------------------
/Sources/gecko/resources/Blob.hx:
--------------------------------------------------------------------------------
1 | package gecko.resources;
2 |
3 | typedef Blob = kha.Blob;
--------------------------------------------------------------------------------
/Sources/gecko/resources/Font.hx:
--------------------------------------------------------------------------------
1 | package gecko.resources;
2 |
3 | typedef Font = kha.Font;
--------------------------------------------------------------------------------
/Sources/gecko/resources/Image.hx:
--------------------------------------------------------------------------------
1 | package gecko.resources;
2 |
3 | typedef Image = kha.Image;
--------------------------------------------------------------------------------
/Sources/gecko/resources/Sound.hx:
--------------------------------------------------------------------------------
1 | package gecko.resources;
2 |
3 | typedef Sound = kha.Sound;
--------------------------------------------------------------------------------
/Sources/gecko/resources/Video.hx:
--------------------------------------------------------------------------------
1 | package gecko.resources;
2 |
3 | typedef Video = kha.Video;
--------------------------------------------------------------------------------
/examples/sprites/Assets/kenney/readme.md:
--------------------------------------------------------------------------------
1 | Assets from the Kenney pack: https://kenney.nl/assets
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "Kha"]
2 | path = Kha
3 | url = https://github.com/KTXSoftware/Kha
4 |
--------------------------------------------------------------------------------
/Sources/gecko/input/KeyCode.hx:
--------------------------------------------------------------------------------
1 | package gecko.input;
2 |
3 | typedef KeyCode = kha.input.KeyCode;
--------------------------------------------------------------------------------
/Sources/gecko/math/Matrix.hx:
--------------------------------------------------------------------------------
1 | package gecko.math;
2 |
3 | typedef Matrix = kha.math.FastMatrix3;
--------------------------------------------------------------------------------
/Sources/gecko/tween/Ease.hx:
--------------------------------------------------------------------------------
1 | package gecko.tween;
2 |
3 |
4 |
5 | typedef Ease = Float -> Float;
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/readme.md:
--------------------------------------------------------------------------------
1 | Assets from the Kenney pack: https://kenney.nl/assets
--------------------------------------------------------------------------------
/templates/sample/Sources/Game.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | class Game {
4 | public function new(){}
5 | }
--------------------------------------------------------------------------------
/Sources/gecko/render/Framebuffer.hx:
--------------------------------------------------------------------------------
1 | package gecko.render;
2 |
3 | typedef Framebuffer = kha.Framebuffer;
--------------------------------------------------------------------------------
/examples/basic/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | example: true
3 | title: Basic
4 | category: Basics
5 | priority: -1
6 | ---
--------------------------------------------------------------------------------
/examples/text/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | example: true
3 | title: Text
4 | category: Basics
5 | priority: 5
6 | ---
--------------------------------------------------------------------------------
/examples/shapes/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | example: true
3 | title: Shapes
4 | category: Basics
5 | priority: 0
6 | ---
--------------------------------------------------------------------------------
/examples/sprites/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | example: true
3 | title: Sprites
4 | category: Basics
5 | priority: 1
6 | ---
--------------------------------------------------------------------------------
/examples/animation/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | example: true
3 | title: Animation
4 | category: Basics
5 | priority: 3
6 | ---
--------------------------------------------------------------------------------
/examples/nineslice/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | example: true
3 | title: Nine Slice
4 | category: Basics
5 | priority: 4
6 | ---
--------------------------------------------------------------------------------
/Sources/gecko/render/BlendingFactor.hx:
--------------------------------------------------------------------------------
1 | package gecko.render;
2 |
3 | typedef BlendingFactor = kha.graphics4.BlendingFactor;
--------------------------------------------------------------------------------
/examples/demo/Assets/Ubuntu-B.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/Ubuntu-B.ttf
--------------------------------------------------------------------------------
/examples/text/Assets/Ubuntu-B.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/text/Assets/Ubuntu-B.ttf
--------------------------------------------------------------------------------
/examples/flappy/Assets/Ubuntu-B.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/flappy/Assets/Ubuntu-B.ttf
--------------------------------------------------------------------------------
/examples/khashmup/Assets/bullet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/khashmup/Assets/bullet.png
--------------------------------------------------------------------------------
/examples/parenttransform/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | example: true
3 | title: Parent Transform
4 | category: Basics
5 | priority: 6
6 | ---
--------------------------------------------------------------------------------
/examples/scrollingsprite/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | example: true
3 | title: Scrolling Sprite
4 | category: Basics
5 | priority: 2
6 | ---
--------------------------------------------------------------------------------
/templates/basic/Assets/Ubuntu-B.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/templates/basic/Assets/Ubuntu-B.ttf
--------------------------------------------------------------------------------
/templates/sample/Assets/Ubuntu-B.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/templates/sample/Assets/Ubuntu-B.ttf
--------------------------------------------------------------------------------
/templates/sample/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | example: true
3 | title: ExampleTitle
4 | category: ExampleCategory
5 | priority: 0
6 | ---
--------------------------------------------------------------------------------
/Sources/gecko/IDrawable.hx:
--------------------------------------------------------------------------------
1 | package gecko;
2 |
3 | interface IDrawable {
4 | public function draw(graphics:Graphics) : Void;
5 | }
--------------------------------------------------------------------------------
/Sources/gecko/IUpdatable.hx:
--------------------------------------------------------------------------------
1 | package gecko;
2 |
3 | interface IUpdatable {
4 | public function update(delta:Float) : Void;
5 | }
--------------------------------------------------------------------------------
/Sources/gecko/render/BlendingOperation.hx:
--------------------------------------------------------------------------------
1 | package gecko.render;
2 |
3 | typedef BlendingOperation = kha.graphics4.BlendingOperation;
--------------------------------------------------------------------------------
/Sources/gecko/render/VerticalTextAlign.hx:
--------------------------------------------------------------------------------
1 | package gecko.render;
2 |
3 | typedef VerticalTextAlign = kha.graphics2.VerTextAlignment;
--------------------------------------------------------------------------------
/examples/animation/Assets/Ubuntu-B.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/animation/Assets/Ubuntu-B.ttf
--------------------------------------------------------------------------------
/examples/bunnyrender/Assets/rabbit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/bunnyrender/Assets/rabbit.png
--------------------------------------------------------------------------------
/examples/khashmup/Assets/Ubuntu-B.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/khashmup/Assets/Ubuntu-B.ttf
--------------------------------------------------------------------------------
/examples/khashmup/Assets/enemyShip.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/khashmup/Assets/enemyShip.png
--------------------------------------------------------------------------------
/examples/sprites/Assets/kenney/pig.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/sprites/Assets/kenney/pig.png
--------------------------------------------------------------------------------
/Sources/gecko/render/HorizontalTextAlign.hx:
--------------------------------------------------------------------------------
1 | package gecko.render;
2 |
3 | typedef HorizontalTextAlign = kha.graphics2.HorTextAlignment;
--------------------------------------------------------------------------------
/examples/bunnyentities/Assets/rabbit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/bunnyentities/Assets/rabbit.png
--------------------------------------------------------------------------------
/examples/bunnyrender/Assets/Ubuntu-B.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/bunnyrender/Assets/Ubuntu-B.ttf
--------------------------------------------------------------------------------
/examples/demo/Assets/audio/Retro-Beat.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/audio/Retro-Beat.wav
--------------------------------------------------------------------------------
/examples/khashmup/Assets/bulletShoot.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/khashmup/Assets/bulletShoot.wav
--------------------------------------------------------------------------------
/examples/khashmup/Assets/playerShip.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/khashmup/Assets/playerShip.png
--------------------------------------------------------------------------------
/examples/khashmup/Assets/smokeOrange0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/khashmup/Assets/smokeOrange0.png
--------------------------------------------------------------------------------
/examples/khashmup/Assets/smokeOrange1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/khashmup/Assets/smokeOrange1.png
--------------------------------------------------------------------------------
/examples/khashmup/Assets/smokeOrange2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/khashmup/Assets/smokeOrange2.png
--------------------------------------------------------------------------------
/examples/khashmup/Assets/smokeOrange3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/khashmup/Assets/smokeOrange3.png
--------------------------------------------------------------------------------
/examples/sprites/Assets/kenney/hippo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/sprites/Assets/kenney/hippo.png
--------------------------------------------------------------------------------
/examples/sprites/Assets/kenney/monkey.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/sprites/Assets/kenney/monkey.png
--------------------------------------------------------------------------------
/examples/sprites/Assets/kenney/panda.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/sprites/Assets/kenney/panda.png
--------------------------------------------------------------------------------
/examples/sprites/Assets/kenney/parrot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/sprites/Assets/kenney/parrot.png
--------------------------------------------------------------------------------
/examples/sprites/Assets/kenney/snake.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/sprites/Assets/kenney/snake.png
--------------------------------------------------------------------------------
/Sources/gecko/ScreenMode.hx:
--------------------------------------------------------------------------------
1 | package gecko;
2 |
3 | enum ScreenMode {
4 | None;
5 | Fill;
6 | AspectFit;
7 | AspectFill;
8 | }
--------------------------------------------------------------------------------
/Sources/gecko/components/draw/MovieComponent.hx:
--------------------------------------------------------------------------------
1 | package gecko.components.draw;
2 |
3 | class MovieComponent extends DrawComponent {
4 |
5 | }
--------------------------------------------------------------------------------
/examples/basic/Assets/shipYellow_manned.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/basic/Assets/shipYellow_manned.png
--------------------------------------------------------------------------------
/examples/bunnyentities/Assets/Ubuntu-B.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/bunnyentities/Assets/Ubuntu-B.ttf
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/pig.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/pig.png
--------------------------------------------------------------------------------
/examples/flappy/Assets/readme.md:
--------------------------------------------------------------------------------
1 | Assets from https://imgur.com/gallery/1uKOr (CC BY-NC 4.0)
2 | Font kenpixel_mini_square.ttf from Kenney Pack
--------------------------------------------------------------------------------
/examples/khashmup/Assets/enemyExplosion.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/khashmup/Assets/enemyExplosion.wav
--------------------------------------------------------------------------------
/examples/sprites/Assets/kenney/elephant.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/sprites/Assets/kenney/elephant.png
--------------------------------------------------------------------------------
/examples/sprites/Assets/kenney/giraffe.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/sprites/Assets/kenney/giraffe.png
--------------------------------------------------------------------------------
/examples/sprites/Assets/kenney/penguin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/sprites/Assets/kenney/penguin.png
--------------------------------------------------------------------------------
/Sources/gecko/components/draw/CameraComponent.hx:
--------------------------------------------------------------------------------
1 | package gecko.components.draw;
2 |
3 | class CameraComponent extends DrawComponent {
4 |
5 | }
--------------------------------------------------------------------------------
/docs/examples/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Examples
3 | ---
4 |
5 | # Examples
6 | Use the sidebar to check differents examples and their source code.
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/giraffe.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/giraffe.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/hippo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/hippo.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/monkey.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/monkey.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/panda.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/panda.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/parrot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/parrot.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/penguin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/penguin.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/rabbit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/rabbit.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/snake.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/snake.png
--------------------------------------------------------------------------------
/examples/khashmup/Assets/playerExplosion.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/khashmup/Assets/playerExplosion.wav
--------------------------------------------------------------------------------
/examples/text/Assets/kenpixel_mini_square.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/text/Assets/kenpixel_mini_square.ttf
--------------------------------------------------------------------------------
/Sources/gecko/Float32.hx:
--------------------------------------------------------------------------------
1 | package gecko;
2 |
3 | //Alias for cpp.Float32 (fallback to haxe float in other platforms)
4 | typedef Float32 = kha.FastFloat;
--------------------------------------------------------------------------------
/Sources/gecko/ScreenOptions.hx:
--------------------------------------------------------------------------------
1 | package gecko;
2 |
3 | typedef ScreenOptions = {
4 | width:Int,
5 | height:Int,
6 | ?mode:ScreenMode
7 | };
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/elephant.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/elephant.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/enemyUFO.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/enemyUFO.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/red_cross.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/red_cross.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/wingMan1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/wingMan1.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/wingMan2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/wingMan2.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/wingMan3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/wingMan3.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/wingMan4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/wingMan4.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/wingMan5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/wingMan5.png
--------------------------------------------------------------------------------
/examples/flappy/Assets/images/flappydoge_bg1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/flappy/Assets/images/flappydoge_bg1.png
--------------------------------------------------------------------------------
/examples/flappy/Assets/images/flappydoge_bg2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/flappy/Assets/images/flappydoge_bg2.png
--------------------------------------------------------------------------------
/examples/flappy/Assets/kenpixel_mini_square.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/flappy/Assets/kenpixel_mini_square.ttf
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/green_panel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/green_panel.png
--------------------------------------------------------------------------------
/examples/flappy/Assets/images/flappydoge_anim01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/flappy/Assets/images/flappydoge_anim01.png
--------------------------------------------------------------------------------
/examples/flappy/Assets/images/flappydoge_anim02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/flappy/Assets/images/flappydoge_anim02.png
--------------------------------------------------------------------------------
/examples/flappy/Assets/images/flappydoge_anim03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/flappy/Assets/images/flappydoge_anim03.png
--------------------------------------------------------------------------------
/examples/flappy/Assets/images/flappydoge_anim04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/flappy/Assets/images/flappydoge_anim04.png
--------------------------------------------------------------------------------
/examples/flappy/Assets/images/flappydoge_floor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/flappy/Assets/images/flappydoge_floor.png
--------------------------------------------------------------------------------
/examples/flappy/Assets/images/flappydoge_pipe.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/flappy/Assets/images/flappydoge_pipe.png
--------------------------------------------------------------------------------
/examples/khashmup/Assets/kenpixel_mini_square.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/khashmup/Assets/kenpixel_mini_square.ttf
--------------------------------------------------------------------------------
/examples/animation/Assets/images/kenney/wingMan1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/animation/Assets/images/kenney/wingMan1.png
--------------------------------------------------------------------------------
/examples/animation/Assets/images/kenney/wingMan2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/animation/Assets/images/kenney/wingMan2.png
--------------------------------------------------------------------------------
/examples/animation/Assets/images/kenney/wingMan3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/animation/Assets/images/kenney/wingMan3.png
--------------------------------------------------------------------------------
/examples/animation/Assets/images/kenney/wingMan4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/animation/Assets/images/kenney/wingMan4.png
--------------------------------------------------------------------------------
/examples/animation/Assets/images/kenney/wingMan5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/animation/Assets/images/kenney/wingMan5.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/grey_button08.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/grey_button08.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/starBackground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/starBackground.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/opengameart/golem-atk.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/opengameart/golem-atk.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/opengameart/golem-die.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/opengameart/golem-die.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/opengameart/mountain.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/opengameart/mountain.png
--------------------------------------------------------------------------------
/examples/parenttransform/Assets/car_green_small_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/parenttransform/Assets/car_green_small_1.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/pixelExplosion00.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/pixelExplosion00.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/pixelExplosion01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/pixelExplosion01.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/pixelExplosion02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/pixelExplosion02.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/pixelExplosion03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/pixelExplosion03.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/pixelExplosion04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/pixelExplosion04.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/pixelExplosion05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/pixelExplosion05.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/pixelExplosion06.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/pixelExplosion06.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/pixelExplosion07.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/pixelExplosion07.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/kenney/pixelExplosion08.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/kenney/pixelExplosion08.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/opengameart/carbon_fiber.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/opengameart/carbon_fiber.png
--------------------------------------------------------------------------------
/examples/demo/Assets/images/opengameart/golem-walk.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/demo/Assets/images/opengameart/golem-walk.png
--------------------------------------------------------------------------------
/examples/nineslice/Assets/images/kenney/green_panel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/nineslice/Assets/images/kenney/green_panel.png
--------------------------------------------------------------------------------
/examples/animation/Assets/images/opengameart/golem-atk.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/animation/Assets/images/opengameart/golem-atk.png
--------------------------------------------------------------------------------
/examples/animation/Assets/images/opengameart/golem-die.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/animation/Assets/images/opengameart/golem-die.png
--------------------------------------------------------------------------------
/examples/nineslice/Assets/images/kenney/grey_button08.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/nineslice/Assets/images/kenney/grey_button08.png
--------------------------------------------------------------------------------
/examples/animation/Assets/images/kenney/pixelExplosion00.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/animation/Assets/images/kenney/pixelExplosion00.png
--------------------------------------------------------------------------------
/examples/animation/Assets/images/kenney/pixelExplosion01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/animation/Assets/images/kenney/pixelExplosion01.png
--------------------------------------------------------------------------------
/examples/animation/Assets/images/kenney/pixelExplosion02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/animation/Assets/images/kenney/pixelExplosion02.png
--------------------------------------------------------------------------------
/examples/animation/Assets/images/kenney/pixelExplosion03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/animation/Assets/images/kenney/pixelExplosion03.png
--------------------------------------------------------------------------------
/examples/animation/Assets/images/kenney/pixelExplosion04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/animation/Assets/images/kenney/pixelExplosion04.png
--------------------------------------------------------------------------------
/examples/animation/Assets/images/kenney/pixelExplosion05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/animation/Assets/images/kenney/pixelExplosion05.png
--------------------------------------------------------------------------------
/examples/animation/Assets/images/kenney/pixelExplosion06.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/animation/Assets/images/kenney/pixelExplosion06.png
--------------------------------------------------------------------------------
/examples/animation/Assets/images/kenney/pixelExplosion07.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/animation/Assets/images/kenney/pixelExplosion07.png
--------------------------------------------------------------------------------
/examples/animation/Assets/images/kenney/pixelExplosion08.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/animation/Assets/images/kenney/pixelExplosion08.png
--------------------------------------------------------------------------------
/examples/animation/Assets/images/opengameart/golem-walk.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/animation/Assets/images/opengameart/golem-walk.png
--------------------------------------------------------------------------------
/examples/khashmup/Sources/components/OutBoundsComponent.hx:
--------------------------------------------------------------------------------
1 | package components;
2 |
3 | import gecko.components.Component;
4 |
5 | class OutBoundsComponent extends Component {}
--------------------------------------------------------------------------------
/examples/scrollingsprite/Assets/images/opengameart/mountain.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/scrollingsprite/Assets/images/opengameart/mountain.png
--------------------------------------------------------------------------------
/Sources/gecko/render/BlendMode.hx:
--------------------------------------------------------------------------------
1 | package gecko.render;
2 |
3 | enum BlendMode {
4 | None;
5 | Normal;
6 | Add;
7 | Multiply;
8 | Screen;
9 | Erase;
10 | }
--------------------------------------------------------------------------------
/Sources/gecko/input/MouseButton.hx:
--------------------------------------------------------------------------------
1 | package gecko.input;
2 |
3 | @:enum abstract MouseButton(Int) from Int to Int {
4 | var LEFT = 0;
5 | var RIGHT = 1;
6 | var CENTER = 2;
7 | }
--------------------------------------------------------------------------------
/examples/scrollingsprite/Assets/images/opengameart/carbon_fiber.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Nazariglez/Gecko2D/master/examples/scrollingsprite/Assets/images/opengameart/carbon_fiber.png
--------------------------------------------------------------------------------
/Sources/gecko/macros/IAutoPool.hx:
--------------------------------------------------------------------------------
1 | package gecko.macros;
2 |
3 | @:remove @:autoBuild(gecko.macros.PoolBuilder.build())
4 | interface IAutoPool {
5 | public function beforeDestroy():Void;
6 | }
--------------------------------------------------------------------------------
/templates/empty/Sources/Game.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Scene;
4 | import gecko.Gecko;
5 |
6 | class Game {
7 | public function new(){
8 | trace("welcome!");
9 | }
10 | }
--------------------------------------------------------------------------------
/Sources/gecko/components/input/TouchComponent.hx:
--------------------------------------------------------------------------------
1 | package gecko.components.input;
2 |
3 | import gecko.components.Component;
4 |
5 | class TouchComponent extends Component {
6 | //todo touch component
7 | }
--------------------------------------------------------------------------------
/examples/scrollingsprite/Assets/images/opengameart/readme.md:
--------------------------------------------------------------------------------
1 | - mountan.png from https://opengameart.org/content/hand-painted-mountain-texture
2 | - carbon_fiber.png from https://opengameart.org/content/carbon-fiber
--------------------------------------------------------------------------------
/docs/guide/screen.md:
--------------------------------------------------------------------------------
1 | # Screen Modes
2 |
3 | ## None
4 | ## Fill
5 | ## Aspect Fit
6 | ## Aspect Fill
7 |
8 | ::: warning Section in progress
9 | We're working in this section, please be patient.
10 | :::
--------------------------------------------------------------------------------
/Sources/gecko/components/misc/BehaviorComponent.hx:
--------------------------------------------------------------------------------
1 | package gecko.components.misc;
2 |
3 | @:isBaseComponent
4 | class BehaviorComponent extends Component implements IUpdatable {
5 | public function update(dt:Float) {}
6 | }
--------------------------------------------------------------------------------
/docs/faq.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: "FAQs"
3 | ---
4 |
5 | # Frequently Asked Questions
6 |
7 | ## Which platforms are supported?
8 |
9 | ## Why use an Entity-Component-System architecture?
10 |
11 | ## How can I help to improve the framework?
--------------------------------------------------------------------------------
/examples/flappy/Sources/GameState.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | enum FlappyState {
4 | Idle;
5 | Playing;
6 | Falling;
7 | End;
8 | }
9 |
10 | class GameState {
11 | static public var State:FlappyState = FlappyState.Idle;
12 | }
--------------------------------------------------------------------------------
/examples/animation/Assets/images/opengameart/readme.md:
--------------------------------------------------------------------------------
1 | - golem-atk.png from https://opengameart.org/content/lpc-golem
2 | - golem-die.png from https://opengameart.org/content/lpc-golem
3 | - golem-walk.png from https://opengameart.org/content/lpc-golem
--------------------------------------------------------------------------------
/Sources/gecko/BaseObject.hx:
--------------------------------------------------------------------------------
1 | package gecko;
2 |
3 | import gecko.macros.IAutoPool;
4 |
5 | class BaseObject implements IAutoPool {
6 | public var id(default, null):Int = Gecko.getUniqueID();
7 | public function new(){}
8 | public function beforeDestroy(){}
9 | }
--------------------------------------------------------------------------------
/examples/demo/Sources/Main.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Gecko;
4 |
5 | class Main {
6 | public static function main() {
7 | Gecko.init(_onReady, {width: 800, height: 600});
8 | }
9 |
10 | private static function _onReady() {
11 | var game = new Game();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/templates/basic/Sources/Main.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Gecko;
4 |
5 | class Main {
6 | public static function main() {
7 | Gecko.init(_onReady, {width: 800, height: 600});
8 | }
9 |
10 | private static function _onReady() {
11 | var game = new Game();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/templates/empty/Sources/Main.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Gecko;
4 |
5 | class Main {
6 | public static function main() {
7 | Gecko.init(_onReady, {width: 800, height: 600});
8 | }
9 |
10 | private static function _onReady() {
11 | var game = new Game();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/docs/.vuepress/override.styl:
--------------------------------------------------------------------------------
1 | .theme-container.api-docs {
2 | .page {
3 | .content {
4 | width: 100%;
5 | height: 100%;
6 | margin: 0;
7 | padding: 0;
8 | max-width: 100% !important;
9 | max-height: 100% !important;
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/examples/bunnyrender/Sources/Main.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Gecko;
4 |
5 | class Main {
6 | public static function main() {
7 | Gecko.init(_onReady, {width: 800, height: 600});
8 | }
9 |
10 | private static function _onReady() {
11 | var game = new Game();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es5",
4 | "lib": [
5 | "es2015"
6 | ],
7 | "sourceMap": true
8 | },
9 |
10 | "exclude": [
11 | "node_modules/**/*",
12 | "Kha/**/*",
13 | "examples/**/*"
14 | ]
15 | }
--------------------------------------------------------------------------------
/examples/bunnyentities/Sources/Main.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Gecko;
4 |
5 | class Main {
6 | public static function main() {
7 | Gecko.init(_onReady, {width: 800, height: 600});
8 | }
9 |
10 | private static function _onReady() {
11 | var game = new Game();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/Sources/gecko/math/Random.hx:
--------------------------------------------------------------------------------
1 | package gecko.math;
2 |
3 | /*
4 | * From Kha code.
5 | * Random number generator
6 | *
7 | * Please use this one instead of the native Haxe one to
8 | * keep consistency between different platforms.
9 | *
10 | */
11 |
12 | typedef Random = kha.math.Random;
--------------------------------------------------------------------------------
/scripts/devkhamake.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 | const path = require("path");
3 |
4 | const pkgPath = path.resolve(process.cwd(), "package.json");
5 | let pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
6 | pkg.dependencies["khamake"] = "file:Kha/Tools/khamake";
7 |
8 | fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2), "utf8");
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | .vscode
3 | node_modules
4 | build
5 | kha_build
6 | *.log
7 | examples/**/Libraries/gecko
8 | examples/**/korefile.js
9 | examples/**/khafile.js
10 | examples/test
11 | build_templates/docs/**/khafile.js
12 | build_templates/docs/**/korefile.js
13 | build_templates/docs/build
14 | docs/.vuepress/dist
15 |
16 |
17 | !*/.gitkeep
--------------------------------------------------------------------------------
/examples/flappy/Sources/Config.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 |
4 |
5 | class Config {
6 | static public var PipesSpeed:Float = 120;
7 | static public var GapBetweenPipes:Float = 120;
8 | static public var SpawnTimeBetweenPipes:Float = 1.8;
9 | static public var PlayerJumpHeight:Float = 60;
10 | static public var PlayerJumpTime:Float = 0.26;
11 | }
--------------------------------------------------------------------------------
/examples/demo/Assets/images/opengameart/readme.md:
--------------------------------------------------------------------------------
1 | - mountan.png from https://opengameart.org/content/hand-painted-mountain-texture
2 | - carbon_fiber.png from https://opengameart.org/content/carbon-fiber
3 | - golem-atk.png from https://opengameart.org/content/lpc-golem
4 | - golem-die.png from https://opengameart.org/content/lpc-golem
5 | - golem-walk.png from https://opengameart.org/content/lpc-golem
--------------------------------------------------------------------------------
/examples/flappy/readme.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Flappy
3 | example: true
4 | category: Demos
5 | priority: 0
6 | source: false
7 | ---
8 |
9 | Flappy Doge
10 | ===========
11 |
12 | A classic FlappyBird clone created using the BehaviorSystem and BehaviorComponents, in a way similar to an Entity-Component architecture,
13 | which it's a good structure to create (for example) games in a little time for game jams.
--------------------------------------------------------------------------------
/cli/main.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import {run} from './cli';
3 | import {nodeVersion, getRequiredNodeVersion} from './utils';
4 | import * as colors from 'colors';
5 |
6 | if(nodeVersion()[0] < getRequiredNodeVersion()[0]){
7 | console.error(colors.red("Invalid node version. Must be >= " + getRequiredNodeVersion().join(".")));
8 | }else{
9 | run();
10 | }
11 |
12 |
--------------------------------------------------------------------------------
/Sources/gecko/utils/ArrayHelper.hx:
--------------------------------------------------------------------------------
1 | package gecko.utils;
2 |
3 | class ArrayHelper {
4 | inline static public function clear(arr:Array) {
5 | #if js
6 | untyped __js__('{0}.length = 0', arr);
7 | #else
8 | arr.splice(0, arr.length);
9 | #end
10 | }
11 |
12 | inline static public function has(arr:Array, obj:T) : Bool {
13 | return arr.indexOf(obj) != -1;
14 | }
15 | }
--------------------------------------------------------------------------------
/examples/basic/Sources/Main.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Gecko;
4 |
5 | class Main {
6 | public static function main() {
7 | Gecko.init(_onReady, {
8 | width: 800,
9 | height: 600,
10 | maximizable: true,
11 | resizable: true,
12 | screen: {
13 | width: 800,
14 | height: 600,
15 | mode: gecko.ScreenMode.AspectFit
16 | }
17 | });
18 | }
19 |
20 | private static function _onReady() {
21 | var game = new Game();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/examples/text/Sources/Main.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Gecko;
4 |
5 | class Main {
6 | public static function main() {
7 | Gecko.init(_onReady, {
8 | width: 800,
9 | height: 600,
10 | maximizable: true,
11 | resizable: true,
12 | screen: {
13 | width: 800,
14 | height: 600,
15 | mode: gecko.ScreenMode.AspectFit
16 | }
17 | });
18 | }
19 |
20 | private static function _onReady() {
21 | var game = new Game();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Sources/gecko/utils/PoolOptions.hx:
--------------------------------------------------------------------------------
1 | package gecko.utils;
2 |
3 | //todo scalesys where:
4 | //todo {window: {width:X, height:N}, view: {width:X, height:N}}
5 | //todo and view it's scaled with matrix transform
6 | //todo see this https://www.youtube.com/watch?v=SE2Ded01lUU
7 |
8 | typedef PoolOptions = {
9 | @:optional var args:Array;
10 | @:optional var amount:Int;
11 | @:optional var init:T->Void;
12 | @:optional var reset:T->Void;
13 | }
--------------------------------------------------------------------------------
/examples/animation/Sources/Main.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Gecko;
4 |
5 | class Main {
6 | public static function main() {
7 | Gecko.init(_onReady, {
8 | width: 800,
9 | height: 600,
10 | maximizable: true,
11 | resizable: true,
12 | screen: {
13 | width: 800,
14 | height: 600,
15 | mode: gecko.ScreenMode.AspectFit
16 | }
17 | });
18 | }
19 |
20 | private static function _onReady() {
21 | var game = new Game();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/examples/nineslice/Sources/Main.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Gecko;
4 |
5 | class Main {
6 | public static function main() {
7 | Gecko.init(_onReady, {
8 | width: 800,
9 | height: 600,
10 | maximizable: true,
11 | resizable: true,
12 | screen: {
13 | width: 800,
14 | height: 600,
15 | mode: gecko.ScreenMode.AspectFit
16 | }
17 | });
18 | }
19 |
20 | private static function _onReady() {
21 | var game = new Game();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/examples/shapes/Sources/Main.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Gecko;
4 |
5 | class Main {
6 | public static function main() {
7 | Gecko.init(_onReady, {
8 | width: 800,
9 | height: 600,
10 | maximizable: true,
11 | resizable: true,
12 | screen: {
13 | width: 800,
14 | height: 600,
15 | mode: gecko.ScreenMode.AspectFit
16 | }
17 | });
18 | }
19 |
20 | private static function _onReady() {
21 | var game = new Game();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/examples/sprites/Sources/Main.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Gecko;
4 |
5 | class Main {
6 | public static function main() {
7 | Gecko.init(_onReady, {
8 | width: 800,
9 | height: 600,
10 | maximizable: true,
11 | resizable: true,
12 | screen: {
13 | width: 800,
14 | height: 600,
15 | mode: gecko.ScreenMode.AspectFit
16 | }
17 | });
18 | }
19 |
20 | private static function _onReady() {
21 | var game = new Game();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/templates/sample/Sources/Main.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Gecko;
4 |
5 | class Main {
6 | public static function main() {
7 | Gecko.init(_onReady, {
8 | width: 800,
9 | height: 600,
10 | maximizable: true,
11 | resizable: true,
12 | screen: {
13 | width: 800,
14 | height: 600,
15 | mode: gecko.ScreenMode.AspectFit
16 | }
17 | });
18 | }
19 |
20 | private static function _onReady() {
21 | var game = new Game();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/examples/parenttransform/Sources/Main.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Gecko;
4 |
5 | class Main {
6 | public static function main() {
7 | Gecko.init(_onReady, {
8 | width: 800,
9 | height: 600,
10 | maximizable: true,
11 | resizable: true,
12 | screen: {
13 | width: 800,
14 | height: 600,
15 | mode: gecko.ScreenMode.AspectFit
16 | }
17 | });
18 | }
19 |
20 | private static function _onReady() {
21 | var game = new Game();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/examples/scrollingsprite/Sources/Main.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Gecko;
4 |
5 | class Main {
6 | public static function main() {
7 | Gecko.init(_onReady, {
8 | width: 800,
9 | height: 600,
10 | maximizable: true,
11 | resizable: true,
12 | screen: {
13 | width: 800,
14 | height: 600,
15 | mode: gecko.ScreenMode.AspectFit
16 | }
17 | });
18 | }
19 |
20 | private static function _onReady() {
21 | var game = new Game();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/docs/.vuepress/examples.json:
--------------------------------------------------------------------------------
1 | [
2 | "",
3 | {
4 | "title": "Basics",
5 | "collapsable": true,
6 | "children": [
7 | "basic",
8 | "shapes",
9 | "sprites",
10 | "scrollingsprite",
11 | "animation",
12 | "nineslice",
13 | "text",
14 | "parenttransform"
15 | ]
16 | },
17 | {
18 | "title": "Demos",
19 | "collapsable": true,
20 | "children": [
21 | "flappy",
22 | "khashmup"
23 | ]
24 | }
25 | ]
--------------------------------------------------------------------------------
/examples/flappy/Sources/Main.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.ScreenMode;
4 | import gecko.Gecko;
5 |
6 | class Main {
7 | public static function main() {
8 | Gecko.init(_onReady, {
9 | width: 288,
10 | height: 512,
11 | maximizable: true,
12 | resizable: true,
13 | screen: {
14 | width: 288,
15 | height: 512,
16 | mode: ScreenMode.AspectFit
17 | }
18 | });
19 | }
20 |
21 | private static function _onReady() {
22 | var game = new Game();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/examples/bunnyentities/Sources/BounceComponent.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.components.Component;
4 | import gecko.math.Point;
5 |
6 |
7 | class BounceComponent extends Component {
8 | public var speed:Point;
9 |
10 | public function init(speedX:Float, speedY:Float) {
11 | speed = Point.create(speedX, speedY);
12 | }
13 |
14 | override public function beforeDestroy() {
15 | speed.destroy();
16 | speed = null;
17 |
18 | super.beforeDestroy();
19 | }
20 | }
--------------------------------------------------------------------------------
/docs/guide/ecs.md:
--------------------------------------------------------------------------------
1 | # Entity Component System
2 | Gecko2D use a kind of '[Entity Component System](https://en.wikipedia.org/wiki/Entity%E2%80%93component%E2%80%93system)' architecture.
3 |
4 | ## Scene
5 | The object `gecko.Scene` is the root of our __ECS__. Each __Scene__ is independent of the others, and has his own [entities](#entity) and [systems](#system).
6 |
7 | ## Entity
8 |
9 | ## System
10 |
11 | ## Component
12 |
13 | ::: warning Section in progress
14 | We're working in this section, please be patient.
15 | :::
--------------------------------------------------------------------------------
/examples/khashmup/Sources/Main.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Gecko;
4 | import gecko.ScreenMode;
5 |
6 | class Main {
7 | public static function main() {
8 | Gecko.init(_onReady, {
9 | width: 800,
10 | height: 600,
11 | bgColor: 0x26004d,
12 | maximizable: true,
13 | resizable: true,
14 | screen: {
15 | width: 800,
16 | height: 600,
17 | mode: ScreenMode.AspectFit
18 | }
19 | });
20 | }
21 |
22 | private static function _onReady() {
23 | var game = new Game();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Sources/gecko/GeckoOptions.hx:
--------------------------------------------------------------------------------
1 | package gecko;
2 |
3 | import kha.System.SystemOptions;
4 |
5 | typedef GeckoOptions = {
6 | ?title:String,
7 | ?width:Int,
8 | ?height:Int,
9 | ?antialiasing:Int,
10 | ?randomSeed:Int,
11 | ?fullScreen:Bool,
12 | ?resizable:Bool,
13 | ?bgColor:Color,
14 | ?maximizable:Bool, //todo use screenSize instead maximizable in html5 and pc to use window size
15 | ?useFixedDelta:Bool,
16 | ?fps:Int,
17 | ?screen:ScreenOptions,
18 | ?khaOptions:SystemOptions
19 | };
--------------------------------------------------------------------------------
/cli/cmd/version.ts:
--------------------------------------------------------------------------------
1 | import {Command, ActionCallback} from '../cli';
2 | import {ENGINE_NAME} from '../const';
3 |
4 | declare const __non_webpack_require__:any;
5 |
6 | export const cmd:Command = {
7 | name: "version",
8 | alias: ["-v", "--version"],
9 | usage: `print ${ENGINE_NAME} version`,
10 | action: _action
11 | };
12 |
13 | function _action(args:string[], cb:ActionCallback) {
14 | console.log(`${ENGINE_NAME} version: ${__non_webpack_require__("../../package.json").version}`);
15 | cb(null, args);
16 | }
--------------------------------------------------------------------------------
/Sources/gecko/components/motion/RotationComponent.hx:
--------------------------------------------------------------------------------
1 | package gecko.components.motion;
2 |
3 |
4 |
5 | class RotationComponent extends Component {
6 | public var speed:Float;
7 | public var acceleration:Float;
8 |
9 | public function init(speed:Float, acceleration:Float = 0) {
10 | this.speed = speed;
11 | this.acceleration = acceleration;
12 | }
13 |
14 | override public function beforeDestroy(){
15 | speed = 0;
16 | acceleration = 0;
17 |
18 | super.beforeDestroy();
19 | }
20 | }
--------------------------------------------------------------------------------
/examples/khashmup/readme.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: KhaShmup
3 | example: true
4 | category: Demos
5 | priority: 0
6 | source: false
7 | ---
8 |
9 | KhaShmup
10 | ====
11 |
12 | This example it's an adaptation of the [Jamiltron's KhaShmup](https://github.com/jamiltron/KhaShmup/tree/master) which is the one of the first and the best tutorials about kha online.
13 |
14 | In this examples we're using an Entity-Component-System architecutre using some systems and components included in the framework and others created for this example to make a simple Shoot'em up.
--------------------------------------------------------------------------------
/scripts/koremake.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const path = require("path");
4 | const dir = path.resolve(__dirname, "../Kha/Kore/Tools/koremake");
5 | const spawn = require("cross-spawn");
6 |
7 | var env = {};
8 | for(var k in process.env){
9 | if(process.env.hasOwnProperty(k) && k.indexOf("npm") === -1){
10 | env[k] = process.env[k];
11 | }
12 | }
13 |
14 | const child = spawn("npm", ["install"], {cwd: dir, env:env});
15 | child.stderr.on("data", d => console.log(d.toString()));
16 | child.stdout.on("data", d => console.log(d.toString()));
--------------------------------------------------------------------------------
/webpack.config.js:
--------------------------------------------------------------------------------
1 | const production = (process.env.NODE_ENV === "production");
2 |
3 | module.exports = {
4 | devtool: !production ? 'inline-source-map' : false,
5 | entry: ['./cli/main.ts'],
6 | target: "node",
7 | node: {
8 | __dirname: false,
9 | __filename: false,
10 | process: false,
11 | },
12 | output: {
13 | filename: './cli/bin/cli.js',
14 | },
15 | resolve: {
16 | extensions: ['.ts', '.js']
17 | },
18 | module: {
19 | loaders: [
20 | {
21 | test: /\.ts$/,
22 | loader: 'ts-loader'
23 | }
24 | ]
25 | }
26 | };
--------------------------------------------------------------------------------
/Sources/gecko/systems/misc/BehaviorSystem.hx:
--------------------------------------------------------------------------------
1 | package gecko.systems.misc;
2 |
3 | import gecko.components.misc.BehaviorComponent;
4 |
5 | class BehaviorSystem extends System implements IUpdatable {
6 | public function init(){
7 | filter.base([BehaviorComponent]);
8 | }
9 |
10 | override public function update(dt:Float) {
11 | eachEntity(function(e:Entity){
12 | var components:Array = e.getComponentsOfType(BehaviorComponent);
13 | for(c in components){
14 | c.update(dt);
15 | }
16 | });
17 | }
18 | }
--------------------------------------------------------------------------------
/docs/examples/flappy.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Flappy
3 | ---
4 | # Flappy
5 |
6 |
7 | Flappy Doge
8 | ===========
9 |
10 | A classic FlappyBird clone created using the BehaviorSystem and BehaviorComponents, in a way similar to an Entity-Component architecture,
11 | which it's a good structure to create (for example) games in a little time for game jams.
12 |
13 | [Source Code](https://github.com/Nazariglez/Gecko2D/tree/master/examples/flappy)
14 |
--------------------------------------------------------------------------------
/templates/basic/Sources/scenes/MainScene.hx:
--------------------------------------------------------------------------------
1 | package scenes;
2 |
3 | import gecko.systems.draw.DrawSystem;
4 | import gecko.Screen;
5 | import gecko.Scene;
6 | import gecko.components.draw.TextComponent;
7 |
8 | class MainScene extends Scene {
9 | public function init() {
10 | addSystem(DrawSystem.create());
11 | _addWelcomeText();
12 | }
13 |
14 | private function _addWelcomeText() {
15 | var entity = createEntity();
16 | entity.addComponent(TextComponent.create("Welcome to your Gecko2D game!", "Ubuntu-B.ttf", 40));
17 | entity.transform.position.set(Screen.centerX, Screen.centerY);
18 | }
19 | }
--------------------------------------------------------------------------------
/examples/khashmup/Sources/components/PlayerComponent.hx:
--------------------------------------------------------------------------------
1 | package components;
2 |
3 |
4 | import gecko.input.KeyCode;
5 | import gecko.components.Component;
6 |
7 | class PlayerComponent extends Component {
8 | public var left:KeyCode;
9 | public var right:KeyCode;
10 | public var up:KeyCode;
11 | public var down:KeyCode;
12 | public var speed:Float = 0;
13 |
14 | public function init(leftKey:KeyCode, rightKey:KeyCode, upKey:KeyCode, downKey:KeyCode, speed:Float = 400){
15 | left = leftKey;
16 | right = rightKey;
17 | up = upKey;
18 | down = downKey;
19 |
20 | this.speed = speed;
21 | }
22 | }
--------------------------------------------------------------------------------
/cli/commands.ts:
--------------------------------------------------------------------------------
1 | import {Command} from "./cli";
2 | import * as build from './cmd/build';
3 | import * as help from './cmd/help';
4 | import * as init from './cmd/init';
5 | import * as version from './cmd/version';
6 | import * as serve from './cmd/serve';
7 | import * as watch from './cmd/watch';
8 | import * as docs from './cmd/docs';
9 | import * as dir from './cmd/dir';
10 | import * as khafile from "./cmd/khafile";
11 |
12 | export const commands:Command[] = [
13 | build,
14 | help,
15 | init,
16 | version,
17 | serve,
18 | watch,
19 | //docs,
20 | dir,
21 | khafile
22 | ].map(c => c.cmd).sort((a, b)=>{
23 | if(a.name < b.name) return -1;
24 | if(a.name > b.name) return 1;
25 | return 0;
26 | });
--------------------------------------------------------------------------------
/docs/api.md:
--------------------------------------------------------------------------------
1 | ---
2 | pageClass: api-docs
3 | ---
4 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/docs/examples/khashmup.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: KhaShmup
3 | ---
4 | # KhaShmup
5 |
6 |
7 | KhaShmup
8 | ====
9 |
10 | This example it's an adaptation of the [Jamiltron's KhaShmup](https://github.com/jamiltron/KhaShmup/tree/master) which is the one of the first and the best tutorials about kha online.
11 |
12 | In this examples we're using an Entity-Component-System architecutre using some systems and components included in the framework and others created for this example to make a simple Shoot'em up.
13 |
14 | [Source Code](https://github.com/Nazariglez/Gecko2D/tree/master/examples/khashmup)
15 |
--------------------------------------------------------------------------------
/cli/cmd/help.ts:
--------------------------------------------------------------------------------
1 | import {Command, ActionCallback} from '../cli';
2 | import {commands} from '../commands';
3 | import * as C from '../const';
4 |
5 | export const cmd:Command = {
6 | name: "help",
7 | alias: ["-h", "--help"],
8 | usage: "print command list help",
9 | action: _action
10 | };
11 |
12 | function _action(args:string[], cb:ActionCallback) {
13 | let txt = `Usage: ${C.ENGINE_NAME} [ options ]
14 |
15 | Commands:\n`;
16 |
17 | commands.forEach(cmd => {
18 | txt += ` ${cmd.name}`;
19 | if(cmd.alias&&cmd.alias.length){
20 | txt += `, ${cmd.alias.join(", ")}`;
21 | }
22 | txt += "\n";
23 | txt += ` - ${cmd.usage}\n\n`;
24 | });
25 |
26 | console.log(txt);
27 | cb(null, args);
28 | }
--------------------------------------------------------------------------------
/docs/examples/test.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: TestTitle
3 | ---
4 | # TestTitle
5 |
6 |
7 | ```haxe
8 | package;
9 |
10 | import gecko.Scene;
11 | import gecko.Gecko;
12 |
13 | class Game {
14 | public function new(){
15 | trace("welcome!");
16 | var scene = Gecko.currentScene;
17 | scene.addSystem(gecko.systems.draw.DrawSystem.create());
18 | var e = scene.createEntity();
19 | e.addComponent(gecko.components.draw.CircleComponent.create(true, 60));
20 |
21 | e.transform.position.set(gecko.Screen.centerX, gecko.Screen.centerY);
22 | }
23 | }
24 | ```
25 |
26 | [Source Code](https://github.com/Nazariglez/Gecko2D/tree/master/examples/test)
27 |
--------------------------------------------------------------------------------
/cli/cmd/dir.ts:
--------------------------------------------------------------------------------
1 | import {Command, ActionCallback} from '../cli';
2 | import {ENGINE_NAME, ENGINE_PATH, KHA_PATH} from '../const';
3 | import * as path from 'path';
4 |
5 | const usage = `print the directory where ${ENGINE_NAME} is installed
6 | ${ENGINE_NAME} dir [ -kha ]
7 |
8 | where [ -kha ] print the Kha directory`;
9 |
10 | export const cmd:Command = {
11 | name: "dir",
12 | alias: [],
13 | usage: usage,
14 | action: _action
15 | };
16 |
17 | function _action(args:string[], cb:ActionCallback) {
18 | var kha:boolean = false;
19 |
20 | if(args.length && args[0] === "-kha"){
21 | args.shift();
22 | kha = true;
23 | }
24 |
25 | if(kha){
26 | console.log(KHA_PATH);
27 | }else{
28 | console.log(ENGINE_PATH);
29 | }
30 |
31 | cb(null, args);
32 | }
--------------------------------------------------------------------------------
/Sources/gecko/components/motion/MovementComponent.hx:
--------------------------------------------------------------------------------
1 | package gecko.components.motion;
2 |
3 | import gecko.math.Point;
4 |
5 | class MovementComponent extends Component {
6 | public var speed:Point;
7 | public var acceleration:Point;
8 | public var friction:Point; //just if acceleration = 0
9 |
10 | public function init(speed:Point, ?acceleration:Point, ?friction:Point) {
11 | this.speed = speed;
12 | this.acceleration = acceleration != null ? acceleration : Point.create();
13 | this.friction = friction != null ? friction : Point.create();
14 | }
15 |
16 | override public function beforeDestroy(){
17 | speed.destroy();
18 | speed = null;
19 | acceleration.destroy();
20 | acceleration = null;
21 | friction.destroy();
22 | friction = null;
23 |
24 | super.beforeDestroy();
25 | }
26 | }
--------------------------------------------------------------------------------
/examples/khashmup/Sources/components/ShootComponent.hx:
--------------------------------------------------------------------------------
1 | package components;
2 |
3 | import gecko.IUpdatable;
4 |
5 | import gecko.input.KeyCode;
6 | import gecko.components.Component;
7 |
8 | class ShootComponent extends Component implements IUpdatable {
9 | public var key:KeyCode;
10 | public var delay:Float = 0;
11 | public var speed:Float = 0;
12 |
13 | private var _time:Float = 0;
14 |
15 | public function init(shootKey:KeyCode, shotSpeed:Float = 720, timeInterval:Float = 0.25) {
16 | key = shootKey;
17 | delay = timeInterval;
18 | speed = shotSpeed;
19 | _time = 0;
20 | }
21 |
22 | public function update(dt:Float) {
23 | if(_time > 0)_time -= dt;
24 | }
25 |
26 | inline public function resetTimer() {
27 | _time = delay;
28 | }
29 |
30 | inline public function canShoot() : Bool {
31 | return _time <= 0;
32 | }
33 | }
--------------------------------------------------------------------------------
/Sources/gecko/Storage.hx:
--------------------------------------------------------------------------------
1 | package gecko;
2 |
3 | import kha.Storage as KhaStorage;
4 | import kha.StorageFile;
5 |
6 | class Storage extends BaseObject {
7 | public var _file:StorageFile;
8 |
9 | public function init(fileName:String = "default.gecko") {
10 | _file = KhaStorage.namedFile(fileName);
11 | }
12 |
13 | //todo clear function?
14 |
15 | public function read() : String {
16 | var content = _file.readString();
17 | return content != null ? content : "";
18 | }
19 |
20 | inline public function write(data:String) {
21 | _file.writeString(data);
22 | }
23 |
24 | inline public function writeObject(object:Dynamic) {
25 | _file.writeObject(object);
26 | }
27 |
28 | inline public function readObject() {
29 | return _file.readObject();
30 | }
31 |
32 | override public function beforeDestroy() {
33 | super.beforeDestroy();
34 |
35 | _file = null;
36 | }
37 | }
--------------------------------------------------------------------------------
/scripts/khamake.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const path = require("path");
4 | const dir = path.resolve(__dirname, "../Kha/Tools/khamake");
5 | const spawn = require("cross-spawn");
6 |
7 | var env = {};
8 | for(var k in process.env){
9 | if(process.env.hasOwnProperty(k) && k.indexOf("npm") === -1){
10 | env[k] = process.env[k];
11 | }
12 | }
13 |
14 | const child = spawn("npm", ["install"], {cwd: dir, env:env});
15 | child.stderr.on("data", d => console.log(d.toString()));
16 | child.stdout.on("data", d => console.log(d.toString()));
17 |
18 | /*
19 | const commitHash = require('child_process')
20 | .execSync('git rev-parse HEAD', {cwd: dir})
21 | .toString().trim();
22 |
23 | const pkgPath = path.resolve(process.cwd(), "package.json");
24 | let pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
25 | pkg.dependencies["khamake"] = "github:kode/khamake#" + commitHash;
26 |
27 | fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2), "utf8");
28 | */
29 |
30 |
--------------------------------------------------------------------------------
/examples/basic/Sources/Game.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Screen;
4 | import gecko.components.draw.SpriteComponent;
5 | import gecko.Gecko;
6 | import gecko.Assets;
7 | import gecko.systems.draw.DrawSystem;
8 |
9 | class Game {
10 | public function new(){
11 | //add the draw system to the current scene
12 | Gecko.currentScene.addSystem(DrawSystem.create());
13 |
14 | //load assets
15 | Assets.load([
16 | "shipYellow_manned.png"
17 | ], _onAssetsLoaded).start();
18 | }
19 |
20 | private function _onAssetsLoaded() {
21 | //create a new entity in the current scene
22 | var entity = Gecko.currentScene.createEntity();
23 |
24 | //center the entity in the middle of the screen
25 | entity.transform.position.set(Screen.centerX, Screen.centerY);
26 |
27 | //add a sprite component to the scene
28 | entity.addComponent(SpriteComponent.create("shipYellow_manned.png"));
29 | }
30 | }
--------------------------------------------------------------------------------
/Sources/gecko/math/Vector2i.hx:
--------------------------------------------------------------------------------
1 | package gecko.math;
2 |
3 | class Vector2i extends BaseObject {
4 | public var x: Int;
5 | public var y: Int;
6 |
7 | public function init(x: Int = 0, y: Int = 0): Void {
8 | this.x = x;
9 | this.y = y;
10 | }
11 |
12 | public inline function setFrom(v: Vector2i): Void {
13 | this.x = v.x;
14 | this.y = v.y;
15 | }
16 |
17 | public inline function add(vec: Vector2i): Vector2i {
18 | return Vector2i.create(x + vec.x, y + vec.y);
19 | }
20 |
21 | public inline function sub(vec: Vector2i): Vector2i {
22 | return Vector2i.create(x - vec.x, y - vec.y);
23 | }
24 |
25 | public inline function mult(value: Int): Vector2i {
26 | return Vector2i.create(x * value, y * value);
27 | }
28 |
29 | public inline function div(value: Int): Vector2i {
30 | return Vector2i.create(Std.int(x / value), Std.int(y / value));
31 | }
32 |
33 | public inline function dot(v: Vector2i): Float {
34 | return x * v.x + y * v.y;
35 | }
36 | }
--------------------------------------------------------------------------------
/examples/khashmup/Sources/systems/OutBoundsSystem.hx:
--------------------------------------------------------------------------------
1 | package systems;
2 |
3 | import gecko.Entity;
4 |
5 | import gecko.math.Rect;
6 | import gecko.systems.System;
7 | import gecko.IUpdatable;
8 |
9 | import components.OutBoundsComponent;
10 |
11 | class OutBoundsSystem extends System implements IUpdatable {
12 | public var bounds:Rect;
13 |
14 | public function init(bounds:Rect) {
15 | filter.all([OutBoundsComponent]);
16 |
17 | this.bounds = bounds;
18 | }
19 |
20 | override public function update(dt:Float) {
21 | eachEntity(function(e:Entity){
22 | //destroy entity if is out of bounds
23 | if(e.transform.top > bounds.bottom || e.transform.bottom < bounds.top || e.transform.left > bounds.right || e.transform.right < bounds.left){
24 | e.destroy();
25 | }
26 | });
27 | }
28 |
29 | override public function beforeDestroy() {
30 | super.beforeDestroy();
31 |
32 | //destroy rect bounds
33 | bounds.destroy();
34 | bounds = null;
35 | }
36 | }
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # Gecko2D
2 |
3 | > A Cross-platform Game Framework
4 |
5 | Gecko2D is a flexible and powerful cross-platform game framework that will allow you to create games easily and deploy it
6 | to browsers, mobile devices, desktop, and even consoles.
7 |
8 | Under the hood, Gecko2D is an [Entity-Component-System](https://en.wikipedia.org/wiki/Entity%E2%80%93component%E2%80%93system) framework built on top of [Haxe](http://haxe.org) and [Kha](http://kha.tech) which allow the best performance and real cross-platform
9 | compilation, using Javascript and WebGL when compile to browsers, and C++ when compile to mobile using metal or opengl, to desktop using opengl, directx or vulkan, and consoles with their own drivers.
10 |
11 | This framework aims to be a solid foundation for all your games, allowing you to port your games to others platforms using the same source code, saving time and money.
12 |
13 | ## Dependencies
14 | - Git
15 | - Node.js >= 9
16 |
17 | ## How to install
18 | ```
19 | npm install gecko2d -g
20 | ```
21 |
22 | ## Documentation
23 | More info: [https://nazariglez.github.io/Gecko2D](https://nazariglez.github.io/Gecko2D)
24 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | The MIT License
3 |
4 | Copyright (c) 2017-2018 Nazarí González
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
--------------------------------------------------------------------------------
/Sources/gecko/World.hx:
--------------------------------------------------------------------------------
1 | package gecko;
2 |
3 | import gecko.utils.Event;
4 |
5 | class World {
6 | public var currentScene(default, null):Scene = Scene.createWithDrawSystem();
7 | private var _nextScene:Scene;
8 | private var _destroyCurrentScene:Bool = false;
9 |
10 | public var onSceneChanged:EventScene->Void>;
11 |
12 | public function new(){
13 | onSceneChanged = Event.create();
14 | }
15 |
16 | public function changeScene(sceneIn:Scene, destroyCurrentScene:Bool = false) {
17 | _destroyCurrentScene = destroyCurrentScene;
18 | _nextScene = sceneIn;
19 | }
20 |
21 | public function update(delta:Float) {
22 | if(_nextScene != null){
23 | var scene = currentScene;
24 |
25 | currentScene = _nextScene;
26 | _nextScene = null;
27 |
28 | onSceneChanged.emit(scene, currentScene);
29 |
30 | if(_destroyCurrentScene){
31 | scene.destroy();
32 | }
33 | }
34 |
35 | currentScene.process(delta);
36 | }
37 |
38 | public function draw(g:Graphics) {
39 | currentScene.processDraw(g);
40 | }
41 | }
--------------------------------------------------------------------------------
/cli/cmd/docs.ts:
--------------------------------------------------------------------------------
1 | import {Command, ActionCallback} from '../cli';
2 | import {ENGINE_NAME, DOCS_PATH} from '../const';
3 | import * as http from 'http';
4 | import * as colors from 'colors';
5 | import * as nodeStatic from 'node-static';
6 |
7 | const PORT = 8081;
8 |
9 | export const cmd:Command = {
10 | name: "docs",
11 | alias: [],
12 | usage: `serve the ${ENGINE_NAME} documentation at ${PORT}`,
13 | action: _action
14 | };
15 |
16 | function _action(args:string[], cb:ActionCallback) {
17 | console.log(colors.yellow(`Serving documentation on '${colors.magenta(PORT.toString())}'`))
18 |
19 | const serv = new nodeStatic.Server(DOCS_PATH + "/.vuepress/dist", {cache: 0});
20 | const htmlServer = http.createServer((req, res)=>{
21 | req.addListener("end", ()=>serv.serve(req, res)).resume();
22 | });
23 |
24 | htmlServer.on("error", (e:any)=>{
25 | if(e.code === "EADDRINUSE") {
26 | cb(new Error(`Error: Port ${PORT} is already in use.`));
27 | return;
28 | } else {
29 | cb(e);
30 | return;
31 | }
32 | });
33 |
34 | htmlServer.listen(PORT);
35 | cb(null, args);
36 | }
--------------------------------------------------------------------------------
/Sources/gecko/components/draw/ProgressBarComponent.hx:
--------------------------------------------------------------------------------
1 | package gecko.components.draw;
2 |
3 | import gecko.components.draw.DrawComponent;
4 | import gecko.Graphics;
5 | import gecko.Color;
6 |
7 | class ProgressBarComponent extends DrawComponent {
8 | public var progress:Int = 0;
9 | public var lineColor:Color;
10 | public var fillColor:Color;
11 | public var outlineWidth:Int = 2;
12 |
13 | public function init(?lineColor:Color, ?fillColor:Color, outlineWidth:Int = 2) {
14 | this.lineColor = lineColor != null ? lineColor : Color.White;
15 | this.fillColor = fillColor != null ? fillColor : Color.OliveDrab;
16 | this.outlineWidth = outlineWidth;
17 | }
18 |
19 | override public function draw(g:Graphics) {
20 | g.color = fillColor;
21 | g.fillRect(0, 0, entity.transform.size.x*(progress/100), entity.transform.size.y);
22 |
23 | g.color = lineColor;
24 | g.drawRect(0, 0, entity.transform.size.x, entity.transform.size.y, outlineWidth);
25 | }
26 |
27 | override public function beforeDestroy() {
28 | super.beforeDestroy();
29 |
30 | progress = 0;
31 | outlineWidth = 2;
32 | }
33 | }
--------------------------------------------------------------------------------
/Sources/gecko/ConfigFile.hx:
--------------------------------------------------------------------------------
1 | package gecko;
2 |
3 | class ConfigFile extends BaseObject {
4 | private var _file:Storage;
5 | private var _config:Map = new Map();
6 |
7 | public function init(configName:String = "default") {
8 | _file = Storage.create(configName + "__config_file.gecko");
9 |
10 | var map = _file.readObject();
11 | if(map == null){
12 | _config = new Map();
13 | }else{
14 | _config = cast map;
15 | }
16 | }
17 |
18 | public function set(key:String, value:Dynamic) {
19 | _config.set(key, value);
20 | _file.writeObject(_config);
21 | }
22 |
23 | public function get(key:String) : Dynamic {
24 | return _config.get(key);
25 | }
26 |
27 | public function remove(key:String) {
28 | _config.remove(key);
29 | _file.writeObject(_config);
30 | }
31 |
32 | public function clear() {
33 | _config = new Map();
34 | _file.writeObject(_config);
35 | }
36 |
37 | override public function beforeDestroy() {
38 | super.beforeDestroy();
39 | _file.destroy();
40 |
41 | _file = null;
42 | _config = null;
43 | }
44 | }
--------------------------------------------------------------------------------
/examples/demo/Sources/scenes/DrawScrollingSpriteScene.hx:
--------------------------------------------------------------------------------
1 | package scenes;
2 |
3 | import gecko.Screen;
4 |
5 | import gecko.components.draw.ScrollingSpriteComponent;
6 |
7 | class DrawScrollingSpriteScene extends CustomScene {
8 | override public function init(closeButton:Bool = false) {
9 | super.init(closeButton);
10 |
11 | //background
12 | var scroll1 = _createScrollingSprite("images/opengameart/mountain.png", Screen.centerX, Screen.centerY, Screen.width, Screen.height);
13 | scroll1.speed.x = 20;
14 |
15 | var scroll2 = _createScrollingSprite("images/opengameart/carbon_fiber.png", 150, Screen.centerY, 200, 500);
16 | scroll2.speed.y = -30;
17 |
18 | var scroll3 = _createScrollingSprite("images/opengameart/carbon_fiber.png", 550, Screen.centerY, 400, 300);
19 | scroll3.speed.set(20, 20);
20 | scroll3.scale.set(0.5, 0.5);
21 | }
22 |
23 | private function _createScrollingSprite(sprite:String, x:Float, y:Float, width:Float, height:Float) : ScrollingSpriteComponent {
24 | var e = createEntity();
25 | e.transform.position.set(x, y);
26 |
27 | return e.addComponent(ScrollingSpriteComponent.create(sprite, width, height));
28 | }
29 | }
--------------------------------------------------------------------------------
/Sources/gecko/utils/FPSCounter.hx:
--------------------------------------------------------------------------------
1 | package gecko.utils;
2 |
3 |
4 | import kha.Scheduler;
5 |
6 | class FPSCounter {
7 | public var delta:Float = 0;
8 | public var fps:Float = 0;
9 | public var ms:Float = 0;
10 | public var timeToMeasure:Float = 1;
11 |
12 | private var _frames:Float = 0;
13 | private var _elapsed:Float = 0;
14 | private var _last:Float = 0;
15 |
16 | public var isFixed(default, null):Bool = false;
17 |
18 | public function new(isFixed:Bool = false){
19 | this.isFixed = isFixed;
20 | _last = isFixed ? Scheduler.time() : Scheduler.realTime();
21 | }
22 |
23 | public function tick() {
24 | var now = isFixed ? Scheduler.time() : Scheduler.realTime();
25 | _frames++;
26 | delta = now - _last;
27 | _elapsed += delta;
28 | _last = now;
29 |
30 | if(_elapsed >= timeToMeasure){
31 | fps = Math.round((_frames/_elapsed)*100)/100;
32 | ms = Math.round((_elapsed/_frames)*1000);
33 | _frames = 0;
34 | _elapsed = 0;
35 | }
36 | }
37 |
38 | public function clear() {
39 | _frames = 0;
40 | _elapsed = 0;
41 | _last = isFixed ? Scheduler.time() : Scheduler.realTime();
42 | }
43 | }
--------------------------------------------------------------------------------
/examples/demo/dev.gecko.toml:
--------------------------------------------------------------------------------
1 | # development gecko config.
2 | name = "Demo"
3 | sources = ["Sources"]
4 | shaders = [] #shaders directory
5 | libraries = [] #libs at Libraries folder or haxelib
6 | output = "build" #build output
7 | debug = true #compile in debug mode
8 |
9 | [html5]
10 | webgl = true
11 | canvas = "kanvas" #canvas id
12 | script = "game" #script name
13 | serve_port = 8080 #port to serve the build with gecko serve
14 | html_file = "" #inject the script in a custom html
15 |
16 | [osx]
17 | graphics = "opengl" #mac graphics [opengl | metal]
18 |
19 | [windows]
20 | graphics = "direct3d11" #windows graphics [direct3d11 | direct3d9 | direct3d12 | opengl]
21 |
22 | [flags] #custom compiler flags
23 | #debug_collisions = true
24 |
25 | [core]
26 | clean_temp = false #clean temporal files after compile
27 | compile = true #if false, the game will not be compiled, and the "resources" to compile will stay at ./kha_build
28 | compiler_parameters = [] #haxe compiler parameters (ex: "-dce full")
29 | ffmpeg = "" #ffmpeg drivers path (could be absolute)
30 | haxe = ""
31 | kha = ""
32 |
--------------------------------------------------------------------------------
/scripts/api.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const spawn = require("cross-spawn");
4 | const fs = require("fs-extra");
5 | const path = require("path");
6 | const replace = require("replace");
7 |
8 | console.log("Generating API docs...");
9 |
10 | let sourceDir = path.resolve(__dirname, "../", "Sources").split("/").join("\/");
11 | var regex = new RegExp(`<${sourceDir}[.\\s\\S]*<\/${sourceDir}>`);
12 |
13 | let build = spawn.sync("gecko", ["build", "html5"], {cwd: path.resolve(__dirname, "../build_templates/docs")});
14 | if(build.error){
15 | console.error(build.stderr);
16 | throw build.error;
17 | }
18 |
19 | let xmlText = fs.readFileSync(path.resolve(__dirname, "../build_templates/docs/build/docs/gecko.xml"), 'utf8');
20 | xmlText = xmlText.replace(regex, "");
21 |
22 | fs.writeFileSync(path.resolve(__dirname, "../build_templates/docs/build/docs/gecko.xml"), xmlText, 'utf8');
23 |
24 | let dox = spawn.sync("haxelib", ["run","dox", "-i", "docs"], {cwd: path.resolve(__dirname, "../build_templates/docs/build")});
25 | if(dox.error){
26 | console.error(dox.stderr);
27 | throw dox.error;
28 | }
29 |
30 | replace({
31 | regex: "http:",
32 | replacement: "https:",
33 | paths: [path.resolve(__dirname, "../build_templates/docs/build/pages")],
34 | recursive: true,
35 | silent: true,
36 | async: false
37 | });
--------------------------------------------------------------------------------
/examples/basic/dev.gecko.toml:
--------------------------------------------------------------------------------
1 | # development gecko config.
2 | name = "Gecko2D-Game"
3 | sources = ["Sources"]
4 | shaders = [] #shaders directory
5 | libraries = [] #libs at Libraries folder or haxelib
6 | output = "build" #build output
7 | debug = false #compile in debug mode
8 |
9 | [html5]
10 | webgl = true
11 | canvas = "kanvas" #canvas id
12 | script = "game" #script name
13 | serve_port = 8080 #port to serve the build with gecko serve
14 | html_file = "" #inject the script in a custom html
15 |
16 | [osx]
17 | graphics = "opengl" #mac graphics [opengl | metal]
18 |
19 | [windows]
20 | graphics = "direct3d11" #windows graphics [direct3d11 | direct3d9 | direct3d12 | opengl]
21 |
22 | [flags] #custom compiler flags
23 | #debug_collisions = true
24 |
25 | [core]
26 | clean_temp = false #clean temporal files after compile
27 | compile = false #if false, the game will not be compiled, and the "resources" to compile will stay at the build directory
28 | compiler_parameters = [] #haxe compiler parameters (ex: "-dce full")
29 | ffmpeg = "" #ffmpeg drivers path (could be absolute)
30 | haxe = ""
31 | kha = ""
32 |
--------------------------------------------------------------------------------
/examples/bunnyrender/dev.gecko.toml:
--------------------------------------------------------------------------------
1 | # development gecko config.
2 | name = "bunnyrender"
3 | sources = ["Sources"]
4 | shaders = [] #shaders directory
5 | libraries = [] #libs at Libraries folder or haxelib
6 | output = "build" #build output
7 | debug = true #compile in debug mode
8 |
9 | [html5]
10 | webgl = true
11 | canvas = "kanvas" #canvas id
12 | script = "game" #script name
13 | serve_port = 8080 #port to serve the build with gecko serve
14 | html_file = "" #inject the script in a custom html
15 |
16 | [osx]
17 | graphics = "opengl" #mac graphics [opengl | metal]
18 |
19 | [windows]
20 | graphics = "direct3d11" #windows graphics [direct3d11 | direct3d9 | direct3d12 | opengl]
21 |
22 | [flags] #custom compiler flags
23 | #debug_collisions = true
24 |
25 | [core]
26 | clean_temp = false #clean temporal files after compile
27 | compile = true #if false, the game will not be compiled, and the "resources" to compile will stay at ./kha_build
28 | compiler_parameters = [] #haxe compiler parameters (ex: "-dce full")
29 | ffmpeg = "" #ffmpeg drivers path (could be absolute)
30 | haxe = ""
31 | kha = ""
32 |
--------------------------------------------------------------------------------
/examples/text/dev.gecko.toml:
--------------------------------------------------------------------------------
1 | # development gecko config.
2 | name = "Gecko2D-Game"
3 | sources = ["Sources"]
4 | shaders = [] #shaders directory
5 | libraries = [] #libs at Libraries folder or haxelib
6 | output = "build" #build output
7 | debug = false #compile in debug mode
8 |
9 | [html5]
10 | webgl = true
11 | canvas = "kanvas" #canvas id
12 | script = "game" #script name
13 | serve_port = 8080 #port to serve the build with gecko serve
14 | html_file = "" #inject the script in a custom html
15 |
16 | [osx]
17 | graphics = "opengl" #mac graphics [opengl | metal]
18 |
19 | [windows]
20 | graphics = "direct3d11" #windows graphics [direct3d11 | direct3d9 | direct3d12 | opengl]
21 |
22 | [flags] #custom compiler flags
23 | #debug_collisions = true
24 |
25 | [core]
26 | clean_temp = false #clean temporal files after compile
27 | compile = false #if false, the game will not be compiled, and the "resources" to compile will stay at the build directory
28 | compiler_parameters = [] #haxe compiler parameters (ex: "-dce full")
29 | ffmpeg = "" #ffmpeg drivers path (could be absolute)
30 | haxe = ""
31 | kha = ""
32 |
--------------------------------------------------------------------------------
/docs/examples/basic.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Basic
3 | ---
4 | # Basic
5 |
6 |
7 |
8 | ```haxe
9 | package;
10 |
11 | import gecko.Screen;
12 | import gecko.components.draw.SpriteComponent;
13 | import gecko.Gecko;
14 | import gecko.Assets;
15 | import gecko.systems.draw.DrawSystem;
16 |
17 | class Game {
18 | public function new(){
19 | //add the draw system to the current scene
20 | Gecko.currentScene.addSystem(DrawSystem.create());
21 |
22 | //load assets
23 | Assets.load([
24 | "shipYellow_manned.png"
25 | ], _onAssetsLoaded).start();
26 | }
27 |
28 | private function _onAssetsLoaded() {
29 | //create a new entity in the current scene
30 | var entity = Gecko.currentScene.createEntity();
31 |
32 | //center the entity in the middle of the screen
33 | entity.transform.position.set(Screen.centerX, Screen.centerY);
34 |
35 | //add a sprite component to the scene
36 | entity.addComponent(SpriteComponent.create("shipYellow_manned.png"));
37 | }
38 | }
39 | ```
40 |
41 |
42 | [Source Code](https://github.com/Nazariglez/Gecko2D/tree/master/examples/basic)
43 |
--------------------------------------------------------------------------------
/examples/animation/dev.gecko.toml:
--------------------------------------------------------------------------------
1 | # development gecko config.
2 | name = "Gecko2D-Game"
3 | sources = ["Sources"]
4 | shaders = [] #shaders directory
5 | libraries = [] #libs at Libraries folder or haxelib
6 | output = "build" #build output
7 | debug = false #compile in debug mode
8 |
9 | [html5]
10 | webgl = true
11 | canvas = "kanvas" #canvas id
12 | script = "game" #script name
13 | serve_port = 8080 #port to serve the build with gecko serve
14 | html_file = "" #inject the script in a custom html
15 |
16 | [osx]
17 | graphics = "opengl" #mac graphics [opengl | metal]
18 |
19 | [windows]
20 | graphics = "direct3d11" #windows graphics [direct3d11 | direct3d9 | direct3d12 | opengl]
21 |
22 | [flags] #custom compiler flags
23 | #debug_collisions = true
24 |
25 | [core]
26 | clean_temp = false #clean temporal files after compile
27 | compile = false #if false, the game will not be compiled, and the "resources" to compile will stay at the build directory
28 | compiler_parameters = [] #haxe compiler parameters (ex: "-dce full")
29 | ffmpeg = "" #ffmpeg drivers path (could be absolute)
30 | haxe = ""
31 | kha = ""
32 |
--------------------------------------------------------------------------------
/examples/bunnyentities/dev.gecko.toml:
--------------------------------------------------------------------------------
1 | # development gecko config.
2 | name = "bunnyentities"
3 | sources = ["Sources"]
4 | shaders = [] #shaders directory
5 | libraries = [] #libs at Libraries folder or haxelib
6 | output = "build" #build output
7 | debug = false #compile in debug mode
8 |
9 | [html5]
10 | webgl = true
11 | canvas = "kanvas" #canvas id
12 | script = "game" #script name
13 | serve_port = 8080 #port to serve the build with gecko serve
14 | html_file = "" #inject the script in a custom html
15 |
16 | [osx]
17 | graphics = "opengl" #mac graphics [opengl | metal]
18 |
19 | [windows]
20 | graphics = "direct3d11" #windows graphics [direct3d11 | direct3d9 | direct3d12 | opengl]
21 |
22 | [flags] #custom compiler flags
23 | #debug_collisions = true
24 |
25 | [core]
26 | clean_temp = false #clean temporal files after compile
27 | compile = true #if false, the game will not be compiled, and the "resources" to compile will stay at ./kha_build
28 | compiler_parameters = [] #haxe compiler parameters (ex: "-dce full")
29 | ffmpeg = "" #ffmpeg drivers path (could be absolute)
30 | haxe = ""
31 | kha = ""
32 |
--------------------------------------------------------------------------------
/examples/flappy/dev.gecko.toml:
--------------------------------------------------------------------------------
1 | # development gecko config.
2 | name = "Gecko2D-Flappy"
3 | sources = ["Sources"]
4 | shaders = [] #shaders directory
5 | libraries = [] #libs at Libraries folder or haxelib
6 | output = "build" #build output
7 | debug = false #compile in debug mode
8 |
9 | [html5]
10 | webgl = true
11 | canvas = "kanvas" #canvas id
12 | script = "game" #script name
13 | serve_port = 8080 #port to serve the build with gecko serve
14 | html_file = "" #inject the script in a custom html
15 |
16 | [osx]
17 | graphics = "opengl" #mac graphics [opengl | metal]
18 |
19 | [windows]
20 | graphics = "direct3d11" #windows graphics [direct3d11 | direct3d9 | direct3d12 | opengl]
21 |
22 | [flags] #custom compiler flags
23 | #debug_collisions = true
24 |
25 | [core]
26 | clean_temp = false #clean temporal files after compile
27 | compile = false #if false, the game will not be compiled, and the "resources" to compile will stay at the build directory
28 | compiler_parameters = [] #haxe compiler parameters (ex: "-dce full")
29 | ffmpeg = "" #ffmpeg drivers path (could be absolute)
30 | haxe = ""
31 | kha = ""
32 |
--------------------------------------------------------------------------------
/examples/nineslice/dev.gecko.toml:
--------------------------------------------------------------------------------
1 | # development gecko config.
2 | name = "Gecko2D-Game"
3 | sources = ["Sources"]
4 | shaders = [] #shaders directory
5 | libraries = [] #libs at Libraries folder or haxelib
6 | output = "build" #build output
7 | debug = false #compile in debug mode
8 |
9 | [html5]
10 | webgl = true
11 | canvas = "kanvas" #canvas id
12 | script = "game" #script name
13 | serve_port = 8080 #port to serve the build with gecko serve
14 | html_file = "" #inject the script in a custom html
15 |
16 | [osx]
17 | graphics = "opengl" #mac graphics [opengl | metal]
18 |
19 | [windows]
20 | graphics = "direct3d11" #windows graphics [direct3d11 | direct3d9 | direct3d12 | opengl]
21 |
22 | [flags] #custom compiler flags
23 | #debug_collisions = true
24 |
25 | [core]
26 | clean_temp = false #clean temporal files after compile
27 | compile = false #if false, the game will not be compiled, and the "resources" to compile will stay at the build directory
28 | compiler_parameters = [] #haxe compiler parameters (ex: "-dce full")
29 | ffmpeg = "" #ffmpeg drivers path (could be absolute)
30 | haxe = ""
31 | kha = ""
32 |
--------------------------------------------------------------------------------
/examples/shapes/dev.gecko.toml:
--------------------------------------------------------------------------------
1 | # development gecko config.
2 | name = "Gecko2D-Game"
3 | sources = ["Sources"]
4 | shaders = [] #shaders directory
5 | libraries = [] #libs at Libraries folder or haxelib
6 | output = "build" #build output
7 | debug = false #compile in debug mode
8 |
9 | [html5]
10 | webgl = true
11 | canvas = "kanvas" #canvas id
12 | script = "game" #script name
13 | serve_port = 8080 #port to serve the build with gecko serve
14 | html_file = "" #inject the script in a custom html
15 |
16 | [osx]
17 | graphics = "opengl" #mac graphics [opengl | metal]
18 |
19 | [windows]
20 | graphics = "direct3d11" #windows graphics [direct3d11 | direct3d9 | direct3d12 | opengl]
21 |
22 | [flags] #custom compiler flags
23 | #debug_collisions = true
24 |
25 | [core]
26 | clean_temp = false #clean temporal files after compile
27 | compile = false #if false, the game will not be compiled, and the "resources" to compile will stay at the build directory
28 | compiler_parameters = [] #haxe compiler parameters (ex: "-dce full")
29 | ffmpeg = "" #ffmpeg drivers path (could be absolute)
30 | haxe = ""
31 | kha = ""
32 |
--------------------------------------------------------------------------------
/examples/sprites/dev.gecko.toml:
--------------------------------------------------------------------------------
1 | # development gecko config.
2 | name = "Gecko2D-Game"
3 | sources = ["Sources"]
4 | shaders = [] #shaders directory
5 | libraries = [] #libs at Libraries folder or haxelib
6 | output = "build" #build output
7 | debug = false #compile in debug mode
8 |
9 | [html5]
10 | webgl = true
11 | canvas = "kanvas" #canvas id
12 | script = "game" #script name
13 | serve_port = 8080 #port to serve the build with gecko serve
14 | html_file = "" #inject the script in a custom html
15 |
16 | [osx]
17 | graphics = "opengl" #mac graphics [opengl | metal]
18 |
19 | [windows]
20 | graphics = "direct3d11" #windows graphics [direct3d11 | direct3d9 | direct3d12 | opengl]
21 |
22 | [flags] #custom compiler flags
23 | #debug_collisions = true
24 |
25 | [core]
26 | clean_temp = false #clean temporal files after compile
27 | compile = false #if false, the game will not be compiled, and the "resources" to compile will stay at the build directory
28 | compiler_parameters = [] #haxe compiler parameters (ex: "-dce full")
29 | ffmpeg = "" #ffmpeg drivers path (could be absolute)
30 | haxe = ""
31 | kha = ""
32 |
--------------------------------------------------------------------------------
/examples/khashmup/dev.gecko.toml:
--------------------------------------------------------------------------------
1 | # development gecko config.
2 | name = "Gecko2D-KhaShmup"
3 | sources = ["Sources"]
4 | shaders = [] #shaders directory
5 | libraries = [] #libs at Libraries folder or haxelib
6 | output = "build" #build output
7 | debug = false #compile in debug mode
8 |
9 | [html5]
10 | webgl = true
11 | canvas = "kanvas" #canvas id
12 | script = "game" #script name
13 | serve_port = 8080 #port to serve the build with gecko serve
14 | html_file = "" #inject the script in a custom html
15 |
16 | [osx]
17 | graphics = "opengl" #mac graphics [opengl | metal]
18 |
19 | [windows]
20 | graphics = "direct3d11" #windows graphics [direct3d11 | direct3d9 | direct3d12 | opengl]
21 |
22 | [flags] #custom compiler flags
23 | #debug_collisions = true
24 |
25 | [core]
26 | clean_temp = false #clean temporal files after compile
27 | compile = true #if false, the game will not be compiled, and the "resources" to compile will stay at the build directory
28 | compiler_parameters = [] #haxe compiler parameters (ex: "-dce full")
29 | ffmpeg = "" #ffmpeg drivers path (could be absolute)
30 | haxe = ""
31 | kha = ""
32 |
--------------------------------------------------------------------------------
/examples/parenttransform/dev.gecko.toml:
--------------------------------------------------------------------------------
1 | # development gecko config.
2 | name = "Gecko2D-Game"
3 | sources = ["Sources"]
4 | shaders = [] #shaders directory
5 | libraries = [] #libs at Libraries folder or haxelib
6 | output = "build" #build output
7 | debug = false #compile in debug mode
8 |
9 | [html5]
10 | webgl = true
11 | canvas = "kanvas" #canvas id
12 | script = "game" #script name
13 | serve_port = 8080 #port to serve the build with gecko serve
14 | html_file = "" #inject the script in a custom html
15 |
16 | [osx]
17 | graphics = "opengl" #mac graphics [opengl | metal]
18 |
19 | [windows]
20 | graphics = "direct3d11" #windows graphics [direct3d11 | direct3d9 | direct3d12 | opengl]
21 |
22 | [flags] #custom compiler flags
23 | #debug_collisions = true
24 |
25 | [core]
26 | clean_temp = false #clean temporal files after compile
27 | compile = false #if false, the game will not be compiled, and the "resources" to compile will stay at the build directory
28 | compiler_parameters = [] #haxe compiler parameters (ex: "-dce full")
29 | ffmpeg = "" #ffmpeg drivers path (could be absolute)
30 | haxe = ""
31 | kha = ""
32 |
--------------------------------------------------------------------------------
/examples/scrollingsprite/dev.gecko.toml:
--------------------------------------------------------------------------------
1 | # development gecko config.
2 | name = "Gecko2D-Game"
3 | sources = ["Sources"]
4 | shaders = [] #shaders directory
5 | libraries = [] #libs at Libraries folder or haxelib
6 | output = "build" #build output
7 | debug = false #compile in debug mode
8 |
9 | [html5]
10 | webgl = true
11 | canvas = "kanvas" #canvas id
12 | script = "game" #script name
13 | serve_port = 8080 #port to serve the build with gecko serve
14 | html_file = "" #inject the script in a custom html
15 |
16 | [osx]
17 | graphics = "opengl" #mac graphics [opengl | metal]
18 |
19 | [windows]
20 | graphics = "direct3d11" #windows graphics [direct3d11 | direct3d9 | direct3d12 | opengl]
21 |
22 | [flags] #custom compiler flags
23 | #debug_collisions = true
24 |
25 | [core]
26 | clean_temp = false #clean temporal files after compile
27 | compile = false #if false, the game will not be compiled, and the "resources" to compile will stay at the build directory
28 | compiler_parameters = [] #haxe compiler parameters (ex: "-dce full")
29 | ffmpeg = "" #ffmpeg drivers path (could be absolute)
30 | haxe = ""
31 | kha = ""
32 |
--------------------------------------------------------------------------------
/docs/.vuepress/config.js:
--------------------------------------------------------------------------------
1 | let baseDir = (process.env.baseDir === false || process.env.baseDir === 'false') ? null : '/Gecko2D/';
2 |
3 | module.exports = {
4 | title: "Gecko2D",
5 | description: "A flexible and powerful Cross-Platform 2D Game Framework",
6 | base: baseDir,
7 |
8 | themeConfig: {
9 | repo: "Nazariglez/Gecko2D",
10 | docsDir: 'docs',
11 | nav: [
12 | { text: 'Home', link: '/' },
13 | {
14 | text: 'Getting Started',
15 | link: '/getting-started/',
16 | },
17 | {
18 | text: 'Guide',
19 | link: '/guide/'
20 | },
21 | {
22 | text: 'Examples',
23 | link: '/examples/',
24 | },
25 | {
26 | text: 'API',
27 | link: '/api'
28 | }
29 | ],
30 | sidebar: {
31 | "/examples/": require("./examples.json"),
32 | "/guide/": [
33 | {
34 | title: "Guide",
35 | collapsable: false,
36 | children: [
37 | '',
38 | 'ecs',
39 | 'screen'
40 | ]
41 | }
42 | ]
43 | }
44 | }
45 | };
--------------------------------------------------------------------------------
/cli/const.ts:
--------------------------------------------------------------------------------
1 | import * as path from "path";
2 |
3 | export const ENGINE_NAME = "gecko";
4 | export const FLAG_PREFIX = "flag_";
5 | export const CURRENT_PATH = process.cwd();
6 | export const TEMP_RELATIVE_PATH = "./build";
7 | export const KHAFILE_RELATIVE_PATH = "./khafile.js";
8 | export const KHAFILE_PATH = path.resolve(CURRENT_PATH, KHAFILE_RELATIVE_PATH);
9 | export const TEMP_PATH = path.join(CURRENT_PATH, TEMP_RELATIVE_PATH);
10 | export const TEMP_BUILD_PATH = path.join(TEMP_PATH, "build");
11 | export const ENGINE_PATH = path.resolve(__dirname, "../../");
12 | export const ENGINE_SOURCE_PATH = path.join(ENGINE_PATH, "Sources");
13 | export const COMMANDS_PATH = path.resolve(ENGINE_PATH, "cli/cmd");
14 | export const KHA_PATH = path.join(ENGINE_PATH, "Kha");
15 | export const KHA_MAKE_PATH = path.join(KHA_PATH, (process.platform === 'win32') ? "make.bat" : "make.sh");
16 | export const HAXE_PATH = path.join(KHA_PATH, "Tools", "haxe");
17 | export const TEMPLATES_PATH = path.join(ENGINE_PATH, "templates");
18 | export const EXAMPLES_PATH = path.join(ENGINE_PATH, "examples");
19 | export const GAME_TEMPLATE_PATH = path.join(TEMPLATES_PATH, "game");
20 | export const BUILD_TEMPLATES_PATH = path.join(ENGINE_PATH, "build_templates");
21 | export const HTML5_TEMPLATE_PATH = path.join(BUILD_TEMPLATES_PATH, "html5");
22 | export const DOCS_PATH = path.resolve(ENGINE_PATH, "docs");
23 |
24 | export const HTML5_SERVE_PORT = 8080;
--------------------------------------------------------------------------------
/Sources/gecko/components/input/DraggableComponent.hx:
--------------------------------------------------------------------------------
1 | package gecko.components.input;
2 |
3 | import gecko.math.Rect;
4 | import gecko.utils.Event;
5 | import gecko.components.Component;
6 | import gecko.input.MouseButton;
7 |
8 | class DraggableComponent extends Component {
9 | public var onDragStart:EventVoid>;
10 | public var onDragStop:EventVoid>;
11 |
12 | public var dragButton:MouseButton = MouseButton.LEFT;
13 |
14 | public var isDragged:Bool = false;
15 | public var bounds:Rect;
16 |
17 | public function new(){
18 | super();
19 | onDragStart = Event.create();
20 | onDragStop = Event.create();
21 | }
22 |
23 | public function init(button:MouseButton = MouseButton.LEFT) {
24 | dragButton = button;
25 | }
26 |
27 | public function setBounds(x:Float, y:Float, width:Float, height:Float) {
28 | if(bounds == null){
29 | bounds = Rect.create(x, y, width, height);
30 | }else{
31 | bounds.set(x, y, width, height);
32 | }
33 | }
34 |
35 | override public function beforeDestroy(){
36 | onDragStart.clear();
37 | onDragStop.clear();
38 |
39 | dragButton = MouseButton.LEFT;
40 | isDragged = false;
41 |
42 | if(bounds != null){
43 | bounds.destroy();
44 | bounds = null;
45 | }
46 |
47 | super.beforeDestroy();
48 | }
49 | }
--------------------------------------------------------------------------------
/examples/khashmup/Sources/scenes/MainScene.hx:
--------------------------------------------------------------------------------
1 | package scenes;
2 |
3 | import gecko.Gecko;
4 | import gecko.input.Keyboard;
5 | import gecko.input.KeyCode;
6 | import gecko.Screen;
7 | import gecko.components.draw.TextComponent;
8 | import gecko.Entity;
9 |
10 | import gecko.systems.draw.DrawSystem;
11 | import gecko.Scene;
12 |
13 | class MainScene extends Scene {
14 | public function init() {
15 | addSystem(DrawSystem.create());
16 |
17 | _createText("KHA SHMUP", Screen.centerX, 100, 80);
18 | _createText("Arrow keys to move, 'Z' key to shoot.\nPress 'Z' to start.", Screen.centerX, Screen.height-120, 30, "center");
19 |
20 | //bind keyboard
21 | Keyboard.onPressed += _onPressed;
22 | }
23 |
24 | private function _onPressed(key:KeyCode){
25 | //on pressed Z start the game
26 | if(key == KeyCode.Z) {
27 | //unbind the event attached to the keyboard to start the game
28 | Keyboard.onPressed -= _onPressed;
29 |
30 | //goto the gamescene and destroy this scene
31 | Gecko.world.changeScene(GameScene.create(), true);
32 | }
33 | }
34 |
35 | public function _createText(text:String, x:Float, y:Float, size:Int, align:String = "left"){
36 | var e:Entity = createEntity();
37 | e.transform.position.set(x, y);
38 | e.addComponent(TextComponent.create(text, "kenpixel_mini_square.ttf", size, align));
39 | }
40 | }
--------------------------------------------------------------------------------
/examples/demo/Sources/scenes/DrawSpriteScene.hx:
--------------------------------------------------------------------------------
1 | package scenes;
2 |
3 | import gecko.components.draw.SpriteComponent;
4 |
5 |
6 | class DrawSpriteScene extends CustomScene {
7 | override public function init(closeButton:Bool = false) {
8 | super.init(closeButton);
9 |
10 | //sprites to draw
11 | var spriteNames = [
12 | "images/kenney/elephant.png",
13 | "images/kenney/hippo.png",
14 | "images/kenney/monkey.png",
15 | "images/kenney/giraffe.png",
16 | "images/kenney/panda.png",
17 | "images/kenney/parrot.png",
18 | "images/kenney/snake.png",
19 | "images/kenney/penguin.png",
20 | "images/kenney/pig.png"
21 | ];
22 |
23 |
24 | //Draw sprites in a grid
25 | var minX = 155;
26 | var minY = 110;
27 |
28 | var gapX = 250;
29 | var gapY = 180;
30 |
31 | var i = 0;
32 | for(x in 0...3){
33 | for(y in 0...3){
34 | _addSprite(spriteNames[i], minX + gapX*x, minY + gapY*y);
35 |
36 | i++;
37 | }
38 | }
39 | }
40 |
41 | //Create an add the sprite
42 | private function _addSprite(sprite:String, x:Float, y:Float) {
43 | var e = createEntity();
44 | e.addComponent(SpriteComponent.create(sprite));
45 |
46 | e.transform.position.set(x, y);
47 | e.transform.scale.set(0.4, 0.4); //scale because they're too big
48 | }
49 | }
--------------------------------------------------------------------------------
/Sources/gecko/input/HotKey.hx:
--------------------------------------------------------------------------------
1 | package gecko.input;
2 |
3 |
4 |
5 | class HotKey extends BaseObject {
6 | public var key:KeyCode = KeyCode.Unknown;
7 |
8 | public var wasPressed(get, null):Bool;
9 | public var wasReleased(get, null):Bool;
10 | public var isDown(get, null):Bool;
11 | public var downDuration(get, null):Float;
12 |
13 | public var isControlDown(get, null):Bool;
14 | public var isAltDown(get, null):Bool;
15 | public var isShiftDown(get, null):Bool;
16 |
17 | public function init(key:KeyCode) {
18 | this.key = key;
19 | }
20 |
21 | override public function beforeDestroy() {
22 | super.beforeDestroy();
23 | key = KeyCode.Unknown;
24 | }
25 |
26 | inline function get_downDuration() : Float {
27 | return Keyboard.downDuration(key);
28 | }
29 |
30 | inline function get_wasPressed() : Bool {
31 | return Keyboard.wasPressed(key);
32 | }
33 |
34 | inline function get_wasReleased() : Bool {
35 | return Keyboard.wasReleased(key);
36 | }
37 |
38 | inline function get_isDown() : Bool {
39 | return Keyboard.isDown(key);
40 | }
41 |
42 | inline function get_isControlDown() : Bool {
43 | return Keyboard.isDown(KeyCode.Control);
44 | }
45 |
46 | inline function get_isShiftDown() : Bool {
47 | return Keyboard.isDown(KeyCode.Shift);
48 | }
49 |
50 | inline function get_isAltDown() : Bool {
51 | return Keyboard.isDown(KeyCode.Alt);
52 | }
53 | }
--------------------------------------------------------------------------------
/Sources/gecko/utils/Event.hx:
--------------------------------------------------------------------------------
1 | package gecko.utils;
2 |
3 | import haxe.macro.Expr;
4 |
5 | private typedef Evt = {
6 | //var once:Map; //todo once?
7 | var handlers:Array;
8 | };
9 |
10 | abstract Event(Evt) from Evt to Event {
11 | public var handlers(get, never):Array;
12 | inline function get_handlers() : Array {
13 | return this.handlers;
14 | }
15 |
16 | static inline public function create(){
17 | return new Event({handlers:new Array()});
18 | }
19 |
20 | private inline function new(me:Evt) {
21 | this = me;
22 | }
23 |
24 | public macro function emit(e1:Expr, extra:Array) {
25 | var e = macro handler($a{extra});
26 | return macro {
27 | var handlers = $e1.handlers;
28 | if(handlers.length != 0){
29 | for(handler in handlers){
30 | $e;
31 | }
32 | }
33 | };
34 | }
35 |
36 | //todo add a reflection emit to use at runtime
37 |
38 | public function clear() {
39 | if(this.handlers.length == 0)return;
40 | this.handlers = []; //todo, remove all events instead create a new array?
41 | }
42 |
43 | /*public function once(handler:T) {
44 | //todo
45 | }*/
46 |
47 | @:op(A += B) inline function on(b:T) {
48 | this.handlers.push(b);
49 | }
50 |
51 | @:op(A -= B) inline function off(b:T) {
52 | this.handlers.remove(b);
53 | }
54 | }
--------------------------------------------------------------------------------
/Sources/gecko/components/draw/SpriteComponent.hx:
--------------------------------------------------------------------------------
1 | package gecko.components.draw;
2 |
3 | import gecko.Graphics;
4 | import gecko.resources.Texture;
5 | import gecko.Assets;
6 |
7 | class SpriteComponent extends DrawComponent {
8 | static public function createFromTexture(texture:Texture) : SpriteComponent {
9 | var sprite = SpriteComponent.create("");
10 | sprite.texture = texture;
11 | return sprite;
12 | }
13 |
14 | public var texture(get, set):Texture;
15 | private var _texture:Texture;
16 |
17 | public function init(texture:String) {
18 | this.texture = Assets.textures.get(texture);
19 |
20 | onAddedToEntity += _setTransformSize;
21 | }
22 |
23 | override public function draw(g:Graphics){
24 | if(_texture == null)return;
25 | g.drawTexture(_texture, 0, 0);
26 | }
27 |
28 | override public function beforeDestroy(){
29 | super.beforeDestroy();
30 |
31 | texture = null;
32 | onAddedToEntity -= _setTransformSize;
33 | }
34 |
35 | private function _setTransformSize(e:Entity) {
36 | if(e.transform != null){
37 | e.transform.size.set(_texture.width, _texture.height);
38 | }
39 | }
40 |
41 | inline function get_texture():Texture {
42 | return _texture;
43 | }
44 |
45 | function set_texture(value:Texture):Texture {
46 | if(value == _texture)return _texture;
47 | _texture = value;
48 |
49 | if(_texture != null && entity != null && entity.transform != null){
50 | entity.transform.size.set(_texture.width, _texture.height);
51 | }
52 |
53 | return _texture;
54 | }
55 | }
--------------------------------------------------------------------------------
/examples/bunnyentities/Sources/BounceSystem.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Transform;
4 |
5 | import gecko.systems.System;
6 | import gecko.IUpdatable;
7 | import gecko.Screen;
8 |
9 | class BounceSystem extends System implements IUpdatable {
10 | public var gravity:Float;
11 |
12 | public function init(gravity:Float){
13 | filter.equal(BounceComponent);
14 |
15 | this.gravity = gravity;
16 | }
17 |
18 | override public function update(dt:Float) {
19 | for(e in getEntities()){
20 | var transform:Transform = e.transform;
21 | var movement:BounceComponent = e.getComponent(BounceComponent);
22 |
23 | transform.position.set(
24 | transform.position.x + movement.speed.x,
25 | transform.position.y + movement.speed.y
26 | );
27 |
28 | movement.speed.y += gravity;
29 |
30 | if(transform.position.x > Screen.width){
31 | movement.speed.x *= -1;
32 | transform.position.x = Screen.width;
33 | }else if(transform.position.x < 0){
34 | movement.speed.x *= -1;
35 | transform.position.x = 0;
36 | }
37 |
38 | if(transform.position.y > Screen.height){
39 | movement.speed.y *= -0.85;
40 | transform.position.y = Screen.height;
41 |
42 | if(Math.random() > 0.5){
43 | movement.speed.y -= Math.random() * 6;
44 | }
45 |
46 | }else if(transform.position.y < 0){
47 | movement.speed.y = 0;
48 | transform.position.y = 0;
49 | }
50 | }
51 | }
52 | }
--------------------------------------------------------------------------------
/Sources/gecko/macros/GeckoBuilder.hx:
--------------------------------------------------------------------------------
1 | package gecko.macros;
2 |
3 | #if macro
4 | import haxe.macro.Context;
5 | import haxe.macro.Expr;
6 | #end
7 |
8 | class GeckoBuilder {
9 | #if macro
10 | public static macro function build() : Array {
11 | var fields = Context.getBuildFields();
12 | var defines = Context.getDefines();
13 |
14 | var title = "Gecko2D-Game";
15 | if(defines.exists("game_name")){
16 | title = defines["game_name"];
17 | }
18 |
19 | _addField(fields, "gameTitle", title);
20 | _createFlags(defines, fields);
21 |
22 | return fields;
23 | }
24 |
25 | private static function _addField(fields:Array, key:String, val:String) {
26 | fields.push({
27 | name: key,
28 | access: [ APublic, AStatic ],
29 | kind: FVar(macro : String, macro $v{val}),
30 | pos: Context.currentPos()
31 | });
32 | }
33 |
34 | private static function _createFlags(defines:Map, fields:Array) {
35 | var toAdd:Bool = false;
36 |
37 | var flags:Array = [macro $v{""} => $v{""}];
38 |
39 | for (k in defines.keys()) {
40 | var key = $v{k};
41 | if(key.indexOf("flag_") == 0){
42 | toAdd = true;
43 | flags.push(macro $v{key.substr(5)} => $v{Std.string(defines.get(key))});
44 | }
45 | }
46 |
47 | fields.push({
48 | name: "Flags",
49 | meta: null,
50 | kind: FieldType.FVar(macro : Map, macro $a{flags}),
51 | access: [APublic, AStatic],
52 | pos: Context.currentPos(),
53 | });
54 | }
55 | #end
56 | }
--------------------------------------------------------------------------------
/Sources/gecko/utils/MathHelper.hx:
--------------------------------------------------------------------------------
1 | package gecko.utils;
2 |
3 | import gecko.math.Matrix;
4 | class MathHelper {
5 | static private var _deg2rad:Float = Math.PI/180;
6 | static private var _rad2deg:Float = 180/Math.PI;
7 |
8 | inline public static function toDegrees(radians:Float) : Float {
9 | return radians * MathHelper._rad2deg;
10 | }
11 |
12 | inline public static function toRadians(degrees:Float) : Float {
13 | return degrees * MathHelper._deg2rad;
14 | }
15 |
16 | inline public static function clamp(value:Float, min:Float, max:Float) : Float {
17 | return value < min ? min : value > max ? max : value;
18 | }
19 |
20 | inline public static function clampInt(value:Int, min:Int, max:Int) : Int {
21 | return value < min ? min : value > max ? max : value;
22 | }
23 |
24 | inline public static function lerp(value:Float, start:Float, end:Float) : Float {
25 | return (1 - value) * start + value * end;
26 | }
27 |
28 | inline public static function inverseLerp(value:Float, start:Float, end:Float) : Float {
29 | return (value-start)/(end-start);
30 | }
31 |
32 | inline public static function inheritTransform(matrix:Matrix, child:Matrix, parent:Matrix) {
33 | matrix._00 = (child._00 * parent._00) + (child._01 * parent._10);
34 | matrix._01 = (child._00 * parent._01) + (child._01 * parent._11);
35 | matrix._10 = (child._10 * parent._00) + (child._11 * parent._10);
36 | matrix._11 = (child._10 * parent._01) + (child._11 * parent._11);
37 |
38 | matrix._20 = (child._20 * parent._00) + (child._21 * parent._10) + parent._20;
39 | matrix._21 = (child._20 * parent._01) + (child._21 * parent._11) + parent._21;
40 |
41 | }
42 | }
--------------------------------------------------------------------------------
/examples/sprites/Sources/Game.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Gecko;
4 |
5 | import gecko.components.draw.SpriteComponent;
6 | import gecko.systems.draw.DrawSystem;
7 |
8 | class Game {
9 | private var _spritesToLoad:Array = [
10 | "kenney/elephant.png",
11 | "kenney/hippo.png",
12 | "kenney/monkey.png",
13 | "kenney/giraffe.png",
14 | "kenney/panda.png",
15 | "kenney/parrot.png",
16 | "kenney/snake.png",
17 | "kenney/penguin.png",
18 | "kenney/pig.png"
19 | ];
20 |
21 | public function new(){
22 | //add draw system
23 | Gecko.currentScene.addSystem(DrawSystem.create());
24 |
25 | //load the sprites
26 | gecko.Assets.load(_spritesToLoad, _onLoadAssets).start();
27 | }
28 |
29 | //Create an add the sprite
30 | private function _createSprite(spriteName:String, x:Float, y:Float) {
31 | //create an entity in the current scene
32 | var entity = Gecko.currentScene.createEntity();
33 |
34 | //add a spriteComponent using the sprite name
35 | entity.addComponent(SpriteComponent.create(spriteName));
36 |
37 | //set the position and the scale
38 | entity.transform.position.set(x, y);
39 | entity.transform.scale.set(0.4, 0.4);
40 | }
41 |
42 | private function _onLoadAssets(){
43 | //Draw 9 sprites in a grid
44 | var minX = 155;
45 | var minY = 110;
46 |
47 | var gapX = 250;
48 | var gapY = 180;
49 |
50 | var i = 0;
51 | for(x in 0...3){
52 | for(y in 0...3){
53 | _createSprite(_spritesToLoad[i], minX + gapX*x, minY + gapY*y);
54 |
55 | i++;
56 | }
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/examples/demo/Sources/scenes/DrawNineSliceScene.hx:
--------------------------------------------------------------------------------
1 | package scenes;
2 |
3 | import gecko.Color;
4 | import gecko.components.draw.NineSliceComponent;
5 |
6 | import gecko.math.Random;
7 |
8 | class DrawNineSliceScene extends CustomScene {
9 | var _colors = [Color.Red, Color.Green, Color.Blue, Color.White, Color.Yellow, Color.Orange, Color.Brown, Color.Magenta];
10 | var _sprites = ["images/kenney/grey_button08.png", "images/kenney/green_panel.png"];
11 |
12 | override public function init(closeButton:Bool = false){
13 | super.init(closeButton);
14 |
15 | _createNineSlice(50, 50, 200, 100);
16 | _createNineSlice(50, 170, 100, 400);
17 | _createNineSlice(170, 170, 400, 400);
18 | _createNineSlice(270, 50, 60, 100);
19 | _createNineSlice(350, 50, 40, 40);
20 | _createNineSlice(350, 110, 40, 40);
21 | _createNineSlice(410, 50, 120, 100);
22 | _createNineSlice(550, 50, 200, 40);
23 | _createNineSlice(550, 110, 200, 40);
24 | _createNineSlice(590, 170, 160, 80);
25 | _createNineSlice(590, 270, 60, 300);
26 | _createNineSlice(670, 270, 80, 300);
27 | }
28 |
29 | private function _createNineSlice(x:Float, y:Float, width:Float, height:Float) {
30 | var e = createEntity();
31 | e.transform.position.set(x, y);
32 | e.addComponent(NineSliceComponent.create(_getRandomSprite(), width, height));
33 |
34 | //e.renderer.color = _getRandomColor();
35 | e.transform.anchor.set(0,0);
36 | }
37 |
38 | private function _getRandomSprite() : String {
39 | return _sprites[Random.getUpTo(_sprites.length-1)];
40 | }
41 |
42 | private function _getRandomColor() : Color {
43 | return _colors[Random.getUpTo(_colors.length-1)];
44 | }
45 | }
--------------------------------------------------------------------------------
/templates/basic/Sources/Game.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Scene;
4 | import gecko.Gecko;
5 | import gecko.Screen;
6 | import gecko.Entity;
7 | import gecko.Assets;
8 | import gecko.components.draw.ProgressBarComponent;
9 |
10 | class Game {
11 | private var _assetsToLoad:Array = [
12 | //your assets here
13 | "Ubuntu-B.ttf"
14 | ];
15 |
16 | public function new(){
17 | if(_assetsToLoad.length != 0){
18 | _loadAssets();
19 | }else{
20 | _gotoMainScene();
21 | }
22 | }
23 |
24 | public function _gotoMainScene() {
25 | Gecko.world.changeScene(scenes.MainScene.create(), true);
26 | }
27 |
28 | //Add a loaderbar an go to mainScene when the load finish
29 | public function _loadAssets() {
30 | var currentScene = Gecko.currentScene;
31 |
32 | var entity = currentScene.createEntity();
33 | entity.transform.position.set(Screen.centerX, Screen.centerY);
34 | entity.transform.size.set(500, 40);
35 |
36 | var progressBar = entity.addComponent(ProgressBarComponent.create());
37 |
38 | var loader = Assets.load(_assetsToLoad);
39 | loader.onProgressEnd += function(progress:Int, assetName:String){
40 | progressBar.progress = progress; //update the loaderBar
41 | };
42 |
43 | loader.onComplete += function(){
44 | //added a little delay before go to the mainScene
45 | var timer = currentScene.timerManager.createTimer(0.5);
46 | timer.destroyOnEnd = true;
47 |
48 | timer.onEnd += function(){
49 | _gotoMainScene();
50 | };
51 |
52 | timer.start();
53 | };
54 |
55 | //start load
56 | loader.start();
57 | }
58 | }
--------------------------------------------------------------------------------
/Sources/gecko/utils/Chain.hx:
--------------------------------------------------------------------------------
1 | package gecko.utils;
2 |
3 | class Chain {
4 | @:generic static public function each(arr:Array, cb:T->(?String->Void)->Void, done:?String -> Void){
5 | var count = 0;
6 | var canceled = false;
7 |
8 | for(i in 0...arr.length){
9 | if(canceled){
10 | break;
11 | }
12 |
13 | cb(arr[i], function(?err:String){
14 | if(canceled){ return; }
15 |
16 | if(err != null && err != ""){
17 | canceled = true;
18 | done(err);
19 | return;
20 | }
21 |
22 | count++;
23 |
24 | if(count == arr.length){
25 | done();
26 | }
27 | });
28 | }
29 | }
30 |
31 | @:generic static public function eachSeries(arr:Array, cb:T->(?String->Void)->Void, done:?String -> Void){
32 | var callback = function(){
33 | done();
34 | };
35 |
36 | var copyArr = arr.copy();
37 | copyArr.reverse();
38 | for(i in 0...copyArr.length){
39 | callback = function(element, _callback){
40 | return function(){
41 | cb(element, function(?err:String){
42 | if(err != null){
43 | done(err);
44 | return;
45 | }
46 |
47 | _callback();
48 | });
49 | }
50 | }(copyArr[i], callback);
51 | }
52 |
53 | callback();
54 | }
55 |
56 | @:generic static public function eachLimit(limit:Int, arr:Array, cb:T->(?String->Void)->Void, done:?String -> Void){
57 | //todo
58 | }
59 | }
--------------------------------------------------------------------------------
/Sources/gecko/Time.hx:
--------------------------------------------------------------------------------
1 | package gecko;
2 |
3 | import kha.Scheduler;
4 |
5 | class Time {
6 | static private var _initTime:Float = Scheduler.realTime();
7 |
8 | static public var scale:Float = 1;
9 |
10 | static public var fixedDelta(get, null):Float;
11 | static public var fixedTime(default, null):Float = 0;
12 |
13 | static public var fixedUnscaledDelta(default, null):Float = 0;
14 | static public var fixedUnscaledTime(default, null):Float = 0;
15 |
16 | static public var delta(get, null):Float;
17 | static public var time(default, null):Float = 0;
18 |
19 | static public var unscaledDelta(default, null):Float = 0;
20 | static public var unscaledTime(default, null):Float = 0;
21 |
22 | static public var realTime(get, null):Float;
23 |
24 | static private var _lastFixedNow:Float = 0;
25 | static private var _lastNow:Float = 0;
26 |
27 | static private function _tick() {
28 | var fixedNow = Scheduler.time();
29 | var now = Scheduler.realTime();
30 |
31 | fixedUnscaledDelta = fixedNow - _lastFixedNow;
32 | unscaledDelta = now - _lastNow;
33 |
34 | fixedUnscaledTime += fixedUnscaledDelta;
35 | unscaledTime += unscaledDelta;
36 |
37 | fixedTime += fixedUnscaledDelta * scale;
38 | time += unscaledDelta * scale;
39 |
40 | _lastNow = now;
41 | _lastFixedNow = fixedNow;
42 | }
43 |
44 | static private function _clear() {
45 | _lastNow = Scheduler.realTime();
46 | _lastFixedNow = Scheduler.time();
47 | }
48 |
49 | inline static function get_fixedDelta():Float {
50 | return fixedUnscaledDelta * scale;
51 | }
52 |
53 | inline static function get_delta():Float {
54 | return unscaledDelta * scale;
55 | }
56 |
57 | inline static function get_realTime():Float {
58 | return Scheduler.realTime() - _initTime;
59 | }
60 | }
--------------------------------------------------------------------------------
/examples/parenttransform/Sources/Game.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 |
4 | import gecko.components.draw.DrawComponent;
5 | import gecko.components.draw.SpriteComponent;
6 | import gecko.Screen;
7 | import gecko.Gecko;
8 | import gecko.systems.draw.DrawSystem;
9 | import gecko.Assets;
10 |
11 | class Game {
12 | public function new(){
13 | Gecko.currentScene.addSystem(DrawSystem.create());
14 |
15 | Assets.load([
16 | "car_green_small_1.png"
17 | ], _onAssetsLoaded).start();
18 | }
19 |
20 | private function _onAssetsLoaded() {
21 | //create a new container in the middle of the screen with a 200x350 of size
22 | var container = Gecko.currentScene.createEntity();
23 | container.transform.size.set(200, 350);
24 | container.transform.position.set(Screen.centerX, Screen.centerY);
25 |
26 | //add a empty draw-component to the container
27 | container.addComponent(DrawComponent.create());
28 |
29 |
30 | //create an 5x5 grid of cars
31 | for(x in 0...5){
32 | for(y in 0...5){
33 | var car = Gecko.currentScene.createEntity();
34 | car.transform.parent = container.transform; //set the container transform as the parent transform
35 |
36 | //localPosition is the position inside the parent
37 | car.transform.localPosition.set(x * 40, y * 70);
38 |
39 | //anchor to left-top
40 | car.transform.anchor.set(0,0);
41 |
42 | //sprite component
43 | car.addComponent(SpriteComponent.create("car_green_small_1.png"));
44 | }
45 | }
46 |
47 | //attach to the onUpdate event of gecko a simple function
48 | Gecko.onUpdate += function(delta:Float) {
49 | //rotate the container using delta time
50 | container.transform.rotation += 1 * delta;
51 | };
52 | }
53 | }
--------------------------------------------------------------------------------
/examples/scrollingsprite/Sources/Game.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Gecko;
4 | import gecko.Screen;
5 |
6 | import gecko.Assets;
7 | import gecko.systems.draw.DrawSystem;
8 | import gecko.components.draw.ScrollingSpriteComponent;
9 |
10 | class Game {
11 | public function new(){
12 | //add the draw system
13 | Gecko.currentScene.addSystem(DrawSystem.create());
14 |
15 | //Load the sprites
16 | Assets.load([
17 | "images/opengameart/mountain.png",
18 | "images/opengameart/carbon_fiber.png"
19 | ], _onLoadAssets).start();
20 | }
21 |
22 | //create an entity with a scrolling-component using spritename, position and size
23 | private function _createScrollingSprite(sprite:String, x:Float, y:Float, width:Float, height:Float) : ScrollingSpriteComponent {
24 | //create a new entity in the currentScene
25 | var entity = Gecko.currentScene.createEntity();
26 |
27 | //set his position in the screen
28 | entity.transform.position.set(x, y);
29 |
30 | //add the ScrollingComponent using the width and height passed and return the component
31 | return entity.addComponent(ScrollingSpriteComponent.create(sprite, width, height));
32 | }
33 |
34 | private function _onLoadAssets() {
35 | //create a scrollingSprite using the spriteName, position, and size
36 | var scroll1 = _createScrollingSprite("images/opengameart/mountain.png", Screen.centerX, Screen.centerY, Screen.width, Screen.height);
37 | scroll1.speed.x = 20;
38 |
39 | var scroll2 = _createScrollingSprite("images/opengameart/carbon_fiber.png", 150, Screen.centerY, 200, 500);
40 | scroll2.speed.y = -30;
41 |
42 | var scroll3 = _createScrollingSprite("images/opengameart/carbon_fiber.png", 550, Screen.centerY, 400, 300);
43 | scroll3.speed.set(20, 20);
44 | scroll3.scale.set(0.5, 0.5);
45 | }
46 | }
--------------------------------------------------------------------------------
/Sources/gecko/components/draw/CircleComponent.hx:
--------------------------------------------------------------------------------
1 | package gecko.components.draw;
2 |
3 | import gecko.Graphics;
4 | import gecko.Entity;
5 | import gecko.components.draw.DrawComponent;
6 |
7 | class CircleComponent extends DrawComponent {
8 | public var radius(get, set):Float;
9 | private var _radius:Float = 1;
10 |
11 | public var fill:Bool = false;
12 | public var strength:Float = 2;
13 | public var segments:Int = 0;
14 | public var diameter(default, null):Float = 4;
15 |
16 | public function init(fill:Bool, radius:Float = 1, strength:Float = 2, segments:Int = 0) {
17 | this.radius = radius;
18 | this.fill = fill;
19 | this.strength = strength;
20 | this.segments = segments;
21 |
22 | onAddedToEntity += _setTransformSize;
23 | }
24 |
25 | override public function draw(g:Graphics) {
26 | if(fill){
27 | g.fillCircle(_radius, _radius, _radius);
28 | }else{
29 | g.drawCircle(_radius, _radius, _radius, strength, segments);
30 | }
31 | }
32 |
33 | override public function beforeDestroy() {
34 | super.beforeDestroy();
35 |
36 | onAddedToEntity -= _setTransformSize;
37 |
38 | radius = 1;
39 | fill = false;
40 | strength = 2;
41 | }
42 |
43 | private function _setTransformSize(e:Entity) {
44 | if(e.transform != null){
45 | e.transform.size.set(diameter, diameter);
46 | }
47 | }
48 |
49 | inline function get_radius():Float {
50 | return _radius;
51 | }
52 |
53 | function set_radius(value:Float):Float {
54 | if(value == _radius)return _radius;
55 |
56 | _radius = value;
57 | diameter = _radius * 2;
58 |
59 | if(entity != null && entity.transform != null){
60 | entity.transform.size.set(diameter, diameter);
61 | }
62 |
63 | return _radius;
64 | }
65 |
66 | }
--------------------------------------------------------------------------------
/examples/khashmup/Sources/systems/ShootSystem.hx:
--------------------------------------------------------------------------------
1 | package systems;
2 |
3 | import gecko.Audio;
4 | import gecko.components.collision.aabb.HitBoxComponent;
5 | import gecko.math.Point;
6 | import gecko.components.motion.MovementComponent;
7 | import gecko.components.draw.SpriteComponent;
8 | import gecko.input.Keyboard;
9 | import gecko.Entity;
10 |
11 | import gecko.IUpdatable;
12 | import gecko.systems.System;
13 |
14 | import components.ShootComponent;
15 | import components.OutBoundsComponent;
16 |
17 | class ShootSystem extends System implements IUpdatable {
18 | public function init(){
19 | filter.equal(ShootComponent);
20 | }
21 |
22 | override public function update(dt:Float) {
23 | eachEntity(function(e:Entity){
24 | var shootComponent:ShootComponent = e.getComponent(ShootComponent);
25 | shootComponent.update(dt);
26 |
27 | if(Keyboard.isDown(shootComponent.key) && shootComponent.canShoot()){
28 | shootComponent.resetTimer();
29 |
30 | shoot(
31 | e.transform.left + e.transform.width / 2,
32 | e.transform.top,
33 | -shootComponent.speed
34 | );
35 | }
36 | });
37 | }
38 |
39 | public function shoot(x:Float, y:Float, speedY:Float) {
40 | if(scene == null)return;
41 |
42 | var shot = scene.createEntity();
43 | shot.addComponent(SpriteComponent.create("bullet.png"));
44 | shot.addComponent(MovementComponent.create(Point.create(0, speedY)));
45 | shot.addComponent(HitBoxComponent.create());
46 | shot.addComponent(OutBoundsComponent.create());
47 |
48 | shot.transform.anchor.set(0.5, 1);
49 | shot.transform.position.set(x, y);
50 |
51 | shot.addTag("shot");
52 |
53 | var audio:Audio = Audio.create("bulletShoot.wav");
54 | audio.destroyOnEnd = true;
55 | audio.play();
56 | }
57 | }
--------------------------------------------------------------------------------
/cli/cmd/khafile.ts:
--------------------------------------------------------------------------------
1 | import {parseConfig, Config, getConfigFile, generateKhafileContent, createKhaFile} from '../config';
2 | import { Command, ActionCallback } from '../cli';
3 | import { existsConfigFile, createFolder } from '../utils';
4 | import * as C from '../const';
5 | import * as path from 'path';
6 | import * as fs from 'fs-extra';
7 |
8 | const usage = `generate the khafile.js using the config file
9 | ${C.ENGINE_NAME} khafile [ -c config ]
10 |
11 | where [ -c config ] can be the prefix of a config file.`;
12 |
13 | export const cmd:Command = {
14 | name: "khafile",
15 | alias: ["k"],
16 | usage: usage,
17 | action: _action
18 | };
19 |
20 | interface buildParseArgs {
21 | err?:string
22 | args:string[]
23 | config:string
24 | }
25 |
26 | function _parseArgs(args:string[]) : buildParseArgs {
27 | let parsed:buildParseArgs = {
28 | err: "",
29 | args: args,
30 | config: ""
31 | };
32 |
33 | if(!args.length){
34 | return parsed;
35 | }
36 |
37 | if(args.length >= 2 && args[0] === "-c"){
38 | args.shift();
39 | let file = args.shift();
40 | if(file[0] === "-"){
41 | parsed.err = `Invalid config '-c ${file}'.`;
42 | return parsed;
43 | }
44 |
45 | parsed.config = file;
46 | }
47 |
48 | parsed.args = args;
49 | return parsed;
50 | }
51 |
52 | function _action(args:string[], cb:ActionCallback) {
53 | if(!existsConfigFile()){
54 | cb(new Error(`Invalid ${C.ENGINE_NAME} project. Config file not found.`));
55 | return;
56 | }
57 |
58 | const parsed = _parseArgs(args);
59 | if(parsed.err){
60 | cb(new Error(parsed.err));
61 | return;
62 | }
63 |
64 | args = parsed.args;
65 |
66 | console.log("Generating khafile.js...");
67 | let err = createKhaFile(parsed.config);
68 | if(err){
69 | cb(err);
70 | return;
71 | }
72 |
73 | cb(null, args);
74 | }
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "gecko2d",
3 | "version": "0.0.30",
4 | "description": "A flexible and powerful Cross-Platform 2D Game Framework",
5 | "main": "main.js",
6 | "preferGlobal": true,
7 | "bin": {
8 | "gecko": "main.js"
9 | },
10 | "scripts": {
11 | "update-kha": "git submodule foreach --recursive git pull origin master",
12 | "dev": "webpack --config webpack.config.js --progress --colors --watch",
13 | "build": "webpack --config webpack.config.js --progress --colors",
14 | "api": "node scripts/api.js && cp -R ./build_templates/docs/build/pages ./docs/.vuepress/dist/api_docs",
15 | "localdocs": "baseDir=false npm run docs",
16 | "docs": "node scripts/examples.js && vuepress build docs && node scripts/examples.js --build && npm run api",
17 | "ghpages": "npm run docs && cd docs/.vuepress/dist && git init && git add -A && git commit -m 'deploy pages' && git push -f git@github.com:nazariglez/Gecko2D.git master:gh-pages && npm run localdocs",
18 | "postinstall": "node scripts/khamake.js && node scripts/koremake.js"
19 | },
20 | "repository": {
21 | "type": "git",
22 | "url": "https://github.com/Nazariglez/Gecko2D.git"
23 | },
24 | "engines": {
25 | "node": ">=9.0.0"
26 | },
27 | "author": "Nazariglez",
28 | "license": "MIT",
29 | "bugs": {
30 | "url": "https://github.com/Nazariglez/Gecko2D/issues"
31 | },
32 | "homepage": "https://github.com/Nazariglez/Gecko2D",
33 | "devDependencies": {
34 | "@types/colors": "^1.1.3",
35 | "@types/node": "^8.0.46",
36 | "replace": "^0.3.0",
37 | "ts-loader": "^2.3.7",
38 | "typescript": "^2.5.3",
39 | "webpack": "^3.6.0"
40 | },
41 | "dependencies": {
42 | "async": "^2.5.0",
43 | "colors": "^1.1.2",
44 | "cross-spawn": "^6.0.5",
45 | "fs-extra": "^4.0.2",
46 | "is-url": "^1.2.2",
47 | "js-yaml": "^3.11.0",
48 | "node-static": "^0.7.10",
49 | "node-watch": "^0.5.5",
50 | "toml": "^2.3.3",
51 | "uglify-js": "^3.1.5"
52 | }
53 | }
--------------------------------------------------------------------------------
/Sources/gecko/math/Vector2g.hx:
--------------------------------------------------------------------------------
1 | package gecko.math;
2 |
3 | class Vector2g { //todo add observer
4 | public var x(get, set):T;
5 | private var _x:T;
6 | public var y(get, set):T;
7 | private var _y:T;
8 |
9 | private var _observer:Vector2g -> Void;
10 | public var isObserved(default, null):Bool;
11 |
12 | inline public function new(x:T, y:T) {
13 | set(x, y);
14 | }
15 |
16 | public function setObserver(cb:Vector2g -> Void) : Void {
17 | isObserved = true;
18 | _observer = cb;
19 | }
20 |
21 | public function removeObserver() : Void {
22 | isObserved = false;
23 | }
24 |
25 | public inline function set(x:T, y:T) {
26 | if(x != _x || y != _y){
27 | _setX(x);
28 | _setY(y);
29 | if(isObserved)_observer(this);
30 | }
31 | }
32 |
33 | inline private function _setX(x:T) {
34 | _x = x;
35 | }
36 |
37 | inline private function _setY(y:T) {
38 | _y = y;
39 | }
40 |
41 | public inline function clone(vec:Vector2g) : Vector2g {
42 | return new Vector2g(x, y);
43 | }
44 |
45 | public inline function copy(vec:Vector2g) : Void {
46 | set(vec.x, vec.y);
47 | }
48 |
49 | public inline function isEqual(vec:Vector2g) : Bool {
50 | return (x == vec.x && y == vec.y);
51 | }
52 |
53 | inline function get_x():T {
54 | return _x;
55 | }
56 |
57 | function set_x(value:T):T {
58 | if(value == _x)return _x;
59 | _x = value;
60 | if(isObserved)_observer(this);
61 | return value;
62 | }
63 |
64 | inline function set_y(value:T):T {
65 | if(value == _y)return _y;
66 | _y = value;
67 | if(isObserved)_observer(this);
68 | return value;
69 | }
70 |
71 | inline function get_y():T {
72 | return _y;
73 | }
74 |
75 | inline public function toString() : String {
76 | return 'Vector2g($_x, $_y)';
77 | }
78 | }
--------------------------------------------------------------------------------
/cli/cli.ts:
--------------------------------------------------------------------------------
1 | import * as colors from 'colors';
2 | import * as fs from 'fs-extra';
3 | import * as path from 'path';
4 | import * as C from './const';
5 | import {commands} from './commands';
6 |
7 | const inputArgs = process.argv.slice(2);
8 | let commandList:{[key:string]:Command} = {};
9 |
10 | export type ActionCallback = (err:Error, args?:string[])=>void;
11 |
12 | export interface Command {
13 | name:string
14 | alias?:string[]
15 | usage:string
16 | action:(args:string[], cb:ActionCallback)=>void
17 | }
18 |
19 | export function run(){
20 | commands.forEach(registerCommand);
21 |
22 | if(!inputArgs.length){
23 | _showHelp();
24 | return;
25 | }
26 |
27 | _processArgs();
28 | }
29 |
30 | export function registerCommand(command:Command) {
31 | commandList[command.name] = command;
32 | if(command.alias && command.alias.length) {
33 | command.alias.forEach(cmd => {
34 | commandList[cmd] = command;
35 | });
36 | }
37 | }
38 |
39 | function _processArgs(){
40 | let args = inputArgs;
41 | _consumeArgs(args);
42 | }
43 |
44 | function _consumeArgs(args:string[]){
45 | if(args.length){
46 | let cmd = args.shift();
47 | _runCommand(cmd, args, (err, args)=>{
48 | if(err){
49 | console.error(colors.red(err.message));
50 | if(err.message === "Invalid command."){
51 | _showHelp();
52 | }
53 | return;
54 | }
55 |
56 | _consumeArgs(args);
57 | });
58 | }
59 | }
60 |
61 | function _showHelp() {
62 | _runCommand("help", [], (err)=>{
63 | if(err){
64 | console.error(colors.red(err.message));
65 | }
66 | });
67 | }
68 |
69 | function _runCommand(cmd:string, args:string[], cb:ActionCallback) {
70 | let command = commandList[cmd];
71 | if(!command){
72 | return cb(new Error("Invalid command."));
73 | }
74 |
75 | command.action(args, cb);
76 | }
--------------------------------------------------------------------------------
/Sources/gecko/tween/TweenManager.hx:
--------------------------------------------------------------------------------
1 | package gecko.tween;
2 |
3 |
4 |
5 | class TweenManager extends BaseObject {
6 | public var tweens:Array = [];
7 | private var _tweensToDelete:Array = [];
8 |
9 | private var _isProcessing:Bool = false;
10 |
11 | public function tick(delta:Float) {
12 | _isProcessing = true;
13 | for(t in tweens){
14 | if(!t.isActive){
15 | continue;
16 | }
17 |
18 | t.update(delta);
19 |
20 | if(t.isEnded && t.destroyOnEnd) {
21 | t.destroy();
22 | }
23 | }
24 |
25 | while(_tweensToDelete.length > 0){
26 | var t = _tweensToDelete.shift();
27 | _remove(t);
28 | }
29 |
30 | _isProcessing = false;
31 | }
32 |
33 | inline public function createTween(target:Dynamic, valuesTo:Dynamic, time:Float, ?easing:Ease) : Tween {
34 | return Tween.create(target, valuesTo, time, easing, this);
35 | }
36 |
37 | public function createGroup(tweens:Array) : TweenGroup {
38 | return TweenGroup.create(tweens);
39 | }
40 |
41 | inline public function removeTween(tween:Tween) {
42 | if(_isProcessing){
43 | _tweensToDelete.push(tween);
44 | }else{
45 | _remove(tween);
46 | }
47 | }
48 |
49 | public function clear() {
50 | for(t in tweens){
51 | t.clear();
52 | }
53 | }
54 |
55 | public function cleanTweens() {
56 | while(tweens.length > 0){
57 | var t = tweens.shift();
58 | t.destroy();
59 | }
60 |
61 | while(_tweensToDelete.length > 0){
62 | var t = _tweensToDelete.shift();
63 | t.destroy();
64 | }
65 | }
66 |
67 | inline private function _remove(tween:Tween) {
68 | tweens.remove(tween);
69 | }
70 |
71 | override public function beforeDestroy(){
72 | super.beforeDestroy();
73 | cleanTweens();
74 | _isProcessing = false;
75 | }
76 | }
--------------------------------------------------------------------------------
/Sources/gecko/timer/TimerManager.hx:
--------------------------------------------------------------------------------
1 | package gecko.timer;
2 |
3 |
4 |
5 | class TimerManager extends BaseObject {
6 | public var timers:Array = [];
7 | private var _timersToDelete:Array = [];
8 | private var _isProcessing:Bool = false;
9 |
10 | public function tick(delta:Float) {
11 | _isProcessing = true;
12 | for(t in timers){
13 | if(!t.isActive){
14 | continue;
15 | }
16 |
17 | t.update(delta);
18 |
19 | if(t.isEnded && t.destroyOnEnd) {
20 | t.destroy();
21 | }
22 | }
23 |
24 | while(_timersToDelete.length > 0){
25 | var t = _timersToDelete.shift();
26 | _remove(t);
27 | }
28 |
29 | _isProcessing = false;
30 | }
31 |
32 | inline public function createTimer(time:Float, delay:Float = 0, loop:Bool = false, repeat:Int = 0) : Timer {
33 | return Timer.create(time, delay, loop, repeat, this);
34 | }
35 |
36 | inline public function createGroup(timers:Array) : TimerGroup {
37 | return TimerGroup.create(timers);
38 | }
39 |
40 | inline public function removeTimer(timer:Timer) {
41 | if(_isProcessing){
42 | _timersToDelete.push(timer);
43 | }else{
44 | _remove(timer);
45 | }
46 | }
47 |
48 | public function clear(){
49 | for(t in timers){
50 | t.clear();
51 | }
52 | }
53 |
54 | public function cleanTimers() {
55 | while(timers.length > 0){
56 | var t = timers.shift();
57 | t.destroy();
58 | }
59 |
60 | while(_timersToDelete.length > 0){
61 | var t = _timersToDelete.shift();
62 | t.destroy();
63 | }
64 | }
65 |
66 | inline private function _remove(timer:Timer) {
67 | timers.remove(timer);
68 | }
69 |
70 | override public function beforeDestroy(){
71 | super.beforeDestroy();
72 |
73 | cleanTimers();
74 |
75 | _isProcessing = false;
76 | }
77 | }
--------------------------------------------------------------------------------
/cli/utils.ts:
--------------------------------------------------------------------------------
1 | import * as fs from 'fs-extra';
2 | import * as path from 'path';
3 | import {ENGINE_NAME, CURRENT_PATH, TEMP_PATH, ENGINE_PATH} from "./const";
4 |
5 | export function existsConfigFile() : boolean {
6 | const findName = `${ENGINE_NAME}.toml`;
7 | const files = fs.readdirSync(CURRENT_PATH);
8 |
9 | let exists = false;
10 |
11 | for(let i = 0; i < files.length; i++){
12 | if(files[i].indexOf(findName) !== -1){
13 | exists = true;
14 | break;
15 | }
16 | }
17 |
18 | return exists;
19 | }
20 |
21 | export function createFolder(folder:string) : Error {
22 | let err:Error;
23 |
24 | if(fs.existsSync(folder)){
25 | return err;
26 | }
27 | try {
28 | fs.mkdirSync(folder)
29 | } catch(e){
30 | err = e
31 | }
32 |
33 | return err
34 | }
35 |
36 | export function trimLineSpaces(input:string) : string {
37 | return input.split("\n").map((line)=>line.trim()).join("\n");
38 | }
39 |
40 | export function copyEngineToProject() : Error {
41 | let err:Error;
42 |
43 | try {
44 | fs.copySync(path.join(ENGINE_PATH, "Sources"), path.join(CURRENT_PATH, "Libraries", ENGINE_NAME, "Sources"));
45 | }catch(e){
46 | err = e;
47 | }
48 |
49 | return err;
50 | }
51 |
52 | export function removeEngineFromLibraries() : Error {
53 | let err:Error;
54 | try {
55 | fs.removeSync(path.join(CURRENT_PATH, "Libraries", ENGINE_NAME));
56 | }catch(e){
57 | err = e;
58 | }
59 |
60 | return err;
61 | }
62 |
63 | export function nodeVersion() : [number, number, number] {
64 | let v = process.version;
65 | v = v.replace("v", "");
66 |
67 | let arr = v.split(/[\.||-]/);
68 | return [parseInt(arr[0]), parseInt(arr[1]), parseInt(arr[2])];
69 | }
70 |
71 | export function getRequiredNodeVersion() : [number, number, number] {
72 | let v = require("../package.json").engines.node;
73 | v = v.replace(">=", "");
74 |
75 | let arr = v.split(/[\.||-]/);
76 | return [parseInt(arr[0]), parseInt(arr[1]), parseInt(arr[2])];
77 | }
--------------------------------------------------------------------------------
/docs/examples/drawsprites.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Draw Sprites
3 | ---
4 | # Draw Sprites
5 |
6 |
7 | ```haxe
8 | package;
9 |
10 | import gecko.Gecko;
11 | import gecko.Float32;
12 | import gecko.components.draw.SpriteComponent;
13 | import gecko.systems.draw.DrawSystem;
14 |
15 | class Game {
16 | private var _spritesToLoad:Array = [
17 | "kenney/elephant.png",
18 | "kenney/hippo.png",
19 | "kenney/monkey.png",
20 | "kenney/giraffe.png",
21 | "kenney/panda.png",
22 | "kenney/parrot.png",
23 | "kenney/snake.png",
24 | "kenney/penguin.png",
25 | "kenney/pig.png"
26 | ];
27 |
28 | public function new(){
29 | //add draw system
30 | Gecko.currentScene.addSystem(DrawSystem.create());
31 |
32 | //load the sprites
33 | gecko.Assets.load(_spritesToLoad, _onLoadAssets).start();
34 | }
35 |
36 | //Create an add the sprite
37 | private function _createSprite(spriteName:String, x:Float32, y:Float32) {
38 | //create an entity in the current scene
39 | var entity = Gecko.currentScene.createEntity();
40 |
41 | //add a spriteComponent using the sprite name
42 | entity.addComponent(SpriteComponent.create(spriteName));
43 |
44 | //set the position and the scale
45 | entity.transform.position.set(x, y);
46 | entity.transform.scale.set(0.4, 0.4);
47 | }
48 |
49 | private function _onLoadAssets(){
50 | //Draw 9 sprites in a grid
51 | var minX = 155;
52 | var minY = 110;
53 |
54 | var gapX = 250;
55 | var gapY = 180;
56 |
57 | var i = 0;
58 | for(x in 0...3){
59 | for(y in 0...3){
60 | _createSprite(_spritesToLoad[i], minX + gapX*x, minY + gapY*y);
61 |
62 | i++;
63 | }
64 | }
65 | }
66 | }
67 | ```
68 |
69 | [Source Code](https://github.com/Nazariglez/Gecko2D/tree/master/examples/drawsprites)
70 |
--------------------------------------------------------------------------------
/docs/examples/sprites.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Sprites
3 | ---
4 | # Sprites
5 |
6 |
7 |
8 | ```haxe
9 | package;
10 |
11 | import gecko.Gecko;
12 |
13 | import gecko.components.draw.SpriteComponent;
14 | import gecko.systems.draw.DrawSystem;
15 |
16 | class Game {
17 | private var _spritesToLoad:Array = [
18 | "kenney/elephant.png",
19 | "kenney/hippo.png",
20 | "kenney/monkey.png",
21 | "kenney/giraffe.png",
22 | "kenney/panda.png",
23 | "kenney/parrot.png",
24 | "kenney/snake.png",
25 | "kenney/penguin.png",
26 | "kenney/pig.png"
27 | ];
28 |
29 | public function new(){
30 | //add draw system
31 | Gecko.currentScene.addSystem(DrawSystem.create());
32 |
33 | //load the sprites
34 | gecko.Assets.load(_spritesToLoad, _onLoadAssets).start();
35 | }
36 |
37 | //Create an add the sprite
38 | private function _createSprite(spriteName:String, x:Float, y:Float) {
39 | //create an entity in the current scene
40 | var entity = Gecko.currentScene.createEntity();
41 |
42 | //add a spriteComponent using the sprite name
43 | entity.addComponent(SpriteComponent.create(spriteName));
44 |
45 | //set the position and the scale
46 | entity.transform.position.set(x, y);
47 | entity.transform.scale.set(0.4, 0.4);
48 | }
49 |
50 | private function _onLoadAssets(){
51 | //Draw 9 sprites in a grid
52 | var minX = 155;
53 | var minY = 110;
54 |
55 | var gapX = 250;
56 | var gapY = 180;
57 |
58 | var i = 0;
59 | for(x in 0...3){
60 | for(y in 0...3){
61 | _createSprite(_spritesToLoad[i], minX + gapX*x, minY + gapY*y);
62 |
63 | i++;
64 | }
65 | }
66 | }
67 | }
68 | ```
69 |
70 |
71 | [Source Code](https://github.com/Nazariglez/Gecko2D/tree/master/examples/sprites)
72 |
--------------------------------------------------------------------------------
/examples/flappy/Sources/Game.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.input.Mouse;
4 | import gecko.Gecko;
5 | import gecko.Screen;
6 | import gecko.Assets;
7 | import gecko.components.draw.ProgressBarComponent;
8 |
9 | class Game {
10 | private var _assetsToLoad:Array = [
11 | //your assets here
12 | "images/flappydoge_bg1.png",
13 | "images/flappydoge_floor.png",
14 | "images/flappydoge_pipe.png",
15 |
16 | "images/flappydoge_anim01.png",
17 | "images/flappydoge_anim02.png",
18 | "images/flappydoge_anim03.png",
19 | "images/flappydoge_anim04.png",
20 |
21 | "kenpixel_mini_square.ttf"
22 | ];
23 |
24 | public function new(){
25 | Mouse.enable();
26 |
27 | if(_assetsToLoad.length != 0){
28 | _loadAssets();
29 | }else{
30 | _gotoMainScene();
31 | }
32 | }
33 |
34 | public function _gotoMainScene() {
35 | Gecko.world.changeScene(scenes.MainScene.create(), true);
36 | }
37 |
38 | //Add a loaderbar an go to mainScene when the load finish
39 | public function _loadAssets() {
40 | var currentScene = Gecko.currentScene;
41 |
42 | var entity = currentScene.createEntity();
43 | entity.transform.position.set(Screen.centerX, Screen.centerY);
44 | entity.transform.size.set(Screen.width*0.8, 20);
45 |
46 | var progressBar = entity.addComponent(ProgressBarComponent.create());
47 |
48 | var loader = Assets.load(_assetsToLoad);
49 | loader.onProgressEnd += function(progress:Int, assetName:String){
50 | progressBar.progress = progress; //update the loaderBar
51 | };
52 |
53 | loader.onComplete += function(){
54 | //added a little delay before go to the mainScene
55 | var timer = currentScene.timerManager.createTimer(0.5);
56 | timer.destroyOnEnd = true;
57 |
58 | timer.onEnd += function(){
59 | _gotoMainScene();
60 | };
61 |
62 | timer.start();
63 | };
64 |
65 | //start load
66 | loader.start();
67 | }
68 | }
--------------------------------------------------------------------------------
/examples/nineslice/Sources/Game.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Assets;
4 | import gecko.Gecko;
5 |
6 | import gecko.math.Random;
7 | import gecko.systems.draw.DrawSystem;
8 | import gecko.components.draw.NineSliceComponent;
9 |
10 | class Game {
11 | var _spritesToLoad = ["images/kenney/grey_button08.png", "images/kenney/green_panel.png"];
12 |
13 | public function new(){
14 | //add the draw system to the current scene
15 | Gecko.currentScene.addSystem(DrawSystem.create());
16 |
17 | //load the assets
18 | Assets.load(_spritesToLoad, _onLoadAssets).start();
19 | }
20 |
21 | //create nine-slice sprites using positon and size
22 | private function _createNineSlice(x:Float, y:Float, width:Float, height:Float) {
23 | //create an entity in the current scene
24 | var entity = Gecko.currentScene.createEntity();
25 |
26 | //set his position in the screen
27 | entity.transform.position.set(x, y);
28 |
29 | //add the nine-slice component using a random spritename and a size
30 | entity.addComponent(NineSliceComponent.create(_getRandomSprite(), width, height));
31 |
32 | //e.renderer.color = _getRandomColor();
33 | entity.transform.anchor.set(0,0);
34 | }
35 |
36 | private function _onLoadAssets() {
37 | //add a lot of nine-slice components in the screen
38 | _createNineSlice(50, 50, 200, 100);
39 | _createNineSlice(50, 170, 100, 400);
40 | _createNineSlice(170, 170, 400, 400);
41 | _createNineSlice(270, 50, 60, 100);
42 | _createNineSlice(350, 50, 40, 40);
43 | _createNineSlice(350, 110, 40, 40);
44 | _createNineSlice(410, 50, 120, 100);
45 | _createNineSlice(550, 50, 200, 40);
46 | _createNineSlice(550, 110, 200, 40);
47 | _createNineSlice(590, 170, 160, 80);
48 | _createNineSlice(590, 270, 60, 300);
49 | _createNineSlice(670, 270, 80, 300);
50 | }
51 |
52 | //return a random spritename
53 | private function _getRandomSprite() : String {
54 | return _spritesToLoad[Random.getUpTo(_spritesToLoad.length-1)];
55 | }
56 | }
--------------------------------------------------------------------------------
/examples/demo/Sources/scenes/CustomScene.hx:
--------------------------------------------------------------------------------
1 | package scenes;
2 |
3 | import gecko.components.draw.DrawComponent;
4 | import gecko.systems.misc.BehaviorSystem;
5 | import gecko.systems.draw.DrawSystem;
6 | import gecko.Gecko;
7 |
8 | import gecko.components.input.MouseComponent;
9 | import gecko.components.draw.SpriteComponent;
10 | import gecko.Screen;
11 | import gecko.Entity;
12 | import gecko.systems.input.InteractivitySystem;
13 | import gecko.Scene;
14 | import gecko.Color;
15 |
16 | class CustomScene extends Scene {
17 | public var hud:Entity;
18 |
19 | public function init(closeButton:Bool = false) {
20 | addSystem(DrawSystem.create());
21 | addSystem(BehaviorSystem.create());
22 | addSystem(InteractivitySystem.create());
23 |
24 | hud = createEntity();
25 | hud.addComponent(DrawComponent.create());
26 | hud.transform.fixedToCamera = true;
27 | hud.transform.size.set(Screen.width, Screen.height);
28 | hud.transform.position.set(Screen.centerX, Screen.centerY);
29 |
30 | if(closeButton){
31 | _addCloseButton();
32 | }
33 | }
34 |
35 | override public function beforeDestroy() {
36 | super.beforeDestroy();
37 |
38 | hud = null;
39 | }
40 |
41 | private function _addCloseButton() : Entity {
42 | var btn = createEntity();
43 | btn.transform.parent = hud.transform;
44 | btn.transform.position.set(Screen.width-20, 20);
45 | btn.transform.anchor.set(1, 0);
46 |
47 | var sprite = btn.addComponent(SpriteComponent.create("images/kenney/red_cross.png"));
48 |
49 | var mouse = btn.addComponent(MouseComponent.create());
50 | mouse.onClick += _gotoMainScene;
51 |
52 | mouse.onOver += function(x:Float, y:Float) {
53 | sprite.color = Color.Red;
54 | };
55 |
56 | mouse.onOut += function(x:Float, y:Float) {
57 | sprite.color = Color.White;
58 | };
59 |
60 | return btn;
61 | }
62 |
63 | private function _gotoMainScene(x:Float, y:Float) {
64 | Gecko.world.changeScene(MainScene.create(), true);
65 | }
66 | }
--------------------------------------------------------------------------------
/examples/demo/Sources/scenes/DrawShapeScene.hx:
--------------------------------------------------------------------------------
1 | package scenes;
2 |
3 | import gecko.components.draw.PolygonComponent;
4 | import gecko.math.Point;
5 |
6 | import gecko.components.draw.DrawComponent;
7 | import gecko.Color;
8 | import gecko.components.draw.CircleComponent;
9 | import gecko.components.draw.RectangleComponent;
10 |
11 | class DrawShapeScene extends CustomScene {
12 | override public function init(closeButton:Bool = false) {
13 | super.init(closeButton);
14 |
15 | //circles
16 | _createShape(100, 150, CircleComponent.create(true, 60), Color.Red); //fill
17 | _createShape(300, 150, CircleComponent.create(false, 60, 8), Color.Red);
18 |
19 | //rects
20 | _createShape(500, 150, RectangleComponent.create(true, 120, 120), Color.Green); //fill
21 | _createShape(700, 150, RectangleComponent.create(false, 120, 120, 8), Color.Green);
22 |
23 | //triangles
24 | var trianglePoints = [Point.create(60, 0), Point.create(0, 120), Point.create(120, 120)];
25 | _createShape(100, 400, PolygonComponent.create(true, trianglePoints), Color.Blue); //fill
26 | _createShape(300, 400, PolygonComponent.create(false, trianglePoints, 8), Color.Blue);
27 |
28 | //hexagons
29 | var hexagonPoints = [
30 | Point.create(0, 40),
31 | Point.create(40, 0),
32 | Point.create(80, 0),
33 | Point.create(120, 40),
34 | Point.create(120, 80),
35 | Point.create(80, 120),
36 | Point.create(40, 120),
37 | Point.create(0, 80)
38 | ];
39 | _createShape(500, 400, PolygonComponent.create(true, hexagonPoints), Color.Yellow); //fill
40 | _createShape(700, 400, PolygonComponent.create(false, hexagonPoints, 8), Color.Yellow);
41 |
42 | }
43 |
44 | //create a generic entitiy to add a shape draw component
45 | private function _createShape(x:Float, y:Float, shapeComponent:DrawComponent, color:Color) {
46 | var e = createEntity();
47 | e.transform.position.set(x, y);
48 | e.addComponent(shapeComponent);
49 |
50 | shapeComponent.color = color;
51 | }
52 | }
--------------------------------------------------------------------------------
/docs/guide/README.md:
--------------------------------------------------------------------------------
1 | # Base Object
2 | This framework use object pooling to avoid garbage collector issues. Some objects, like scenes, entites, componentes, or systems (among other objects) inherit from `gecko.BaseObject`, which is a special object without functionality defined, but allow us to recycle our instances.
3 |
4 | Every object inherited from `gecko.BaseObject` must be instantiated via the static method `MyObject.create()`, this will check his pool to get and reuse an old instance, or if no one exists create it. When you're done with your object, just destroy it with the instance method `myObject.destroy()` and it will be returned to his pool.
5 |
6 | To manage how your objects are created or destroyed you can use two instance methods, `init` and `beforeDestroy`.
7 | - __init__: this method is executed always when you use `MyObject.create()`. You can add some parameters to it, and this params will be passed to the __create__ method.
8 | - __beforeDestroy__: this method is executed before your object is destroyed, use it to clean it or do whatever you need before recycle it. This methods needs to be override because is inherited from __BaseObject__.
9 |
10 | For example:
11 | ```haxe
12 | class MyObject extends gecko.BaseObject {
13 | var name:String = "";
14 |
15 | public function init(name:String){
16 | this.name = name;
17 | trace(name);
18 | }
19 |
20 | override public function beforeDestroy() {
21 | trace("i will be destroyed!!!!");
22 | }
23 | }
24 | ```
25 |
26 | ```haxe
27 | var myObject = MyObject.create("Jonh Doe"); //print "Jonh Doe"
28 |
29 | //do something with your object and when you're done just destroy it
30 | myObject.destroy();
31 | ```
32 |
33 | Keep in mind that is possible `beforeDestroy` may not be executed when you use `myObject.destroy()`. If the game loop o the rendering loop is running the destruction of your object will be delayed to the end of the frame. If you need to know the state of your object use `myObject.isAlreadyDestroyed` which is a boolean value.
34 |
35 | In some (unsual) cases maybe you want acces to your object's pool to check their length, clear, debug, or whatever, just use `MyObject.getPool()`.
--------------------------------------------------------------------------------
/docs/readme.md:
--------------------------------------------------------------------------------
1 | ---
2 | home: true
3 | actionText: Getting Started
4 | actionLink: /getting-started/
5 | features:
6 | - title: Open Source
7 | details: Gecko has no black boxes, the source code is available for everyone in github, to be revised, fixed, improved, or whatever you want.
8 | - title: Native Performance
9 | details: Export your game to Javascript, C++ and C using OpenGL, DirectX, Metal, etc... This allow run your game at maximun speed.
10 | - title: Crossplatform
11 | details: Your game will be multiplatform by default, browser, desktop, mobile and consoles are supported. Also Gecko2D provide some utils to work with differentes screen resolutions.
12 | footer: MIT Licensed | Copyright © 2018-present Nazarí González
13 | ---
14 |
15 | Gecko2D is a flexible and powerful cross-platform game framework that will allow you to create games easily and deploy it
16 | to browsers, mobile devices, desktop, and even consoles.
17 |
18 | Under the hood, Gecko2D is an [Entity-Component-System](https://en.wikipedia.org/wiki/Entity%E2%80%93component%E2%80%93system) framework built on top of [Haxe](http://haxe.org) and [Kha](http://kha.tech) which allow the best performance and real cross-platform
19 | compilation, using Javascript and WebGL when compile to browsers, and C++ when compile to mobile using metal or opengl, to desktop using opengl, directx or vulkan, and consoles with their own drivers.
20 |
21 | This framework aims to be a solid foundation for all your games, allowing you to port your games to others platforms using the same source code, saving time and money.
22 |
23 | # Quick start
24 | Install it via __npm__
25 | ```
26 | npm install gecko2d -g
27 | ```
28 | And create a new project with `gecko init` in a empty folder. Use `gecko watch` to serve your game at [http://localhost:8080](http://localhost:8080) and recompile when change.
29 |
30 | Easy right?
31 |
32 | # Contributing
33 | Contributions are welcome! Feel free to fix, improve or test features you want. Just try to coordinate with the community before work on anything to avoid duplicate or not wanted features.
34 |
35 | ::: warning Gecko2D it's under development.
36 | Some issues may occur until we reach a major version.
37 | :::
--------------------------------------------------------------------------------
/examples/khashmup/Sources/Game.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.input.Keyboard;
4 | import gecko.Gecko;
5 | import gecko.Screen;
6 | import gecko.Assets;
7 | import gecko.components.draw.ProgressBarComponent;
8 |
9 | class Game {
10 | private var _assetsToLoad:Array = [
11 | "bullet.png",
12 | "bulletShoot.wav",
13 | "enemyExplosion.wav",
14 | "enemyShip.png",
15 | "kenpixel_mini_square.ttf",
16 | "playerExplosion.wav",
17 | "playerShip.png",
18 | "smokeOrange0.png",
19 | "smokeOrange1.png",
20 | "smokeOrange2.png",
21 | "smokeOrange3.png",
22 | ];
23 |
24 | public function new(){
25 | //enable keyboard events
26 | Keyboard.enable();
27 |
28 | //load the assets or go to the mainScene
29 | if(_assetsToLoad.length != 0){
30 | _loadAssets();
31 | }else{
32 | _gotoMainScene();
33 | }
34 | }
35 |
36 | public function _gotoMainScene() {
37 | Gecko.world.changeScene(scenes.MainScene.create(), true);
38 | }
39 |
40 | //Add a loaderbar and go to mainScene when the load finish
41 | public function _loadAssets() {
42 | var currentScene = Gecko.currentScene;
43 |
44 | var entity = currentScene.createEntity();
45 | entity.transform.position.set(Screen.centerX, Screen.centerY);
46 | entity.transform.size.set(500, 40);
47 |
48 | var progressBar = entity.addComponent(ProgressBarComponent.create());
49 |
50 | var loader = Assets.load(_assetsToLoad);
51 | loader.onProgressEnd += function(progress:Int, assetName:String){
52 | progressBar.progress = progress; //update the loaderBar
53 | };
54 |
55 | loader.onComplete += function(){
56 | //added a little delay before go to the mainScene
57 | var timer = currentScene.timerManager.createTimer(0.5);
58 | timer.destroyOnEnd = true;
59 |
60 | timer.onEnd += function(){
61 | _gotoMainScene();
62 | };
63 |
64 | timer.start();
65 | };
66 |
67 | //start load
68 | loader.start();
69 | }
70 | }
--------------------------------------------------------------------------------
/Sources/gecko/components/draw/RectangleComponent.hx:
--------------------------------------------------------------------------------
1 | package gecko.components.draw;
2 |
3 | import gecko.Graphics;
4 | import gecko.Entity;
5 | import gecko.components.draw.DrawComponent;
6 |
7 | class RectangleComponent extends DrawComponent {
8 | public var width(get, set):Float;
9 | private var _width:Float = 0;
10 |
11 | public var height(get, set):Float;
12 | private var _height:Float = 0;
13 |
14 | public var strength:Int = 2;
15 | public var fill:Bool = false;
16 |
17 | public function init(fill:Bool, width:Float, height:Float, strength:Int = 2) {
18 | this.width = width;
19 | this.height = height;
20 | this.fill = fill;
21 | this.strength = strength;
22 |
23 | onAddedToEntity += _setTransformSize;
24 | }
25 |
26 | override public function draw(g:Graphics) {
27 | if(fill){
28 | g.fillRect(0, 0, _width, _height);
29 | }else{
30 | g.drawRect(0, 0, _width, _height, strength);
31 | }
32 | }
33 |
34 | private function _setTransformSize(e:Entity) {
35 | if(e.transform != null){
36 | e.transform.size.set(_width, _height);
37 | }
38 | }
39 |
40 | override public function beforeDestroy(){
41 | super.beforeDestroy();
42 |
43 | width = 0;
44 | height = 0;
45 | fill = false;
46 | strength = 2;
47 |
48 | onAddedToEntity -= _setTransformSize;
49 | }
50 |
51 | inline function get_width():Float {
52 | return _width;
53 | }
54 |
55 | inline function get_height():Float {
56 | return _height;
57 | }
58 |
59 | function set_width(value:Float):Float {
60 | if(value == _width)return _width;
61 |
62 | _width = value;
63 |
64 | if(entity != null && entity.transform != null){
65 | entity.transform.size.x = _width;
66 | }
67 |
68 | return _width;
69 | }
70 |
71 | function set_height(value:Float):Float {
72 | if(value == _height)return _height;
73 |
74 | _height = value;
75 |
76 | if(entity != null && entity.transform != null){
77 | entity.transform.size.y = _height;
78 | }
79 |
80 | return _height;
81 | }
82 | }
--------------------------------------------------------------------------------
/Sources/gecko/components/draw/PolygonComponent.hx:
--------------------------------------------------------------------------------
1 | package gecko.components.draw;
2 |
3 | import gecko.math.Point;
4 | import gecko.Graphics;
5 | import gecko.Entity;
6 | import gecko.components.draw.DrawComponent;
7 |
8 | class PolygonComponent extends DrawComponent {
9 | private var _points:Array;
10 |
11 | public var fill:Bool = false;
12 | public var strength:Float = 2;
13 |
14 | private var _width:Float = 0;
15 | private var _height:Float = 0;
16 |
17 | public function init(fill:Bool, points:Array, strength:Float = 2) {
18 | this.fill = fill;
19 | this.strength = strength;
20 | setPoints(points);
21 |
22 | onAddedToEntity += _setTransformSize;
23 | }
24 |
25 | public function setPoints(points:Array) {
26 | _points = points;
27 | checkBounds();
28 | }
29 |
30 | public function checkBounds() {
31 | var minX = Math.POSITIVE_INFINITY;
32 | var minY = Math.POSITIVE_INFINITY;
33 | var maxX = Math.NEGATIVE_INFINITY;
34 | var maxY = Math.NEGATIVE_INFINITY;
35 |
36 | for(p in _points) {
37 | if(p.x < minX)minX = p.x;
38 | if(p.x > maxX)maxX = p.x;
39 | if(p.y < minY)minY = p.y;
40 | if(p.y > maxY)maxY = p.y;
41 | }
42 |
43 | _width = maxX - minX;
44 | _height = maxY - minY;
45 |
46 | if(entity != null){
47 | _setTransformSize(entity);
48 | }
49 | }
50 |
51 | inline public function getPoints() : Array {
52 | return _points;
53 | }
54 |
55 | override public function draw(g:Graphics) {
56 | if(fill){
57 | g.fillPolygon(0, 0, _points);
58 | }else{
59 | g.drawPolygon(0, 0, _points, strength);
60 | }
61 | }
62 |
63 | override public function beforeDestroy() {
64 | super.beforeDestroy();
65 |
66 | onAddedToEntity -= _setTransformSize;
67 |
68 | fill = false;
69 |
70 | while(_points.length > 0){
71 | _points.pop().destroy();
72 | }
73 | }
74 |
75 | private function _setTransformSize(e:Entity) {
76 | if(e.transform != null){
77 | e.transform.size.set(_width, _height);
78 | }
79 | }
80 | }
--------------------------------------------------------------------------------
/examples/shapes/Sources/Game.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 | import gecko.Gecko;
4 | import gecko.Color;
5 |
6 | import gecko.math.Point;
7 | import gecko.components.draw.CircleComponent;
8 | import gecko.components.draw.RectangleComponent;
9 | import gecko.components.draw.PolygonComponent;
10 | import gecko.components.draw.DrawComponent;
11 |
12 | class Game {
13 | public function new(){
14 | //circles
15 | _createShape(100, 150, CircleComponent.create(true, 60), Color.Red); //fill
16 | _createShape(300, 150, CircleComponent.create(false, 60, 8), Color.Red);
17 |
18 | //rects
19 | _createShape(500, 150, RectangleComponent.create(true, 120, 120), Color.Green); //fill
20 | _createShape(700, 150, RectangleComponent.create(false, 120, 120, 8), Color.Green);
21 |
22 | //triangles
23 | var trianglePoints = [Point.create(60, 0), Point.create(0, 120), Point.create(120, 120)];
24 | _createShape(100, 400, PolygonComponent.create(true, trianglePoints), Color.Blue); //fill
25 | _createShape(300, 400, PolygonComponent.create(false, trianglePoints, 8), Color.Blue);
26 |
27 | //hexagons
28 | var hexagonPoints = [
29 | Point.create(0, 40),
30 | Point.create(40, 0),
31 | Point.create(80, 0),
32 | Point.create(120, 40),
33 | Point.create(120, 80),
34 | Point.create(80, 120),
35 | Point.create(40, 120),
36 | Point.create(0, 80)
37 | ];
38 | _createShape(500, 400, PolygonComponent.create(true, hexagonPoints), Color.Yellow); //fill
39 | _createShape(700, 400, PolygonComponent.create(false, hexagonPoints, 8), Color.Yellow);
40 |
41 | }
42 |
43 | //create a generic entitiy to add a shape draw component
44 | private function _createShape(x:Float, y:Float, shapeComponent:DrawComponent, color:Color) {
45 | //create an entity in the current scene
46 | var entity = Gecko.currentScene.createEntity();
47 |
48 | //add the shape component
49 | entity.addComponent(shapeComponent);
50 | shapeComponent.color = color; //set a color for the shape
51 |
52 | //set the position to draw the entity on the screen
53 | entity.transform.position.set(x, y);
54 | }
55 | }
--------------------------------------------------------------------------------
/docs/examples/scrollingsprite.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Scrolling Sprite
3 | ---
4 | # Scrolling Sprite
5 |
6 |
7 |
8 | ```haxe
9 | package;
10 |
11 | import gecko.Gecko;
12 | import gecko.Screen;
13 |
14 | import gecko.Assets;
15 | import gecko.systems.draw.DrawSystem;
16 | import gecko.components.draw.ScrollingSpriteComponent;
17 |
18 | class Game {
19 | public function new(){
20 | //add the draw system
21 | Gecko.currentScene.addSystem(DrawSystem.create());
22 |
23 | //Load the sprites
24 | Assets.load([
25 | "images/opengameart/mountain.png",
26 | "images/opengameart/carbon_fiber.png"
27 | ], _onLoadAssets).start();
28 | }
29 |
30 | //create an entity with a scrolling-component using spritename, position and size
31 | private function _createScrollingSprite(sprite:String, x:Float, y:Float, width:Float, height:Float) : ScrollingSpriteComponent {
32 | //create a new entity in the currentScene
33 | var entity = Gecko.currentScene.createEntity();
34 |
35 | //set his position in the screen
36 | entity.transform.position.set(x, y);
37 |
38 | //add the ScrollingComponent using the width and height passed and return the component
39 | return entity.addComponent(ScrollingSpriteComponent.create(sprite, width, height));
40 | }
41 |
42 | private function _onLoadAssets() {
43 | //create a scrollingSprite using the spriteName, position, and size
44 | var scroll1 = _createScrollingSprite("images/opengameart/mountain.png", Screen.centerX, Screen.centerY, Screen.width, Screen.height);
45 | scroll1.speed.x = 20;
46 |
47 | var scroll2 = _createScrollingSprite("images/opengameart/carbon_fiber.png", 150, Screen.centerY, 200, 500);
48 | scroll2.speed.y = -30;
49 |
50 | var scroll3 = _createScrollingSprite("images/opengameart/carbon_fiber.png", 550, Screen.centerY, 400, 300);
51 | scroll3.speed.set(20, 20);
52 | scroll3.scale.set(0.5, 0.5);
53 | }
54 | }
55 | ```
56 |
57 |
58 | [Source Code](https://github.com/Nazariglez/Gecko2D/tree/master/examples/scrollingsprite)
59 |
--------------------------------------------------------------------------------
/docs/examples/parenttransform.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Parent Transform
3 | ---
4 | # Parent Transform
5 |
6 |
7 |
8 | ```haxe
9 | package;
10 |
11 |
12 | import gecko.components.draw.DrawComponent;
13 | import gecko.components.draw.SpriteComponent;
14 | import gecko.Screen;
15 | import gecko.Gecko;
16 | import gecko.systems.draw.DrawSystem;
17 | import gecko.Assets;
18 |
19 | class Game {
20 | public function new(){
21 | Gecko.currentScene.addSystem(DrawSystem.create());
22 |
23 | Assets.load([
24 | "car_green_small_1.png"
25 | ], _onAssetsLoaded).start();
26 | }
27 |
28 | private function _onAssetsLoaded() {
29 | //create a new container in the middle of the screen with a 200x350 of size
30 | var container = Gecko.currentScene.createEntity();
31 | container.transform.size.set(200, 350);
32 | container.transform.position.set(Screen.centerX, Screen.centerY);
33 |
34 | //add a empty draw-component to the container
35 | container.addComponent(DrawComponent.create());
36 |
37 |
38 | //create an 5x5 grid of cars
39 | for(x in 0...5){
40 | for(y in 0...5){
41 | var car = Gecko.currentScene.createEntity();
42 | car.transform.parent = container.transform; //set the container transform as the parent transform
43 |
44 | //localPosition is the position inside the parent
45 | car.transform.localPosition.set(x * 40, y * 70);
46 |
47 | //anchor to left-top
48 | car.transform.anchor.set(0,0);
49 |
50 | //sprite component
51 | car.addComponent(SpriteComponent.create("car_green_small_1.png"));
52 | }
53 | }
54 |
55 | //attach to the onUpdate event of gecko a simple function
56 | Gecko.onUpdate += function(delta:Float) {
57 | //rotate the container using delta time
58 | container.transform.rotation += 1 * delta;
59 | };
60 | }
61 | }
62 | ```
63 |
64 |
65 | [Source Code](https://github.com/Nazariglez/Gecko2D/tree/master/examples/parenttransform)
66 |
--------------------------------------------------------------------------------
/examples/bunnyentities/Sources/Game.hx:
--------------------------------------------------------------------------------
1 | package;
2 |
3 |
4 | import gecko.components.draw.TextComponent;
5 | import gecko.components.draw.SpriteComponent;
6 | import gecko.Screen;
7 | import gecko.resources.Font;
8 | import gecko.Color;
9 | import gecko.Graphics;
10 | import gecko.Gecko;
11 | import gecko.Assets;
12 | import gecko.Entity;
13 | import gecko.input.Mouse;
14 |
15 | class Game {
16 | private var _count:Int = 0;
17 | private var _font:Font;
18 |
19 | public function new(){
20 | Assets.load([
21 | "rabbit.png",
22 | "Ubuntu-B.ttf"
23 | ], _onAssetsLoaded).start();
24 | }
25 |
26 | private function _onAssetsLoaded() {
27 | _font = Assets.fonts.get("Ubuntu-B.ttf");
28 |
29 | Gecko.currentScene.addSystem(BounceSystem.create(0.75));
30 | Gecko.onDraw += _onDraw;
31 |
32 | Mouse.enable();
33 | Mouse.onLeftPressed += function(x:Float, y:Float){
34 | _addBunny(100);
35 | };
36 |
37 | Mouse.onRightPressed += function(x:Float, y:Float){
38 | _addBunny(500);
39 | };
40 |
41 | _addBackgroundText();
42 | _addBunny();
43 | }
44 |
45 | private function _onDraw(g:Graphics) {
46 | g.color = Color.White;
47 | g.fillRect(0, 0, 150, 50);
48 | g.color = Color.Black;
49 | g.font = _font;
50 | g.fontSize = 18;
51 | g.drawText('${Gecko.renderTicker.fps}fps - ${Gecko.renderTicker.ms}ms', 10, 5);
52 | g.color = Color.Orange;
53 | g.drawText('Bunnies: ${_count}', 10, 25);
54 | }
55 |
56 | private function _createBunny() : Entity {
57 | var bunny = Entity.create();
58 | bunny.addComponent(SpriteComponent.create("rabbit.png"));
59 | bunny.addComponent(BounceComponent.create(Math.random() * 10, Math.random() * 10 - 5));
60 | return bunny;
61 | }
62 |
63 | private function _addBunny(amount:Int = 1) {
64 | for(i in 0...amount) {
65 | _count++;
66 | Gecko.currentScene.addEntity(_createBunny());
67 | }
68 | }
69 |
70 | private function _addBackgroundText() {
71 | var textEntity = Gecko.currentScene.createEntity();
72 | textEntity.addComponent(TextComponent.create("Left click to add 100 bunnies.\nRight click to add 500 bunnies.", "Ubuntu-B.ttf", 30, "center"));
73 | textEntity.transform.position.set(Screen.centerX, Screen.centerY);
74 | }
75 | }
--------------------------------------------------------------------------------
/examples/khashmup/Sources/systems/PlayerSystem.hx:
--------------------------------------------------------------------------------
1 | package systems;
2 |
3 | import gecko.components.motion.MovementComponent;
4 | import gecko.Entity;
5 | import gecko.math.Rect;
6 | import gecko.input.Keyboard;
7 |
8 | import gecko.IUpdatable;
9 | import gecko.systems.System;
10 |
11 | import components.PlayerComponent;
12 |
13 | class PlayerSystem extends System implements IUpdatable {
14 | public var bounds:Rect;
15 |
16 | public function init(bounds:Rect){
17 | filter.all([PlayerComponent, MovementComponent]);
18 |
19 | this.bounds = bounds;
20 | }
21 |
22 | override public function update(dt:Float) {
23 | eachEntity(function(e:Entity){
24 | var player:PlayerComponent = e.getComponent(PlayerComponent);
25 | var movement:MovementComponent = e.getComponent(MovementComponent);
26 |
27 | //move entity horizontally
28 | if(Keyboard.isDown(player.left)){
29 | movement.speed.x = -player.speed;
30 | }else if(Keyboard.isDown(player.right)){
31 | movement.speed.x = player.speed;
32 | }else{
33 | movement.speed.x = 0;
34 | }
35 |
36 | //move entity vertically
37 | if(Keyboard.isDown(player.up)){
38 | movement.speed.y = -player.speed;
39 | }else if(Keyboard.isDown(player.down)){
40 | movement.speed.y = player.speed;
41 | }else{
42 | movement.speed.y = 0;
43 | }
44 |
45 | //check x bounds
46 | if(e.transform.left < bounds.left){
47 | e.transform.position.x = bounds.left + e.transform.width * e.transform.anchor.x;
48 | }else if(e.transform.right > bounds.right){
49 | e.transform.position.x = bounds.right - e.transform.width * e.transform.anchor.x;
50 | }
51 |
52 | //check y bounds
53 | if(e.transform.top < bounds.top){
54 | e.transform.position.y = bounds.top + e.transform.height * e.transform.anchor.y;
55 | }else if(e.transform.bottom > bounds.bottom){
56 | e.transform.position.y = bounds.bottom - e.transform.height * e.transform.anchor.y;
57 | }
58 | });
59 | }
60 |
61 | override public function beforeDestroy() {
62 | super.beforeDestroy();
63 |
64 | //destroy rect bounds
65 | bounds.destroy();
66 | bounds = null;
67 | }
68 | }
--------------------------------------------------------------------------------
/docs/examples/nineslice.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Nine Slice
3 | ---
4 | # Nine Slice
5 |
6 |
7 |
8 | ```haxe
9 | package;
10 |
11 | import gecko.Assets;
12 | import gecko.Gecko;
13 |
14 | import gecko.math.Random;
15 | import gecko.systems.draw.DrawSystem;
16 | import gecko.components.draw.NineSliceComponent;
17 |
18 | class Game {
19 | var _spritesToLoad = ["images/kenney/grey_button08.png", "images/kenney/green_panel.png"];
20 |
21 | public function new(){
22 | //add the draw system to the current scene
23 | Gecko.currentScene.addSystem(DrawSystem.create());
24 |
25 | //load the assets
26 | Assets.load(_spritesToLoad, _onLoadAssets).start();
27 | }
28 |
29 | //create nine-slice sprites using positon and size
30 | private function _createNineSlice(x:Float, y:Float, width:Float, height:Float) {
31 | //create an entity in the current scene
32 | var entity = Gecko.currentScene.createEntity();
33 |
34 | //set his position in the screen
35 | entity.transform.position.set(x, y);
36 |
37 | //add the nine-slice component using a random spritename and a size
38 | entity.addComponent(NineSliceComponent.create(_getRandomSprite(), width, height));
39 |
40 | //e.renderer.color = _getRandomColor();
41 | entity.transform.anchor.set(0,0);
42 | }
43 |
44 | private function _onLoadAssets() {
45 | //add a lot of nine-slice components in the screen
46 | _createNineSlice(50, 50, 200, 100);
47 | _createNineSlice(50, 170, 100, 400);
48 | _createNineSlice(170, 170, 400, 400);
49 | _createNineSlice(270, 50, 60, 100);
50 | _createNineSlice(350, 50, 40, 40);
51 | _createNineSlice(350, 110, 40, 40);
52 | _createNineSlice(410, 50, 120, 100);
53 | _createNineSlice(550, 50, 200, 40);
54 | _createNineSlice(550, 110, 200, 40);
55 | _createNineSlice(590, 170, 160, 80);
56 | _createNineSlice(590, 270, 60, 300);
57 | _createNineSlice(670, 270, 80, 300);
58 | }
59 |
60 | //return a random spritename
61 | private function _getRandomSprite() : String {
62 | return _spritesToLoad[Random.getUpTo(_spritesToLoad.length-1)];
63 | }
64 | }
65 | ```
66 |
67 |
68 | [Source Code](https://github.com/Nazariglez/Gecko2D/tree/master/examples/nineslice)
69 |
--------------------------------------------------------------------------------
/Sources/gecko/systems/collision/aabb/AABBSystem.hx:
--------------------------------------------------------------------------------
1 | package gecko.systems.collision.aabb;
2 |
3 | import gecko.components.collision.aabb.HitBoxComponent;
4 |
5 |
6 | class AABBSystem extends System implements IUpdatable {
7 | public function init(){
8 | filter.equal(HitBoxComponent);
9 | }
10 |
11 | override public function update(dt:Float) {
12 | eachEntity(function(e:Entity){
13 | var box1:HitBoxComponent = e.getComponent(HitBoxComponent);
14 |
15 | eachEntity(function(e2){
16 | if(e == e2)return;
17 |
18 | var box2:HitBoxComponent = e2.getComponent(HitBoxComponent);
19 |
20 | var canCollideBox1 = box1.canCollideWith(e2);
21 | var canCollideBox2 = box2.canCollideWith(e);
22 |
23 | if(!(canCollideBox1 && canCollideBox2)){
24 | return;
25 | }
26 |
27 | var isAlreadyColliding = box1.isCollidingWith(e2);
28 | var existsCollision = box1.left < box2.right && box1.right > box2.left && box1.top < box2.bottom && box1.bottom > box2.top;
29 |
30 | if(existsCollision){
31 | if(isAlreadyColliding){
32 | if(canCollideBox1) box1.onCollidingWith.emit(e2);
33 | if(canCollideBox2) box2.onCollidingWith.emit(e);
34 | }else{
35 | if(canCollideBox1){
36 | box1.collidingWith.push(e2);
37 | box1.onCollideStart.emit(e2);
38 | }
39 |
40 | if(canCollideBox2){
41 | box2.collidingWith.push(e);
42 | box2.onCollideStart.emit(e);
43 | }
44 | }
45 | }else{
46 | if(isAlreadyColliding){
47 | //todo dispatch always the remove and emit stop because a tag can be change while the system is updating?
48 |
49 | if(canCollideBox1){
50 | box1.collidingWith.remove(e2);
51 | box1.onCollideStop.emit(e2);
52 | }
53 |
54 | if(canCollideBox2){
55 | box2.collidingWith.remove(e);
56 | box2.onCollideStop.emit(e);
57 | }
58 | }
59 | }
60 | });
61 | });
62 | }
63 |
64 | }
--------------------------------------------------------------------------------
/Sources/gecko/macros/KeyboardBuilder.hx:
--------------------------------------------------------------------------------
1 | package gecko.macros;
2 |
3 | #if macro
4 | import haxe.macro.Context;
5 | import haxe.macro.Expr;
6 | using haxe.macro.Tools;
7 | import gecko.input.KeyCode;
8 |
9 | class KeyboardBuilder {
10 | public static macro function build():Array {
11 |
12 | var fields = haxe.macro.Context.getBuildFields();
13 | var n1 = $a{_getKeyNames(KeyCode)};
14 | var n2 = $a{_getKeyValues(KeyCode)};
15 |
16 | var map:Array = [];
17 |
18 | //fix this little hack. If this line is deleted the compiler send an error (array access is not allowd)
19 | n1[0] = n1[0];
20 |
21 | for(i in 0...n1.length){
22 | var name = n1[i];
23 | //trace(name);
24 | var key = n2[i];
25 | map.push(macro $v{name} => cast($v{key}, KeyCode));
26 | }
27 |
28 | fields.push({
29 | name: "keyList",
30 | access: [Access.APublic, Access.AStatic],
31 | kind: FieldType.FVar(macro:Map, macro $a{map}),
32 | pos: haxe.macro.Context.currentPos(),
33 | });
34 |
35 | return fields;
36 | }
37 |
38 | private static macro function _getKeyNames(typePath:Expr):Expr {
39 | var type = Context.getType(typePath.toString());
40 |
41 | switch (type.follow()) {
42 | case TAbstract(_.get() => ab, _) if (ab.meta.has(":enum")):
43 | var valueExprs = [];
44 | for (field in ab.impl.get().statics.get()) {
45 | if (field.meta.has(":enum") && field.meta.has(":impl")) {
46 | valueExprs.push(macro $v{field.name.toLowerCase()});
47 | }
48 | }
49 | return macro $a{valueExprs};
50 | default:
51 | throw new Error(type.toString() + " should be @:enum abstract", typePath.pos);
52 | }
53 | }
54 |
55 |
56 | private static macro function _getKeyValues(typePath:Expr):Expr {
57 | var type = Context.getType(typePath.toString());
58 |
59 | switch (type.follow()) {
60 | case TAbstract(_.get() => ab, _) if (ab.meta.has(":enum")):
61 | var valueExprs = [];
62 | for (field in ab.impl.get().statics.get()) {
63 | if (field.meta.has(":enum") && field.meta.has(":impl")) {
64 | var fieldName = field.name;
65 | valueExprs.push(macro $typePath.$fieldName);
66 | }
67 | }
68 | return macro $a{valueExprs};
69 | default:
70 | throw new Error(type.toString() + " should be @:enum abstract", typePath.pos);
71 | }
72 | }
73 | }
74 | #end
--------------------------------------------------------------------------------
/docs/examples/drawshapes.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Draw Shapes
3 | ---
4 | # Draw Shapes
5 |
6 |
7 | ```haxe
8 | package;
9 |
10 | import gecko.Gecko;
11 | import gecko.Color;
12 | import gecko.Float32;
13 | import gecko.math.Point;
14 | import gecko.components.draw.CircleComponent;
15 | import gecko.components.draw.RectangleComponent;
16 | import gecko.components.draw.PolygonComponent;
17 | import gecko.components.draw.DrawComponent;
18 |
19 | class Game {
20 | public function new(){
21 | //circles
22 | _createShape(100, 150, CircleComponent.create(true, 60), Color.Red); //fill
23 | _createShape(300, 150, CircleComponent.create(false, 60, 8), Color.Red);
24 |
25 | //rects
26 | _createShape(500, 150, RectangleComponent.create(true, 120, 120), Color.Green); //fill
27 | _createShape(700, 150, RectangleComponent.create(false, 120, 120, 8), Color.Green);
28 |
29 | //triangles
30 | var trianglePoints = [Point.create(60, 0), Point.create(0, 120), Point.create(120, 120)];
31 | _createShape(100, 400, PolygonComponent.create(true, trianglePoints), Color.Blue); //fill
32 | _createShape(300, 400, PolygonComponent.create(false, trianglePoints, 8), Color.Blue);
33 |
34 | //hexagons
35 | var hexagonPoints = [
36 | Point.create(0, 40),
37 | Point.create(40, 0),
38 | Point.create(80, 0),
39 | Point.create(120, 40),
40 | Point.create(120, 80),
41 | Point.create(80, 120),
42 | Point.create(40, 120),
43 | Point.create(0, 80)
44 | ];
45 | _createShape(500, 400, PolygonComponent.create(true, hexagonPoints), Color.Yellow); //fill
46 | _createShape(700, 400, PolygonComponent.create(false, hexagonPoints, 8), Color.Yellow);
47 |
48 | }
49 |
50 | //create a generic entitiy to add a shape draw component
51 | private function _createShape(x:Float32, y:Float32, shapeComponent:DrawComponent, color:Color) {
52 | //create an entity in the current scene
53 | var entity = Gecko.currentScene.createEntity();
54 |
55 | //add the shape component
56 | entity.addComponent(shapeComponent);
57 | shapeComponent.color = color; //set a color for the shape
58 |
59 | //set the position to draw the entity on the screen
60 | entity.transform.position.set(x, y);
61 | }
62 | }
63 | ```
64 |
65 | [Source Code](https://github.com/Nazariglez/Gecko2D/tree/master/examples/drawshapes)
66 |
--------------------------------------------------------------------------------
/docs/examples/shapes.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Shapes
3 | ---
4 | # Shapes
5 |
6 |
7 |
8 | ```haxe
9 | package;
10 |
11 | import gecko.Gecko;
12 | import gecko.Color;
13 |
14 | import gecko.math.Point;
15 | import gecko.components.draw.CircleComponent;
16 | import gecko.components.draw.RectangleComponent;
17 | import gecko.components.draw.PolygonComponent;
18 | import gecko.components.draw.DrawComponent;
19 |
20 | class Game {
21 | public function new(){
22 | //circles
23 | _createShape(100, 150, CircleComponent.create(true, 60), Color.Red); //fill
24 | _createShape(300, 150, CircleComponent.create(false, 60, 8), Color.Red);
25 |
26 | //rects
27 | _createShape(500, 150, RectangleComponent.create(true, 120, 120), Color.Green); //fill
28 | _createShape(700, 150, RectangleComponent.create(false, 120, 120, 8), Color.Green);
29 |
30 | //triangles
31 | var trianglePoints = [Point.create(60, 0), Point.create(0, 120), Point.create(120, 120)];
32 | _createShape(100, 400, PolygonComponent.create(true, trianglePoints), Color.Blue); //fill
33 | _createShape(300, 400, PolygonComponent.create(false, trianglePoints, 8), Color.Blue);
34 |
35 | //hexagons
36 | var hexagonPoints = [
37 | Point.create(0, 40),
38 | Point.create(40, 0),
39 | Point.create(80, 0),
40 | Point.create(120, 40),
41 | Point.create(120, 80),
42 | Point.create(80, 120),
43 | Point.create(40, 120),
44 | Point.create(0, 80)
45 | ];
46 | _createShape(500, 400, PolygonComponent.create(true, hexagonPoints), Color.Yellow); //fill
47 | _createShape(700, 400, PolygonComponent.create(false, hexagonPoints, 8), Color.Yellow);
48 |
49 | }
50 |
51 | //create a generic entitiy to add a shape draw component
52 | private function _createShape(x:Float, y:Float, shapeComponent:DrawComponent, color:Color) {
53 | //create an entity in the current scene
54 | var entity = Gecko.currentScene.createEntity();
55 |
56 | //add the shape component
57 | entity.addComponent(shapeComponent);
58 | shapeComponent.color = color; //set a color for the shape
59 |
60 | //set the position to draw the entity on the screen
61 | entity.transform.position.set(x, y);
62 | }
63 | }
64 | ```
65 |
66 |
67 | [Source Code](https://github.com/Nazariglez/Gecko2D/tree/master/examples/shapes)
68 |
--------------------------------------------------------------------------------
/Sources/gecko/systems/motion/MotionSystem.hx:
--------------------------------------------------------------------------------
1 | package gecko.systems.motion;
2 |
3 | import gecko.components.motion.RotationComponent;
4 | import gecko.components.motion.MovementComponent;
5 |
6 |
7 | class MotionSystem extends System implements IUpdatable {
8 | public function init(){
9 | filter.any([MovementComponent, RotationComponent]);
10 | }
11 |
12 | override public function update(dt:Float) {
13 | eachEntity(function(e:Entity){
14 | var transform:Transform = e.transform;
15 | var movement:MovementComponent = e.getComponent(MovementComponent);
16 | var rotation:RotationComponent = e.getComponent(RotationComponent);
17 |
18 | if(movement != null){
19 | //accel and friction
20 | if(movement.acceleration.x != 0){
21 |
22 | movement.speed.x += movement.acceleration.x*dt;
23 |
24 | }else if(movement.friction.x > 0 && movement.speed.x != 0){
25 |
26 | var fx = movement.friction.x*dt;
27 |
28 | if(movement.speed.x > 0){
29 | movement.speed.x -= fx;
30 | if(movement.speed.x < 0)movement.speed.x = 0;
31 | }else if(movement.speed.x < 0){
32 | movement.speed.x += fx;
33 | if(movement.speed.x > 0)movement.speed.x = 0;
34 | }
35 |
36 | }
37 |
38 | if(movement.acceleration.y != 0){
39 |
40 | movement.speed.y += movement.acceleration.y*dt;
41 |
42 | }else if(movement.friction.y > 0 && movement.speed.y != 0){
43 |
44 | var fy = movement.friction.y*dt;
45 |
46 | if(movement.speed.y > 0){
47 | movement.speed.y -= fy;
48 | if(movement.speed.y < 0)movement.speed.y = 0;
49 | }else if(movement.speed.y < 0){
50 | movement.speed.y += fy;
51 | if(movement.speed.y > 0)movement.speed.y = 0;
52 | }
53 |
54 | }
55 |
56 | //speed update the current position
57 | transform.position.set(
58 | transform.localPosition.x + movement.speed.x*dt,
59 | transform.localPosition.y + movement.speed.y*dt
60 | );
61 | }
62 |
63 | if(rotation != null){
64 | rotation.speed += rotation.acceleration*dt;
65 | transform.localRotation += rotation.speed*dt;
66 | }
67 | });
68 | }
69 | }
--------------------------------------------------------------------------------
/Sources/gecko/utils/EventEmitter.hx:
--------------------------------------------------------------------------------
1 | package gecko.utils;
2 |
3 | import haxe.macro.Expr;
4 | import haxe.macro.Context;
5 |
6 | class EventEmitter {
7 | public var eventsOnce:Map> = new Map>();
8 | public var events:Map> = new Map>();
9 |
10 | public function new(){}
11 |
12 | public macro function emit(e1:Expr, extra:Array) {
13 | var eventName = extra.shift();
14 | var e = macro evt($a{extra});
15 | return macro {
16 | if($e1.eventsOnce.exists($eventName)){
17 | for(evt in $e1.eventsOnce[$eventName]){
18 | $e;
19 | }
20 | }
21 |
22 | if($e1.events.exists($eventName)){
23 | for(evt in $e1.events[$eventName]){
24 | $e;
25 | }
26 | }
27 | };
28 | }
29 |
30 | public function emitReflect(event:String, args: Dynamic = null){
31 | if(eventsOnce.exists(event)){
32 | for(evt in eventsOnce[event]){
33 | Reflect.callMethod(null, evt, args);
34 | off(event, evt);
35 | }
36 | }
37 |
38 | if(events.exists(event)){
39 | for(evt in events[event]){
40 | Reflect.callMethod(null, evt, args);
41 | }
42 | }
43 | }
44 |
45 | public function on(event:String, handler:Dynamic, once:Bool = false){
46 | if(handler == null){
47 | return;
48 | }
49 |
50 | if(!once){
51 | if(!events.exists(event)){
52 | events[event] = [];
53 | }
54 |
55 | events[event].push(handler);
56 | }else{
57 | if(!eventsOnce.exists(event)){
58 | eventsOnce[event] = [];
59 | }
60 |
61 | eventsOnce[event].push(handler);
62 | }
63 | }
64 |
65 | public function off(event:String, handler:Dynamic){
66 | if(handler == null){
67 | return;
68 | }
69 |
70 | if(eventsOnce.exists(event)){
71 | eventsOnce[event].remove(handler);
72 | if(eventsOnce[event].length == 0){
73 | eventsOnce.remove(event);
74 | }
75 | }
76 |
77 | if(events.exists(event)){
78 | events[event].remove(handler);
79 | if(events[event].length == 0){
80 | events.remove(event);
81 | }
82 | }
83 | }
84 |
85 | public function removeAllListeners(event:String) {
86 | events.remove(event);
87 | eventsOnce.remove(event);
88 | }
89 | }
--------------------------------------------------------------------------------
/examples/demo/Sources/scenes/Camera1Scene.hx:
--------------------------------------------------------------------------------
1 | package scenes;
2 |
3 | import gecko.Camera;
4 | import gecko.components.misc.BehaviorComponent;
5 | import gecko.Camera.CameraStyle;
6 | import gecko.math.Rect;
7 | import gecko.Graphics;
8 |
9 | import gecko.input.KeyCode;
10 | import gecko.input.Keyboard;
11 | import gecko.components.draw.SpriteComponent;
12 | import gecko.components.draw.ScrollingSpriteComponent;
13 |
14 | using gecko.utils.MathHelper;
15 |
16 | class Camera1Scene extends CustomScene {
17 | override public function init(closeButton:Bool = false) {
18 | super.init(closeButton);
19 |
20 | _createExample();
21 | }
22 |
23 | private function _createExample() {
24 | var BG_WIDTH = 2000;
25 | var BG_HEIGHT = 2000;
26 |
27 | var cam = createCamera();
28 |
29 | var bg = createEntity();
30 | bg.addComponent(GridBackgroundComponent.create("images/kenney/starBackground.png", BG_WIDTH, BG_HEIGHT));
31 | bg.transform.position.set(BG_WIDTH/2, BG_HEIGHT/2);
32 |
33 | var player = createEntity();
34 | player.addComponent(SpriteComponent.create("images/kenney/enemyUFO.png"));
35 | player.transform.position.set(BG_WIDTH/2, BG_HEIGHT/2);
36 | player.addComponent(PlayerMovement.create(cam));
37 |
38 | cam.follow(player, CameraStyle.LOCKON, 0.4, 0.4);
39 | cam.bounds = Rect.create(0, 0, BG_WIDTH, BG_HEIGHT);
40 | }
41 | }
42 |
43 | class PlayerMovement extends BehaviorComponent {
44 | public var cam:Camera;
45 |
46 | public function init(cam:Camera) {
47 | this.cam = cam;
48 | }
49 |
50 | override public function update(dt:Float) {
51 | if(Keyboard.isDown(KeyCode.Left)) entity.transform.position.x -= 350*dt;
52 | if(Keyboard.isDown(KeyCode.Right)) entity.transform.position.x += 350*dt;
53 | if(Keyboard.isDown(KeyCode.Up)) entity.transform.position.y -= 350*dt;
54 | if(Keyboard.isDown(KeyCode.Down)) entity.transform.position.y += 350*dt;
55 | if(Keyboard.isDown(KeyCode.Z)) cam.rotation += (10).toRadians() * dt;
56 | if(Keyboard.isDown(KeyCode.X)) cam.rotation -= (10).toRadians() * dt;
57 |
58 | if(Keyboard.isDown(KeyCode.A) && cam.zoom > 0.5) cam.zoom -= 0.1*dt;
59 | if(Keyboard.isDown(KeyCode.S) && cam.zoom < 1.5) cam.zoom += 0.1*dt;
60 | }
61 |
62 | override public function beforeDestroy() {
63 | super.beforeDestroy();
64 | cam = null;
65 | }
66 | }
67 |
68 | //Custom drawableComponent to draw a grid
69 | class GridBackgroundComponent extends ScrollingSpriteComponent {
70 | override public function draw(g:Graphics) {
71 | super.draw(g);
72 |
73 | var cols = Std.int(width/100);
74 | var rows = Std.int(height/100);
75 |
76 | g.color = 0xEEEEEE;
77 |
78 | for(xx in 0...cols){
79 | for(yy in 0...rows){
80 | g.drawLine(0, yy*100, width, yy*100, 5);
81 | g.drawLine(xx*100, 0, xx*100, height, 5);
82 | }
83 | }
84 |
85 | }
86 | }
--------------------------------------------------------------------------------