├── assets ├── basic.rsprite └── basic.rmap ├── .gitignore ├── src ├── libs │ ├── sys │ │ ├── Thanks.md │ │ ├── sys.rs │ │ └── windows.rs │ ├── terminal.rs │ ├── escape │ │ └── escape.rs │ ├── cursor.rs │ ├── keycode.rs │ └── keyin.rs ├── build.rs ├── misc │ ├── check.rs │ └── colour.rs ├── physics │ ├── physics.rs │ ├── collision.rs │ └── particle.rs ├── lib.rs ├── map │ ├── sprite.rs │ └── loader.rs ├── c │ └── key.c ├── backend │ ├── b.rs │ └── a.rs ├── UI │ └── ui.rs ├── test │ └── test.rs └── core.rs ├── examples ├── README.md └── snake │ ├── Cargo.toml │ ├── ast │ └── map.rmap │ └── src │ └── main.rs ├── help ├── readme.md ├── oldtutorial.md └── tutorial.md ├── .github └── workflows │ └── rust.yml ├── Cargo.toml ├── license └── readme.md /assets/basic.rsprite: -------------------------------------------------------------------------------- 1 | #### 2 | ### 3 | #### -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | Cargo.lock 3 | /examples/snake/target -------------------------------------------------------------------------------- /src/libs/sys/Thanks.md: -------------------------------------------------------------------------------- 1 | Thanks for the following teams: 2 | winapi_utils 3 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Example games 2 | All example code is under the MIT license -------------------------------------------------------------------------------- /src/libs/sys/sys.rs: -------------------------------------------------------------------------------- 1 | #[cfg(windows)] 2 | #[path = "windows.rs"] 3 | pub mod windows; 4 | -------------------------------------------------------------------------------- /help/readme.md: -------------------------------------------------------------------------------- 1 | # This folder has the tutorial 2 | 3 | ## Old tutorial is for version below 0.9.0 -------------------------------------------------------------------------------- /src/build.rs: -------------------------------------------------------------------------------- 1 | //extern crate gcc; 2 | 3 | fn main() { 4 | // compiles the c script 5 | println!("cargo:rerun-if-changed=src/c/key.c"); 6 | cc::Build::new().file("./src/c/key.c").compile("key"); 7 | } 8 | -------------------------------------------------------------------------------- /assets/basic.rmap: -------------------------------------------------------------------------------- 1 | ############################ 2 | # @ # 3 | # # 4 | # IIIIIIIIIIII # 5 | # # 6 | # # 7 | # # 8 | ############################ -------------------------------------------------------------------------------- /src/libs/terminal.rs: -------------------------------------------------------------------------------- 1 | use crate::check::check_win; 2 | use crate::escape; 3 | 4 | pub fn set_terminal_size(x: usize, y: usize) { 5 | check_win(); 6 | print!("\x1B[8;{};{}t", y, x); 7 | } 8 | 9 | pub fn restore() { 10 | escape::restore(); 11 | } 12 | pub fn save() { 13 | escape::restore(); 14 | } 15 | -------------------------------------------------------------------------------- /examples/snake/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "snake" 3 | version = "0.1.0" 4 | authors = ["TheSlam <32799244+salmmanfred@users.noreply.github.com>"] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | ccdb = "1.6.0" 11 | rand = "0.8.3" -------------------------------------------------------------------------------- /examples/snake/ast/map.rmap: -------------------------------------------------------------------------------- 1 | ############################## 2 | # # 3 | # # 4 | # # 5 | # # 6 | # # 7 | # # 8 | # # 9 | # # 10 | ############################## -------------------------------------------------------------------------------- /src/libs/sys/windows.rs: -------------------------------------------------------------------------------- 1 | #[cfg(windows)] 2 | pub fn enable_virtual_terminal_processing() { 3 | use winapi_util::console::Console; 4 | 5 | if let Ok(mut term) = Console::stdout() { 6 | let _ = term.set_virtual_terminal_processing(true); 7 | } 8 | if let Ok(mut term) = Console::stderr() { 9 | let _ = term.set_virtual_terminal_processing(true); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/misc/check.rs: -------------------------------------------------------------------------------- 1 | // checks so everything is in order 2 | use crate::sys; 3 | pub fn thread_check(threads: i8, lenght: i64) { 4 | // thread check 5 | if threads as i64 > lenght { 6 | panic!("More Threads than lines") 7 | } 8 | if threads % 2 == 1 && threads != 1 { 9 | panic!("Threads are odd") 10 | } 11 | } 12 | 13 | pub fn check_win() { 14 | if cfg!(windows) { 15 | #[cfg(windows)] 16 | sys::windows::enable_virtual_terminal_processing(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/libs/escape/escape.rs: -------------------------------------------------------------------------------- 1 | use crate::check::check_win; 2 | use crate::sys; 3 | //https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797 4 | pub fn hide_cursor() { 5 | check_win(); 6 | print!("\x1B[?25l"); 7 | } 8 | pub fn show_cursor() { 9 | check_win(); 10 | print!("\x1B[?25h"); 11 | } 12 | pub fn set_cursor_pos(x: i64, y: i64) { 13 | check_win(); 14 | print!("\x1B[{};{}H", x, y) 15 | } 16 | pub fn clear() { 17 | check_win(); 18 | print!("\u{001b}c"); 19 | } 20 | pub fn restore() { 21 | print!("\x1B[?47l"); 22 | } 23 | pub fn save() { 24 | print!("\x1B[?47h"); 25 | } 26 | -------------------------------------------------------------------------------- /src/libs/cursor.rs: -------------------------------------------------------------------------------- 1 | //! rust side of the c script 2 | 3 | use crate::escape; 4 | use crate::sys; 5 | 6 | pub fn gotoxy(x: i64, y: i64) { 7 | check_win(); 8 | 9 | escape::set_cursor_pos(x as i64, y as i64); 10 | } 11 | pub fn clear() { 12 | check_win(); 13 | gotoxy(0, 0); 14 | } 15 | pub fn mega_clear() { 16 | check_win(); 17 | escape::clear(); 18 | } 19 | pub fn hide_cursor() { 20 | check_win(); 21 | 22 | escape::hide_cursor(); 23 | } 24 | pub fn show_cursor() { 25 | check_win(); 26 | escape::show_cursor(); 27 | } 28 | 29 | fn check_win() { 30 | #[cfg(windows)] 31 | sys::windows::enable_virtual_terminal_processing(); 32 | } 33 | -------------------------------------------------------------------------------- /.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | name: Rust 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | env: 10 | CARGO_TERM_COLOR: always 11 | 12 | jobs: 13 | linux: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Build 20 | run: cargo build --verbose 21 | - name: Run tests 22 | run: cargo test --verbose 23 | 24 | windows: 25 | runs-on: windows-latest 26 | steps: 27 | - uses: actions/checkout@v2 28 | - name: Build 29 | run: cargo build --verbose 30 | - name: Run tests 31 | run: cargo test --verbose 32 | 33 | 34 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ccdb" 3 | version = "1.6.1" 4 | authors = ["TheSlam <32799244+salmmanfred@users.noreply.github.com>"] 5 | edition = "2018" 6 | links = "./src/c/" 7 | build = "./src/build.rs" 8 | license = "MIT" 9 | repository = "https://github.com/salmmanfred/ccdb" 10 | description = "A small terminal based game engine" 11 | readme = "README.md" 12 | keywords = ["gamedev", "graphics","multithreading","engine","terminal"] 13 | exclude = ["./depric/"] 14 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 15 | 16 | [dependencies] 17 | openfile = "1.1.0" 18 | winapi-util = "0.1.5" 19 | 20 | [build-dependencies] 21 | cc = "1.0" -------------------------------------------------------------------------------- /src/physics/physics.rs: -------------------------------------------------------------------------------- 1 | use crate::collision; 2 | use crate::core; 3 | use crate::loader::map; 4 | //const Gdrag: i64 = 1; 5 | 6 | pub fn render_physics(screen: &mut core::Screen, physobj: Vec, G: i64) { 7 | // since acore and bcore use diffrent screens i have to do it this way 8 | let map = screen.gmap(); 9 | let phsob = physobj; 10 | screen.load_map(renderphys(map, phsob, G)); 11 | } 12 | 13 | fn renderphys(screen: map, physobj: Vec, g_drag: i64) -> map { 14 | let mut mp = map { 15 | chars: screen.chars, 16 | x: screen.x, 17 | y: screen.y, 18 | }; 19 | 20 | for i in physobj { 21 | // just adds physics to all objects 22 | for _ in 0..g_drag { 23 | mp.y[i as usize] += 1; 24 | if collision::get_collision(i as usize, &mut mp) { 25 | mp.y[i as usize] -= 1; 26 | } 27 | } 28 | } 29 | mp 30 | } 31 | -------------------------------------------------------------------------------- /src/physics/collision.rs: -------------------------------------------------------------------------------- 1 | use crate::loader; 2 | /* 3 | struct colmap{ 4 | pub cols: Vec, 5 | pub with: Vec 6 | }*/ 7 | 8 | pub fn get_collision(pos: usize, screen: &loader::map) -> bool { 9 | //just sees if an object has collided with another 10 | 11 | for x in 0..screen.chars.len() { 12 | if x != pos { 13 | if screen.x[x] == screen.x[pos] { 14 | if screen.y[x] == screen.y[pos] { 15 | return true; 16 | } 17 | } 18 | } 19 | } 20 | false 21 | } 22 | 23 | pub fn find_collision(pos: usize, screen: &loader::map) -> i64 { 24 | for x in 0..screen.chars.len() { 25 | if x != pos { 26 | if screen.x[x] == screen.x[pos] { 27 | if screen.y[x] == screen.y[pos] { 28 | return x as i64; 29 | } 30 | } 31 | } 32 | } 33 | return -1; 34 | } 35 | -------------------------------------------------------------------------------- /src/misc/colour.rs: -------------------------------------------------------------------------------- 1 | /*pub const reset: &str = "\x1b[0m"; 2 | pub const bright:&str = "\x1b[1m"; 3 | pub const dim:&str = "\x1b[2m"; 4 | pub const underscore:&str = "\x1b[4m"; 5 | pub const blink:&str = "\x1b[5m"; 6 | pub const reverse:&str = "\x1b[7m"; 7 | pub const hidden:&str = "\x1b[8m"; 8 | 9 | pub const black:&str = "\x1b[30m"; 10 | pub const red:&str = "\x1b[31m"; 11 | pub const green:&str = "\x1b[32m"; 12 | pub const yellow:&str = "\x1b[33m"; 13 | pub const blue:&str = "\x1b[34m"; 14 | pub const magenta:&str = "\x1b[35m"; 15 | pub const cyan:&str = "\x1b[36m"; 16 | pub const white:&str = "\x1b[37m"; 17 | 18 | pub const BGblack:&str = "\x1b[40m"; 19 | pub const BGred:&str = "\x1b[41m"; 20 | pub const BGgreen:&str = "\x1b[42m"; 21 | pub const BGyellow:&str = "\x1b[43m"; 22 | pub const BGblue:&str = "\x1b[44m"; 23 | pub const BGmagenta:&str = "\x1b[45m"; 24 | pub const BGcyan:&str = "\x1b[46m"; 25 | pub const BGwhite:&str = "\x1b[47m"; 26 | 27 | // ANSI colour stuff*/ 28 | -------------------------------------------------------------------------------- /src/libs/keycode.rs: -------------------------------------------------------------------------------- 1 | pub const A: usize = 97; 2 | pub const B: usize = 98; 3 | pub const C: usize = 99; 4 | pub const D: usize = 100; 5 | pub const E: usize = 101; 6 | pub const F: usize = 102; 7 | pub const G: usize = 103; 8 | pub const H: usize = 104; 9 | pub const I: usize = 105; 10 | pub const J: usize = 106; 11 | pub const K: usize = 107; 12 | pub const L: usize = 108; 13 | pub const M: usize = 109; 14 | pub const N: usize = 110; 15 | pub const O: usize = 111; 16 | pub const P: usize = 112; 17 | pub const Q: usize = 113; 18 | pub const R: usize = 114; 19 | pub const S: usize = 115; 20 | pub const T: usize = 116; 21 | pub const U: usize = 117; 22 | pub const V: usize = 118; 23 | pub const W: usize = 119; 24 | pub const X: usize = 120; 25 | pub const Y: usize = 121; 26 | pub const Z: usize = 60; 27 | 28 | pub const ESC: usize = 27; 29 | pub const SPACE: usize = 32; 30 | pub const ENTER: usize = 13; 31 | 32 | pub const ISARROW: usize = 224; 33 | pub const UP_ARROW: usize = 72; 34 | pub const DOWN_ARROW: usize = 80; 35 | pub const LEFT_ARROW: usize = 75; 36 | pub const RIGHT_ARROW: usize = 77; 37 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021 Manfred 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /src/libs/keyin.rs: -------------------------------------------------------------------------------- 1 | //! rust side of the c script 2 | //#[link(name="key", kind="static")] 3 | 4 | extern "C" { 5 | fn getkey() -> usize; 6 | } 7 | pub fn call() -> usize { 8 | #[cfg(windows)] 9 | extern "C" { 10 | fn getkey() -> usize; 11 | } 12 | 13 | unsafe { 14 | if cfg!(windows) { 15 | #[cfg(windows)] 16 | { 17 | return getkey(); 18 | } 19 | //return 0; 20 | } 21 | } 22 | return 0; 23 | } 24 | 25 | pub fn call2() -> usize { 26 | #[cfg(linux)] 27 | extern "C" { 28 | fn getkeyL() -> usize; 29 | } 30 | 31 | unsafe { 32 | if cfg!(linux) { 33 | #[cfg(linux)] 34 | { 35 | return getkeyL(); 36 | } 37 | } else { 38 | return 0; 39 | } 40 | } 41 | return 0; 42 | } 43 | 44 | pub fn get_key() -> usize { 45 | //println!("ok"); 46 | #[cfg(windows)] 47 | { 48 | return call(); 49 | } 50 | 51 | #[cfg(target_os = "linux")] 52 | { 53 | return call2(); 54 | } 55 | 56 | //return 0; 57 | } 58 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | // ! Olive backend 2 | #[path = "backend/b.rs"] 3 | mod b; 4 | //pub mod bcore; 5 | // ! Banana backend 6 | #[path = "backend/a.rs"] 7 | mod a; 8 | //pub mod acore; 9 | // ! core 10 | pub mod core; 11 | 12 | // ! libs 13 | #[path = "libs/cursor.rs"] 14 | pub mod cursor; 15 | #[path = "libs/escape/escape.rs"] 16 | pub mod escape; 17 | #[path = "libs/keycode.rs"] 18 | pub mod keycode; 19 | #[path = "libs/keyin.rs"] 20 | pub mod keyin; 21 | #[path = "libs/sys/sys.rs"] 22 | mod sys; 23 | #[path = "libs/terminal.rs"] 24 | pub mod terminal; 25 | 26 | // ! map 27 | #[path = "map/loader.rs"] 28 | pub mod loader; 29 | #[path = "map/sprite.rs"] 30 | pub mod sprite; 31 | 32 | // ! misc 33 | #[path = "misc/check.rs"] 34 | pub mod check; 35 | #[path = "misc/colour.rs"] 36 | pub mod colour; 37 | // ! physics 38 | #[path = "physics/collision.rs"] 39 | pub mod collision; 40 | #[path = "physics/particle.rs"] 41 | pub mod particle; 42 | #[path = "physics/physics.rs"] 43 | pub mod physics; 44 | 45 | // ! UI 46 | #[path = "UI/ui.rs"] 47 | pub mod ui; 48 | 49 | // ! TEST 50 | #[path = "test/test.rs"] 51 | mod test; 52 | #[cfg(test)] 53 | mod tests { 54 | use crate::test; 55 | #[test] 56 | fn test() { 57 | test::t(); 58 | } 59 | #[test] 60 | fn test2() { 61 | test::check_const(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/map/sprite.rs: -------------------------------------------------------------------------------- 1 | //use crate::loader; 2 | 3 | pub struct sprite { 4 | pub chars: Vec, 5 | pub x: Vec, 6 | pub y: Vec, 7 | } 8 | impl sprite { 9 | pub fn move_xy(&mut self, modif_x: i64, modif_y: i64) { 10 | for x in 0..self.x.len() { 11 | self.x[x] += modif_x; 12 | self.y[x] += modif_y; 13 | } 14 | } 15 | pub fn set_xy(&mut self, x: i64, y: i64) { 16 | let difx = self.x[0] - x; 17 | let dify = self.y[0] - y; 18 | for x in 0..self.x.len() { 19 | self.x[x] += difx; 20 | self.y[x] += dify; 21 | } 22 | } 23 | } 24 | 25 | pub fn load(filename: &str) -> sprite { 26 | let file = openfile::readFileLines(filename); // calls and returns what loadvec does 27 | loadvec(file) 28 | } 29 | 30 | pub fn loadvec(file: Vec) -> sprite { 31 | let mut x: Vec = Vec::new(); 32 | let mut y: Vec = Vec::new(); 33 | let mut c: Vec = Vec::new(); 34 | let mut yy = 0; 35 | let mut xx = 0; 36 | 37 | for i in file { 38 | for ii in i.chars() { 39 | // ignore the spaces 40 | if ii != ' ' { 41 | x.push(xx); 42 | y.push(yy); 43 | c.push(ii.to_string()) 44 | } 45 | xx += 1; 46 | } 47 | xx = 0; 48 | yy += 1; 49 | } 50 | 51 | sprite { 52 | chars: c, 53 | x: x, 54 | y: y, 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/c/key.c: -------------------------------------------------------------------------------- 1 | //#include 2 | // defines what platform 3 | #if defined(_WIN64) 4 | #define PLAT "windows" 5 | #include 6 | 7 | /*char getkeyd() { 8 | //if (PLAT == "windows"){} 9 | 10 | int key_code = _getch(); 11 | //printf("%d\n", key_code); 12 | return (char) key_code; 13 | 14 | }*/ 15 | 16 | /*int keydownd(){ 17 | if (_kbhit()){ 18 | return 1; 19 | } 20 | return 0; 21 | }*/ 22 | char getkey(){ 23 | if (_kbhit()){ 24 | int key_code = _getch(); 25 | 26 | 27 | 28 | return key_code; 29 | } 30 | return 0; 31 | } 32 | #elif defined(__linux__) 33 | #define PLAT "linux" 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | int kbhit(void) 40 | { 41 | struct termios oldt, newt; 42 | int ch; 43 | int oldf; 44 | 45 | tcgetattr(STDIN_FILENO, &oldt); 46 | newt = oldt; 47 | newt.c_lflag &= ~(ICANON | ECHO); 48 | tcsetattr(STDIN_FILENO, TCSANOW, &newt); 49 | oldf = fcntl(STDIN_FILENO, F_GETFL, 0); 50 | fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK); 51 | 52 | ch = getchar(); 53 | 54 | tcsetattr(STDIN_FILENO, TCSANOW, &oldt); 55 | fcntl(STDIN_FILENO, F_SETFL, oldf); 56 | 57 | if(ch != EOF) 58 | { 59 | ungetc(ch, stdin); 60 | return 1; 61 | } 62 | 63 | return 0; 64 | } 65 | 66 | int getkeyL() 67 | { 68 | 69 | if (kbhit()){ 70 | return getchar(); 71 | } 72 | return 0; 73 | 74 | 75 | 76 | } 77 | #endif -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # ccdb: The cmd game engine 2 | (Thats also multi threaded) 3 | 4 | 5 | # How to use 6 | 7 | [Tutorial](https://github.com/salmmanfred/ccdb/blob/master/help/tutorial.md) 8 | 9 | # Multi threading 10 | If you want to use multi threading you have to use ACore 11 | The amount of threads cannot be odd 12 | If you have more threads than lines the program will crash 13 | 14 | # Contributing 15 | If you have linux it would be nice if you could test the keyin and cursor libraries to see if they will work on linux! 16 | 17 | 18 | 19 | # screenshots / gifs 20 | 21 | ![2021-04-23_18-17-31](https://user-images.githubusercontent.com/32799244/115900503-508a7900-a460-11eb-8bac-21ee4e9658d7.gif) 22 | 23 | ![2021-04-24_14-32-41](https://user-images.githubusercontent.com/32799244/115958979-1970a200-a50a-11eb-8e06-280bfefca134.gif) 24 | 25 | ## Buttons system 26 | ![2021-04-23_18-22-30](https://user-images.githubusercontent.com/32799244/115901069-035ad700-a461-11eb-906b-976c37b09f4a.gif) 27 | 28 | # Releases 29 | [Releases](https://github.com/salmmanfred/ccdb/releases) 30 | 31 | # Upcoming 32 | [ccdb-script](https://github.com/salmmanfred/ccdb-script) 33 | 34 | # Roadmap 35 | v0.2.0: Add a function to find all of a certain character or just the first one DONE 36 | v0.3.0: Being able to get the output in a string instead of the cmd DONE 37 | v0.4.0: Physics and collision DONE 38 | v0.5.0: Loading of ascii sprites from file DONE 39 | v0.6.0: Key input rework DONE (+ some rework to the aCore(IT works allot better)) 40 | v0.7.0: Rework of variable names and function names DONE 41 | v0.8.0: Adding a way to load in a folder DONE 42 | v0.9.0: Getting the code ready for 1.0.0 DONE 43 | v1.0.0: optimization DONE 44 | v1.1.0: Terminal control DONE 45 | v1.2.0: UI DONE 46 | v1.3.0: Quality update DONE 47 | v1.4.0: Fixing linux support DONE 48 | v1.5.0: Water physics DONE 49 | v1.6.0: Change how the core system works DONE 50 | v1.7.0: Smoke physics 51 | -------------------------------------------------------------------------------- /src/backend/b.rs: -------------------------------------------------------------------------------- 1 | use crate::core::{Cort, Screen}; 2 | use crate::loader; 3 | //use crate::colour; 4 | 5 | pub fn run(screen: &Screen, size: i64, size2: i64, Cort: &mut Cort) -> loader::map { 6 | let mut line: String = "".to_string(); 7 | let mut X = screen.x.clone(); // load in a sprite 8 | let mut Y = screen.y.clone(); 9 | let mut C = screen.chars.clone(); 10 | 11 | for x in 0..screen.sprite.len() { 12 | // does the actually loading 13 | C.extend(screen.sprite[x].chars.clone()); 14 | X.extend(screen.sprite[x].x.clone()); 15 | Y.extend(screen.sprite[x].y.clone()); 16 | } 17 | 18 | for sx in 0..size { 19 | // splits everything into a bunch of X lines then calls make line to make said x lines 20 | let mut betterx: Vec = Vec::new(); 21 | let mut bettern: Vec = Vec::new(); 22 | //betterx.remove() 23 | // splits it into the correct y section 24 | for x in 0..C.len() { 25 | if sx == Y[x] { 26 | betterx.push(X[x]); 27 | bettern.push(C[x].clone()); 28 | } 29 | } 30 | /* for x in 0..screen.sprite.len(){ 31 | if screen.sprite[x].y[x] == sx{ 32 | } 33 | }*/ 34 | // makes the line and prints it 35 | line.push_str(&format!( 36 | "{}\n", 37 | make_line(&screen, betterx, bettern, size2) 38 | )); 39 | } 40 | Cort.renderd = line; 41 | loader::map { 42 | x: X.clone(), 43 | y: Y.clone(), 44 | chars: C.clone(), 45 | } 46 | } 47 | pub fn make_line(screen: &Screen, betterx: Vec, bettern: Vec, size: i64) -> String { 48 | let mut vc: Vec<&str> = Vec::new(); 49 | // really complicated version of what was in banana 50 | for i in 0..size { 51 | // size is the lenght of the entire line 52 | let masi = i; 53 | let mut rus = 1; 54 | let mut run = true; 55 | for i in 0..betterx.len() { 56 | // finds the correct char? 57 | 58 | if betterx[i] == masi { 59 | vc.push(&bettern[i]); 60 | rus = 0; 61 | break; 62 | } 63 | } 64 | if run { 65 | if rus == 1 { 66 | vc.push(" "); 67 | } 68 | if i == 0 { 69 | vc.push(""); 70 | } /*else if i == size-1{ 71 | 72 | vc.push(""); 73 | break; 74 | 75 | }*/ 76 | } 77 | } 78 | vc.into_iter().collect::() 79 | } 80 | -------------------------------------------------------------------------------- /help/oldtutorial.md: -------------------------------------------------------------------------------- 1 | # THE OLD TUTORIAL THIS NO LONGER WORKS 2 | 3 | ```rust 4 | 5 | extern crate ccdb; 6 | use ccdb::acore::{core,screen}; // there are 2 diffrent Acores there is Acore and there is banana both work the same way when talking to them 7 | use ccdb::loader::{load,toMap};// this is the loader which makes it so you can load a map from file or load a map from string 8 | use ccdb::keyin; // For key input 9 | use ccdb::cursor; // for moving the cursor 10 | use ccdb::keycode; // for key codes (work in progress) 11 | use ccdb::sprite; // for sprites 12 | use ccdb::collision; // for collision 13 | 14 | pub fn main() { 15 | 16 | cursor::clear(); // clears the screen 17 | cursor::hideCursor(); // hides the cursor 18 | let assets = loader::loadFromFolder("./maps/".to_string(),".rmap".to_string(),".rsprite".to_string());//you can load assets using loadFromFolder you will be rewarded with a folder struct 19 | let map1 = assets.loadAssetMap("map");// you can get your map using assets.loadAssetMap for getting the map 20 | let psprite = assets.loadAssetSprite("sprite");// sprite can be found using this 21 | 22 | let x = Acore{ 23 | name: "Test project".to_string(), // name of the project 24 | desc: " - A test project".to_string(), // descirption (short ) 25 | linelenght: 20,// how many charecters per line 26 | lines: 4, // how many lines 27 | debug: true, // This will make it so that CCDB (VERSION) is not shown 28 | threads: 2, // How many threads 29 | output_string: false,// if you want the output to be in string form or if you want it to just print to the console 30 | 31 | }; 32 | 33 | 34 | let mut f = screen{ 35 | chars: vec!("0".to_string(),"1".to_string()), // these are the different ascii "items" that get renderd X and Y are the cordinates 36 | x: vec!(1,2), 37 | y: vec!(1,2), 38 | delay: 10,// delay between each frame for 39 | sprite: Vec::new(),// the sprite vector contains all the sprites that are going to be renderd 40 | 41 | }; 42 | 43 | let mut a = x.setup(); // set up the Acore struct 44 | //! map loading stuff 45 | f.loadmap(load("./maps/map.rmap")); // loads in the map 46 | let player = f.findX("@".to_string()); // gets the player position in the screen.chars section findAllOfX works the same but returns a vector 47 | f.loadmap(toMap("#####\n33333".to_string()));//if you want to make a map out of a string 48 | 49 | //! physics stuff 50 | a.addphysics(player); // adds phycis to an object 51 | a.addphysicsForAllX(&f,"I".to_string());// adds physics to all objects with the correct char 52 | a.removephysics(player); // remove physics form an object 53 | a.changePhysics(-1); // change the gravity constant to make gravity stronger or weaker or upside down 54 | let mut sprite = sprite::load("./maps/sprite.rsprite"); // loads the sprite from a text file 55 | f.sprite.push(sprite);//push the sprite to the sprite vector 56 | f.sprite[0].setxy(2,-2);//sets the position of the sprite 57 | loop { 58 | 59 | cursor::clear();// clear the screen 60 | a.render(&mut f);// renders it all does not work with Bcore 61 | println!("{}",a.render(&mut f););// if you are using Bcore the output gets output in a string ( Does not work with Acore ) 62 | f.sprite[0].movexy(1, 0); // moves the sprite to the side 63 | 64 | if keyin::keydown(){ // checks if there is a keydown 65 | 66 | 67 | match keyin::getkey(){// gets said keycode 68 | 97 =>{ 69 | f.x[player as usize] -= 1; 70 | } 71 | 100 =>{ 72 | f.x[player as usize] += 1; 73 | } 74 | 119 =>{ 75 | f.y[player as usize] -= 1; 76 | } 77 | 115 =>{ 78 | f.y[player as usize] += 1; 79 | } 80 | _ =>{ 81 | 82 | } 83 | } 84 | 85 | 86 | } 87 | 88 | 89 | } 90 | ``` -------------------------------------------------------------------------------- /src/UI/ui.rs: -------------------------------------------------------------------------------- 1 | use crate::keyin; 2 | 3 | pub enum ButtonAction { 4 | Press, 5 | Idle, 6 | Hover, 7 | } 8 | 9 | pub struct Button { 10 | pub text: String, 11 | pub pos: i64, 12 | imsel: bool, // if the button is pressed down 13 | pub hover: bool, 14 | } 15 | impl Button { 16 | pub fn new(y: i64, text: &str) -> Button { 17 | Button { 18 | text: text.to_string(), 19 | pos: y, 20 | imsel: false, 21 | hover: false, 22 | } 23 | } 24 | pub fn get_status(&mut self) -> ButtonAction { 25 | //gets the status 26 | 27 | if self.imsel { 28 | self.imsel = false; 29 | return ButtonAction::Press; 30 | } 31 | 32 | if self.hover { 33 | self.hover = false; 34 | 35 | return ButtonAction::Hover; 36 | } 37 | return ButtonAction::Idle; 38 | } 39 | } 40 | 41 | pub struct UI { 42 | pub buttons: Vec