Skip to content

Commit

Permalink
Merge pull request #41 from Brian-Catcow-B/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Brian-Catcow-B authored Jan 29, 2021
2 parents 286b6ad + 43dea86 commit b005119
Show file tree
Hide file tree
Showing 13 changed files with 346 additions and 365 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[alias]
optwin = "build -Z unstable-options --profile opt --target x86_64-pc-windows-gnu"
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 21 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
# cargo-features = ["named-profiles"]

[package]
name = "rustrisn-t"
version = "0.0.2"
authors = ["Brian Billman"]
name = "tetrisn-t"
version = "0.1.0"
authors = ["Brian \"Catcow\" B"]
edition = "2018"


[profile.dev]
opt-level = 0
overflow-checks = false # it's a feature, not a bug; overflow is used for player colors in tile.rs
overflow-checks = false # used in ./src/game/piece.rs when rotating and moving pieces left

[profile.release]
opt-level = 3

# [profile.opt]
# inherits = "release"
#
# opt-level = 3
# overflow-checks = false
# debug = false
# debug-assertions = false
# lto = false
# panic = 'unwind'
# incremental = true
# codegen-units = 16
# rpath = false


[dependencies]
# ggez = "0.5"
ggez = { git = "https://github.com/Brian-Catcow-B/ggez.git", branch = "master-custom-gamepads" }
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT/X Consortium License

@ 2020 Brian Billman <brianjbillman@gmail.com>
@ 2020 Brian "Catcow" B <scooterpawn@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
Expand Down
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
# Rustrisn-t
Tetrisn-t rewritten in Rust, better.
# Tetrisn-t
Tetrisn-t (python version) rewritten in Rust, better.

Binaries for Windows and Linux are included in each tagged release (except 0.0.1) in the `release` folder.

Make sure your monitor's refresh rate is set to 60FPS; otherwise the game runs at a different speed than intended; this will eventually be fixed.
Binaries for Windows and Linux are included in each tagged release.

# Build
Download and install cargo, then
Download and install cargo, then set rustup default to 1.47.0 to avoid an error in the ggez library introduced with rust 1.48.0 by running
```
rustup default 1.47.0
```
then build with
```
cargo build --release
```
and find the resulting binary in `./target/release/`

Google any errors that occur, if they do.

# Gamepads
In the "Controls" menu, keyboard control schemes and setting players to use gamepads are both possible and mostly self explanatory.
It is possible to connect multiple keyboards to one PC and use both separately, but the inputs show up as the same, so the keyboard control schemes are not allowed to overlap, even across separate keyboards.
There is a check in place, which will give a notice when a key is attempted to be re-used.
Unfortunately, these settings are not saved, so they will have to be reconfigured each time the program is opened; eventually it will be implemented.
Unfortunately, these settings are not saved yet, so they will have to be reconfigured each time the program is opened; eventually, saved control schemes will be implemented.

Setting a player to use a gamepad is easily done in the "Controls" menu by pressing 'G', as it states.
The game decides which specific gamepad controls which player by assigning a gamepad's id to the first player that doesn't yet have an assigned gamepad id as soon as an unassigned gamepad has a button/axis pressed during gameplay.
Because of weird coding stuff, this is done each game no matter what, but might eventually be extended to be the entire instance of the program.

## Custom Layouts and Obscure Compatibility
This program uses SDL2 gamepad configurations for controllers.
A list of automatically-detected controllers can be found in the `resources` folder in `gamecontrollerdb.txt`, which is a copy of this file: https://github.com/gabomdq/SDL_GameControllerDB/blob/master/gamecontrollerdb.txt
The `resources` folder with its contents must be in the same location as the binary (exe for Windows users) in order for gamepads to continue to be detected; create a shortcut to the binary if you want to open it from elsewhere.
### Windows
Because ggez only supports xinput, a program like rewasd is required for non-xinput controllers, which allows remapping of non-xinput controllers to act as an xinput controller.
rewasd does cost money (unless you download an earlier version from 3rd party), but here's an alternative: http://ds4windows.com/

### Linux
For linux, this program uses SDL2 gamepad configurations for controllers.
A list of automatically-detected controllers can be found in the `resources` folder in `gamecontrollerdb.txt`, which is based on this file: https://github.com/gabomdq/SDL_GameControllerDB/blob/master/gamecontrollerdb.txt
The `resources` folder with its contents must be in the same location as the binary on launch in order for gamepads to be detected; create a shortcut to the binary if you want to open it from elsewhere.

