Open dobrite opened 7 years ago
Python tutorial:
import libtcodpy as libtcod
SCREEN_WIDTH = 80
SCREEN_HEIGHT = 50
LIMIT_FPS = 20
libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/libtcod tutorial', False)
libtcod.sys_set_fps(LIMIT_FPS)
while not libtcod.console_is_window_closed():
libtcod.console_set_default_foreground(0, libtcod.white)
libtcod.console_put_char(0, 1, 1, '@', libtcod.BKGND_NONE)
libtcod.console_flush()
Rust tutorial:
extern crate tcod;
use tcod::console::*;
use tcod::colors;
const SCREEN_WIDTH: i32 = 80;
const SCREEN_HEIGHT: i32 = 50;
const LIMIT_FPS: i32 = 20;
fn main() {
let mut root = Root::initializer()
.font("arial10x10.png", FontLayout::Tcod)
.font_type(FontType::Greyscale)
.size(SCREEN_WIDTH, SCREEN_HEIGHT)
.title("Rust/libtcod tutorial")
.init();
tcod::system::set_fps(LIMIT_FPS);
while !root.window_closed() {
root.set_default_foreground(colors::WHITE);
root.put_char(1, 1, '@', BackgroundFlag::None);
root.flush();
root.wait_for_keypress(true);
}
}
gltile tutorial
extern crate glium;
extern crate gltile;
extern crate looper;
extern crate pixset;
use gltile::colors;
use pixset::Pix;
fn main() {
let mut events_loop = glium::glutin::EventsLoop::new();
let window = glium::glutin::WindowBuilder::new().with_dimensions(1_280, 800);
let context = glium::glutin::ContextBuilder::new();
let display = glium::Display::new(window, context, &events_loop).unwrap();
let mut renderer = gltile::Renderer::new(&display, &pixset::TILESET);
let tile = gltile::Tile::make(*colors::WHITE, *colors::BLACK, Pix::Dood);
renderer.set((1, 1), tile);
let render = |_| {
renderer.render();
looper::Action::Continue
};
let update = |_| {
let mut action = looper::Action::Continue;
events_loop.poll_events(|event| match event {
glium::glutin::Event::WindowEvent { event, .. } => {
match event {
glium::glutin::WindowEvent::Closed => action = looper::Action::Stop,
_ => (),
}
}
_ => (),
});
action
};
looper::Looper::new(60.0).run(render, update);
}
Currently the "show an
@
on the screen" requires way too much boilerplate. Make some attempt to reduce it!