From f9a28dcf35f1ae4f873c289ba9f9af53831408f9 Mon Sep 17 00:00:00 2001 From: LiteHell Date: Fri, 7 Jun 2024 16:45:51 +0900 Subject: [PATCH] feat: use janggu control on title screen --- game/src/game/title.rs | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/game/src/game/title.rs b/game/src/game/title.rs index 8b12304..1565900 100644 --- a/game/src/game/title.rs +++ b/game/src/game/title.rs @@ -1,10 +1,8 @@ +use std::time::Instant; use std::{path::Path, time::Duration}; use num_rational::Rational64; -use sdl2::{ - event::Event, image::LoadTexture, keyboard::Keycode, pixels::Color, rect::Rect, render::Canvas, - video::Window, -}; +use sdl2::{image::LoadTexture, pixels::Color, rect::Rect, render::Canvas, video::Window}; use crate::constants::DEFAULT_FONT_COLOR; use crate::constants::DEFAULT_FONT_PATH as FONT_PATH; @@ -13,6 +11,8 @@ use crate::constants::DEFAULT_VIDEO_PATH as VIDEO_PATH; use crate::create_streaming_iyuv_texture; +use super::game_player::janggu_state_with_tick::JangguStateWithTick; + use super::{ common::{event_loop_common, render_common}, game_common_context::GameCommonContext, @@ -130,22 +130,27 @@ pub(crate) fn render_title(common_context: &mut GameCommonContext) -> TitleResul background_video_size.1 ) .expect("Failed to create texture for title background video"); + let mut janggu_state = JangguStateWithTick::new(); + let title_started_at = Instant::now(); + janggu_state.update( + common_context.read_janggu_state(), + title_started_at.elapsed().as_millis() as i128, + ); loop { for event in common_context.event_pump.poll_iter() { if event_loop_common(&event, &mut common_context.coins) { return TitleResult::Exit; } - match event { - Event::KeyDown { - keycode: Some(Keycode::Return), - .. - } => { - if common_context.coins >= common_context.price { - common_context.coins -= common_context.price; - return TitleResult::StartGame; - } - } - _ => {} + } + + janggu_state.update( + common_context.read_janggu_state(), + title_started_at.elapsed().as_millis() as i128, + ); + if janggu_state.궁채.is_keydown_now || janggu_state.열채.is_keydown_now { + if common_context.coins >= common_context.price { + common_context.coins -= common_context.price; + return TitleResult::StartGame; } }