From 417833fc41c4db4141310d7a21964aea3b969744 Mon Sep 17 00:00:00 2001 From: FantasyPvP <80643031+FantasyPvP@users.noreply.github.com> Date: Mon, 27 Nov 2023 00:21:34 +0000 Subject: [PATCH] fixed stuff no progress :skull: --- src/user/bin/asteroids/game.rs | 23 +++++ src/user/bin/asteroids/mod.rs | 2 + src/user/bin/asteroids/render.rs | 2 + src/user/bin/crystal_rpg/engine.rs | 53 ----------- src/user/bin/crystal_rpg/entity.rs | 102 --------------------- src/user/bin/crystal_rpg/init.rs | 129 --------------------------- src/user/bin/crystal_rpg/items.rs | 19 ---- src/user/bin/crystal_rpg/mod.rs | 6 -- src/user/bin/crystal_rpg/player.rs | 82 ----------------- src/user/bin/crystal_rpg/renderer.rs | 0 src/user/bin/grapher.rs | 7 +- src/user/bin/mod.rs | 2 +- src/user/bin/shell.rs | 16 +--- src/user/lib/libgui/cg_core.rs | 17 +--- src/user/lib/libgui/cg_widgets.rs | 3 +- 15 files changed, 40 insertions(+), 423 deletions(-) create mode 100644 src/user/bin/asteroids/game.rs create mode 100644 src/user/bin/asteroids/mod.rs create mode 100644 src/user/bin/asteroids/render.rs delete mode 100644 src/user/bin/crystal_rpg/engine.rs delete mode 100644 src/user/bin/crystal_rpg/entity.rs delete mode 100644 src/user/bin/crystal_rpg/init.rs delete mode 100644 src/user/bin/crystal_rpg/items.rs delete mode 100644 src/user/bin/crystal_rpg/mod.rs delete mode 100644 src/user/bin/crystal_rpg/player.rs delete mode 100644 src/user/bin/crystal_rpg/renderer.rs diff --git a/src/user/bin/asteroids/game.rs b/src/user/bin/asteroids/game.rs new file mode 100644 index 0000000..8f73e16 --- /dev/null +++ b/src/user/bin/asteroids/game.rs @@ -0,0 +1,23 @@ +use crate::system::std::application::Application; +use async_trait::async_trait; +use alloc::boxed::Box; +use alloc::string::String; +use alloc::vec::Vec; +use crate::std::application::Error; + +pub struct Player { + pub health: u32, + pub score: u32 +} +impl Player { + pub fn new() -> Player { + Player { + health: 5, + score: 0 + } + } +} + +pub struct Game { + pub player: Player +} diff --git a/src/user/bin/asteroids/mod.rs b/src/user/bin/asteroids/mod.rs new file mode 100644 index 0000000..9f9ab08 --- /dev/null +++ b/src/user/bin/asteroids/mod.rs @@ -0,0 +1,2 @@ +mod render; +mod game; \ No newline at end of file diff --git a/src/user/bin/asteroids/render.rs b/src/user/bin/asteroids/render.rs new file mode 100644 index 0000000..ccdd546 --- /dev/null +++ b/src/user/bin/asteroids/render.rs @@ -0,0 +1,2 @@ +use crate::println; + diff --git a/src/user/bin/crystal_rpg/engine.rs b/src/user/bin/crystal_rpg/engine.rs deleted file mode 100644 index 336e770..0000000 --- a/src/user/bin/crystal_rpg/engine.rs +++ /dev/null @@ -1,53 +0,0 @@ -use super::entity::Enemy; -use alloc::vec::Vec; - -pub enum Event { - PlayerKilled, - EntityKilled(Enemy), -} - -pub enum Choice { - A(A), - B(B), -} - -impl core::fmt::Display for Event { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match self { - Event::PlayerKilled => write!(f, "Player killed!"), - Event::EntityKilled(x) => write!(f, "Entity killed! {}", x), - } - } -} - -impl core::fmt::Display for Choice where - A: core::fmt::Display, - B: core::fmt::Display -{ - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match self { - Choice::A(a) => write!(f, "{}", a), - Choice::B(b) => write!(f, "{}", b), - } - } -} - -pub fn eventcheck(e: (A, Option>)) -> Choice { - match e.1 { - Some(events) => { - for event in events { - match event { - Event::PlayerKilled => { - return Choice::B(event) - } - Event::EntityKilled(entity) => { - return Choice::B(event) - } - } - } - }, - None => (), - }; - - Choice::A(e.0) -} \ No newline at end of file diff --git a/src/user/bin/crystal_rpg/entity.rs b/src/user/bin/crystal_rpg/entity.rs deleted file mode 100644 index 6f4b524..0000000 --- a/src/user/bin/crystal_rpg/entity.rs +++ /dev/null @@ -1,102 +0,0 @@ -use super::player::Player; -use super::engine::Event; - -use alloc::{string::String, vec::Vec, vec}; -use crate::std::random; - - -pub trait Entity { - fn attack_entity(&mut self, _: &mut EntityObject) -> (AttackResult, Option>) { - (AttackResult::Miss, None) - } -} -pub enum EntityObject<'a> { - Player(&'a mut Player), - Enemy(&'a mut Enemy), -} - -#[derive(Debug, Clone, Copy)] -pub enum AttackResult { - Miss, - GlancingBlow(f64), - Hit(f64), - CriticalHit(f64), - FriendlyFire, -} - -impl core::fmt::Display for AttackResult { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - match self { - AttackResult::Miss => write!(f, "Missed!"), - AttackResult::GlancingBlow(damage) => write!(f, "Glancing Blow: {}", damage), - AttackResult::Hit(damage) => write!(f, "Hit: {}", damage), - AttackResult::CriticalHit(damage) => write!(f, "Critical Hit: {}", damage), - AttackResult::FriendlyFire => write!(f, "Friendly Fire (no damage dealt)!"), - } - } -} - - -#[derive(Debug, Clone, Copy)] -pub struct Enemy { - pub health_points: f64, - pub max_health_points: f64, - pub base_attack_damage: f64, - pub speed: f64, -} -impl Enemy { - pub fn new() -> Self { - Self { - health_points: 200.0, - max_health_points: 200.0, - base_attack_damage: 5.0, - speed: 100.0, - } - } -} -impl core::fmt::Display for Enemy { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - write!(f, "Enemy: {}/{}", self.health_points, self.max_health_points) - } -} - -impl Entity for Enemy { - fn attack_entity(&mut self, target: &mut EntityObject) -> (AttackResult, Option>) { - let mut entity = if let EntityObject::Player(player) = target { - player - } else { - return (AttackResult::FriendlyFire, None); - }; - - // combat implementation - - let dmg: f64; - - let r = random::Random::int(0, 125) as f64; - let rs = self.speed / entity.speed * 100 as f64; - - let attack = if r < rs * 0.2 { - dmg = self.base_attack_damage * 1.5; - entity.health_points -= dmg; - AttackResult::CriticalHit(dmg) - - } else if r < rs * 0.8 { - dmg = self.base_attack_damage; - entity.health_points -= dmg; - AttackResult::Hit(dmg) - - } else if r < rs { - dmg = self.base_attack_damage * 0.5; - entity.health_points -= dmg; - AttackResult::GlancingBlow(dmg) - } else { - AttackResult::Miss - }; - - if entity.health_points <= 0.0 { - return (attack, Some(vec![Event::PlayerKilled])); - } else { - return (attack, None) - } - } -} \ No newline at end of file diff --git a/src/user/bin/crystal_rpg/init.rs b/src/user/bin/crystal_rpg/init.rs deleted file mode 100644 index 56ca7f6..0000000 --- a/src/user/bin/crystal_rpg/init.rs +++ /dev/null @@ -1,129 +0,0 @@ -use async_trait::async_trait; -use super::{ - engine::{Choice, Event, eventcheck}, - entity::{Enemy, Entity, EntityObject}, - player::Player, -}; - -use alloc::{borrow::ToOwned, format, string::{String, ToString}, vec::Vec, boxed::Box}; - -use crate::{ - std::{ - io::{self, println, serial_println}, - random, - }, - std::application::{ - Application, - Error, - }, -}; -use crate::std::io::{KeyStroke, Stdin}; - -pub struct GameLoop; - - -#[async_trait] -impl Application for GameLoop { - fn new() -> Self { - Self {} - } - async fn run(&mut self, _args: Vec) -> Result<(), Error> { - - let mut username: String = io::Stdin::readline().await; - username = username.trim().to_string(); - - let mut player = Player::new(username); - - let mut enemy = Enemy::new(); - - for _ in 0..30 { - match (eventcheck(player.attack_entity(&mut EntityObject::Enemy(&mut enemy)))) { - Choice::A(result) => { - println!("{}", result); - }, - Choice::B(event) => { - println!("{}", event); - match event { - Event::PlayerKilled => { - println!(" [!] {} was slain by Enemy\n\n[ You lost! ]", player.username); - break; - } - Event::EntityKilled(entity) => { - println!("\n [!] Enemy was slain by {}\n\n [ You won! ]", player.username); - break; - } - } - } - } - println!("{}", eventcheck(enemy.attack_entity(&mut EntityObject::Player(&mut player)))); - println!("[{}\n[{}", player, enemy); - } - - // FRAMEGEN.lock().render_frame(); - - - let string = String::from(format!( -"┌────────────────────────────┐ -│ {} -│ {} / {} -└────────────────────────────┘" - , player.username, player.health_points, player.max_health_points)); - // let mut healthbar = Element::from_str(string); - // healthbar.render((1, 1)); - // - // let new2 = String::from("[an element]"); - // let mut new = Element::from_str(new2); - // - // - // new.render((10, 10)); - // new.render((10, 15)); - // new.render((5, 20)); - // new.render((34, 16)); - // - // - // FRAMEGEN.lock().render_frame(); - // - // let fr = FRAMEGEN.lock().get_frame().to_owned(); - // serial_println!("{}", { - // let mut string = String::new(); - // for row in fr { - // let mut r = String::new(); - // for col in row { - // r.push(col.character as char); - // } - // string.push_str(&r); - // string.push('\n') - // }; - // string - // }); - - - loop { - if let KeyStroke::Char(c) = Stdin::keystroke().await { - println!("{}", c) - } - } - - Ok(()) - } -} - -fn random() -> u64 { - let r = random::Random::int(0, 125) as u64; - r -} - - - - - - - - - - - - - - - diff --git a/src/user/bin/crystal_rpg/items.rs b/src/user/bin/crystal_rpg/items.rs deleted file mode 100644 index 2003b32..0000000 --- a/src/user/bin/crystal_rpg/items.rs +++ /dev/null @@ -1,19 +0,0 @@ - - -#[derive(Debug, Clone, Copy)] -pub struct Armour; -#[derive(Debug, Clone, Copy)] -pub struct Weapon; -#[derive(Debug, Clone, Copy)] -pub struct Charm; -#[derive(Debug, Clone, Copy)] -pub struct OtherItem; - - -#[derive(Debug, Clone, Copy)] -pub enum Item { - Armour(Armour), - Weapon(Weapon), - Charm(Charm), - Other(OtherItem), -} diff --git a/src/user/bin/crystal_rpg/mod.rs b/src/user/bin/crystal_rpg/mod.rs deleted file mode 100644 index 6758733..0000000 --- a/src/user/bin/crystal_rpg/mod.rs +++ /dev/null @@ -1,6 +0,0 @@ -pub mod player; -pub mod items; -pub mod entity; -pub mod engine; -pub mod renderer; -pub mod init; \ No newline at end of file diff --git a/src/user/bin/crystal_rpg/player.rs b/src/user/bin/crystal_rpg/player.rs deleted file mode 100644 index 4a574fd..0000000 --- a/src/user/bin/crystal_rpg/player.rs +++ /dev/null @@ -1,82 +0,0 @@ -use super::{ - items::{Item, Armour}, - entity::{Entity, EntityObject, AttackResult}, - engine::Event, -}; - - -use alloc::{string::String, vec::Vec, vec}; - -use crate::std::random; - -pub struct Player { - pub username: String, - pub health_points: f64, - pub max_health_points: f64, - pub base_attack_damage: f64, - pub speed: f64, - - pub inventory: [ Item ; 15 ], - pub equipped: [ Item ; 7 ], // helmet, chestplate, leggings, boots, mainhand, offhand, charm -} -impl Player { - pub fn new(username: String) -> Self { - Self { - username, - health_points: 100.0, - max_health_points: 100.0, - base_attack_damage: 10.0, - speed: 100.0, - inventory: [ Item::Armour(Armour {}); 15 ], - equipped: [ Item::Armour(Armour {}); 7 ], - } - } -} -impl core::fmt::Display for Player { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - write!(f, "{}: {}/{}", self.username, self.health_points, self.max_health_points) - } -} - - - -impl Entity for Player { - fn attack_entity(&mut self, target: &mut EntityObject) -> (AttackResult, Option>) { - let mut entity = if let EntityObject::Enemy(enemy) = target { - enemy - } else { - return (AttackResult::FriendlyFire, None); - }; - - // combat implementation - - let dmg: f64; - - let r = random::Random::int(0, 125) as f64; - let rs = self.speed / entity.speed * 100 as f64; - - let attack = if r < rs * 0.2 { - dmg = self.base_attack_damage * 1.5; - entity.health_points -= dmg; - AttackResult::CriticalHit(dmg) - - } else if r < rs * 0.8 { - dmg = self.base_attack_damage; - entity.health_points -= dmg; - AttackResult::Hit(dmg) - - } else if r < rs { - dmg = self.base_attack_damage * 0.5; - entity.health_points -= dmg; - AttackResult::GlancingBlow(dmg) - } else { - AttackResult::Miss - }; - - if entity.health_points <= 0.0 { - return (attack, Some(vec![Event::EntityKilled(entity.clone())])); - } else { - return (attack, None) - } - } -} \ No newline at end of file diff --git a/src/user/bin/crystal_rpg/renderer.rs b/src/user/bin/crystal_rpg/renderer.rs deleted file mode 100644 index e69de29..0000000 diff --git a/src/user/bin/grapher.rs b/src/user/bin/grapher.rs index 53b3362..3050f04 100644 --- a/src/user/bin/grapher.rs +++ b/src/user/bin/grapher.rs @@ -13,10 +13,11 @@ use crate::std::frame::{self, Frame, Position, Dimensions, ColouredChar, RenderE use crate::std::io::{Color, KeyStroke, Screen, Stdin}; use crate::user::lib::libgui::{ - cg_core::{CgComponent, CgTextInput, CgInputHandler, CgContainer}, - cg_widgets::CgContainerWidget, + cg_core::{CgComponent}, + cg_widgets::CgContainer, cg_inputs::CgLineEdit, }; +use crate::user::lib::libgui::cg_core::CgTextEdit; use super::calc; @@ -79,7 +80,7 @@ impl Application for Grapher { let mut commandresult = String::new(); while let c = Stdin::keystroke().await { - let mut container = CgContainerWidget::new( + let mut container = CgContainer::new( Position::new(0, 0), Dimensions::new(80, 25), true, diff --git a/src/user/bin/mod.rs b/src/user/bin/mod.rs index c766da5..c687b42 100644 --- a/src/user/bin/mod.rs +++ b/src/user/bin/mod.rs @@ -1,5 +1,4 @@ pub mod calc; -pub mod crystal_rpg; pub mod crystalfetch; pub mod rickroll; pub mod shell; @@ -11,3 +10,4 @@ mod snake; mod grapher; mod gameoflife; mod tetris; +mod asteroids; diff --git a/src/user/bin/shell.rs b/src/user/bin/shell.rs index 5fe4a1f..4998a8e 100644 --- a/src/user/bin/shell.rs +++ b/src/user/bin/shell.rs @@ -3,23 +3,19 @@ use lazy_static::lazy_static; use spin::Mutex; use alloc::{boxed::Box, string::{String, ToString}, vec, vec::Vec}; -use core::future::Future; use vga::writers::{GraphicsWriter, PrimitiveDrawing}; use crate::{print, printerr, println, serial_println, std, std::application::{Application, Error}, user::bin::*}; -use crate::kernel::render::ColorCode; -use crate::std::frame::{Dimensions, Position}; +use crate::std::frame::{Dimensions, Position, ColorCode}; use crate::std::io::{Color, write, Screen, Stdin, Serial, KeyStroke}; use crate::std::random::Random; use crate::user::bin::gigachad_detector::GigachadDetector; use crate::user::bin::grapher::Grapher; use crate::user::lib::libgui::{ - cg_core::{CgComponent}, - cg_widgets::{CgTextBox, CgContainer}, + cg_core::{CgComponent, CgTextEdit}, + cg_widgets::{CgTextBox, CgContainer, CgIndicatorBar, CgIndicatorWidget, CgLabel, CgStatusBar}, + cg_inputs::CgLineEdit, }; -use crate::user::lib::libgui::cg_core::CgTextEdit; -use crate::user::lib::libgui::cg_inputs::CgLineEdit; -use crate::user::lib::libgui::cg_widgets::{CgIndicatorBar, CgIndicatorWidget, CgLabel, CgStatusBar}; lazy_static! { pub static ref CMD: Mutex = Mutex::new(CommandHandler::new()); @@ -110,10 +106,6 @@ async fn exec() -> Result<(), Error> { let mut cmd = tasks::Tasks::new(); cmd.run(args).await?; } - "play" => { - let mut gameloop = crystal_rpg::init::GameLoop::new(); - gameloop.run(args).await?; - } "VGA" => { use vga::colors::Color16; use vga::writers::{GraphicsWriter, Graphics640x480x16}; diff --git a/src/user/lib/libgui/cg_core.rs b/src/user/lib/libgui/cg_core.rs index 595c08b..6d17bb8 100644 --- a/src/user/lib/libgui/cg_core.rs +++ b/src/user/lib/libgui/cg_core.rs @@ -3,9 +3,10 @@ use alloc::string::String; use alloc::vec; use alloc::vec::Vec; use core::slice::from_mut; -use crate::kernel::render::{ColorCode, RenderError, ScreenChar}; use crate::{printerr, serial_println}; -use crate::std::frame::{ColouredChar, Dimensions, Position, special_char, Frame}; +use crate::std::frame::{ColouredChar, Dimensions, Position, special_char, Frame, RenderError, ColorCode}; +use crate::user::lib::libgui::cg_inputs::CgLineEdit; +use crate::user::lib::libgui::cg_widgets::{CgContainer, CgTextBox, CgIndicatorBar, CgIndicatorWidget, CgLabel, CgStatusBar}; /// implement this trait if you require the widget to be able to have an outline pub trait CgOutline: CgComponent { @@ -25,15 +26,3 @@ pub trait CgTextEdit: CgComponent { fn move_cursor(&mut self, direction: bool); // true = right, false = left fn clear(&mut self); } - - - - - - - - - - - - diff --git a/src/user/lib/libgui/cg_widgets.rs b/src/user/lib/libgui/cg_widgets.rs index 32eb4d4..eba760a 100644 --- a/src/user/lib/libgui/cg_widgets.rs +++ b/src/user/lib/libgui/cg_widgets.rs @@ -2,12 +2,11 @@ use alloc::{boxed::Box, format, string::String, vec, vec::Vec}; use alloc::fmt::format; use alloc::string::ToString; use core::cmp::{max, min}; -use crate::kernel::render::{ColorCode, RenderError}; use crate::serial_println; use super::cg_core::{ CgComponent, CgOutline }; -use crate::std::frame::{ColouredChar, Dimensions, Position, Frame}; +use crate::std::frame::{ColouredChar, Dimensions, Position, Frame, RenderError, ColorCode}; use crate::std::io::Color; pub struct CgContainer<'a> {