Skip to content

Commit

Permalink
Finishig touches
Browse files Browse the repository at this point in the history
  • Loading branch information
micheletascaadevinta committed Mar 5, 2023
1 parent 361f767 commit 14aae93
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 21 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@


# TrainYard
# Trainyard

[![CreativeCommons](https://img.shields.io/github/license/micoloth/opentrainyard)](https://github.com/micoloth/OpenTrainyard/#license)
[![Bevy.io](https://img.shields.io/crates/v/bevy.svg)](https://crates.io/crates/bevy)
[![Rust](https://github.com/bevyengine/bevy/workflows/CI/badge.svg)](https://github.com/micoloth/OpenTrainyard/actions)


Clone of the original iOs puzzle game, [Trainyard](https://trainyard.ca/) by [Matt Rix](https://twitter.com/MattRix).

Implemented in the [Bevy](https://bevyengine.org/) game engine.

You can play it online here! https://micoloth.github.io/OpenTrainyard/


# Discord

Join the discord
Join the discord to discuss the game and the engine [here](https://discord.gg/umnMwFdA)


# Limitations
Expand Down
Binary file modified assets/samples/icon_crop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 7 additions & 6 deletions commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ TODO:
- DONE Back to title button + credits + icon + go directly to 1st level
- DONE best scores
- DONE Best Score in Won menu And solution menu..
- Music
- Particle effect .....
- Ghost train direction in stop (+start?) and split
- You MIGHT WANT to fix the 3-collision problem..
- credit text
- Discord link
- DONE Particle effect .....
- DONE Ghost train direction in stop (+start?) and split
- DONE credit text
- DONE Discord link
- DONE You MIGHT WANT to fix the 3-collision problem..

- WONT DO Music

9 changes: 5 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta id="extViewportMeta" name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<title>TrainYard</title> <!-- ToDo -->
<title>Trainyard</title> <!-- ToDo -->
<link data-trunk rel="copy-dir" href="assets" />
<link data-trunk rel="copy-dir" href="credits" />
<link data-trunk rel="copy-file" href="build/windows/icon.ico" />
Expand Down Expand Up @@ -41,7 +41,8 @@
<!-- 1. Define the div: -->
<div id="popup_star" class="popup" style="display:none; position:fixed; top:50%; left:50%; transform:translate(-50%, -50%); background-color:rgba(23, 23, 30, 0.8); color:white; padding:20px; border-radius:10px; text-align:center;">
<h1>Thanks for playing Trainyard!</h1>
<p>If you like this, please consider starring the Github Repo
<p>You can join the <a href="https://discord.gg/umnMwFdA" target="_blank" style="color:rgb(159, 190, 255);">Discord here</a> to discuss about it.</p>
<p>If you like the game, please consider starring the Github Repo
<a href="https://github.com/micoloth" target="_blank" style="color:rgb(159, 190, 255);">here</a>.
<br>
It would mean a lot!
Expand All @@ -58,8 +59,8 @@ <h2>Remember to not procrastinate too much!</h2>
<!-- 2. Define Javascript logic to show the div after 10 seconds: -->
<script>
// Check if it is the first time the user is on the page:
if (localStorage.getItem("firstTime") === null) {
localStorage.setItem("firstTime", "false");
if (localStorage.getItem("first_time") === null) {
localStorage.setItem("first_time", "false");
setTimeout(function () { document.getElementById("popup_star").style.display = "block"; }, 200000); // 10 minutes: 600000
setTimeout(function () { document.getElementById("popup_timer").style.display = "block"; }, 600000); // 10 minutes: 600000
}
Expand Down
4 changes: 2 additions & 2 deletions src/menu_credits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fn setup_menu_credits(
) {
let width = windows.get_primary().unwrap().width();
let height = windows.get_primary().unwrap().height();
//Write "TrainYard" at the top of the page:
//Write "Trainyard" at the top of the page:
let mut ec = commands.spawn(NodeBundle {
style: Style {
position_type: PositionType::Absolute,
Expand All @@ -78,7 +78,7 @@ fn setup_menu_credits(
text: Text {
sections: vec![
TextSection {
value: "Credits go entirely to the original creator of\nthis great puzzle:\n".to_string(),
value: "Credits go entirely to the original creator\nof this great puzzle:\n".to_string(),
style: TextStyle { font: font_assets.fira_sans.clone(), font_size:22., color: Color::rgb(0.9, 0.9, 0.9), },
},
TextSection {
Expand Down
4 changes: 2 additions & 2 deletions src/menu_title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn setup_menu(
},
MainMenuElem{}));

//Write "TrainYard" at the top of the page:
//Write "Trainyard" at the top of the page:
let mut ec = commands.spawn(NodeBundle {
style: Style {
position_type: PositionType::Absolute,
Expand All @@ -129,7 +129,7 @@ fn setup_menu(
style: Style { position_type: PositionType::Absolute, margin: UiRect::all(Val::Auto), ..default() },
text: Text {
sections: vec![TextSection {
value: "TrainYard".to_string(),
value: "Trainyard".to_string(),
style: TextStyle { font: font_assets.fira_sans.clone(), font_size: 45., color: Color::rgb(0.9, 0.9, 0.9), },
}],
alignment: TextAlignment{ vertical: VerticalAlign::Center, horizontal: HorizontalAlign::Center, },
Expand Down
28 changes: 23 additions & 5 deletions src/simulator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


use bevy::prelude::Component;
use bevy::{prelude::Component, log};

// wrongs:
// lt
Expand Down Expand Up @@ -419,16 +419,17 @@ pub fn check_border_collisions(trains: Vec<Train>, field: Vec<Vec<Tile>>) -> (Ve

// # 4. For each train, change their >SIDE< only following track
pub fn check_crashed(trains: Vec<Train>, field: Vec<Vec<Tile>>) -> (bool, Vec<Vec<Tile>>, Vec<Train>){

let mut new_trains: Vec<Train> = Vec::new();
let mut crashed = false;
for (_, train) in trains.iter().enumerate(){
let tile = &field[train.pos.py][train.pos.px];
if !can_pass_through(tile, train.pos.side) {crashed=true; continue;}
new_trains.push(train.clone());
};

// // println!(">>>> {:?}", print_tile(&new_field[3][5]));
// println!("after 4 trains{:?}; Crashed: {:?}, Completed: {:?}", new_trains, crashed, completed);
return (crashed, field, trains);
return (crashed, field, new_trains);
}

// # 4. For each train, change their >SIDE< only following track
Expand Down Expand Up @@ -488,12 +489,29 @@ pub fn check_center_colliding(trains: Vec<Train>, field: Vec<Vec<Tile>>) -> (Vec
for (i, t1) in trains.iter().enumerate(){
for (j, t2) in trains[i+1..].iter().enumerate(){
if are_colliding_center_coloring(*t1, *t2, &field) || are_colliding_center_coloring_different_tracks(*t1, *t2, &field){
// // println!("\n>>Center colliding! {:?} {:?}", t1, t2);
let newcol = mix_colors(t1.c, t2.c);
// Check if there is a THIRD train colliding with the first two:
// Get all OTHER trains that are colliding with t1:
let mut colliding_with_t1: Vec<usize> = Vec::new();
for (i2, t3) in trains.iter().enumerate(){
if i2 == i || i2 == (i+1+j) {continue;}
if are_colliding_center_coloring(*t1, *t3, &field) || are_colliding_center_coloring_different_tracks(*t1, *t3, &field){
colliding_with_t1.push(i2);
}
}
// Log a message to console with logging library:
log::info!("COLLISION: {:?} {:?} {:?} {:?}", t1, t2, colliding_with_t1, trains);
// If not empty:
let newcol = if colliding_with_t1.len() > 0 { Colorz::BROWN_ }
else{ mix_colors(t1.c, t2.c) };

newly_collided_trains.push(Train{c: newcol, pos: t1.pos});
newly_collided_trains.push(Train{c: newcol, pos: t2.pos});
new_trains[i].c = newcol;
new_trains[i+j+1].c = newcol;
for i3 in colliding_with_t1.iter(){
new_trains[*i3].c = newcol;
newly_collided_trains.push(Train{c: newcol, pos: trains[*i3].pos});
}
break;
}
}
Expand Down

0 comments on commit 14aae93

Please sign in to comment.