In case custom layouts or compatibility for obscure gamepads are desired, here is a cross-platform SDL2 configurer: https://generalarcade.com/gamepadtool/. A quick guide on how to use it is as follows:
In case a gamepad is not detected or a different layout is desired, here is a cross-platform SDL2 configurer: https://generalarcade.com/gamepadtool/. A quick guide on how to use it is as follows:
1. Download, install, open
2. Select desired gamepad in the dropdown on the top
3. Select "Create A New Mapping"
Expand Down
46 changes: 5 additions & 41 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,8 @@ const LITTLE_TEXT_SCALE: f32 = 20.0;
// for each level (as the index), the number of frames it takes for a piece to move down one row (everything after 29 is also 0)
// it's actually 1 less than the number of frames it takes the piece to fall because the game logic works out better that way
const FALL_DELAY_VALUES: [u8; 30] = [
48 - 1,
43 - 1,
38 - 1,
33 - 1,
28 - 1,
23 - 1,
18 - 1,
13 - 1,
8 - 1,
6 - 1,
5 - 1,
5 - 1,
5 - 1,
4 - 1,
4 - 1,
4 - 1,
3 - 1,
3 - 1,
3 - 1,
2 - 1,
2 - 1,
2 - 1,
2 - 1,
2 - 1,
2 - 1,
2 - 1,
2 - 1,
2 - 1,
2 - 1,
1 - 1,
47, 42, 37, 32, 27, 22, 17, 12, 7, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0,
];

// number of frames between downward movements when holding down
Expand Down Expand Up @@ -287,10 +259,6 @@ impl Game {
.scale(Scale::uniform(LITTLE_TEXT_SCALE * 2.0)),
);

println!(
"[+] starting game with {} players and at level {}",
game_options.num_players, game_options.starting_level
);
Self {
board: Board::new(board_width, BOARD_HEIGHT, game_options.num_players),
num_players: game_options.num_players,
Expand Down Expand Up @@ -498,7 +466,7 @@ impl Game {
player.fall_countdown = if self.level < 30 {
FALL_DELAY_VALUES[self.level as usize]
} else {
1 - 1
0
};
player.force_fall_countdown = FORCE_FALL_DELAY;
// add more spawn delay if locking the piece caused a line clear
Expand All @@ -510,7 +478,7 @@ impl Game {
player.fall_countdown = if self.level < 30 {
FALL_DELAY_VALUES[self.level as usize]
} else {
1 - 1
0
};
player.force_fall_countdown = FORCE_FALL_DELAY;
}
Expand Down Expand Up @@ -552,10 +520,6 @@ impl Game {
self.level += 1;
}
self.game_info_text.fragments_mut()[5].text = format!("{:02}", self.level);
println!(
"[+] lines: {}; score: {}",
self.num_cleared_lines, self.score
);
}
}

Expand Down Expand Up @@ -634,7 +598,7 @@ impl Game {
}
}
if self.num_gamepads_to_initialize > 0
&& (value > DETECT_GAMEPAD_AXIS_THRESHOLD || value < -DETECT_GAMEPAD_AXIS_THRESHOLD)
&& !(-DETECT_GAMEPAD_AXIS_THRESHOLD..=DETECT_GAMEPAD_AXIS_THRESHOLD).contains(&value)
{
for map in self.vec_gamepad_id_map_to_player.iter_mut() {
if None == map.0 {
Expand Down
14 changes: 5 additions & 9 deletions src/game/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl Board {

// returns (num_lines_cleared, score_from_cleared_lines)
pub fn attempt_clear_lines(&mut self, level: u8) -> (u8, u32) {
if self.vec_full_lines.len() == 0 {
if self.vec_full_lines.is_empty() {
// nothing to see here
return (0, 0);
}
Expand All @@ -247,7 +247,7 @@ impl Board {
}
}

if vec_clearing_now_indices.len() == 0 {
if vec_clearing_now_indices.is_empty() {
// not much to see here
return (0, 0);
}
Expand Down Expand Up @@ -337,10 +337,6 @@ impl Board {
}
}

println!(
"[+] cleared {} lines, scored {} points",
lines_cleared, score
);
(lines_cleared as u8, score)
}
}
Expand Down Expand Up @@ -420,7 +416,7 @@ mod tests {
(num_cleared_lines, score),
(8, (2 * SCORE_QUADRUPLE_BASE as u32 * (1)) as u64)
);
println!("Passed scoring 2 tetrises on the same frame");
println!("[~] Passed scoring 2 tetrises on the same frame");

// now try with some L's because that can break it
let mut score: u64 = 0;
Expand Down Expand Up @@ -472,7 +468,7 @@ mod tests {
(1 * SCORE_SINGLE_BASE as u32 * (1) + 1 * SCORE_TRIPLE_BASE as u32 * (1)) as u64
)
);
println!("Passed scoring a single as one player and then a triple as another player one frame after");
println!("[~] Passed scoring a single as one player and then a triple as another player one frame after");

// now clear 2 tetrises, the second one 1 frame after the other, which can also break things
let mut score: u64 = 0;
Expand Down Expand Up @@ -522,6 +518,6 @@ mod tests {
(num_cleared_lines, score),
(8, (2 * SCORE_QUADRUPLE_BASE as u32 * (1)) as u64)
);
println!("Passed scoring 2 tetrises one frame apart");
println!("[~] Passed scoring 2 tetrises one frame apart");
}
}
Loading

0 comments on commit b005119

Please sign in to comment.