Skip to content

Instantly share code, notes, and snippets.

Avatar
💤
busy with irl stuff

Joe Clay 17cupsofcoffee

💤
busy with irl stuff
View GitHub Profile
@17cupsofcoffee
17cupsofcoffee / main.rs
Created Mar 4, 2021
A blank Tetra template
View main.rs
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 Sep 8, 2021
Multi-threaded Asset Loading with Tetra
View main.rs
//! 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 Jan 7, 2021
Triangle From Scratch (but it's web)
View Cargo.toml
[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 Sep 6, 2020
Simple crash logging in Tetra
View main.rs
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!(
View main.rs
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 Dec 9, 2019
Pooling sound effects in Tetra
View README.md

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 Sep 17, 2019
Splitting animation state from the texture in Tetra
View anim_state.rs
use tetra::graphics::Rectangle;
#[derive(Debug, Clone)]
pub struct AnimationState {
frames: Vec<Rectangle>,
frame_length: i32,
current_frame: usize,
timer: i32,
}
View vecgrid.rs
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 Mar 2, 2019
main and lib in the same crate
View Cargo.toml
[package]
name = "example"
version = "0.1.0"
authors = ["Joe Clay <27cupsofcoffee@gmail.com>"]
edition = "2018"
[dependencies]
View AkkaMUD04.fs
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 =