More work
This commit is contained in:
parent
bdd464bde2
commit
d030563e49
56
iced-tetris/Cargo.lock
generated
56
iced-tetris/Cargo.lock
generated
@ -18,6 +18,15 @@ version = "0.1.8"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046"
|
checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "addr2line"
|
||||||
|
version = "0.24.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f5fb1d8e4442bd405fdfd1dacb42792696b0cf9cb15882e5d097b742a676d375"
|
||||||
|
dependencies = [
|
||||||
|
"gimli",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "adler2"
|
name = "adler2"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
@ -287,6 +296,21 @@ version = "1.4.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
|
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "backtrace"
|
||||||
|
version = "0.3.74"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a"
|
||||||
|
dependencies = [
|
||||||
|
"addr2line",
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"miniz_oxide",
|
||||||
|
"object",
|
||||||
|
"rustc-demangle",
|
||||||
|
"windows-targets 0.52.6",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bit-set"
|
name = "bit-set"
|
||||||
version = "0.5.3"
|
version = "0.5.3"
|
||||||
@ -1197,6 +1221,12 @@ dependencies = [
|
|||||||
"wasi",
|
"wasi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "gimli"
|
||||||
|
version = "0.31.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "32085ea23f3234fc7846555e85283ba4de91e21016dc0455a16286d87a292d64"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gl_generator"
|
name = "gl_generator"
|
||||||
version = "0.14.0"
|
version = "0.14.0"
|
||||||
@ -1448,6 +1478,7 @@ dependencies = [
|
|||||||
"iced_core",
|
"iced_core",
|
||||||
"log",
|
"log",
|
||||||
"rustc-hash 2.0.0",
|
"rustc-hash 2.0.0",
|
||||||
|
"tokio",
|
||||||
"wasm-bindgen-futures",
|
"wasm-bindgen-futures",
|
||||||
"wasm-timer",
|
"wasm-timer",
|
||||||
]
|
]
|
||||||
@ -2147,6 +2178,15 @@ dependencies = [
|
|||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "object"
|
||||||
|
version = "0.36.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "084f1a5821ac4c651660a94a7153d27ac9d8a53736203f58b31945ded098070a"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.20.1"
|
version = "1.20.1"
|
||||||
@ -2604,6 +2644,12 @@ dependencies = [
|
|||||||
"ordered-multimap",
|
"ordered-multimap",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc-demangle"
|
||||||
|
version = "0.1.24"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc-hash"
|
name = "rustc-hash"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
@ -3038,6 +3084,16 @@ version = "0.1.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tokio"
|
||||||
|
version = "1.40.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998"
|
||||||
|
dependencies = [
|
||||||
|
"backtrace",
|
||||||
|
"pin-project-lite",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "toml_datetime"
|
name = "toml_datetime"
|
||||||
version = "0.6.8"
|
version = "0.6.8"
|
||||||
|
@ -7,7 +7,7 @@ resolver = "2"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
iced = "0.13.1"
|
iced = { version = "0.13.1", features = ["tokio"] }
|
||||||
chrono = "0.4.19"
|
chrono = "0.4.19"
|
||||||
rand = "0.8.4"
|
rand = "0.8.4"
|
||||||
tetris-logic = { path = "../tetris-logic" }
|
tetris-logic = { path = "../tetris-logic" }
|
||||||
|
@ -7,12 +7,17 @@ use iced::{
|
|||||||
use tetris_logic::{BlockGrid, MoveDirection, Tetromino};
|
use tetris_logic::{BlockGrid, MoveDirection, Tetromino};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use iced::{widget::{button, text}, Element, Task};
|
use iced::{
|
||||||
use tetris_logic::BlockGrid;
|
widget::{button, text},
|
||||||
|
Element, Subscription, Task,
|
||||||
|
};
|
||||||
|
use tetris_logic::{BlockGrid, MoveDirection, Tetromino};
|
||||||
|
|
||||||
fn main() -> iced::Result {
|
fn main() -> iced::Result {
|
||||||
//Tetris::run(Settings::default())
|
//Tetris::run(Settings::default())
|
||||||
iced::application(Tetris::title, update, view).run_with(|| (Tetris::new(), Task::none()))
|
iced::application(Tetris::title, update, view)
|
||||||
|
.subscription(subscription)
|
||||||
|
.run_with(|| (Tetris::new(), Task::none()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -25,15 +30,70 @@ enum Message {
|
|||||||
Tick(chrono::DateTime<chrono::Local>),
|
Tick(chrono::DateTime<chrono::Local>),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(_state: &mut Tetris, message: Message) {
|
fn update(state: &mut Tetris, message: Message) {
|
||||||
match message {
|
match message {
|
||||||
Message::Up => todo!(),
|
Message::Pause => state.paused = !state.paused,
|
||||||
Message::Down => todo!(),
|
Message::Tick(_) => {
|
||||||
Message::Left => todo!(),
|
if !state.paused {
|
||||||
Message::Right => todo!(),
|
state.ticks += 1;
|
||||||
Message::Pause => todo!(),
|
}
|
||||||
Message::Tick(_) => todo!(),
|
}
|
||||||
|
Message::Up => {
|
||||||
|
state.blocks.rotate_active_piece();
|
||||||
|
}
|
||||||
|
Message::Down => {
|
||||||
|
state.blocks.move_active_piece(MoveDirection::HardDrop);
|
||||||
|
}
|
||||||
|
Message::Left => {
|
||||||
|
state.blocks.move_active_piece(MoveDirection::Left);
|
||||||
|
}
|
||||||
|
Message::Right => {
|
||||||
|
state.blocks.move_active_piece(MoveDirection::Right);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if state.blocks.piece_currently_active() {
|
||||||
|
if state.ticks % 10 == 0 && !state.paused {
|
||||||
|
state.blocks.move_active_piece(MoveDirection::SoftDrop);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let piece: Tetromino = rand::random();
|
||||||
|
state.blocks.drop_piece(piece);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let lines_removed = state.blocks.clear_pieces();
|
||||||
|
state.lines_removed += lines_removed;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn subscription(_state: &Tetris) -> Subscription<Message> {
|
||||||
|
let keyboard_subscription = iced::keyboard::on_key_press(|key, _modifiers| {
|
||||||
|
use iced::keyboard::key::{Key, Named};
|
||||||
|
match key {
|
||||||
|
Key::Named(Named::ArrowUp) => Some(Message::Up),
|
||||||
|
Key::Named(Named::ArrowDown) => Some(Message::Down),
|
||||||
|
Key::Named(Named::ArrowLeft) => Some(Message::Left),
|
||||||
|
Key::Named(Named::ArrowRight) => Some(Message::Right),
|
||||||
|
Key::Named(Named::Space) => Some(Message::Pause),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
/*
|
||||||
|
let keyboard_subscription = subscription::events_with(|event, status| {
|
||||||
|
if let event::Status::Captured = status {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
match event {
|
||||||
|
Event::Keyboard(keyboard::Event::KeyPressed { key_code, .. }) => {
|
||||||
|
handle_keypress(key_code)
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
|
let time_subscription = iced::time::every(std::time::Duration::from_millis(50))
|
||||||
|
.map(|_| Message::Tick(chrono::Local::now()));
|
||||||
|
Subscription::batch([time_subscription, keyboard_subscription])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(_state: &Tetris) -> Element<Message> {
|
fn view(_state: &Tetris) -> Element<Message> {
|
||||||
@ -224,4 +284,3 @@ fn handle_keypress(key_code: keyboard::KeyCode) -> Option<Message> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user