Skip to content

Add runty8-graphics crate #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ edition = "2021"
default-run = "runty8"
readme = "README.md"

[workspace]
members = ["runty8-graphics"]

[dependencies]
glium = "*"
itertools = "*"
rand = "*"
runty8-graphics = { path = "./runty8-graphics" }
1 change: 0 additions & 1 deletion examples/celeste/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::f32::consts::{FRAC_1_SQRT_2, PI};
use std::path::Path;

use rand::Rng;
use runty8::{App, Button, Pico8};
Expand Down
36 changes: 36 additions & 0 deletions examples/circles/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use runty8::{self, App, Button, Pico8};

fn main() {
runty8::run_app::<Circles>("examples/circles".to_owned()).unwrap();
}

struct Circles {}
impl Circles {
fn do_draw(&self, pico8: &mut Pico8) {
pico8.cls(0);

pico8.rect(0, 0, 127, 127, 7);
for i in 0..=7 {
pico8.circ(5 + i * 15, 64, i, 7);
pico8.circfill(5 + i * 15, 84, i, 7);
pico8.pset(5 + i * 15, 64, 9);
}
}
}

impl App for Circles {
fn init(pico8: &mut Pico8) -> Self {
let this = Self {};

this.do_draw(pico8);
this
}

fn update(&mut self, pico8: &mut Pico8) {
if pico8.btnp(Button::C) {
self.do_draw(pico8);
}
}

fn draw(&mut self, _: &mut Pico8) {}
}
53 changes: 53 additions & 0 deletions examples/shapes/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use rand::Rng;
use runty8::{self, App, Button, Pico8};

fn main() {
runty8::run_app::<Circles>("examples/circles".to_owned()).unwrap();
}

struct Circles {}
impl Circles {
fn do_draw(&self, pico8: &mut Pico8) {
pico8.cls(0);

pico8.rect(0, 0, 127, 127, 7);

fn rand(n: i32) -> i32 {
rand::thread_rng().gen_range(0..n)
}

for _ in 0..=7 {
pico8.rectfill(
rand(128),
rand(128),
rand(128),
rand(128),
rand::thread_rng().gen_range(9..16),
);
pico8.rect(
rand(128),
rand(128),
rand(128),
rand(128),
rand::thread_rng().gen_range(1..8),
);
}
}
}

impl App for Circles {
fn init(pico8: &mut Pico8) -> Self {
let this = Self {};

this.do_draw(pico8);
this
}

fn update(&mut self, pico8: &mut Pico8) {
if pico8.btnp(Button::C) {
self.do_draw(pico8);
}
}

fn draw(&mut self, _: &mut Pico8) {}
}
56 changes: 56 additions & 0 deletions examples/sprites/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use runty8::{self, App, Button, Pico8};

fn main() {
runty8::run_app::<Sprites>("examples/sprites".to_owned()).unwrap();
}

struct Sprites {}
impl Sprites {
fn do_draw(&self, pico8: &mut Pico8) {
pico8.cls(0);

for i in 0..(128 / 8) {
pico8.line(0, i * 8, 127, i * 8, if i % 2 == 0 { 7 } else { 5 });
pico8.line(i * 8, 0, i * 8, 127, if i % 2 == 0 { 6 } else { 13 });
}

pico8.spr_(32, 32, 32, 0.5, 0.5, false, false);
pico8.spr_(32, 40, 40, 1.0, 1.0, false, false);

// TEST FLIPS
const RIGHT_ARROW: usize = 1;
const UP_ARROW: usize = 2;
const UP_RIGHT_ARROW: usize = 3;

pico8.spr_(RIGHT_ARROW, 48, 48, 1.0, 1.0, false, false);
pico8.spr_(RIGHT_ARROW, 48, 64, 1.0, 1.0, true, false);
pico8.spr_(UP_ARROW, 48, 80, 1.0, 1.0, false, false);
pico8.spr_(UP_ARROW, 48, 96, 1.0, 1.0, false, true);

pico8.spr_(UP_RIGHT_ARROW, 80, 48, 1.0, 1.0, false, false);
pico8.spr_(UP_RIGHT_ARROW, 80, 64, 1.0, 1.0, true, false);
pico8.spr_(UP_RIGHT_ARROW, 80, 80, 1.0, 1.0, false, true);
pico8.spr_(UP_RIGHT_ARROW, 80, 96, 1.0, 1.0, true, true);

// TEST BIG SPRITES
pico8.print("BIG SPRITE", 16, 8, 7);
pico8.spr_(7, 16, 16, 2.0, 2.0, false, false);
}
}

impl App for Sprites {
fn init(pico8: &mut Pico8) -> Self {
let this = Self {};

this.do_draw(pico8);
this
}

fn update(&mut self, pico8: &mut Pico8) {
if pico8.btnp(Button::C) {
self.do_draw(pico8);
}
}

fn draw(&mut self, _: &mut Pico8) {}
}
4 changes: 4 additions & 0 deletions examples/sprites/map.ppm

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions examples/sprites/map.txt

Large diffs are not rendered by default.

Loading