Skip to content
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

Rusty roguelike macroquad #119

Merged
merged 4 commits into from
Aug 7, 2022
Merged
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ If you're a developer planning a contribution, it's **crucial** to read the [Con
- [Boing/ggez](#boingggez)
- [Cavern/Macroquad](#cavernmacroquad)
- [Rusty Roguelike/Bevy ECS](#rusty-roguelikebevy-ecs)
- [Rusty Roguelike/Macroquad](#rusty-roguelikemacroquad)
- [Soccer/Fyrox](#soccerfyrox)
- [Source Projects](#source-projects)
- [Libraries](#libraries)
Expand All @@ -32,6 +33,7 @@ The completed ports are:
| Boing | Code the Classics Vol. 1 | Python, PyGame Zero | ggez | Linux |
| Cavern | Code the Classics Vol. 1 | Python, PyGame Zero | Macroquad | Linux |
| Rusty Roguelike | Hands-on Rust: Effective Learning... | bracket-lib, Legion | bracket-lib, Bevy (ECS) | Linux |
| Rusty Roguelike | Hands-on Rust: Effective Learning... | bracket-lib, Legion | Macroquad, Legion | Linux |
| Soccer | Code the Classics Vol. 1 | Python, PyGame Zero | Fyrox | Linux |

## Contribution Infos
Expand Down Expand Up @@ -134,6 +136,10 @@ The port suffers from two Fyrox bugs:
- at least one sound plays with a delay (reported [here](https://github.com/FyroxEngine/Fyrox/issues/324));
- some images render incorrectly (reported [here](https://github.com/FyroxEngine/Fyrox/issues/320)).

### Rusty Roguelike/Macroquad

The graphics portion of the Rusty Roguelike has been ported to Macroquad. The ECS used is still Legion, and the pathfinding is from [bracket-lib](https://github.com/amethyst/bracket-lib)).

## Source Projects

- Code the Classics Vol. 1 ([repository](https://github.com/Wireframe-Magazine/Code-the-Classics) and [book](https://wireframe.raspberrypi.org/books/code-the-classics1))
Expand Down
Binary file added images/readme/rusty_roguelike-macroquad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions rusty_roguelike-macroquad/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
28 changes: 28 additions & 0 deletions rusty_roguelike-macroquad/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "rusty-dungeon"
version = "0.5.0"
authors = ["Olle Wreede <[email protected]>"]
edition = "2021"

[dependencies]
macroquad = "0.3.3"
legion = { version = "=0.3.1", default-features = false, features = ["codegen"] }
getrandom = { version = "0.2", features = ["js"] }
bracket-pathfinding = "0.8.4"
nanoserde = "0.1.26"
lazy_static = "1.4.0"

# Doesn't work with android build
[profile.dev.package.'*']
opt-level = 3

[profile.release]
opt-level = 'z'
lto = true
panic = 'abort'
codegen-units = 1

[package.metadata.scripts]
build-web = "bin/build-web"
serve-web = "bin/serve-web"

17 changes: 17 additions & 0 deletions rusty_roguelike-macroquad/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Rusty Roguelike for Macroquead

A small roguelike based on the example in the Hands-on Rust book by Herbert
Wolverson, but written in Macroquad.

Buy the book from Pragmatic Programmer:

* https://pragprog.com/titles/hwrust/hands-on-rust/

## Acknowledgements

* Herbert Wolverson for the base code
* Item icons by Caz Wolf https://cazwolf.itch.io/
* Floor tiles made by homyakokryak
* Assorted CC0/public domain images from opengameart.org
* Knight by PolygonDan
* Potions by Admurin: https://admurin.itch.io/
Binary file added rusty_roguelike-macroquad/assets/dungeonfont.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions rusty_roguelike-macroquad/assets/template.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
(
entities : [
(
entity_type: Item,
name : "Healing Potion", sprite : 33, levels : [ 0, 1, 2 ],
provides: [ ("Healing", 6) ],
frequency: 2
),
(
entity_type: Item,
name : "Weak Healing Potion", sprite : 33, levels : [ 0, 1, 2 ],
provides: [ ("Healing", 2) ],
frequency: 2
),
(
entity_type: Item,
name : "Dungeon Map", sprite : 123, levels : [ 0, 1, 2 ],
provides: [ ("MagicMap", 0) ],
frequency: 1
),
(
entity_type: Item,
name : "Short Sword", sprite: 115, levels: [ 0, 1, 2 ],
frequency: 1,
base_damage: 1
),
(
entity_type: Item,
name : "2-handed Sword", sprite: 83, levels: [ 0, 1, 2 ],
frequency: 1,
base_damage: 2
),
(
entity_type: Item,
name : "Claymore", sprite: 47, levels: [ 2 ],
frequency: 1,
base_damage: 3
),
(
entity_type: Enemy,
name : "Bat", sprite : 98, levels : [ 0 ],
hp : 1,
frequency: 8,
base_damage: 1
),
(
entity_type: Enemy,
name : "Kobold", sprite : 103, levels : [ 0, 1 ],
hp : 2,
frequency: 5,
base_damage: 1
),
(
entity_type: Enemy,
name : "2-headed Ogre", sprite : 111, levels : [ 0, 1, 2 ],
hp : 4,
frequency: 2,
base_damage: 1
),
(
entity_type: Enemy,
name : "Deep Troll", sprite : 79, levels : [ 1, 2 ],
hp : 6,
frequency: 2,
base_damage: 2
),
(
entity_type: Enemy,
name : "Lindwyrm", sprite : 69, levels : [ 2 ],
hp : 8,
frequency: 1,
base_damage: 3
),
],
)
26 changes: 26 additions & 0 deletions rusty_roguelike-macroquad/src/camera_view.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use crate::prelude::*;

pub struct CameraView {
pub left_x: i32,
pub right_x: i32,
pub top_y: i32,
pub bottom_y: i32,
}

impl CameraView {
pub fn new(player_position: Point) -> Self {
Self {
left_x: player_position.x - DISPLAY_WIDTH / 2,
right_x: player_position.x + DISPLAY_WIDTH / 2,
top_y: player_position.y - DISPLAY_HEIGHT / 2,
bottom_y: player_position.y + DISPLAY_HEIGHT / 2,
}
}

pub fn on_player_move(&mut self, player_position: Point) {
self.left_x = player_position.x - DISPLAY_WIDTH / 2;
self.right_x = player_position.x + DISPLAY_WIDTH / 2;
self.top_y = player_position.y - DISPLAY_HEIGHT / 2;
self.bottom_y = player_position.y + DISPLAY_HEIGHT / 2;
}
}
97 changes: 97 additions & 0 deletions rusty_roguelike-macroquad/src/components.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
use crate::prelude::*;
use std::collections::HashSet;

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Render {
pub color: Color,
pub sprite: Sprite,
}

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Player {
pub map_level: u32,
}

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Enemy;

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct MovingRandomly;

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct WantsToMove {
pub entity: Entity,
pub destination: Point,
}

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Health {
pub current: i32,
pub max: i32,
}

#[derive(Clone, PartialEq)]
pub struct Name(pub String);

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct WantsToAttack {
pub attacker: Entity,
pub victim: Entity,
}

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct ChasingPlayer;

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Item;

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct AmuletOfYala;

#[derive(Clone, Debug, PartialEq)]
pub struct FieldOfView {
pub visible_tiles: HashSet<Point>,
pub radius: i32,
pub is_dirty: bool,
}

impl FieldOfView {
pub fn new(radius: i32) -> Self {
Self {
visible_tiles: HashSet::new(),
radius,
is_dirty: true,
}
}

pub fn clone_dirty(&self) -> Self {
Self {
visible_tiles: HashSet::new(),
radius: self.radius,
is_dirty: true,
}
}
}

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct ProvidesHealing {
pub amount: i32,
}

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct ProvidesDungeonMap;

#[derive(Clone, PartialEq)]
pub struct Carried(pub Entity);

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct ActivateItem {
pub used_by: Entity,
pub item: Entity,
}

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Damage(pub i32);

#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Weapon;
Loading