fixed stuff
no progress 💀
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
mod render;
|
||||
mod game;
|
||||
@@ -0,0 +1,2 @@
|
||||
use crate::println;
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
use super::entity::Enemy;
|
||||
use alloc::vec::Vec;
|
||||
|
||||
pub enum Event {
|
||||
PlayerKilled,
|
||||
EntityKilled(Enemy),
|
||||
}
|
||||
|
||||
pub enum Choice<A, B> {
|
||||
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<A, B> core::fmt::Display for Choice<A, B> 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<A>(e: (A, Option<Vec<Event>>)) -> Choice<A, Event> {
|
||||
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)
|
||||
}
|
||||
@@ -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<Vec<Event>>) {
|
||||
(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<Vec<Event>>) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<String>) -> 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
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
pub mod player;
|
||||
pub mod items;
|
||||
pub mod entity;
|
||||
pub mod engine;
|
||||
pub mod renderer;
|
||||
pub mod init;
|
||||
@@ -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<Vec<Event>>) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+4
-12
@@ -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<CommandHandler> = 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};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user