diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2011/version.md" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2011/version.md" new file mode 100644 index 0000000..c29dada --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2011/version.md" @@ -0,0 +1,3 @@ +moon 0.1.20241106 (79e45ae 2024-11-06) ~/.moon/bin/moon +moonc v0.1.20241106+8f17a3fc7 ~/.moon/bin/moonc +moonrun 0.1.20241106 (79e45ae 2024-11-06) ~/.moon/bin/moonrun \ No newline at end of file diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/.gitignore" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/.gitignore" new file mode 100644 index 0000000..b1283a7 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/.gitignore" @@ -0,0 +1,2 @@ +target/ +.mooncakes/ diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/LICENSE" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/LICENSE" new file mode 100644 index 0000000..d645695 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/LICENSE" @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/README.md" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/README.md" new file mode 100644 index 0000000..6a5244b --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/README.md" @@ -0,0 +1,36 @@ +# Spaceack/hypotrochoid_emulator + +## 内旋轮线模拟器(Hypotrochoid Emulator) + +## 介绍 +内旋轮线模拟器,一款`探索`与`发现`的`图形艺术`游戏,通过调整参数,探索参数与图案特点的关联性。 + +## 玩法 + +- 按`空格键`开始 +- `X`键 切换轮线颜色 +- `Z`键 显示/隐藏参数菜单 +- `左/右`键选择参数 +- `上/下`键调调整参数数值 +- `F8` 截取图像 + +## 参数说明 + +- d: 小圆上固定点到小圆圆心的距离 +- lr: 小圆的半径 +- br: 大圆的半径 +- ti: 旋转次数 + +```bash +# install moonbit +curl -fsSL https://cli.moonbitlang.cn/install/unix.sh | bash +# install wasm4 +npm install -D wasm4 +# +moon update && moon add moonbitlang/wasm4 +# build +moon build --target wasm +# run +npx wasm4 run target/wasm/release/build/hypotrochoid_emulator.wasm + +``` diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/moon.mod.json" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/moon.mod.json" new file mode 100644 index 0000000..ca03124 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/moon.mod.json" @@ -0,0 +1,13 @@ +{ + "name": "Spaceack/hypotrochoid_emulator", + "version": "0.1.0", + "deps": { + "moonbitlang/wasm4": "0.2.2" + }, + "readme": "README.md", + "repository": "", + "license": "Apache-2.0", + "keywords": [], + "description": "", + "source": "src" +} \ No newline at end of file diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/src/lib/hello.mbt" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/src/lib/hello.mbt" new file mode 100644 index 0000000..9012592 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/src/lib/hello.mbt" @@ -0,0 +1,3 @@ +pub fn hello() -> String { + "Hello, world!" +} diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/src/lib/hello_test.mbt" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/src/lib/hello_test.mbt" new file mode 100644 index 0000000..e0e3a7d --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/src/lib/hello_test.mbt" @@ -0,0 +1,5 @@ +test "hello" { + if @lib.hello() != "Hello, world!" { + fail!("@lib.hello() != \"Hello, world!\"") + } +} diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/src/lib/moon.pkg.json" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/src/lib/moon.pkg.json" new file mode 100644 index 0000000..6af8789 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/src/lib/moon.pkg.json" @@ -0,0 +1,21 @@ +{ + // "is-main": true, + "import": ["moonbitlang/wasm4"], + "link": { + "wasm-gc": { + "exports": ["start", "update"], + "import-memory": { + "module": "env", + "name": "memory" + } + }, + "wasm": { + "exports": ["start", "update"], + "import-memory": { + "module": "env", + "name": "memory" + }, + "heap-start-address": 6590 + } + } + } \ No newline at end of file diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/src/moon.pkg.json" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/src/moon.pkg.json" new file mode 100644 index 0000000..4ca3231 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/src/moon.pkg.json" @@ -0,0 +1,21 @@ +{ + // "is-main": true, + "import": ["moonbitlang/wasm4"], + "link": { + "wasm-gc": { + "exports": ["start", "update"], + "import-memory": { + "module": "env", + "name": "memory" + } + }, + "wasm": { + "exports": ["start", "update"], + "import-memory": { + "module": "env", + "name": "memory" + }, + "heap-start-address": 6590 + } + } +} \ No newline at end of file diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/src/top.mbt" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/src/top.mbt" new file mode 100644 index 0000000..8a4e631 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2012/hypotrochoid_emulator/src/top.mbt" @@ -0,0 +1,232 @@ +enum GameState { + GSInit // 初始状态 + GSGameStart +} + +struct GameStat { + mut game_state : GameState + mut d : Double + mut lr : Double + mut br : Double + mut revs : Double + niter : Double + mut color : UInt + mut show_args_bar : Bool + mut select_arg : UInt + rng : @random.Rand +} + +pub struct PrevGamePad { + mut button_1 : Bool + mut button_2 : Bool + mut button_left : Bool + mut button_right : Bool + mut button_up : Bool + mut button_down : Bool +} derive(Eq, Default) + +pub fn butRel(cur_button : Bool, prev_button : Bool) -> Bool { + return cur_button && not(prev_button) +} + +pub fn game_init(self : GameStat) -> Unit { + draw_game_init(self) + let gp1 = @wasm4.get_gamepad() + if butRel(gp1.button_1, prevgp1.button_1) || + butRel(gp1.button_2, prevgp1.button_2) || + butRel(gp1.button_down, prevgp1.button_down) || + butRel(gp1.button_left, prevgp1.button_left) || + butRel(gp1.button_right, prevgp1.button_right) || + butRel(gp1.button_up, prevgp1.button_up) { + self.game_state = GSGameStart + } +} + +pub fn game_start(self : GameStat) -> Unit { + draw_game_init(self) + let gp1 = @wasm4.get_gamepad() + if butRel(gp1.button_2, prevgp1.button_2) { + self.show_args_bar = not(self.show_args_bar) + } else if butRel(gp1.button_1, prevgp1.button_1) { + if self.color < 4 { + self.color = self.color + 1 + } else { + self.color = 2 + } + } else if butRel(gp1.button_right, prevgp1.button_right) { + if self.select_arg < 3 { + self.select_arg = self.select_arg + 1 + } else { + self.select_arg = 0 + } + } else if butRel(gp1.button_left, prevgp1.button_left) { + if self.select_arg > 0 { + self.select_arg = self.select_arg - 1 + } else { + self.select_arg = 3 + } + } else if butRel(gp1.button_up, prevgp1.button_up) { + if self.select_arg == 0 && self.d < 30 { + self.d = self.d + 1 + } else if self.select_arg == 1 && self.lr < 30 { + self.lr = self.lr + 1 + } else if self.select_arg == 2 && self.br < 30 { + self.br = self.br + 1 + } else if self.select_arg == 3 && self.revs < 30 { + self.revs = self.revs + 1 + } + } else if butRel(gp1.button_down, prevgp1.button_down) { + if self.select_arg == 0 && self.d > 1 { + self.d = self.d - 1 + } else if self.select_arg == 1 && self.lr > 1 { + self.lr = self.lr - 1 + } else if self.select_arg == 2 && self.br > 1 { + self.br = self.br - 1 + } else if self.select_arg == 3 && self.br > 1 { + self.revs = self.revs - 1 + } + } +} + +let gs : GameStat = GameStat::new() + +pub fn GameStat::new() -> GameStat { + { + game_state: GSInit, + d: 30, + lr: 24, + br: 4, + revs: 30, + niter: 2000, + color: 2, + show_args_bar: true, + select_arg: 0, + rng: @random.new(), + } +} + +let prevgp1 : PrevGamePad = { + button_1: false, + button_2: false, + button_down: false, + button_left: false, + button_right: false, + button_up: false, +} + +pub fn update() -> Unit { + match gs.game_state { + GSInit => gs.game_init() + GSGameStart => gs.game_start() + } + let gp1 = @wasm4.get_gamepad() + prevgp1.button_1 = gp1.button_1 + prevgp1.button_2 = gp1.button_2 + prevgp1.button_down = gp1.button_down + prevgp1.button_left = gp1.button_left + prevgp1.button_right = gp1.button_right + prevgp1.button_up = gp1.button_up +} + +pub fn start() -> Unit { + @wasm4.trace("Hello world!") + @wasm4.set_palette(4, @wasm4.rgb(0xf9a875)) // 沙粽 + @wasm4.set_palette(2, @wasm4.rgb(0xaa337f)) // 陈玫红 Maximum Red Purple + @wasm4.set_palette(1, @wasm4.rgb(0xC75B7A)) // 暗岩灰 + @wasm4.set_palette(3, @wasm4.rgb(0xD9ABAB)) // 绿 +} + +pub fn draw_game_init(self : GameStat) -> Unit { + match self.game_state { + GSInit => { + @wasm4.text("Hypotrochoid", 30, 10) + @wasm4.text("Emulator V1.0", 30, 20) + @wasm4.text("Press x to start", 20, 150) + hypotrochoid_line( + 80, + 80, + self.d, + self.lr, + self.br, + self.revs, + self.niter, + self.color, + ) + } + GSGameStart => { + if self.show_args_bar { + @wasm4.set_draw_colors(2) + if self.select_arg == 0 { + @wasm4.set_draw_colors(3) + } + @wasm4.text("d:" + self.d.to_string(), 1, 150) + @wasm4.set_draw_colors(2) + if self.select_arg == 1 { + @wasm4.set_draw_colors(3) + } + @wasm4.text("lr:" + self.lr.to_string(), 37, 150) + @wasm4.set_draw_colors(2) + if self.select_arg == 2 { + @wasm4.set_draw_colors(3) + } + @wasm4.text("br:" + self.br.to_string(), 82, 150) + @wasm4.set_draw_colors(2) + if self.select_arg == 3 { + @wasm4.set_draw_colors(3) + } + @wasm4.text("ti:" + self.revs.to_string(), 120, 150) + } + hypotrochoid_line( + 80, + 80, + self.d, + self.lr, + self.br, + self.revs, + self.niter, + self.color, + ) + } + } +} + +fn x_coordinate(d : Double, lr : Double, br : Double, theta : Double) -> Double { + (br - lr) * @math.cos(theta) + d * @math.cos((br - lr) / lr * theta) +} + +fn y_coordinate(d : Double, lr : Double, br : Double, theta : Double) -> Double { + (br - lr) * @math.sin(theta) + d * @math.sin((br - lr) / lr * theta) +} + +fn linspace(start : Double, stop : Double, num : Double) -> Array[Double] { + let step : Double = (stop - start) / (num - 1) + let value = [] + for x = 0.0; x < num; x = x + 1 { + value.push(start + step * x) + } else { + return value + } +} + +pub fn hypotrochoid_line( + offset_x : Int, + offset_y : Int, + d : Double, + lr : Double, + br : Double, + revs : Double, + niter : Double, + color : UInt +) -> Unit { + let revs = revs + let d = d + let lr = lr + let br = br + let niter = niter + let thetas = linspace(0.0, revs * 2.0 * @math.pi, niter) + for theta in thetas { + let x = (@math.round(x_coordinate(d, lr, br, theta)).to_int() + offset_x).reinterpret_as_uint() + let y = (@math.round(y_coordinate(d, lr, br, theta)).to_int() + offset_y).reinterpret_as_uint() + @wasm4.set_frame_buffer(y * 160 + x, color) + } +} diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/.gitignore" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/.gitignore" new file mode 100644 index 0000000..b1283a7 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/.gitignore" @@ -0,0 +1,2 @@ +target/ +.mooncakes/ diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/LICENSE" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/LICENSE" new file mode 100644 index 0000000..d645695 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/LICENSE" @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/README.md" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/README.md" new file mode 100644 index 0000000..9245199 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/README.md" @@ -0,0 +1 @@ +# Spaceack/l_system_emulator \ No newline at end of file diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/moon.mod.json" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/moon.mod.json" new file mode 100644 index 0000000..1ed21b8 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/moon.mod.json" @@ -0,0 +1,14 @@ +{ + "name": "Spaceack/l_system_emulator", + "version": "0.1.0", + "deps": { + "moonbitlang/wasm4": "0.2.2", + "moonbitlang/x": "0.4.11" + }, + "readme": "README.md", + "repository": "", + "license": "Apache-2.0", + "keywords": [], + "description": "", + "source": "src" +} \ No newline at end of file diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/src/lib/hello.mbt" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/src/lib/hello.mbt" new file mode 100644 index 0000000..9012592 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/src/lib/hello.mbt" @@ -0,0 +1,3 @@ +pub fn hello() -> String { + "Hello, world!" +} diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/src/lib/hello_test.mbt" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/src/lib/hello_test.mbt" new file mode 100644 index 0000000..e0e3a7d --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/src/lib/hello_test.mbt" @@ -0,0 +1,5 @@ +test "hello" { + if @lib.hello() != "Hello, world!" { + fail!("@lib.hello() != \"Hello, world!\"") + } +} diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/src/lib/moon.pkg.json" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/src/lib/moon.pkg.json" new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/src/lib/moon.pkg.json" @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/src/moon.pkg.json" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/src/moon.pkg.json" new file mode 100644 index 0000000..50ef7c4 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/src/moon.pkg.json" @@ -0,0 +1,21 @@ +{ + // "is-main": true, + "import": ["moonbitlang/wasm4","moonbitlang/x/stack"], + "link": { + "wasm-gc": { + "exports": ["start", "update"], + "import-memory": { + "module": "env", + "name": "memory" + } + }, + "wasm": { + "exports": ["start", "update"], + "import-memory": { + "module": "env", + "name": "memory" + }, + "heap-start-address": 6590 + } + } +} \ No newline at end of file diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/src/top.mbt" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/src/top.mbt" new file mode 100644 index 0000000..77c6e75 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2013/l_system_emulator/src/top.mbt" @@ -0,0 +1,281 @@ +enum GameState { + GSInit // 初始状态 + GSGameStart +} + +struct GameStat { + mut game_state : GameState + vs : String + ps : @hashmap.T[String, String] + x : Int + y : Int + mut tl : Double + mut angle : Double + mut levels : UInt + mut color : UInt + mut show_args_bar : Bool + mut select_arg : UInt +} + +pub struct PrevGamePad { + mut button_1 : Bool + mut button_2 : Bool + mut button_left : Bool + mut button_right : Bool + mut button_up : Bool + mut button_down : Bool +} derive(Eq, Default) + +pub fn butRel(cur_button : Bool, prev_button : Bool) -> Bool { + return cur_button && not(prev_button) +} + +pub fn game_init(self : GameStat) -> Unit { + draw_game_init(self) + let gp1 = @wasm4.get_gamepad() + if butRel(gp1.button_1, prevgp1.button_1) || + butRel(gp1.button_2, prevgp1.button_2) || + butRel(gp1.button_down, prevgp1.button_down) || + butRel(gp1.button_left, prevgp1.button_left) || + butRel(gp1.button_right, prevgp1.button_right) || + butRel(gp1.button_up, prevgp1.button_up) { + self.game_state = GSGameStart + } +} + +pub fn game_start(self : GameStat) -> Unit { + draw_game_init(self) + let gp1 = @wasm4.get_gamepad() + if butRel(gp1.button_2, prevgp1.button_2) { + self.show_args_bar = not(self.show_args_bar) + } else if butRel(gp1.button_1, prevgp1.button_1) { + if self.color < 4 { + self.color = self.color + 1 + } else { + self.color = 2 + } + } else if butRel(gp1.button_right, prevgp1.button_right) { + if self.select_arg < 2 { + self.select_arg = self.select_arg + 1 + } else { + self.select_arg = 0 + } + } else if butRel(gp1.button_left, prevgp1.button_left) { + if self.select_arg > 0 { + self.select_arg = self.select_arg - 1 + } else { + self.select_arg = 2 + } + } else if butRel(gp1.button_up, prevgp1.button_up) { + if self.select_arg == 0 && self.tl < 5 { + if self.levels == 5 && self.tl >= 2 { + + } else { + self.tl = self.tl + 1 + } + } else if self.select_arg == 1 && self.angle < 100 { + self.angle = self.angle + 1 + } else if self.select_arg == 2 && self.levels < 5 { + if (self.tl == 3 || self.tl == 4 || self.tl == 5) && self.levels >= 4 { + + } else { + self.levels = self.levels + 1 + } + } + } else if butRel(gp1.button_down, prevgp1.button_down) { + if self.select_arg == 0 && self.tl > 1 { + self.tl = self.tl - 1 + } else if self.select_arg == 1 && self.angle > 1 { + self.angle = self.angle - 1 + } else if self.select_arg == 2 && self.levels > 1 { + self.levels = self.levels - 1 + } + } + +} + +pub fn game_end(self : GameStat) -> Unit { + +} + +let gs : GameStat = GameStat::new() + +pub fn GameStat::new() -> GameStat { + { + game_state: GSInit, + vs: "X", + ps: @hashmap.of([("X", "F[-X][+X]FX"), ("F", "FF")]), + x: 80, + y: 0, + tl: 3.0, + angle: 35.0, + levels: 3U, + color: 2, + show_args_bar: true, + select_arg: 0, + } +} + +let prevgp1 : PrevGamePad = { + button_1: false, + button_2: false, + button_down: false, + button_left: false, + button_right: false, + button_up: false, +} + +pub fn update() -> Unit { + match gs.game_state { + GSInit => gs.game_init() + GSGameStart => gs.game_start() + } + let gp1 = @wasm4.get_gamepad() + prevgp1.button_1 = gp1.button_1 + prevgp1.button_2 = gp1.button_2 + prevgp1.button_down = gp1.button_down + prevgp1.button_left = gp1.button_left + prevgp1.button_right = gp1.button_right + prevgp1.button_up = gp1.button_up +} + +pub fn start() -> Unit { + @wasm4.trace("Hello world!") + @wasm4.set_palette(4, @wasm4.rgb(0xf9a875)) // 沙粽 + @wasm4.set_palette(2, @wasm4.rgb(0xaa337f)) // 陈玫红 Maximum Red Purple + @wasm4.set_palette(1, @wasm4.rgb(0xC75B7A)) // 暗岩灰 + @wasm4.set_palette(3, @wasm4.rgb(0xD9ABAB)) // 绿 +} + +pub fn draw_game_init(self : GameStat) -> Unit { + match self.game_state { + GSInit => { + @wasm4.text("L-System Trees", 30, 10) + @wasm4.text("Emulator V1.0", 30, 20) + @wasm4.text("Press x to start", 20, 150) + fractal(80, 8, self.vs, self.ps, 2.0, 35.0, 5, self.color) + } + GSGameStart => { + if self.show_args_bar { + @wasm4.set_draw_colors(2) + if self.select_arg == 0 { + @wasm4.set_draw_colors(3) + } + @wasm4.text("l:" + self.tl.to_string(), 1, 150) + @wasm4.set_draw_colors(2) + if self.select_arg == 1 { + @wasm4.set_draw_colors(3) + } + @wasm4.text("a:" + self.angle.to_string(), 45, 150) + @wasm4.set_draw_colors(2) + if self.select_arg == 2 { + @wasm4.set_draw_colors(3) + } + @wasm4.text("lv:" + self.levels.to_string(), 100, 150) + @wasm4.set_draw_colors(2) + + } + fractal( + 80, + 1, + self.vs, + self.ps, + self.tl, + self.angle, + self.levels, + self.color, + ) + } + } +} + +pub fn generate_string( + vs : String, + ps : @hashmap.T[String, String], + levels : UInt +) -> String { + let mut this_vs : String = vs + for i = 0U; i < levels; i = i + 1 { + let mut next_rule = "" + for v in this_vs { + let cv : String = v.to_string() + match ps.get(cv) { + Some(value) => next_rule = next_rule + value + None => next_rule = next_rule + cv + } + } + this_vs = next_rule + } + this_vs +} + +fn l_system( + vs : String, + ps : @hashmap.T[String, String], + x : Int, + y : Int, + tl : Double, + langle : Double, + levels : UInt +) -> Array[(Int, Int)] { + let l_string = generate_string(vs, ps, levels) + let mut x = x + let mut y = y + let coordinates = [] + let mut angle = 90.0 + // let langle = langle + let st : @stack.Stack[(Int, Int, Double)] = @stack.Stack::new() + fn coord(length : Double, langle : Double) { + let rad : Double = langle * @math.pi / 180.0 + let steps = 2.0 + for i = 0.0; i < steps + 1; i = i + 1 { + let nx = x + @math.round(i * length / steps * @math.cos(rad)).to_int() + let ny = y + @math.round(i * length / steps * @math.sin(rad)).to_int() + coordinates.push((nx, ny)) + } + x = x + @math.round(length * @math.cos(rad)).to_int() + y = y + @math.round(length * @math.sin(rad)).to_int() + } + + // @wasm4.trace(l_system) + for char in l_string { + match char { + 'F' | 'G' => coord(tl, angle) + '+' => angle = angle + langle + '-' => angle = angle - langle + '[' => st.push((x, y, angle)) + ']' => + match st.pop() { + Some(value) => { + x = value.0 + y = value.1 + angle = value.2 + } + None => { + () + @wasm4.trace("character not found") + } + } + _ => () + } + } + coordinates +} + +pub fn fractal( + offset_x : Int, + offset_y : Int, + vs : String, + ps : @hashmap.T[String, String], + tl : Double, + angle : Double, + levels : UInt, + color : UInt +) -> Unit { + let thetas = l_system(vs, ps, offset_x, offset_y, tl, angle, levels) + for theta in thetas { + let x = theta.0.reinterpret_as_uint() + let y = (160 - theta.1).reinterpret_as_uint() + @wasm4.set_frame_buffer(y * 160 + x, color) + } +} diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/.gitignore" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/.gitignore" new file mode 100644 index 0000000..b1283a7 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/.gitignore" @@ -0,0 +1,2 @@ +target/ +.mooncakes/ diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/LICENSE" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/LICENSE" new file mode 100644 index 0000000..d645695 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/LICENSE" @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/README.md" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/README.md" new file mode 100644 index 0000000..9245199 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/README.md" @@ -0,0 +1 @@ +# Spaceack/l_system_emulator \ No newline at end of file diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/moon.mod.json" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/moon.mod.json" new file mode 100644 index 0000000..1ed21b8 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/moon.mod.json" @@ -0,0 +1,14 @@ +{ + "name": "Spaceack/l_system_emulator", + "version": "0.1.0", + "deps": { + "moonbitlang/wasm4": "0.2.2", + "moonbitlang/x": "0.4.11" + }, + "readme": "README.md", + "repository": "", + "license": "Apache-2.0", + "keywords": [], + "description": "", + "source": "src" +} \ No newline at end of file diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/src/lib/hello.mbt" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/src/lib/hello.mbt" new file mode 100644 index 0000000..9012592 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/src/lib/hello.mbt" @@ -0,0 +1,3 @@ +pub fn hello() -> String { + "Hello, world!" +} diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/src/lib/hello_test.mbt" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/src/lib/hello_test.mbt" new file mode 100644 index 0000000..e0e3a7d --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/src/lib/hello_test.mbt" @@ -0,0 +1,5 @@ +test "hello" { + if @lib.hello() != "Hello, world!" { + fail!("@lib.hello() != \"Hello, world!\"") + } +} diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/src/lib/moon.pkg.json" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/src/lib/moon.pkg.json" new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/src/lib/moon.pkg.json" @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/src/moon.pkg.json" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/src/moon.pkg.json" new file mode 100644 index 0000000..50ef7c4 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/src/moon.pkg.json" @@ -0,0 +1,21 @@ +{ + // "is-main": true, + "import": ["moonbitlang/wasm4","moonbitlang/x/stack"], + "link": { + "wasm-gc": { + "exports": ["start", "update"], + "import-memory": { + "module": "env", + "name": "memory" + } + }, + "wasm": { + "exports": ["start", "update"], + "import-memory": { + "module": "env", + "name": "memory" + }, + "heap-start-address": 6590 + } + } +} \ No newline at end of file diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/src/top.mbt" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/src/top.mbt" new file mode 100644 index 0000000..df9b764 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2014/l_system_Hilbert_Curve_emulator/src/top.mbt" @@ -0,0 +1,276 @@ +enum GameState { + GSInit // 初始状态 + GSGameStart +} + +struct GameStat { + mut game_state : GameState + vs : String + ps : @hashmap.T[String, String] + x : Int + y : Int + mut tl : Double + angle : Double + mut levels : UInt + mut color : UInt + mut show_args_bar : Bool + mut select_arg : UInt +} + +pub struct PrevGamePad { + mut button_1 : Bool + mut button_2 : Bool + mut button_left : Bool + mut button_right : Bool + mut button_up : Bool + mut button_down : Bool +} derive(Eq, Default) + +pub fn butRel(cur_button : Bool, prev_button : Bool) -> Bool { + return cur_button && not(prev_button) +} + +pub fn game_init(self : GameStat) -> Unit { + draw_game_init(self) + let gp1 = @wasm4.get_gamepad() + if butRel(gp1.button_1, prevgp1.button_1) || + butRel(gp1.button_2, prevgp1.button_2) || + butRel(gp1.button_down, prevgp1.button_down) || + butRel(gp1.button_left, prevgp1.button_left) || + butRel(gp1.button_right, prevgp1.button_right) || + butRel(gp1.button_up, prevgp1.button_up) { + self.game_state = GSGameStart + } +} + +pub fn game_start(self : GameStat) -> Unit { + draw_game_init(self) + let gp1 = @wasm4.get_gamepad() + if butRel(gp1.button_2, prevgp1.button_2) { + self.show_args_bar = not(self.show_args_bar) + } else if butRel(gp1.button_1, prevgp1.button_1) { + if self.color < 4 { + self.color = self.color + 1 + } else { + self.color = 2 + } + } else if butRel(gp1.button_right, prevgp1.button_right) { + if self.select_arg < 2 { + self.select_arg = self.select_arg + 1 + } else { + self.select_arg = 0 + } + } else if butRel(gp1.button_left, prevgp1.button_left) { + if self.select_arg > 0 { + self.select_arg = self.select_arg - 1 + } else { + self.select_arg = 2 + } + } else if butRel(gp1.button_up, prevgp1.button_up) { + if self.select_arg == 0 && self.tl < 9 { + if self.levels == 5 && self.tl >= 2 { + + } else { + self.tl = self.tl + 1 + } + } else if self.select_arg == 1 && self.levels < 4 { + + self.levels = self.levels + 1 + + } + } else if butRel(gp1.button_down, prevgp1.button_down) { + if self.select_arg == 0 && self.tl > 1 { + self.tl = self.tl - 1 + } else if self.select_arg == 1 && self.levels > 1 { + self.levels = self.levels - 1 + } + } + +} + + +let gs : GameStat = GameStat::new() + +pub fn GameStat::new() -> GameStat { + { + game_state: GSInit, + vs: "A", + ps: @hashmap.of([("A", "-BF+AFA+FB-"), ("B", "+AF-BFB-FA+")]), + x: 1, + y: 1, + tl: 2.0, + angle: 90.0, + levels: 2U, + color: 2, + show_args_bar: true, + select_arg: 0, + } +} + +let prevgp1 : PrevGamePad = { + button_1: false, + button_2: false, + button_down: false, + button_left: false, + button_right: false, + button_up: false, +} + +pub fn update() -> Unit { + match gs.game_state { + GSInit => gs.game_init() + GSGameStart => gs.game_start() + } + let gp1 = @wasm4.get_gamepad() + prevgp1.button_1 = gp1.button_1 + prevgp1.button_2 = gp1.button_2 + prevgp1.button_down = gp1.button_down + prevgp1.button_left = gp1.button_left + prevgp1.button_right = gp1.button_right + prevgp1.button_up = gp1.button_up +} + +pub fn start() -> Unit { + @wasm4.trace("Hello world!") + @wasm4.set_palette(4, @wasm4.rgb(0xf9a875)) // 沙粽 + @wasm4.set_palette(2, @wasm4.rgb(0xaa337f)) // 陈玫红 Maximum Red Purple + @wasm4.set_palette(1, @wasm4.rgb(0xC75B7A)) // 暗岩灰 + @wasm4.set_palette(3, @wasm4.rgb(0xD9ABAB)) // 绿 +} + +pub fn draw_game_init(self : GameStat) -> Unit { + match self.game_state { + GSInit => { + @wasm4.set_draw_colors(4) + @wasm4.text("L-System", 10, 10) + + @wasm4.text("Hilbert Curve", 30, 20) + + @wasm4.text("Emulator V1.0", 40, 30) + @wasm4.set_draw_colors(3) + @wasm4.text("Press x to start", 20, 150) + fractal(50, 40, "A", @hashmap.of([("A", "-BF+AFA+FB-"), ("B", "+AF-BFB-FA+")]), 4.0, 90.0, 4, self.color) + } + GSGameStart => { + if self.show_args_bar { + @wasm4.set_draw_colors(2) + if self.select_arg == 0 { + @wasm4.set_draw_colors(3) + } + @wasm4.text("l:" + self.tl.to_string(), 1, 150) + @wasm4.set_draw_colors(2) + if self.select_arg == 1 { + @wasm4.set_draw_colors(3) + } + @wasm4.text("lv:" + self.levels.to_string(), 45, 150) + @wasm4.set_draw_colors(2) + if self.select_arg == 2 { + @wasm4.set_draw_colors(3) + } + + + } + fractal( + 10, + 20, + self.vs, + self.ps, + self.tl, + self.angle, + self.levels, + self.color, + ) + } + } +} + +pub fn generate_string( + vs : String, + ps : @hashmap.T[String, String], + levels : UInt +) -> String { + let mut this_vs : String = vs + for i = 0U; i < levels; i = i + 1 { + let mut next_rule = "" + for v in this_vs { + let cv : String = v.to_string() + match ps.get(cv) { + Some(value) => next_rule = next_rule + value + None => next_rule = next_rule + cv + } + } + this_vs = next_rule + } + this_vs +} + +fn l_system( + vs : String, + ps : @hashmap.T[String, String], + x : Int, + y : Int, + tl : Double, + langle : Double, + levels : UInt +) -> Array[(Int, Int)] { + let l_string = generate_string(vs, ps, levels) + let mut x = x + let mut y = y + let coordinates = [] + let mut angle = 90.0 + // let langle = langle + let st : @stack.Stack[(Int, Int, Double)] = @stack.Stack::new() + fn coord(length : Double, langle : Double) { + let rad : Double = langle * @math.pi / 180.0 + let steps = 4.0 + for i = 0.0; i < steps + 1; i = i + 1 { + let nx = x + @math.round(i * length / steps * @math.cos(rad)).to_int() + let ny = y + @math.round(i * length / steps * @math.sin(rad)).to_int() + coordinates.push((nx, ny)) + } + x = x + @math.round(length * @math.cos(rad)).to_int() + y = y + @math.round(length * @math.sin(rad)).to_int() + } + + // @wasm4.trace(l_system) + for char in l_string { + match char { + 'F' | 'G' => coord(tl, angle) + '+' => angle = angle + langle + '-' => angle = angle - langle + '[' => st.push((x, y, angle)) + ']' => + match st.pop() { + Some(value) => { + x = value.0 + y = value.1 + angle = value.2 + } + None => { + () + @wasm4.trace("character not found") + } + } + _ => () + } + } + coordinates +} + +pub fn fractal( + offset_x : Int, + offset_y : Int, + vs : String, + ps : @hashmap.T[String, String], + tl : Double, + angle : Double, + levels : UInt, + color : UInt +) -> Unit { + let thetas = l_system(vs, ps, offset_x, offset_y, tl, angle, levels) + for theta in thetas { + let x = theta.0.reinterpret_as_uint() + let y = (160 - theta.1).reinterpret_as_uint() + @wasm4.set_frame_buffer(y * 160 + x, color) + } +} diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/.gitignore" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/.gitignore" new file mode 100644 index 0000000..b1283a7 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/.gitignore" @@ -0,0 +1,2 @@ +target/ +.mooncakes/ diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/LICENSE" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/LICENSE" new file mode 100644 index 0000000..d645695 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/LICENSE" @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/README.md" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/README.md" new file mode 100644 index 0000000..f87c0ad --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/README.md" @@ -0,0 +1 @@ +# Spaceack/TheLegendOfMoonbit diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/moon.mod.json" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/moon.mod.json" new file mode 100644 index 0000000..3cb2b1f --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/moon.mod.json" @@ -0,0 +1,14 @@ +{ + "name": "Spaceack/TheLegendOfMoonbit", + "version": "0.1.0", + "deps": { + "moonbitlang/wasm4": "0.2.2", + "moonbitlang/x": "0.4.11" + }, + "readme": "README.md", + "repository": "", + "license": "Apache-2.0", + "keywords": [], + "description": "", + "source": "src" +} \ No newline at end of file diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/bug.mbt" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/bug.mbt" new file mode 100644 index 0000000..e9d80ab --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/bug.mbt" @@ -0,0 +1,16 @@ +pub fn bug(self : GameStat) -> Unit { + let bugs_bytes2 : Bytes = Bytes::from_array(player) + @wasm4.blit( + @wasm4.sprite(bugs_bytes2), + self.bug_x, + self.bug_y, + 8, + 9, + @wasm4.BlitFlag::{ + one_bit_per_pixel: false, + rotate: false, + flip_x: false, + flip_y: false, + }, + ) +} diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/draw_game_init.mbt" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/draw_game_init.mbt" new file mode 100644 index 0000000..ce2f05c --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/draw_game_init.mbt" @@ -0,0 +1,25 @@ +pub fn draw_game_init(self : GameStat) -> Unit { + @wasm4.text("Legend of Moonbit", 10, 10) + hypotrochoid_line(120, 40, 12, 9, 3, 6, 300, 4) + fractal_tree(10, 1, "X", 1.0, 35, 2, 2) //小草 + fractal_tree(30, 1, "X", 2.0, 32, 5U, 2) //大树 + fractal_tree(80, 1, "X", 2.0, 36, 4U, 2) // 中等树 + fractal_tree(88, 1, "X", 2.0, 35, 2, 2) //大草 + fractal_tree(121, 1, "X", 1.0, 38, 2, 2) //小草 + fractal_tree(130, 1, "X", 3.0, 28, 3U, 2) // 小树 + fractal_tree(150, 1, "X", 2.0, 24, 5U, 2) + let player_bytes2 : Bytes = Bytes::from_array(x1) + @wasm4.blit( + @wasm4.sprite(player_bytes2), + self.player_x, + self.player_y, + 16, + 16, + @wasm4.BlitFlag::{ + one_bit_per_pixel: false, + rotate: self.player_rotate, + flip_x: self.player_flip_x, + flip_y: false, + }, + ) +} diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/draw_menu.mbt" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/draw_menu.mbt" new file mode 100644 index 0000000..0bb15f6 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/draw_menu.mbt" @@ -0,0 +1,9 @@ +pub fn draw_menu(self : GameStat) -> Unit { + match self.game_state { + GSInitMenu => { + @wasm4.text("Start", 60, 60) + // @wasm4.text("About", 60, 80) + @wasm4.text(">", 50, 60) + } + } +} diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/draw_msg.mbt" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/draw_msg.mbt" new file mode 100644 index 0000000..20dfe84 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/draw_msg.mbt" @@ -0,0 +1,64 @@ +pub fn draw_msg(self : GameStat) -> Unit { + if self.lv == 3 { + if self.player_x == 90 && self.bn < 20 { + self.show_args_bar = false + @wasm4.text("What's that!?", 10, 5) + self.lock_player = true + if not(self.lock_player) { + self.lock_player = true + } + } + if self.player_x == 91 && self.bn < 20 { + self.show_args_bar = false + @wasm4.text("Star is coming!", 10, 5) + if not(self.lock_player) { + self.lock_player = true + } + self.lock_player = true + } else if self.player_x == 92 && self.bn < 20 { + self.show_args_bar = false + if not(self.lock_player) { + self.lock_player = true + } + let mut px = 10 + let mut py = 10 + for n = 0; n < 140; n = n + 1 { + px += 1 + py += 1 + @wasm4.oval(px, py, 20, 20) + } + @wasm4.text("Run!", 10, 5) + self.memory = 1 + self.hp = 50 + + // self.game_state = GS2 + } else if self.player_x == 93 && self.bn < 20 { + self.show_args_bar = false + self.lock_player = true + @wasm4.rect(0, 0, 160, 160) + } else if self.player_x == 94 && self.bn < 2 { + self.player_rotate = true + self.lv = self.lv + 1 + self.game_state = GS2 + } + } else if self.lv == 4 { + self.show_args_bar = false + if self.player_x == 94 && self.bn < 20 { + @wasm4.text("Ahh, It hurts! Who?", 10, 5) + @wasm4.text("Who am I?", 10, 15) + self.player_rotate = false + self.lock_player = true + if not(self.lock_player) { + self.lock_player = true + } + } else if self.player_x == 95 && self.bn < 20 { + @wasm4.text("Where am I?", 10, 5) + self.lock_player = true + if not(self.lock_player) { + self.lock_player = true + } + } else if self.player_x == 96 && self.bn < 20 { + + } + } +} diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/draw_rand.mbt" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/draw_rand.mbt" new file mode 100644 index 0000000..23d2441 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/draw_rand.mbt" @@ -0,0 +1,61 @@ +pub fn draw_background(self : GameStat) -> Unit { + if self.night { + hypotrochoid_line(120, 40, 12, 9, 3, 6, 300, 4) + @wasm4.set_palette(4, @wasm4.rgb(0xf9a875)) // 沙粽 + @wasm4.set_palette(1, @wasm4.rgb(0xaa337f)) // 陈玫红 Maximum Red Purple + @wasm4.set_palette(2, @wasm4.rgb(0xC75B7A)) // 暗岩灰 + @wasm4.set_palette(3, @wasm4.rgb(0xD9ABAB)) // 绿 + } else { + hypotrochoid_line(120, 40, 12, 13, 9, 19, 300, 4) + @wasm4.set_palette(4, @wasm4.rgb(0xf9a875)) // 沙粽 + @wasm4.set_palette(2, @wasm4.rgb(0xaa337f)) // 陈玫红 Maximum Red Purple + @wasm4.set_palette(1, @wasm4.rgb(0xC75B7A)) // 暗岩灰 + @wasm4.set_palette(3, @wasm4.rgb(0xD9ABAB)) // 绿 + } + if self.lv == 1 { + fractal_tree(10, 1, "X", 1.0, 35, 2, 2) //小草 + fractal_tree(30, 1, "X", 2.0, 32, 5U, 2) //大树 + fractal_tree(80, 1, "X", 2.0, 36, 4U, 2) // 中等树 + fractal_tree(88, 1, "X", 2.0, 35, 2, 2) //大草 + fractal_tree(121, 1, "X", 1.0, 38, 2, 2) //小草 + fractal_tree(130, 1, "X", 3.0, 28, 3U, 2) // 小树 + fractal_tree(150, 1, "X", 2.0, 24, 5U, 2) + } else { + if not(self.lock) { + self.tx1 = (self.rng.uint(limit=120) + 10).reinterpret_as_int() + self.tx2 = (self.rng.uint(limit=120) + 10).reinterpret_as_int() + self.tx3 = (self.rng.uint(limit=120) + 10).reinterpret_as_int() + self.tx4 = (self.rng.uint(limit=120) + 10).reinterpret_as_int() + self.tx5 = (self.rng.uint(limit=120) + 10).reinterpret_as_int() + self.tx6 = (self.rng.uint(limit=120) + 10).reinterpret_as_int() + self.tx7 = (self.rng.uint(limit=120) + 10).reinterpret_as_int() + self.tx8 = (self.rng.uint(limit=120) + 10).reinterpret_as_int() + self.txa1 = (self.rng.uint(limit=28) + 10).reinterpret_as_int() + self.txa2 = (self.rng.uint(limit=28) + 10).reinterpret_as_int() + self.txa3 = (self.rng.uint(limit=28) + 10).reinterpret_as_int() + self.lock = true + } + fractal_tree(self.tx1, 1, "X", 2.0, self.txa1.to_double(), 5U, 2) + fractal_tree(self.tx2, 1, "X", 2.0, self.txa2.to_double(), 5U, 2) + fractal_tree(self.tx3, 1, "X", 2.0, self.txa3.to_double(), 4, 2) + fractal_tree(self.tx4, 1, "X", 2.0, self.txa1.to_double(), 4, 2) + fractal_tree(self.tx6, 1, "X", 3.0, self.txa2.to_double(), 3, 2) + fractal_tree(self.tx7, 1, "X", 1.0, self.txa3.to_double(), 2, 2) + fractal_tree(self.tx8, 1, "X", 1.0, self.txa1.to_double(), 2, 2) + fractal_tree(self.tx5, 1, "X", 2.0, self.txa2.to_double(), 2, 2) + } + let player_bytes2 : Bytes = Bytes::from_array(x1) + @wasm4.blit( + @wasm4.sprite(player_bytes2), + self.player_x, + self.player_y, + 16, + 16, + @wasm4.BlitFlag::{ + one_bit_per_pixel: false, + rotate: self.player_rotate, + flip_x: self.player_flip_x, + flip_y: false, + }, + ) +} diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/draw_show_status.mbt" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/draw_show_status.mbt" new file mode 100644 index 0000000..8d05eb3 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/draw_show_status.mbt" @@ -0,0 +1,10 @@ +pub fn show_status(self : GameStat) -> Unit { + if self.show_args_bar { + @wasm4.text("DAY ", 1, 5) + @wasm4.text(self.lv.to_string(), 25, 5) + @wasm4.text("HP ", 45, 5) + @wasm4.text(self.hp.to_string(), 65, 5) + @wasm4.text("Mem", 90, 5) + @wasm4.text(self.memory.to_string(), 120, 5) + } +} diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/graphics_arts.mbt" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/graphics_arts.mbt" new file mode 100644 index 0000000..2a3afe3 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/graphics_arts.mbt" @@ -0,0 +1,104 @@ +fn min(arr : Array[UInt]) -> UInt { + let mut min_value = arr[0] + for value in arr { + if value < min_value { + min_value = value + } + } + min_value +} + +fn max(arr : Array[UInt]) -> UInt { + let mut max_value = arr[0] + for value in arr { + if value > max_value { + max_value = value + } + } + max_value +} + +fn x_coordinate(d : Double, lr : Double, br : Double, theta : Double) -> Double { + (br - lr) * @math.cos(theta) + d * @math.cos((br - lr) / lr * theta) +} + +fn y_coordinate(d : Double, lr : Double, br : Double, theta : Double) -> Double { + (br - lr) * @math.sin(theta) + d * @math.sin((br - lr) / lr * theta) +} + +fn linspace(start : Double, stop : Double, num : Double) -> Array[Double] { + let step : Double = (stop - start) / (num - 1) + let value = [] + for x = 0.0; x < num; x = x + 1 { + value.push(start + step * x) + } else { + return value + } +} + +pub fn hypotrochoid_line( + offset_x : Int, + offset_y : Int, + d : Double, + lr : Double, + br : Double, + revs : Double, + niter : Double, + color : UInt +) -> Unit { + let local_xy : Array[(UInt, UInt)] = Array::new() + let revs = revs + let d = d + let lr = lr + let br = br + let niter = niter + let thetas = linspace(0.0, revs * 2.0 * @math.pi, niter) + for theta in thetas { + let x = (@math.round(x_coordinate(d, lr, br, theta)).to_int() + offset_x).reinterpret_as_uint() + let y = (@math.round(y_coordinate(d, lr, br, theta)).to_int() + offset_y).reinterpret_as_uint() + @wasm4.set_frame_buffer(y * 160 + x, color) + } +} + +fn array_to_bytes( + arr : Array[Array[UInt]], + width : UInt, + height : UInt +) -> Bytes { + let result = Bytes::new(height.reinterpret_as_int()) + for i = 0; i < height.reinterpret_as_int(); i = i + 1 { + let mut byte : UInt = 0 + for j = 0; j < width.reinterpret_as_int(); j = j + 1 { + if arr[i][j] != 0 { + byte = byte | (1 << j).reinterpret_as_uint() + } + } + result[i] = byte.to_byte() + } + result +} + +pub fn calulate_bounding_rect_min(local_xy : Array[(UInt, UInt)]) -> Bytes { + let xs = local_xy.map(fn(p) { p.0 }) + let ys = local_xy.map(fn(p) { p.1 }) + let min_x = min(xs) + let max_x = max(xs) + let min_y = min(ys) + let max_y = max(ys) + let width = max_x - min_x + 1 + let height = max_y - min_y + 1 + let my_rect : Array[Array[UInt]] = Array::new() + let row : Array[UInt] = Array::new() + for x = width; x > 0; x = x - 1 { + row.push(0) + } + for y = height; y > 0; y = y - 1 { + my_rect.push(row) + } + for intr in local_xy { + let yy = (intr.1 - min_y).reinterpret_as_int() + let xx = (intr.0 - min_x).reinterpret_as_int() + my_rect[yy][xx] = 1 + } + array_to_bytes(my_rect, width, height) +} diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/l_system.mbt" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/l_system.mbt" new file mode 100644 index 0000000..15ddfae --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/l_system.mbt" @@ -0,0 +1,92 @@ +pub fn generate_string( + vs : String, + ps : @hashmap.T[String, String], + levels : UInt +) -> String { + let mut this_vs : String = vs + for i = 0U; i < levels; i = i + 1 { + let mut next_rule = "" + for v in this_vs { + let cv : String = v.to_string() + match ps.get(cv) { + Some(value) => next_rule = next_rule + value + None => next_rule = next_rule + cv + } + } + this_vs = next_rule + } + this_vs +} + +fn l_system( + vs : String, + ps : @hashmap.T[String, String], + x : Int, + y : Int, + tl : Double, + langle : Double, + levels : UInt +) -> Array[(Int, Int)] { + let l_string = generate_string(vs, ps, levels) + let mut x = x + let mut y = y + let coordinates = [] + let mut angle = 90.0 + // let langle = langle + let st : @stack.Stack[(Int, Int, Double)] = @stack.Stack::new() + fn coord(length : Double, langle : Double) { + let rad : Double = langle * @math.pi / 180.0 + let steps = 2.0 + for i = 0.0; i < steps + 1; i = i + 1 { + let nx = x + @math.round(i * length / steps * @math.cos(rad)).to_int() + let ny = y + @math.round(i * length / steps * @math.sin(rad)).to_int() + coordinates.push((nx, ny)) + } + x = x + @math.round(length * @math.cos(rad)).to_int() + y = y + @math.round(length * @math.sin(rad)).to_int() + } + + // @wasm4.trace(l_system) + for char in l_string { + match char { + 'F' | 'G' => coord(tl, angle) + '+' => angle = angle + langle + '-' => angle = angle - langle + '[' => st.push((x, y, angle)) + ']' => + match st.pop() { + Some(value) => { + x = value.0 + y = value.1 + angle = value.2 + } + None => { + () + @wasm4.trace("character not found") + } + } + _ => () + } + } + coordinates +} + +pub fn fractal_tree( + offset_x : Int, + offset_y : Int, + vs : String, + tl : Double, + angle : Double, + levels : UInt, + color : UInt +) -> Unit { + let ps : @hashmap.T[String, String] = @hashmap.of( + [("X", "F[-X][+X]FX"), ("F", "FF")], + ) + let thetas = l_system(vs, ps, offset_x, offset_y, tl, angle, levels) + for theta in thetas { + let x = theta.0.reinterpret_as_uint() + let y = (160 - theta.1).reinterpret_as_uint() + @wasm4.set_frame_buffer(y * 160 + x, color) + } +} diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/lib/hello.mbt" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/lib/hello.mbt" new file mode 100644 index 0000000..9012592 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/lib/hello.mbt" @@ -0,0 +1,3 @@ +pub fn hello() -> String { + "Hello, world!" +} diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/lib/hello_test.mbt" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/lib/hello_test.mbt" new file mode 100644 index 0000000..e0e3a7d --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/lib/hello_test.mbt" @@ -0,0 +1,5 @@ +test "hello" { + if @lib.hello() != "Hello, world!" { + fail!("@lib.hello() != \"Hello, world!\"") + } +} diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/lib/moon.pkg.json" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/lib/moon.pkg.json" new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/lib/moon.pkg.json" @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/moon.pkg.json" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/moon.pkg.json" new file mode 100644 index 0000000..50ef7c4 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/moon.pkg.json" @@ -0,0 +1,21 @@ +{ + // "is-main": true, + "import": ["moonbitlang/wasm4","moonbitlang/x/stack"], + "link": { + "wasm-gc": { + "exports": ["start", "update"], + "import-memory": { + "module": "env", + "name": "memory" + } + }, + "wasm": { + "exports": ["start", "update"], + "import-memory": { + "module": "env", + "name": "memory" + }, + "heap-start-address": 6590 + } + } +} \ No newline at end of file diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/static_data.mbt" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/static_data.mbt" new file mode 100644 index 0000000..f147072 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/static_data.mbt" @@ -0,0 +1,12 @@ +let x1 : Array[Byte] = [ + 0xaa, 0x9e, 0xac, 0xaa, 0xaa, 0x57, 0xbf, 0x2a, 0xaa, 0x57, 0xbf, 0x2a, 0xaa, 0x17, + 0xbf, 0x2a, 0xaa, 0x17, 0x03, 0x2a, 0xaa, 0x57, 0x54, 0x2a, 0xa8, 0x55, 0x55, 0x6a, + 0xa9, 0x55, 0x05, 0x0a, 0xaf, 0xd5, 0x55, 0x4a, 0xa8, 0x75, 0x55, 0x4a, 0xaa, 0xd5, + 0x57, 0x2a, 0xaa, 0x1d, 0x7c, 0xaa, 0xa8, 0x75, 0x15, 0x2a, 0xa8, 0x45, 0x15, 0x2a, + 0xaa, 0x10, 0x54, 0xaa, 0xaa, 0x85, 0x52, 0xaa, +] + +let player : Array[Byte] = [ + 0b11000011, 0b11000011, 0b10000001, 0b00100100, 0b00100100, 0b00000000, 0b00100100, + 0b10011001, 0b11000011, +] diff --git "a/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/top.mbt" "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/top.mbt" new file mode 100644 index 0000000..0b21590 --- /dev/null +++ "b/teams/CS\350\265\217\351\207\221\347\214\216\346\211\213-\344\275\234\345\223\2015/the_legend_of_moonbit/src/top.mbt" @@ -0,0 +1,234 @@ +enum GameState { + GSInit // 初始状态 + GSInitMenu //初始菜单 + GSGameStart + GS2 +} + +struct GameStat { + mut game_state : GameState + mut player_x : Int + mut player_y : Int + mut player_flip_x : Bool + mut player_rotate : Bool + mut night : Bool + mut memory : UInt + mut hp : UInt + mut lv : UInt + mut bn : UInt + mut lock : Bool + mut lock_player : Bool + mut tx1 : Int + mut tx2 : Int + mut tx3 : Int + mut tx4 : Int + mut tx5 : Int + mut tx6 : Int + mut tx7 : Int + mut tx8 : Int + mut txa1 : Int + mut txa2 : Int + mut txa3 : Int + mut bug_x : Int + mut bug_y : Int + mut show_args_bar : Bool + rng : @random.Rand +} + +let gs : GameStat = GameStat::new() + +pub fn GameStat::new() -> GameStat { + { + game_state: GSInit, + night: true, + player_x: 45, + player_y: 144, + player_flip_x: false, + player_rotate: false, + memory: 100, + hp: 100, + lv: 1, + bn: 0, + lock: false, + lock_player: false, + tx1: 1, + tx2: 1, + tx3: 1, + tx4: 1, + tx5: 1, + tx6: 1, + tx7: 1, + tx8: 1, + txa1: 32, + txa2: 32, + txa3: 32, + bug_x: 140, + bug_y: 150, + show_args_bar: true, + rng: @random.new(), + } +} + +pub struct PrevGamePad { + mut button_1 : Bool + mut button_2 : Bool + mut button_left : Bool + mut button_right : Bool + mut button_up : Bool + mut button_down : Bool +} derive(Eq, Default) + +pub fn butRel(cur_button : Bool, prev_button : Bool) -> Bool { + return cur_button && not(prev_button) +} + +pub fn game_init(self : GameStat) -> Unit { + draw_game_init(self) + let gp1 = @wasm4.get_gamepad() + if butRel(gp1.button_1, prevgp1.button_1) || + butRel(gp1.button_2, prevgp1.button_2) || + butRel(gp1.button_down, prevgp1.button_down) || + butRel(gp1.button_left, prevgp1.button_left) || + butRel(gp1.button_right, prevgp1.button_right) || + butRel(gp1.button_up, prevgp1.button_up) { + self.game_state = GSInitMenu + } +} + +pub fn game_init_menu(self : GameStat) -> Unit { + draw_game_init(self) + draw_menu(self) + let gp1 = @wasm4.get_gamepad() + if butRel(gp1.button_1, prevgp1.button_1) || + butRel(gp1.button_2, prevgp1.button_2) || + butRel(gp1.button_down, prevgp1.button_down) || + butRel(gp1.button_left, prevgp1.button_left) || + butRel(gp1.button_right, prevgp1.button_right) || + butRel(gp1.button_up, prevgp1.button_up) { + self.game_state = GSGameStart + } +} + +pub fn game_start(self : GameStat) -> Unit { + show_status(self) + draw_background(self) + let gp1 = @wasm4.get_gamepad() + if self.player_x > 1 && + gp1.button_left && + not(self.lock_player) && + self.lv > 7 { + self.player_x = self.player_x - 1 + self.player_flip_x = true + } else if gp1.button_right && not(self.lock_player) { + self.player_x = self.player_x + 1 + self.player_flip_x = false + self.bn = 0 + } else if butRel(gp1.button_up, prevgp1.button_up) && self.player_y > 100 { + for n = 0; n < 30; n = n + 1 { + self.player_y = self.player_y - 1 + } + } + if gp1.button_2 { + self.bn = self.bn + 1 + self.lock_player = false + } + if self.player_y < 144 { + self.player_y = self.player_y + 1 + } + if self.player_x > 144 { + self.lv = self.lv + 1 + self.lock = false + self.player_x = 1 + self.night = not(self.night) + } + draw_msg(self) +} + +pub fn gs2(self : GameStat) -> Unit { + if self.lv > 5 { + bug(self) + } + show_status(self) + draw_msg(self) + draw_background(self) + let gp1 = @wasm4.get_gamepad() + if self.player_x > 1 && + gp1.button_left && + not(self.lock_player) && + self.lv > 1 { + self.player_x = self.player_x - 1 + self.player_flip_x = true + } else if gp1.button_right && not(self.lock_player) { + self.player_x = self.player_x + 1 + if self.lv > 5 { + self.show_args_bar = true + self.bug_x = self.bug_x - 1 + } + if self.bug_x - self.player_x < 10 { + if self.memory < 1000 { + self.memory = self.memory + 1 + } + self.bug_y = 160 + self.bug_x = 0 + } + self.player_flip_x = false + self.bn = 0 + } else if butRel(gp1.button_up, prevgp1.button_up) && self.player_y > 100 { + for n = 0; n < 30; n = n + 1 { + self.player_y = self.player_y - 1 + } + } else if gp1.button_2 { + self.bn = self.bn + 1 + self.lock_player = false + } else if butRel(gp1.button_1, prevgp1.button_1) { + self.show_args_bar = not(self.show_args_bar) + } + if self.player_y < 144 { + self.player_y = self.player_y + 1 + } + if self.player_x > 144 { + self.lv = self.lv + 1 + self.lock = false + self.player_x = 1 + self.bug_x = 140 + self.bug_y = 150 + self.night = not(self.night) + } +} + +pub fn game_end(self : GameStat) -> Unit { + +} + +let prevgp1 : PrevGamePad = { + button_1: false, + button_2: false, + button_down: false, + button_left: false, + button_right: false, + button_up: false, +} + +pub fn update() -> Unit { + match gs.game_state { + GSInit => gs.game_init() + GSInitMenu => gs.game_init_menu() + GSGameStart => gs.game_start() + GS2 => gs.gs2() + } + let gp1 = @wasm4.get_gamepad() + prevgp1.button_1 = gp1.button_1 + prevgp1.button_2 = gp1.button_2 + prevgp1.button_down = gp1.button_down + prevgp1.button_left = gp1.button_left + prevgp1.button_right = gp1.button_right + prevgp1.button_up = gp1.button_up +} + +pub fn start() -> Unit { + @wasm4.trace("Hello world!") + @wasm4.set_palette(4, @wasm4.rgb(0xf9a875)) // 沙粽 + @wasm4.set_palette(1, @wasm4.rgb(0xaa337f)) // 陈玫红 Maximum Red Purple + @wasm4.set_palette(2, @wasm4.rgb(0xC75B7A)) // 暗岩灰 + @wasm4.set_palette(3, @wasm4.rgb(0xD9ABAB)) // 绿 +}