Skip to content

Commit 6dce7b8

Browse files
committed
bounce game initial rust implementation
1 parent 847c9ee commit 6dce7b8

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

13_Bounce/rust/src/main.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ fn main() {
7171
}
7272

7373
let mut l = 0.0;
74+
let mut l_expected = l;
7475

7576
//220 FOR H=INT(-16*(V/32)^2+V^2/32+.5) TO 0 STEP -.5
7677
let mut h = (-16.0 * (v / 32.0).powi(2) + (v.powi(2)) / 32.0 + 0.5).floor();
@@ -82,24 +83,28 @@ fn main() {
8283
}
8384
//225 L=0
8485
l = 0.0;
85-
86+
l_expected = l;
8687
//230 FOR I=1 TO S1
8788
for i in 1..=s1 {
8889
let mut T = 0.0;
8990
//240 FOR T=0 TO T(I) STEP S2
9091
while T <= t[(i - 1) as usize] {
9192
//245 L=L+S2
9293
l = l + s2;
93-
94+
l_expected = l_expected + s2;
95+
9496
//250 IF ABS(H-(.5*(-32)*T^2+V*C^(I-1)*T))>.25 THEN 270
9597
let condition = h - (0.5 * (-32.0) * T.powf(2.0) + v * c.powf((i-1) as f32) * T);
9698
if condition.abs() >= 0.25{
9799
T = T + s2;
98100
continue;
99101
}
102+
// TABS ARE NOT SPACES, BUT A TERMINAL POSITION
100103
//260 PRINT TAB(L/S2);"0";
101-
print!("{}{}", " ".repeat((l / s2) as usize), T);
102-
104+
let spaces = ((l / s2).floor()-1.0) as usize;
105+
print!("{}0", " ".repeat(spaces));
106+
l = l - spaces as f32;
107+
103108
//270 NEXT T
104109
T = T + s2;
105110
}
@@ -128,7 +133,7 @@ fn main() {
128133
print!(" ");
129134

130135
//320 FOR I=1 TO INT(L+1)/S2+1
131-
for _ in 1..=((l+1.0) / s2 + 1.0) as i32 {
136+
for _ in 1..=((l_expected+1.0) / s2 + 1.0) as i32 {
132137
//330 PRINT ".";
133138
print!(".");
134139
//340 NEXT I
@@ -139,7 +144,7 @@ fn main() {
139144
print!("\n 0");
140145

141146
//360 FOR I=1 TO INT(L+.9995)
142-
for i in 1..=((l + 0.9995) as i32) {
147+
for i in 1..=((l_expected + 0.9995) as i32) {
143148
//380 PRINT TAB(INT(I/S2));I;
144149
print!("{}{}", " ".repeat((i as f32 / s2) as usize), i);
145150
//390 NEXT I
@@ -148,7 +153,7 @@ fn main() {
148153
//400 PRINT
149154
//410 PRINT TAB(INT(L+1)/(2*S2)-2);"SECONDS"
150155
//420 PRINT
151-
let tabs = ((l+1.0) / (2.0 * s2) - 2.0) as usize;
156+
let tabs = ((l_expected+1.0) / (2.0 * s2) - 2.0) as usize;
152157
println!("\n{}SECONDS\n", " ".repeat(tabs));
153158

154159
//430 GOTO 135

0 commit comments

Comments
 (0)