init
This commit is contained in:
parent
a573971d49
commit
2967cddf7b
4 changed files with 5162 additions and 49 deletions
5115
resources/td.json
Normal file
5115
resources/td.json
Normal file
File diff suppressed because it is too large
Load diff
BIN
resources/td.png
Normal file
BIN
resources/td.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
91
src/main.rs
91
src/main.rs
|
|
@ -1,52 +1,40 @@
|
||||||
use rust_rl::*;
|
use rust_rl::*;
|
||||||
|
use notan::prelude::*;
|
||||||
|
use notan::draw::create_textures_from_atlas;
|
||||||
|
use notan::draw::{ CreateFont, CreateDraw, DrawImages };
|
||||||
use specs::prelude::*;
|
use specs::prelude::*;
|
||||||
use specs::saveload::{ SimpleMarker, SimpleMarkerAllocator };
|
use specs::saveload::{ SimpleMarker, SimpleMarkerAllocator };
|
||||||
use bracket_lib::prelude::*;
|
use bracket_lib::prelude::*;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
const DISPLAYWIDTH: i32 = 100;
|
const TILESIZE: u32 = 16;
|
||||||
const DISPLAYHEIGHT: i32 = 56;
|
const DISPLAYWIDTH: u32 = 100 * TILESIZE;
|
||||||
|
const DISPLAYHEIGHT: u32 = 56 * TILESIZE;
|
||||||
|
|
||||||
fn main() -> BError {
|
#[notan_main]
|
||||||
// Embedded resources for use in wasm build
|
fn main() -> Result<(), String> {
|
||||||
{
|
let win_config = WindowConfig::new().set_size(DISPLAYWIDTH, DISPLAYHEIGHT).set_vsync(true);
|
||||||
const WORLD_16_16_BYTES: &[u8] = include_bytes!("../resources/world16x16.png");
|
notan
|
||||||
const CURSES_16_16_BYTES: &[u8] = include_bytes!("../resources/curses16x16.png");
|
::init_with(setup)
|
||||||
const CURSES_8_16_BYTES: &[u8] = include_bytes!("../resources/curses8x16.png");
|
.add_config(win_config)
|
||||||
const SINGLE_1_1_BYTES: &[u8] = include_bytes!("../resources/healthbar22x2.png");
|
.add_config(notan::draw::DrawConfig)
|
||||||
let mut lock = bracket_lib::terminal::EMBED.lock();
|
.draw(draw)
|
||||||
lock.add_resource("resources/world16x16.png".to_string(), WORLD_16_16_BYTES);
|
.build()
|
||||||
lock.add_resource("resources/curses16x16.png".to_string(), CURSES_16_16_BYTES);
|
}
|
||||||
lock.add_resource("resources/curses8x16.png".to_string(), CURSES_8_16_BYTES);
|
|
||||||
lock.add_resource("resources/healthbar22x2.png".to_string(), SINGLE_1_1_BYTES);
|
|
||||||
}
|
|
||||||
|
|
||||||
let world_sheet = SpriteSheet {
|
fn setup(gfx: &mut Graphics) -> State {
|
||||||
filename: "resources/world16x16.png".to_string(),
|
let texture = gfx
|
||||||
sprites: register_spritesheet(16, 16, 19, 16),
|
.create_texture()
|
||||||
backing: None,
|
.from_image(include_bytes!("../resources/td.png"))
|
||||||
};
|
.build()
|
||||||
|
.unwrap();
|
||||||
let mut context = BTermBuilder::new()
|
let data = include_bytes!("../resources/td.json");
|
||||||
.with_title("rust-rl")
|
let atlas = create_textures_from_atlas(data, &texture).unwrap();
|
||||||
.with_dimensions(DISPLAYWIDTH, DISPLAYHEIGHT)
|
|
||||||
.with_font("curses16x16.png", 16, 16)
|
|
||||||
.with_font("curses8x16.png", 8, 16)
|
|
||||||
.with_font("healthbar22x2.png", 1, 1)
|
|
||||||
.with_tile_dimensions(16, 16)
|
|
||||||
.with_gutter(2)
|
|
||||||
.with_sprite_console(DISPLAYWIDTH * 16, DISPLAYHEIGHT * 16, 0)
|
|
||||||
.with_sprite_sheet(world_sheet)
|
|
||||||
.with_simple_console_no_bg(DISPLAYWIDTH, DISPLAYHEIGHT, "curses16x16.png")
|
|
||||||
.with_simple_console_no_bg(DISPLAYWIDTH, DISPLAYHEIGHT, "curses16x16.png")
|
|
||||||
.with_sparse_console(DISPLAYWIDTH * 2, DISPLAYHEIGHT, "curses8x16.png")
|
|
||||||
.with_sparse_console(DISPLAYWIDTH * 16, DISPLAYHEIGHT * 16, "healthbar22x2.png")
|
|
||||||
.build()?;
|
|
||||||
if config::CONFIG.visuals.with_scanlines {
|
|
||||||
context.with_post_scanlines(config::CONFIG.visuals.with_screen_burn);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut gs = State {
|
let mut gs = State {
|
||||||
ecs: World::new(),
|
ecs: World::new(),
|
||||||
|
base_texture: texture,
|
||||||
|
atlas,
|
||||||
mapgen_next_state: Some(RunState::MainMenu {
|
mapgen_next_state: Some(RunState::MainMenu {
|
||||||
menu_selection: gui::MainMenuSelection::NewGame,
|
menu_selection: gui::MainMenuSelection::NewGame,
|
||||||
}),
|
}),
|
||||||
|
|
@ -155,17 +143,22 @@ fn main() -> BError {
|
||||||
gamelog::record_event(data::events::EVENT::Level(1));
|
gamelog::record_event(data::events::EVENT::Level(1));
|
||||||
gs.generate_world_map(1, TileType::Floor);
|
gs.generate_world_map(1, TileType::Floor);
|
||||||
|
|
||||||
main_loop(context, gs)
|
gs
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_spritesheet(width: i32, height: i32, rows: i32, columns: i32) -> Vec<Sprite> {
|
fn draw(app: &mut App, gfx: &mut Graphics, state: &mut State) {
|
||||||
let mut sprites: Vec<Sprite> = Vec::new();
|
let mut draw = gfx.create_draw();
|
||||||
for y in 0..rows {
|
draw.clear(Color::BLACK);
|
||||||
for x in 0..columns {
|
let mut x = 10.0;
|
||||||
sprites.push(
|
let mut y = 10.0;
|
||||||
Sprite::new(Rect::with_size(x * width + 1, y * height + 1, width, height))
|
// Draw base texture
|
||||||
);
|
state.atlas.iter().for_each(|(k, tex)| {
|
||||||
|
if y + tex.height() > (gfx.size().1 as f32) * 0.8 {
|
||||||
|
y = 10.0;
|
||||||
|
x += 17.0;
|
||||||
}
|
}
|
||||||
}
|
draw.image(tex).position(x, y);
|
||||||
sprites
|
y += tex.height() + 1.0;
|
||||||
|
});
|
||||||
|
gfx.render(&draw);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,14 @@ use crate::saveload_system;
|
||||||
use crate::morgue;
|
use crate::morgue;
|
||||||
use crate::damage_system;
|
use crate::damage_system;
|
||||||
use crate::data::prelude::*;
|
use crate::data::prelude::*;
|
||||||
|
use notan::prelude::*;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
#[derive(AppState)]
|
||||||
pub struct State {
|
pub struct State {
|
||||||
pub ecs: World,
|
pub ecs: World,
|
||||||
|
pub base_texture: Texture,
|
||||||
|
pub atlas: HashMap<String, Texture>,
|
||||||
pub mapgen_next_state: Option<RunState>,
|
pub mapgen_next_state: Option<RunState>,
|
||||||
pub mapgen_history: Vec<Map>,
|
pub mapgen_history: Vec<Map>,
|
||||||
pub mapgen_index: usize,
|
pub mapgen_index: usize,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue