Skip to content

Instantly share code, notes, and snippets.

View 17cupsofcoffee's full-sized avatar

Joe Clay 17cupsofcoffee

View GitHub Profile
@17cupsofcoffee
17cupsofcoffee / main.rs
Created March 4, 2021 18:05
A blank Tetra template
use tetra::graphics::scaling::{ScalingMode, ScreenScaler};
use tetra::graphics::{self, Color};
use tetra::input::{self, Key};
use tetra::{Context, ContextBuilder, Event, State};
struct Assets {
// assets go here...
}
impl Assets {
@17cupsofcoffee
17cupsofcoffee / main.rs
Last active September 8, 2021 11:13
Multi-threaded Asset Loading with Tetra
//! This is an example of one way you could achieve multi-threaded asset loading with Tetra
//! (or any other Rust game framework).
//!
//! The design is intended to be similar to:
//!
//! * https://github.com/kikito/love-loader
//! * https://github.com/libgdx/libgdx/wiki/Managing-your-assets
//!
//! This should not be taken as production-ready code (for one thing, it only supports
//! textures!) or the 'best' way of implementing this functionality. It's just an example
@17cupsofcoffee
17cupsofcoffee / Cargo.toml
Created January 7, 2021 23:04
Triangle From Scratch (but it's web)
[package]
name = "triangle-from-scratch"
version = "0.1.0"
authors = ["Joe Clay <27cupsofcoffee@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib"]
@17cupsofcoffee
17cupsofcoffee / main.rs
Created September 6, 2020 19:10
Simple crash logging in Tetra
fn run() -> tetra::Result {
ContextBuilder::new("My Game", 1280, 720)
.build()?
.run(GameState::new)
}
fn report_crash(err: TetraError) {
let mut crash_log = File::create("./crash_log.txt").unwrap();
write!(
use ggez::{event, graphics, nalgebra, Context, GameResult};
struct MainState {
spritebatch: graphics::spritebatch::SpriteBatch,
}
impl MainState {
fn new(ctx: &mut Context) -> GameResult<MainState> {
let width: f32 = 128.0;
let height: f32 = 128.0;
@17cupsofcoffee
17cupsofcoffee / README.md
Created December 9, 2019 21:56
Pooling sound effects in Tetra

Here's a quick example of how you can pool instances of a sound effect in Tetra! There's a few advantages to doing this:

  • You cap the number of identical sounds that can play at once, which avoids you accidentally calling play in a loop and blowing out your speakers (not speaking from experience, honest 😅).
  • It gives you a central place to apply variations to the sound - e.g. you could make it so the pitch gets set to a slightly randomized value each time.
  • It's probably slightly more performant than spawning new SoundInstances every time (as always, avoid premature optimization).
@17cupsofcoffee
17cupsofcoffee / anim_state.rs
Created September 17, 2019 17:41
Splitting animation state from the texture in Tetra
use tetra::graphics::Rectangle;
#[derive(Debug, Clone)]
pub struct AnimationState {
frames: Vec<Rectangle>,
frame_length: i32,
current_frame: usize,
timer: i32,
}
pub struct VecGrid<T> {
data: Vec<T>,
width: usize,
height: usize,
}
impl<T> VecGrid<T> {
pub fn new(width: usize, height: usize) -> VecGrid<T> {
VecGrid {
data: Vec::with_capacity(width * height),
@17cupsofcoffee
17cupsofcoffee / Cargo.toml
Last active March 2, 2019 17:33
main and lib in the same crate
[package]
name = "example"
version = "0.1.0"
authors = ["Joe Clay <27cupsofcoffee@gmail.com>"]
edition = "2018"
[dependencies]
open System.Net
open System.Text
open Akka
open Akka.FSharp
open Akka.IO
open Akka.Actor
let system = System.create "system" (Configuration.defaultConfig())
type GreeterMsg =