Compare commits
No commits in common. "75ca8c84ead02faa7b618d59eecc8530689241c3" and "4dd334d6a450b473af3250fbc62dc25dfbbfc8cc" have entirely different histories.
75ca8c84ea
...
4dd334d6a4
|
@ -18,7 +18,8 @@ hex = "^0.4.3"
|
|||
image = "0.23.14"
|
||||
log = "0.4.14"
|
||||
pixels = "0.3.0"
|
||||
rodio-xm = "^0.1.1"
|
||||
rodio = "^0.11.0"
|
||||
rodio-xm = { git = "https://tinybird.dev/max/rodio-xm/", branch = "master" }
|
||||
serde = "^1.0.114"
|
||||
serde_derive = "^1.0.114"
|
||||
toml = "^0.5.6"
|
||||
|
|
5
LICENSE
5
LICENSE
|
@ -1,6 +1,6 @@
|
|||
ANTI-CAPITALIST SOFTWARE LICENSE (v 1.4)
|
||||
|
||||
Copyright © 2022 Max Bradbury
|
||||
Copyright © 2021 Max Bradbury
|
||||
|
||||
This is anti-capitalist software, released for free use by individuals and organizations that do not operate by capitalist principles.
|
||||
|
||||
|
@ -11,7 +11,8 @@ Permission is hereby granted, free of charge, to any person or organization (the
|
|||
2. The User is one of the following:
|
||||
a. An individual person, laboring for themselves
|
||||
b. A non-profit organization
|
||||
c. An organization that seeks shared profit for all of its members, and allows non-members to set the cost of their labour
|
||||
c. An educational institution
|
||||
d. An organization that seeks shared profit for all of its members, and allows non-members to set the cost of their labor
|
||||
|
||||
3. If the User is an organization with owners, then all owners are workers and all workers are owners with equal equity and/or equal vote.
|
||||
|
||||
|
|
7
TODO.md
7
TODO.md
|
@ -2,9 +2,8 @@
|
|||
|
||||
## game data structure
|
||||
|
||||
more colours? max 10? (0-9) max 16? (0-f)
|
||||
more colours? max 10? (0-9)
|
||||
colours not in palette can use modulo
|
||||
background palette and foreground palette? would be good to make interactive stuff obvious
|
||||
|
||||
--
|
||||
|
||||
|
@ -38,10 +37,6 @@ idea:
|
|||
* support older graphics adaptors
|
||||
* player has some graphical tearing on non-integer window sizes
|
||||
|
||||
* show a help splash screen on first boot (with "do not show me this again" checkbox which saves to a local config)
|
||||
* what is peachy?
|
||||
* controls
|
||||
|
||||
### windows
|
||||
|
||||
* ~try to compile~
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::path::PathBuf;
|
|||
use log::error;
|
||||
use pixels::{Error, SurfaceTexture, PixelsBuilder};
|
||||
use pixels::wgpu::BackendBit;
|
||||
use winit::dpi::{LogicalPosition, LogicalSize, PhysicalSize, Size};
|
||||
use winit::dpi::{LogicalPosition, LogicalSize, PhysicalSize};
|
||||
use winit::event::{Event, VirtualKeyCode};
|
||||
use winit::event_loop::{ControlFlow, EventLoop};
|
||||
use winit_input_helper::WinitInputHelper;
|
||||
|
@ -183,11 +183,7 @@ fn main() -> Result<(), Error> {
|
|||
}
|
||||
}
|
||||
|
||||
if
|
||||
input.key_pressed(VirtualKeyCode::Left)
|
||||
||
|
||||
input.key_pressed(VirtualKeyCode::W)
|
||||
{
|
||||
if input.key_pressed(VirtualKeyCode::Left) {
|
||||
let (x, y) = state.player_position;
|
||||
if x > 0 {
|
||||
state.player_position = (x - 1, y);
|
||||
|
@ -195,11 +191,7 @@ fn main() -> Result<(), Error> {
|
|||
}
|
||||
}
|
||||
|
||||
if
|
||||
input.key_pressed(VirtualKeyCode::Right)
|
||||
||
|
||||
input.key_pressed(VirtualKeyCode::D)
|
||||
{
|
||||
if input.key_pressed(VirtualKeyCode::Right) {
|
||||
let (x, y) = state.player_position;
|
||||
if x < state.game.config.width as u8 - 1 {
|
||||
state.player_position = (x + 1, y);
|
||||
|
@ -207,11 +199,7 @@ fn main() -> Result<(), Error> {
|
|||
}
|
||||
}
|
||||
|
||||
if
|
||||
input.key_pressed(VirtualKeyCode::Up)
|
||||
||
|
||||
input.key_pressed(VirtualKeyCode::W)
|
||||
{
|
||||
if input.key_pressed(VirtualKeyCode::Up) {
|
||||
let (x, y) = state.player_position;
|
||||
if y > 0 {
|
||||
state.player_position = (x, y - 1);
|
||||
|
@ -219,11 +207,7 @@ fn main() -> Result<(), Error> {
|
|||
}
|
||||
}
|
||||
|
||||
if
|
||||
input.key_pressed(VirtualKeyCode::Down)
|
||||
||
|
||||
input.key_pressed(VirtualKeyCode::S)
|
||||
{
|
||||
if input.key_pressed(VirtualKeyCode::Down) {
|
||||
let (x, y) = state.player_position;
|
||||
if y < state.game.config.height as u8 - 1 {
|
||||
state.player_position = (x, y + 1);
|
||||
|
@ -252,7 +236,7 @@ fn main() -> Result<(), Error> {
|
|||
fn window_builder(title: &str, event_loop: &EventLoop<()>) -> winit::window::Window {
|
||||
winit::window::WindowBuilder::new()
|
||||
.with_visible(false)
|
||||
// .with_resizable(false)
|
||||
.with_resizable(false)
|
||||
.with_title(title).build(&event_loop).unwrap()
|
||||
}
|
||||
|
||||
|
@ -263,7 +247,7 @@ fn window_builder(title: &str, event_loop: &EventLoop<()>) -> winit::window::Win
|
|||
winit::window::WindowBuilder::new()
|
||||
.with_drag_and_drop(false)
|
||||
.with_visible(false)
|
||||
// .with_resizable(false)
|
||||
.with_resizable(false)
|
||||
.with_title(title).build(&event_loop).unwrap()
|
||||
}
|
||||
|
||||
|
@ -298,21 +282,21 @@ fn create_window(
|
|||
|
||||
let scale = (monitor_height / height * 2.0 / 3.0).round().max(1.0);
|
||||
|
||||
// Resize, centre, and display the window
|
||||
// let min_size: winit::dpi::LogicalSize<f64> =
|
||||
// PhysicalSize::new(width, height).to_logical(hidpi_factor);
|
||||
// Resize, center, and display the window
|
||||
let min_size: winit::dpi::LogicalSize<f64> =
|
||||
PhysicalSize::new(width, height).to_logical(hidpi_factor);
|
||||
|
||||
let default_size =
|
||||
LogicalSize::new(width * scale, height * scale);
|
||||
|
||||
let centre = LogicalPosition::new(
|
||||
let center = LogicalPosition::new(
|
||||
(monitor_width - width * scale) / 2.0,
|
||||
(monitor_height - height * scale) / 2.0,
|
||||
);
|
||||
|
||||
window.set_inner_size(default_size);
|
||||
// window.set_min_inner_size(Some(min_size));
|
||||
window.set_outer_position(centre);
|
||||
window.set_outer_position(center);
|
||||
window.set_visible(true);
|
||||
|
||||
let size = default_size.to_physical::<f64>(hidpi_factor);
|
||||
|
|
|
@ -1,88 +0,0 @@
|
|||
use raylib::prelude::*;
|
||||
use raylib::consts::KeyboardKey;
|
||||
use peachy::Colour;
|
||||
|
||||
// todo state
|
||||
|
||||
fn main() {
|
||||
// todo load game
|
||||
let game = peachy::mock::game::bitsy();
|
||||
|
||||
let (mut rl, thread) = raylib::init()
|
||||
.size((game.config.width * 4) as i32, (game.config.height * 4) as i32)
|
||||
.title("peachy")
|
||||
.build();
|
||||
|
||||
rl.set_target_fps(30); // appropriate?
|
||||
|
||||
let key_up: KeyboardKey = raylib::core::input::key_from_i32(87).unwrap();
|
||||
let key_left: KeyboardKey = raylib::core::input::key_from_i32(65).unwrap();
|
||||
let key_down: KeyboardKey = raylib::core::input::key_from_i32(83).unwrap();
|
||||
let key_right: KeyboardKey = raylib::core::input::key_from_i32(68).unwrap();
|
||||
|
||||
const SIZE: i32 = 32;
|
||||
|
||||
let mut x = SIZE;
|
||||
let mut y = SIZE;
|
||||
|
||||
let palette = game.palettes.get(0).unwrap();
|
||||
|
||||
let avatars = game.get_entities_by_tag(&"avatar".to_string());
|
||||
let avatar = avatars.get(0).unwrap();
|
||||
let image = game.get_image_by_name(&avatar.image).unwrap().clone().into_image(palette);
|
||||
|
||||
// todo how do I create a texture without a file?
|
||||
let mut texture = rl.load_texture(
|
||||
&thread, "src/test-resources/images/avatar.png"
|
||||
).unwrap();
|
||||
|
||||
texture.update_texture(image.as_bytes());
|
||||
|
||||
// let font = rl.load_font(&thread, "src/FuturaStd-Light.otf").unwrap();
|
||||
|
||||
let mut audio = audio::RaylibAudio::init_audio_device();
|
||||
|
||||
let mut music = raylib::audio::Music::load_music_stream(
|
||||
&thread, "src/test-resources/music/another-night.xm"
|
||||
).unwrap();
|
||||
|
||||
audio.play_music_stream(&mut music);
|
||||
|
||||
println!("{}", rl.window_should_close());
|
||||
|
||||
while !rl.window_should_close() {
|
||||
if rl.is_key_pressed(key_up) {
|
||||
y -= SIZE;
|
||||
} else if rl.is_key_pressed(key_left) {
|
||||
x -= SIZE;
|
||||
} else if rl.is_key_pressed(key_down) {
|
||||
y += SIZE;
|
||||
} else if rl.is_key_pressed(key_right) {
|
||||
x += SIZE;
|
||||
}
|
||||
|
||||
audio.update_music_stream(&mut music);
|
||||
|
||||
let mut d = rl.begin_drawing(&thread);
|
||||
|
||||
// d.clear_background(palette.get_colour_raylib(&0));
|
||||
d.clear_background(Color::WHITE);
|
||||
|
||||
d.draw_texture_ex(
|
||||
&texture,
|
||||
raylib::core::math::Vector2 { x: x as f32, y: y as f32 },
|
||||
0.0,
|
||||
4.0,
|
||||
Color::WHITE
|
||||
);
|
||||
|
||||
// d.draw_text_ex(
|
||||
// &font,
|
||||
// "hello",
|
||||
// raylib::core::math::Vector2 { x: 64.0, y: 64.0 },
|
||||
// 32.0,
|
||||
// 4.0,
|
||||
// Color::WHITE
|
||||
// );
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ use std::fs::read_to_string;
|
|||
use image::{DynamicImage, ImageBuffer};
|
||||
use crate::Palette;
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Image {
|
||||
pub name: String,
|
||||
/// colour indices - todo convert to [u8; 64]?
|
||||
|
@ -24,7 +24,7 @@ impl Image {
|
|||
Self { name, pixels }
|
||||
}
|
||||
|
||||
pub fn into_image(self, palette: &Palette) -> DynamicImage {
|
||||
fn into_image(self, palette: &Palette) -> DynamicImage {
|
||||
let mut buffer: Vec<u8> = Vec::new();
|
||||
|
||||
for pixel in self.pixels {
|
||||
|
|
|
@ -5,7 +5,7 @@ mod colour;
|
|||
mod config;
|
||||
mod entity;
|
||||
mod image;
|
||||
pub mod mock;
|
||||
mod mock;
|
||||
mod music;
|
||||
mod palette;
|
||||
mod scene;
|
||||
|
@ -224,9 +224,10 @@ impl Game {
|
|||
Ok(Game { config, images, tiles, palettes, music, entities, scenes })
|
||||
}
|
||||
|
||||
pub fn get_image_by_name(&self, name: &String) -> Option<&Image> {
|
||||
// todo Result<&Image>?
|
||||
pub fn get_image_by_name(&self, name: String) -> Option<&Image> {
|
||||
for image in self.images.iter() {
|
||||
if &image.name == name {
|
||||
if image.name == name {
|
||||
return Some(&image);
|
||||
}
|
||||
}
|
||||
|
|
72
src/mock.rs
72
src/mock.rs
|
@ -1,4 +1,4 @@
|
|||
pub mod image {
|
||||
pub(crate) mod image {
|
||||
use crate::image::Image;
|
||||
|
||||
pub fn _bg() -> Image {
|
||||
|
@ -66,7 +66,7 @@ pub mod image {
|
|||
}
|
||||
}
|
||||
|
||||
pub mod palette {
|
||||
pub(crate) mod palette {
|
||||
use crate::{Palette, Colour};
|
||||
|
||||
pub(crate) fn default() -> Palette {
|
||||
|
@ -80,7 +80,7 @@ pub mod palette {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn soup11() -> Palette {
|
||||
pub(crate) fn soup11() -> Palette {
|
||||
Palette {
|
||||
name: "soup11".into(),
|
||||
colours: vec![
|
||||
|
@ -100,10 +100,10 @@ pub mod palette {
|
|||
}
|
||||
}
|
||||
|
||||
pub mod scenes {
|
||||
pub(crate) mod scenes {
|
||||
use crate::Scene;
|
||||
|
||||
pub fn zero() -> Scene {
|
||||
pub(crate) fn zero() -> Scene {
|
||||
Scene {
|
||||
name: "zero".into(),
|
||||
background: vec![
|
||||
|
@ -145,65 +145,3 @@ pub mod scenes {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod entities {
|
||||
use crate::Entity;
|
||||
|
||||
pub fn bitsy_avatar() -> Entity {
|
||||
Entity {
|
||||
name: "".to_string(),
|
||||
image: "avatar".to_string(),
|
||||
tags: vec!["player".into()]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bitsy_cat() -> Entity {
|
||||
Entity {
|
||||
name: "cat".to_string(),
|
||||
image: "cat".to_string(),
|
||||
tags: vec![]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod tiles {
|
||||
use crate::Tile;
|
||||
|
||||
pub fn bitsy_block() -> Tile {
|
||||
Tile {
|
||||
name: "block".into(),
|
||||
images: vec!["block".into()],
|
||||
wall: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod game {
|
||||
use crate::{Config, Game};
|
||||
|
||||
pub fn bitsy() -> Game {
|
||||
Game {
|
||||
config: Config {
|
||||
name: Some("Write your game's title here".into()),
|
||||
width: 16,
|
||||
height: 16,
|
||||
tick: 400,
|
||||
starting_room: None,
|
||||
version: (0, 1)
|
||||
},
|
||||
entities: vec![
|
||||
crate::mock::entities::bitsy_avatar(),
|
||||
crate::mock::entities::bitsy_cat(),
|
||||
],
|
||||
images: vec![],
|
||||
palettes: vec![],
|
||||
scenes: vec![
|
||||
crate::mock::scenes::zero(),
|
||||
],
|
||||
tiles: vec![
|
||||
crate::mock::tiles::bitsy_block(),
|
||||
],
|
||||
music: vec![]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue