Start updating

This commit is contained in:
Greg Shuflin 2024-10-03 18:12:09 -07:00
parent ea7fcae065
commit bdd464bde2
3 changed files with 2680 additions and 1240 deletions

3858
iced-tetris/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,13 @@
[package]
name = "iced-tetris"
version = "0.1.0"
edition = "2018"
edition = "2021"
resolver = "2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
iced = { git = "https://github.com/hecrj/iced", rev = "099981cfc2f61a1f37e84100592d65babb94fb82", features = ["tokio", "canvas"] }
iced_native = { git = "https://github.com/hecrj/iced", rev = "099981cfc2f61a1f37e84100592d65babb94fb82"}
iced = "0.13.1"
chrono = "0.4.19"
rand = "0.8.4"
tetris-logic = { path = "../tetris-logic" }

View File

@ -1,17 +1,47 @@
/*
use iced::widget::canvas::{self, Path, Stroke, Text};
use iced::{
executor, keyboard, time, Application, Color, Command, Element, Length, Point, Rectangle,
Settings, Size, Subscription,
};
use iced_native::{event, subscription, Event};
use tetris_logic::{BlockGrid, MoveDirection, Tetromino};
*/
use iced::{widget::{button, text}, Element, Task};
use tetris_logic::BlockGrid;
fn main() -> iced::Result {
Tetris::run(Settings::default())
//Tetris::run(Settings::default())
iced::application(Tetris::title, update, view).run_with(|| (Tetris::new(), Task::none()))
}
#[derive(Debug, Clone)]
enum Message {
Up,
Down,
Left,
Right,
Pause,
Tick(chrono::DateTime<chrono::Local>),
}
fn update(_state: &mut Tetris, message: Message) {
match message {
Message::Up => todo!(),
Message::Down => todo!(),
Message::Left => todo!(),
Message::Right => todo!(),
Message::Pause => todo!(),
Message::Tick(_) => todo!(),
}
}
fn view(_state: &Tetris) -> Element<Message> {
button(text("FOO")).on_press(Message::Up).into()
}
struct Tetris {
background_cache: canvas::Cache,
//background_cache: canvas::Cache,
blocks: BlockGrid,
ticks: usize,
paused: bool,
@ -19,9 +49,13 @@ struct Tetris {
}
impl Tetris {
fn title(&self) -> String {
String::from("Tetris - Iced")
}
fn new() -> Tetris {
Tetris {
background_cache: canvas::Cache::default(),
//background_cache: canvas::Cache::default(),
blocks: BlockGrid::new(),
ticks: 0,
paused: false,
@ -30,6 +64,7 @@ impl Tetris {
}
}
/*
impl Application for Tetris {
type Executor = executor::Default;
type Message = Message;
@ -105,7 +140,9 @@ impl Application for Tetris {
.into()
}
}
*/
/*
impl<'a> canvas::Program<Message> for Tetris {
fn draw(&self, bounds: Rectangle, _cursor: canvas::Cursor) -> Vec<canvas::Geometry> {
let game_width = bounds.width / 3.0;
@ -171,7 +208,9 @@ impl<'a> canvas::Program<Message> for Tetris {
vec![background, frame.into_geometry()]
}
}
*/
/*
fn handle_keypress(key_code: keyboard::KeyCode) -> Option<Message> {
use keyboard::KeyCode;
@ -184,13 +223,5 @@ fn handle_keypress(key_code: keyboard::KeyCode) -> Option<Message> {
_ => return None,
})
}
*/
#[derive(Debug)]
enum Message {
Up,
Down,
Left,
Right,
Pause,
Tick(chrono::DateTime<chrono::Local>),
}