/tetrapack

🎮 extension for Tetra (2D game framework)

Primary LanguageRustMIT LicenseMIT

License: MIT

tetrapack 🎒

Extension for the 2D game framework Tetra

While creating my games I filled the tetrapack with useful extensions.
As far as possible I tried to create them independently so that they can be used in other games.

[dependencies.tetrapack]
git = "https://github.com/puppetmaster-/tetrapack"
default-features = false
features = [...]

Features

Feature Description
animation load crate keyframe, is needed for the tetra splash_screen
randomize load crates rand and rand_core
ron_file load crates ron, serde, serde_derive and requires tetra serde_support feature
tilemap load both tilemap features (tilemap_json and tilemap_xml)
tilemap_json load crates serde_json, serde, serde_derive and requires tetra serde_support feature
tilemap_xml load crates serde-xml-rs, serde, serde_derive
sound requires one of the sound features of tetra
all I only use it for testing, of course you could also use it too, then everything is always loaded
default no additional crates are loaded only a few tetrapack extensions are still available

Extensions

Timer runs once and returns a value between 0 and 1.

let my_timer2 = Timer::new(1800);
let my_timer = Timer::new_sec(30);

Can be used as background music. The music is faded in and faded out when stopped manually.
Can be configured with a repeat interval.

// play music.ogg and repeat it after 300 seconds
let my_music = Music::new(ctx,include_bytes!("../../assets/music.ogg"),300)?;

Can be used to draw a custom mouse cursor.

there are the following fixed actions: is_any_key(), is_cancel(),is_confirmation()
and they must be used in the event() function

fn event(&mut self, _ctx: &mut Context, event: Event) -> tetra::Result {
    if is_any_key(&event){
        // do something
    }
    Ok()
}

Tilemap is the extension I use most often and has already gone through many iterations.

It can for example be created by a PyxelEdit tilemap (json).

let my_tilemap = Tilemap::from_pyxeledit(Rectangle::new(0.0,0.0,512.0,512.0),include_str!("../../assets/tilemap.json"));

this is how the visibility of the layer can be set

my_tilemap.visibility(my_tilemap.get_layer_id("logic"),false);

this way a single layer can be drawn

self.my_tilemap.draw_layer(ctx,&self.atlas,TetraVec2::zero(),self.my_tilemap.get_layer_id("top"));

The player start position can be read out this way.

let player_pos = my_tilemap.get_position_from_id(my_tilemap.get_layer_id("logic"),0);

and much more...

If you have a tilemap then you can also create a TileAnimation.

let my_tileanimation = TileAnimation::new(&my_tilemap,&[10,11],vec![Duration::from_millis(1000), Duration::from_millis(500)]);

Custom Type

TetraVec2 as tetra::math::Vec2<f32>


It would be great if this list would grow further...

I have been programming as a hobby for around a year in rust.
It is very possible that my code does not comply with the textbook and contains errors.
If you find something that can be solved better or more elegantly or if you even have a new useful extension,
it would be great if you could contribute to this project then we can all benefit from each other.

Have fun using and extending it.