aboutsummaryrefslogtreecommitdiff
path: root/games/rstnode/rst-client/src/graphics
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2021-02-07 16:44:44 +0100
committerKatharina Fey <kookie@spacekookie.de>2021-02-07 16:44:44 +0100
commit79c8b9ab441493e3b3a37a59263f66896c9c90b3 (patch)
treeca111686fa202369a5730ff8151480b04e391cbb /games/rstnode/rst-client/src/graphics
parentf5b36ff6b99256030201c878608a07d163b4c802 (diff)
rstnode: basic asset loading and prototype sprite rendering
* restructure assets directory * implement asset loading and dynamic conversion to sprites * reload sprites with unique URIs to load at runtime * provide an updated renderer API to give access to client state * use new APIs to draw a single node frame on screen * use colour APIs to dynamically change node frame colour
Diffstat (limited to 'games/rstnode/rst-client/src/graphics')
-rw-r--r--games/rstnode/rst-client/src/graphics/entities/mod.rs18
-rw-r--r--games/rstnode/rst-client/src/graphics/mod.rs18
2 files changed, 30 insertions, 6 deletions
diff --git a/games/rstnode/rst-client/src/graphics/entities/mod.rs b/games/rstnode/rst-client/src/graphics/entities/mod.rs
index d3536d4f5fc2..17f26a8e5a70 100644
--- a/games/rstnode/rst-client/src/graphics/entities/mod.rs
+++ b/games/rstnode/rst-client/src/graphics/entities/mod.rs
@@ -22,20 +22,28 @@ pub struct NodeRndr {
pub inner: Arc<Node>,
}
-impl EventHandler for NodeRndr {
- fn update(&mut self, _: &mut Context) -> GameResult<()> {
+impl Renderer for NodeRndr {
+ fn update(&mut self, _: &mut ClientState, _: &mut Context) -> GameResult<()> {
Ok(())
}
- fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
+ fn draw(&self, s: &ClientState, ctx: &mut Context) -> GameResult<()> {
+ let frame = s.assets().find("frame/frame_s").unwrap();
+
+ frame.draw(
+ ctx,
+ DrawParam::new().dest([256.0, 256.0]).color(graphics::RED),
+ )?;
+
let circ = Mesh::new_circle(
ctx,
DrawMode::fill(),
Point2::from(&self.loc),
- 128.0,
+ 64.0,
0.1,
graphics::WHITE,
- ).unwrap();
+ )
+ .unwrap();
circ.draw(ctx, DrawParam::new()).unwrap();
Ok(())
diff --git a/games/rstnode/rst-client/src/graphics/mod.rs b/games/rstnode/rst-client/src/graphics/mod.rs
index 8118207d70af..095e66f1ad1f 100644
--- a/games/rstnode/rst-client/src/graphics/mod.rs
+++ b/games/rstnode/rst-client/src/graphics/mod.rs
@@ -8,9 +8,25 @@
pub mod entities;
pub mod ui;
+use crate::state::ClientState;
+use ggez::{Context, GameResult};
+
/// A utility module to include everything required to implement a
/// graphics entity
pub(self) mod prelude {
- pub use ggez::{event::EventHandler, graphics::{self, Drawable, DrawParam, Mesh, DrawMode}, Context, GameResult};
+ pub use ggez::{
+ event::EventHandler,
+ graphics::{self, DrawMode, DrawParam, Drawable, Mesh},
+ Context, GameResult,
+ };
pub use mint::Point2;
+
+ pub use super::Renderer;
+ pub use crate::state::ClientState;
+}
+
+/// A rendering trait which is given graphics context, and game state
+pub trait Renderer {
+ fn update(&mut self, _state: &mut ClientState, _ctx: &mut Context) -> GameResult<()>;
+ fn draw(&self, _state: &ClientState, _ctx: &mut Context) -> GameResult<()>;
}