Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6 from MinusKelvin/client-rewrite
Browse files Browse the repository at this point in the history
Client rewrite
  • Loading branch information
MinusKelvin authored Mar 25, 2020
2 parents 86853af + afb963a commit 7cc63be
Show file tree
Hide file tree
Showing 82 changed files with 1,077 additions and 1,180 deletions.
19 changes: 4 additions & 15 deletions battle/src/battle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ pub struct Battle {
p2_rng: Pcg64Mcg,
garbage_rng: Pcg64Mcg,
pub time: u32,
multiplier: f32,
margin_time: Option<u32>,
pub replay: Replay
}

Expand All @@ -38,18 +36,11 @@ impl Battle {
player_1, player_2,
p1_rng, p2_rng, garbage_rng,
time: 0,
margin_time: p1_config.margin_time,
multiplier: 1.0,
}
}

pub fn update(&mut self, p1: Controller, p2: Controller) -> BattleUpdate {
self.time += 1;
if let Some(margin_time) = self.margin_time {
if self.time >= margin_time && (self.time - margin_time) % 1800 == 0 {
self.multiplier += 0.5;
}
}

self.replay.updates.push_back((p1, p2));

Expand All @@ -58,12 +49,12 @@ impl Battle {

for event in &p1_events {
if let &Event::GarbageSent(amt) = event {
self.player_2.garbage_queue += (amt as f32 * self.multiplier) as u32;
self.player_2.garbage_queue += amt;
}
}
for event in &p2_events {
if let &Event::GarbageSent(amt) = event {
self.player_1.garbage_queue += (amt as f32 * self.multiplier) as u32;
self.player_1.garbage_queue += amt;
}
}

Expand All @@ -76,8 +67,7 @@ impl Battle {
events: p2_events,
garbage_queue: self.player_2.garbage_queue
},
time: self.time,
attack_multiplier: self.multiplier
time: self.time
}
}
}
Expand All @@ -86,8 +76,7 @@ impl Battle {
pub struct BattleUpdate {
pub player_1: PlayerUpdate,
pub player_2: PlayerUpdate,
pub time: u32,
pub attack_multiplier: f32
pub time: u32
}

#[derive(Serialize, Deserialize, Clone, Debug)]
Expand Down
3 changes: 0 additions & 3 deletions battle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub struct GameConfig {
pub auto_repeat_rate: u32,
pub soft_drop_speed: u32,
pub lock_delay: u32,
pub margin_time: Option<u32>,
/// Measured in 1/100 of a tick
pub gravity: i32,

Expand All @@ -37,7 +36,6 @@ impl Default for GameConfig {
auto_repeat_rate: 2,
soft_drop_speed: 2,
lock_delay: 30,
margin_time: None,
gravity: 4500,
next_queue_size: 5,
max_garbage_add: 10,
Expand All @@ -56,7 +54,6 @@ impl GameConfig {
auto_repeat_rate: 0,
soft_drop_speed: 0,
lock_delay: 30,
margin_time: None,
gravity: 4500,
next_queue_size: 5,
max_garbage_add: 20,
Expand Down
23 changes: 12 additions & 11 deletions gui/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
[package]
name = "gui"
version = "0.1.0"
authors = ["MinusKelvin <minuskelvin.carlson@gmail.com>"]
authors = ["MinusKelvin <mark.carlson@minuskelvin.net>"]
edition = "2018"
default-run = "gui"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
arrayvec = "0.4.11"
ggez = "0.5.1"
game-util = { git = "https://github.com/MinusKelvin/game-util-rs" }
cold-clear = { path = "../bot" }
libtetris = { path = "../libtetris" }
battle = { path = "../battle" }
cold-clear = { path = "../bot" }
serde = "1"
bincode = "1"
arrayvec = "0.4.11"
rand = "0.7.3"
gilrs = { version = "0.7.4", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.8.11"
bincode = "1.2"
libflate = "0.1"
serde_yaml = "0.8"
rand = "0.7.0"
rand_pcg = "0.2.0"
enumset = "0.4.0"
winit = { version = "0.19", features = ["serde"] }

[build-dependencies]
build-utils = { git = "https://github.com/MinusKelvin/game-util-rs" }
6 changes: 6 additions & 0 deletions gui/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use std::env;
use std::path::Path;

fn main() {
build_utils::gen_sprites("sprites", Path::new(&env::var("OUT_DIR").unwrap()), 1024);
}
Binary file removed gui/resources/sprites.png
Binary file not shown.
Binary file added gui/sprites/blank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/filled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/garbage_bar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/ghost.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/line_clear.0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/line_clear.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/line_clear.10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/line_clear.11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/line_clear.12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/line_clear.13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/line_clear.14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/line_clear.15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/line_clear.16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/line_clear.17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/line_clear.18.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/line_clear.19.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/line_clear.2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/line_clear.20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/line_clear.21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/line_clear.22.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/line_clear.23.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/line_clear.24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/line_clear.25.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/line_clear.26.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gui/sprites/line_clear.27.png
Binary file added gui/sprites/line_clear.28.png
Binary file added gui/sprites/line_clear.29.png
Binary file added gui/sprites/line_clear.3.png
Binary file added gui/sprites/line_clear.30.png
Binary file added gui/sprites/line_clear.31.png
Binary file added gui/sprites/line_clear.32.png
Binary file added gui/sprites/line_clear.33.png
Binary file added gui/sprites/line_clear.34.png
Binary file added gui/sprites/line_clear.4.png
Binary file added gui/sprites/line_clear.5.png
Binary file added gui/sprites/line_clear.6.png
Binary file added gui/sprites/line_clear.7.png
Binary file added gui/sprites/line_clear.8.png
Binary file added gui/sprites/line_clear.9.png
Binary file added gui/sprites/piece.0.png
Binary file added gui/sprites/piece.1.png
Binary file added gui/sprites/piece.2.png
Binary file added gui/sprites/piece.3.png
Binary file added gui/sprites/piece.4.png
Binary file added gui/sprites/piece.5.png
Binary file added gui/sprites/piece.6.png
Binary file added gui/sprites/plan.0.png
Binary file added gui/sprites/plan.1.png
Binary file added gui/sprites/plan.10.png
Binary file added gui/sprites/plan.11.png
Binary file added gui/sprites/plan.12.png
Binary file added gui/sprites/plan.13.png
Binary file added gui/sprites/plan.14.png
Binary file added gui/sprites/plan.15.png
Binary file added gui/sprites/plan.2.png
Binary file added gui/sprites/plan.3.png
Binary file added gui/sprites/plan.4.png
Binary file added gui/sprites/plan.5.png
Binary file added gui/sprites/plan.6.png
Binary file added gui/sprites/plan.7.png
Binary file added gui/sprites/plan.8.png
Binary file added gui/sprites/plan.9.png
70 changes: 70 additions & 0 deletions gui/src/battle_ui.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use game_util::prelude::*;
use battle::{ Battle, BattleUpdate };
use crate::player_draw::PlayerDrawState;
use crate::res::Resources;

pub struct BattleUi {
player_1_graphics: PlayerDrawState,
player_2_graphics: PlayerDrawState,
time: u32
}

impl BattleUi {
pub fn new(battle: &Battle, p1_name: String, p2_name: String) -> Self {
BattleUi {
player_1_graphics: PlayerDrawState::new(battle.player_1.board.next_queue(), p1_name),
player_2_graphics: PlayerDrawState::new(battle.player_2.board.next_queue(), p2_name),
time: 0
}
}

pub fn update(
&mut self,
res: &mut Resources,
update: BattleUpdate,
p1_info_update: Option<cold_clear::Info>,
p2_info_update: Option<cold_clear::Info>
) {
for event in update.player_1.events.iter().chain(update.player_2.events.iter()) {
use battle::Event::*;
match event {
PieceMoved | SoftDropped | PieceRotated => {
if res.move_sound_sink.len() <= 1 {
res.move_sound_sink.append(res.move_sound.sound());
}
}
PiecePlaced { hard_drop_distance, locked, .. } => {
if hard_drop_distance.is_some() {
res.hard_drop.play();
}
if locked.placement_kind.is_clear() {
res.line_clear.play();
}
}
_ => {}
}
}

self.player_1_graphics.update(update.player_1, p1_info_update, update.time);
self.player_2_graphics.update(update.player_2, p2_info_update, update.time);
self.time = update.time;
}

pub fn draw(&self, res: &mut Resources) {
res.text.draw_text(
&format!("{}:{:02}", self.time / 60 / 60, self.time / 60 % 60),
20.0, 1.5,
game_util::Alignment::Center,
[0xFF; 4], 1.0, 0
);

self.player_1_graphics.draw(res, 0.0+1.0);
self.player_2_graphics.draw(res, 20.0+1.0);

res.sprite_batch.render(Transform3D::ortho(
0.0, 40.0,
0.0, 23.0,
-1.0, 1.0
));
}
}
Loading

0 comments on commit 7cc63be

Please sign in to comment.