Skip to content

Commit 4ddeb52

Browse files
committed
zz
1 parent b70f675 commit 4ddeb52

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed

docs/public/st0057-01.png

71.6 KB
Loading

docs/public/st0057-02.png

8.56 KB
Loading

docs/smalltalk/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ title: 碎碎念
66

77
“碎碎念”是本站发布日常随笔的栏目,内容包括项目进展、小点子、有趣的讨论等。
88

9+
- 2024-10-13: [凹语言山寨马斯克星舰小游戏](st0057.md)
910
- 2024-10-06: [凹语言支持map](st0056.md)
1011
- 2024-10-06: [凹语言Native后端达到C语言性能](st0055.md)
1112
- 2024-09-28: [凹语言支持Chrome内置AI](st0054.md)

docs/smalltalk/st0057.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# 凹语言山寨马斯克星舰小游戏
2+
3+
- 时间:2024-10-13
4+
- 撰稿:凹语言开发组
5+
- 转载请注明原文链接:[https://wa-lang.org/smalltalk/st0057.html](https://wa-lang.org/smalltalk/st0057.html)
6+
7+
---
8+
9+
美国太空探索技术公司(SpaceX)新一代重型运载火箭“星舰”当日发射升空。这是“星舰”第五次试飞,将首次尝试用发射塔的机械臂在半空中捕获助推器以实现回收。
10+
11+
![](/st0057-01.png)
12+
13+
为了致敬SpaceX在星舰的最新实验成果,我们用凹语言移植(山寨)一个马斯克星舰小游戏。原始的游戏是TinyGo实现,代码在:[https://github.com/venlinz/simple-game-wasm4](https://github.com/venlinz/simple-game-wasm4)。用凹语言移植后的效果:
14+
15+
![](/st0057-02.png)
16+
17+
## 星舰小游戏代码
18+
19+
代码在主仓库的`waroot/examples/w4-rocket`目录:
20+
21+
```wa
22+
// 版权 @2024 W4-rocket 作者。保留所有权利。
23+
24+
import "syscall/wasm4"
25+
26+
global rocket = [13]byte{
27+
0b00111100,
28+
0b01111110,
29+
0b11111111,
30+
0b11111111,
31+
0b11000011,
32+
0b11000011,
33+
0b11111111,
34+
0b11111111,
35+
0b01111110,
36+
0b11111111,
37+
0b11111111,
38+
0b00111100,
39+
0b00011000,
40+
}
41+
42+
global rocket_unthrust = [13]byte{
43+
0b00111100,
44+
0b01111110,
45+
0b11111111,
46+
0b11111111,
47+
0b11000011,
48+
0b11000011,
49+
0b11111111,
50+
0b11111111,
51+
0b01111110,
52+
0b11111111,
53+
0b11111111,
54+
0b00000000,
55+
0b00000000,
56+
}
57+
58+
global car_pos_x = 0
59+
global car_pos_y = 0
60+
61+
func init {
62+
frameBuffer := wasm4.GetFramebuffer()
63+
for i := range frameBuffer {
64+
frameBuffer[i] = 1 | (1 << 2) | (1 << 4) | (1 << 6)
65+
}
66+
}
67+
68+
#wa:export update
69+
func Update {
70+
wasm4.SetPalette2(0xff0000)
71+
72+
wasm4.SetDrawColorsU16(0x31)
73+
wasm4.Blit(rocket_unthrust[:], car_pos_x, car_pos_y, 8, 13, wasm4.BLIT_1BPP)
74+
75+
gamepad := wasm4.GetGamePad1()
76+
77+
if gamepad&wasm4.BUTTON_LEFT != 0 {
78+
if car_pos_x > 0 {
79+
car_pos_x--
80+
}
81+
wasm4.Blit(rocket_unthrust[:], car_pos_x, car_pos_y, 8, 13, wasm4.BLIT_1BPP)
82+
}
83+
84+
wasm4.Text("<", 0, 150)
85+
if gamepad&wasm4.BUTTON_RIGHT != 0 {
86+
if car_pos_x < 150 {
87+
car_pos_x++
88+
}
89+
wasm4.Blit(rocket_unthrust[:], car_pos_x, car_pos_y, 8, 13, wasm4.BLIT_1BPP)
90+
}
91+
wasm4.Text(">", 152, 150)
92+
if gamepad&wasm4.BUTTON_UP != 0 {
93+
if car_pos_y > 0 {
94+
car_pos_y--
95+
}
96+
wasm4.Blit(rocket[:], car_pos_x, car_pos_y, 8, 13, wasm4.BLIT_1BPP)
97+
}
98+
99+
if gamepad&wasm4.BUTTON_DOWN != 0 {
100+
if car_pos_y < 150 {
101+
car_pos_y++
102+
}
103+
wasm4.Blit(rocket_unthrust[:], car_pos_x, car_pos_y, 8, 13, wasm4.BLIT_1BPP)
104+
}
105+
}
106+
```
107+
108+
游戏虽然简单,主要是通过方向键控制星舰的飞行,但也是凹语言进入星辰大海的第一步。Let's dive!
109+

0 commit comments

Comments
 (0)