Skip to content

Commit 61d45bd

Browse files
authored
Merge pull request #5 from 01010111/dev
Dev
2 parents 17777c8 + dd0d966 commit 61d45bd

File tree

9 files changed

+230
-12
lines changed

9 files changed

+230
-12
lines changed

.travis.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
sudo: required
2+
dist: trusty
3+
4+
language: haxe
5+
6+
haxe:
7+
- "3.4.7"
8+
- "development"
9+
10+
matrix:
11+
allow_failures:
12+
- haxe: development
13+
14+
install:
15+
- haxelib dev zerolib .
16+
17+
script:
18+
- lime build neko
19+
20+
deploy:
21+
- provider: script
22+
haxe: 3.4.7
23+
script: bash ./release_haxelib.sh $HAXELIB_PWD
24+
on:
25+
tags: true

haxelib.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"tags": ["game", "flixel", "openfl", "flash", "html5", "neko", "cpp", "android", "ios", "cross"],
66
"description": "Zerolib is a library of extensions, utilities, and other helpful classes for making games quickly in haxeflixel!",
77
"version": "0.2.3",
8+
"classPath": "zero",
89
"releasenote": "A few bugfixes, better documentation",
910
"contributors": ["01010111"],
1011
"dependencies": {

project.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<project>
3+
<!-- _________________________ Application Settings _________________________ -->
4+
5+
<app title="zerolib" file="zerolib" main="Main" version="0.0.1" company="01010111" />
6+
7+
<!-- _____________________________ Path Settings ____________________________ -->
8+
9+
<classpath name="src" />
10+
11+
<!-- _______________________________ Libraries ______________________________ -->
12+
13+
<haxelib name="flixel" />
14+
<haxelib name="flixel-addons" />
15+
<haxelib name="zerolib" />
16+
17+
<!-- _________________________________ Custom _______________________________ -->
18+
19+
<haxeflag name="--macro" value="include('zero')" />
20+
21+
</project>

release_haxelib.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
rm -f zerolib.zip
3+
zip -r zerolib.zip zero *.md *.json *.hxml run.n
4+
haxelib submit zerolib.zip $HAXELIB_PWD --always

src/Main.hx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package;
2+
class Main { public static function main() {} }
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package zero.flxutil.ecs.components;
2+
3+
import zero.flxutil.ecs.Component;
4+
import flixel.FlxObject.*;
5+
6+
using Math;
7+
8+
/**
9+
* An Animator component for a basic Platformer entity
10+
*/
11+
class PlatformerAnimator extends Component
12+
{
13+
14+
var idle:String;
15+
var walk:String;
16+
var jump:String;
17+
var fall:String;
18+
19+
/**
20+
* Creates a new Animator component for a platformer entity
21+
* @param idle Idle animation name
22+
* @param walk Walk animation name
23+
* @param jump Jump animation name
24+
* @param fall Fall animation name
25+
*/
26+
public function new(idle:String = 'idle', walk:String = 'walk', jump:String = 'jump', fall:String = 'fall')
27+
{
28+
super('platformer_animation');
29+
this.idle = idle;
30+
this.walk = walk;
31+
this.jump = jump;
32+
this.fall = fall;
33+
}
34+
35+
@:dox(hide)
36+
override function update(dt:Float)
37+
{
38+
super.update(dt);
39+
entity.animation.play(animate());
40+
}
41+
42+
function animate():String
43+
{
44+
return entity.isTouching(FLOOR) ? velocity.x.abs() > 0 ? walk : idle : velocity.y > 0 ? jump : fall;
45+
}
46+
47+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package zero.flxutil.ecs.components;
2+
3+
import flixel.FlxObject.*;
4+
import zero.flxutil.input.Controller;
5+
import zero.flxutil.ecs.Component;
6+
7+
/**
8+
* A Component to make an entity in a platformer Jump
9+
*/
10+
class PlatformerJumper extends Component
11+
{
12+
13+
var jump_power:Float;
14+
var jump_button:ControllerButton;
15+
var controller:Controller;
16+
var coyote_time:Float;
17+
18+
var coyote_timer:Float;
19+
var just_jumped_timer:Float;
20+
21+
/**
22+
* Create a new Jumper component with options
23+
* @param options
24+
*/
25+
public function new(options:JumperOptions)
26+
{
27+
super('jumper');
28+
jump_power = options.jump_power;
29+
jump_button = options.jump_button;
30+
controller = options.controller;
31+
coyote_time = options.coyote_time;
32+
}
33+
34+
@:dox(hide)
35+
override public function update(dt:Float)
36+
{
37+
if (coyote_timer > 0) coyote_timer -= dt;
38+
if (just_jumped_timer > 0) just_jumped_timer -= dt;
39+
40+
if (entity.wasTouching & FLOOR > 0) coyote_timer = coyote_time;
41+
if (controller.get_just_pressed(jump_button)) just_jumped_timer = coyote_time;
42+
if (controller.get_just_released(jump_button) && entity.velocity.y < 0) entity.velocity.y *= 0.5;
43+
44+
if (just_jumped_timer <= 0 || coyote_timer <= 0) return;
45+
entity.velocity.y = -jump_power;
46+
just_jumped_timer = 0;
47+
}
48+
49+
}
50+
51+
typedef JumperOptions =
52+
{
53+
controller:Controller,
54+
jump_power:Float,
55+
jump_button:ControllerButton,
56+
coyote_time:Float
57+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package zero.flxutil.ecs.components;
2+
3+
import flixel.FlxObject.*;
4+
import zero.flxutil.input.Controller;
5+
import zero.flxutil.ecs.Component;
6+
7+
/**
8+
* A Component to make an entity in a platformer Walk
9+
*/
10+
class PlatformerWalker extends Component
11+
{
12+
13+
var controller:Controller;
14+
var walk_speed:Float;
15+
var accel_amt:Float;
16+
var drag_amt:Float;
17+
18+
/**
19+
* Create a new Walker component with options
20+
* @param options
21+
*/
22+
public function new(options:WalkerOptions)
23+
{
24+
super('walker');
25+
controller = options.controller;
26+
walk_speed = options.walk_speed;
27+
accel_amt = options.acceleration_force;
28+
drag_amt = options.drag_force;
29+
}
30+
31+
override function on_add()
32+
{
33+
entity.maxVelocity.x = walk_speed;
34+
drag.x = drag_amt;
35+
}
36+
37+
override public function update(dt:Float)
38+
{
39+
acceleration.x = 0;
40+
if (controller.get_pressed(DPAD_LEFT)) acceleration.x -= accel_amt;
41+
if (controller.get_pressed(DPAD_RIGHT)) acceleration.x += accel_amt;
42+
if (entity.facing == LEFT && velocity.x > 0 || entity.facing == RIGHT && velocity.x < 0) velocity.x *= 0.5;
43+
entity.facing = acceleration.x < 0 ? LEFT : acceleration.x > 0 ? RIGHT : entity.facing;
44+
}
45+
46+
}
47+
48+
typedef WalkerOptions =
49+
{
50+
controller:Controller,
51+
walk_speed:Float,
52+
acceleration_force:Float,
53+
drag_force:Float
54+
}

zero/flxutil/editors/ZomeLoader.hx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package zero.flxutil.editors;
22

33
import flixel.tile.FlxTilemap;
44
import flixel.tile.FlxBaseTilemap;
5-
import flixel.tile.FlxTilemapExt;
5+
import flixel.addons.tile.FlxTilemapExt;
66
import flixel.system.FlxAssets;
7+
import haxe.Json;
78

89
/**
910
* A class for loading json levels created with ZOME (01010111/itch.io/zome)
@@ -21,7 +22,7 @@ class ZomeLoader
2122
*/
2223
public function new(json_path:String, tileset_folder:String = 'assets/images/')
2324
{
24-
this.level = openfl.Assets.getText(json_path);
25+
this.level = Json.parse(openfl.Assets.getText(json_path));
2526
this.tileset_folder = tileset_folder;
2627
}
2728

@@ -45,7 +46,7 @@ class ZomeLoader
4546
public function get_tilemap(?options:TilemapOptions):FlxTilemap
4647
{
4748
var tilemap = new FlxTilemap();
48-
tilemap.load_tilemap(tilemap, options);
49+
load_tilemap(tilemap, options);
4950
return tilemap;
5051
}
5152

@@ -57,12 +58,12 @@ class ZomeLoader
5758
public function get_tilemap_ext(?options:TilemapExtOptions):FlxTilemapExt
5859
{
5960
var tilemap = new FlxTilemapExt();
60-
tilemap.load_tilemap(tilemap, options.tilemap_options);
61+
load_tilemap(tilemap, options.tilemap_options);
6162
tilemap.setSlopes(options.northwest_slopes, options.northeast_slopes, options.southwest_slopes, options.southeast_slopes);
6263
return tilemap;
6364
}
6465

65-
function load_tilemap(tilemap:FlxBaseTilemap, options:TilemapOptions)
66+
function load_tilemap(tilemap:FlxTilemap, options:TilemapOptions)
6667
{
6768
options = prep_tilemap_options(options);
6869
tilemap.loadMapFrom2DArray(
@@ -76,6 +77,7 @@ class ZomeLoader
7677
options.collide_index
7778
);
7879
if (options.collision_array != null) set_tile_properties(tilemap, options.collision_array);
80+
if (options.follow) tilemap.follow();
7981
}
8082

8183
function prep_tilemap_options(options:TilemapOptions):TilemapOptions
@@ -87,10 +89,14 @@ class ZomeLoader
8789
if (options.starting_index == null) options.starting_index = 0;
8890
if (options.draw_index == null) options.draw_index = 0;
8991
if (options.collide_index == null) options.collide_index = 1;
92+
if (options.follow == null) options.follow = true;
9093
return options;
9194
}
9295

93-
function set_tile_properties(tilemap:FlxBaseTilemap, collision_array:Array<Int>) for (tile in collision_array) tilemap.setTileProperties(tile, collision_array[tile]);
96+
function set_tile_properties(tilemap:FlxTilemap, collision_array:Array<Int>)
97+
{
98+
for (i in 0...collision_array.length) tilemap.setTileProperties(i, collision_array[i]);
99+
}
94100

95101
}
96102

@@ -109,14 +115,15 @@ typedef TilemapOptions =
109115
?starting_index:Int,
110116
?draw_index:Int,
111117
?collide_index:Int,
112-
?collision_array:Array<Int>
118+
?collision_array:Array<Int>,
119+
?follow:Bool
113120
}
114121

115122
typedef TilemapExtOptions =
116123
{
117-
tilemap_options:TilemapOptions,
118-
northeast_slopes:Array<Int>,
119-
northwest_slopes:Array<Int>,
120-
southeast_slopes:Array<Int>,
121-
southwest_slopes:Array<Int>
124+
?tilemap_options:TilemapOptions,
125+
?northeast_slopes:Array<Int>,
126+
?northwest_slopes:Array<Int>,
127+
?southeast_slopes:Array<Int>,
128+
?southwest_slopes:Array<Int>
122129
}

0 commit comments

Comments
 (0)