-
Notifications
You must be signed in to change notification settings - Fork 17
/
main.rs
105 lines (88 loc) · 2.63 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use runty8::{App, Button, Pico8};
fn main() {
let resources = runty8::load_assets!("moving-box").unwrap();
runty8::debug_run::<ExampleApp>(resources).unwrap();
}
pub struct ExampleApp {
x: i32,
y: i32,
xa: i32,
ya: i32,
yc: i32,
}
impl App for ExampleApp {
fn init(_: &mut Pico8) -> Self {
Self {
x: 6400,
y: 6400,
xa: 0,
ya: 0,
yc: 0,
}
}
fn draw(&mut self, draw_context: &mut Pico8) {
draw_context.cls(0);
draw_context.print(
&format!("X={} Y={} YC={}", self.x / 100, self.y / 100, self.yc),
0,
0,
6,
);
draw_context.line(0, 72, 127, 72, 4);
let x0 = self.x / 100 + 1;
let y0 = self.y / 100 + 1;
#[allow(dead_code, unused_variables)]
let sprite: [u8; 8 * 8] = [
0, 0, 0, 0, 0, 0, 0, 0, //
6, 6, 6, 6, 6, 6, 6, 0, //
6, 7, 7, 7, 7, 7, 6, 0, //
6, 7, 6, 6, 6, 7, 6, 0, //
6, 7, 6, 6, 6, 7, 6, 0, //
6, 7, 6, 6, 6, 7, 6, 0, //
6, 7, 7, 7, 7, 7, 6, 0, //
6, 6, 6, 6, 6, 6, 6, 0, //
];
draw_context.rectfill(x0, y0, x0 + 6, y0 + 6, 4);
// draw_context.raw_spr(sprite, self.x / 100, self.y / 100);
}
fn update(&mut self, state: &mut Pico8) {
// println!("{:?}", state);
// -- lower -100/100 less max spd
// -- lower -10/10 slower start
// if (btn(⬅️) and xa>-100) xa-=10
// if (btn(➡️) and xa<100) xa+=10
// -- lower -200 is higher jump
// if (btn(🅾️) and yc==0) ya=-200 yc=39
// -- lower 5 is more slippery
// -- note: must be divisible by
// -- walking speed
// if (xa<0) xa+=5
// if (xa>0) xa-=5
// x+=xa
// -- lower -1 is more gravity
// -- note: must be divisible by
// -- jumping strength
// if (yc>0) ya+=10 y+=ya yc-=1
if state.btn(Button::Left) && self.xa > -100 {
self.xa -= 10;
}
if state.btn(Button::Right) && self.xa < 100 {
self.xa += 10;
}
if state.btn(Button::Circle) && self.yc == 0 {
self.ya = -200;
self.yc = 39;
}
self.xa += match self.xa.cmp(&0) {
std::cmp::Ordering::Less => 5,
std::cmp::Ordering::Equal => 0,
std::cmp::Ordering::Greater => -5,
};
self.x += self.xa;
if self.yc > 0 {
self.ya += 10;
self.y += self.ya;
self.yc -= 1;
}
}
}