From 2b95cbb3b3e4da4c8afae2ab4972a5c01f158186 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sat, 2 Oct 2021 09:06:06 -0400 Subject: [PATCH] working on texture tiles --- game/assets/default-texture.png | Bin 0 -> 73763 bytes game/src/utilities/mod.rs | 3 +- game/src/utilities/world_paint_texture.rs | 56 ++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 game/assets/default-texture.png create mode 100644 game/src/utilities/world_paint_texture.rs diff --git a/game/assets/default-texture.png b/game/assets/default-texture.png new file mode 100644 index 0000000000000000000000000000000000000000..28ddf0b282864880caa748416d918dafe3844aa0 GIT binary patch literal 73763 zcmeHQ30PBS+NHK?sTJCxN|kNej-rC#f*=BkrNyZzM8UEM7?q)j3n<8*#ht1kRaulR zAOcbq3WyW}q!xvdRD&dhQ!k2w6g4n}fsVR~FR)AL zSNG}tea>C@|4pZ_YF;?^-!nQV{Wa+uF}gB0=WTd5bN$r!g?^HiuYED?(Gl&B;0{a} z(AGr{J>`0!Cw%H{ir!{0Pv2Yoa0!LN8joZViM&>I*@Kdjf6g~A@LrJkq4kCz*?6@J zQ|}+iPX>R|zBpt+G-$X&u!%Rd4n9{>@7C=l2%vhlcy2AeHb*Zcr)tn}7W`6GeTI?0 zd`)3{U0t0>WMX^uCOBBB4PS|}7ITR3eBf^9>3XFS&2u$w`lV(&cN={;qEk}UO{`NT$^`o+qjw&vzkQU%Qzi>2k~t11Kmmwl03`2Zfna$3DI7*`+u#Jx9og2Zhrjjg%9<2TCA-)K7#4q8Ig$&0-p z*uO&|U9+d5`{3Hveqn$Z(m(XCeDQ21{57w> z!cabN|4?c(ujd0+VM$zhPYrA4UbZu5BG!+dLhSN6Ne2YvMZLBQTXvpy?PlJr!e>+u zAiq7%cD{Mlp7ry;pM3tM2e4TJ-VeEm&?`@h3qD*FWOu-nKL%8f1P*PeRX(W?#j6#m6;^3c#w zrbm2H-B0Xxtp_3zF=FF%F!Ppn*mjZoxf18xC7b76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ex|rLC%_& zBWDB<8JDavQN2bh_fuB?f*_cQ2kU)vMW?NH%4d=I6;rOQWJwsLW0a}-cOy45In7y0 zf)KZd?s))S?r_JixMQD?v0OkX-)9A4-hqxO&?YZcW-u5y98M?_KS{>}JZ-o_s-QV$ z2Shd}_v%9Id_gPoD3Y?7=u{Cx+y%ePcdsVsgb#|dZ7bmaHpg{9yUMCQCi!+ZV&HoO zQK#3pEW~ISJwvC3o-Cc~)M2d_e5-?NS+AniChjvD%=r(r+L&_1ctC0)r5209Nb0*R zzGO>+k10D@oj%dV$YQGf?WE#+$?eHA?)5*lj;ggxp96R&JV)2Su(bh$?6Cv&l`{}( z_125#(X&2-Kf^%`-_kdGQxUXzHoh!C3FG*)F}x~KUhAE6S^$3b2f5MM8VW(?-C}Xv zNh=ShVn{RN_S*&_s!ZDS7ef|oi`*rYdDqH5Nv!Yms~n6etWB%Va|~O_oncYW(1qRaRoel?J{cIU|I*m=}cc_mDmZxWz_3p?sKK!hTq^ZrYPl+&UFYgzo(V2jV;rq z{l4!L551Z^KqsF4K-awlb3XtS6}wP2IaSr|OK$e+ee; zZ>R`=ML3S@faBgs;f&id5R*_Iq3WuaeGzeUv7A<@>Uj7QXlb4xaob8`Ye1iqvQrz8 zdY2G&@?tLt-q#I!q9o|@msDyd(G+NplqX9-p#$xa5>;%Z5)FSY2X5u*-z6`LD+}F1 zI0p7enMPw1`W=HPM!TmOS6&3wc%TQ~)}|9z=1~EdrUK}JF9F-%;bb8u|LSr>oizoq zJ0O<16x``f@dN5c@C8x_-yL)en}@<#!@H#5a?a6q=XT2Io!X-<#>x6M+F_f*ai-H@ qLz~GHmJO7kPg$e>7(s6lYGD0)msp+`naF{EHkw&}oo2f8*#80NFhWQG literal 0 HcmV?d00001 diff --git a/game/src/utilities/mod.rs b/game/src/utilities/mod.rs index 9c06995..1f05091 100644 --- a/game/src/utilities/mod.rs +++ b/game/src/utilities/mod.rs @@ -1,3 +1,4 @@ +pub mod anim_render; pub mod datastore; pub mod discord; pub mod game_config; @@ -6,4 +7,4 @@ pub mod math; pub mod non_ref_raylib; pub mod render_layer; pub mod shaders; -pub mod anim_render; +pub mod world_paint_texture; diff --git a/game/src/utilities/world_paint_texture.rs b/game/src/utilities/world_paint_texture.rs new file mode 100644 index 0000000..0ca83fc --- /dev/null +++ b/game/src/utilities/world_paint_texture.rs @@ -0,0 +1,56 @@ +//! Defines a texture that tiles across the whole screen in world space + +use raylib::{ + camera::Camera2D, + color::Color, + math::Vector2, + prelude::{RaylibDraw, RaylibMode2D}, + texture::Texture2D, + RaylibHandle, +}; + +use super::non_ref_raylib::HackedRaylibHandle; + +pub struct WorldPaintTexture { + texture: Texture2D, +} + +impl WorldPaintTexture { + /// Construct a new world paint texture + pub fn new(texture: Texture2D) -> Self { + Self { texture } + } + + pub fn render( + &self, + raylib: &mut RaylibMode2D<'_, HackedRaylibHandle>, + origin: Vector2, + camera: &Camera2D, + ) { + // Convert the screen edges to world space + let top_left = raylib.get_screen_to_world2D(Vector2::new(0.0, 0.0), camera); + let bottom_right = raylib.get_screen_to_world2D(raylib.get_screen_size(), camera); + + // Calculate the distance between the edges and the origin + let left_edge_distance = top_left.x - origin.x; + let right_edge_distance = bottom_right.x - origin.x; + + // Calculate the x position to draw the tile in order for there always to be a tile covering the edges + let left_tile_x = + (left_edge_distance / self.texture.width as f32).floor() * self.texture.width as f32; + let right_tile_x = + (right_edge_distance / self.texture.width as f32).ceil() * self.texture.width as f32; + + // Render the tiles + raylib.draw_texture_v( + &self.texture, + Vector2::new(left_tile_x, origin.y), + Color::WHITE, + ); + raylib.draw_texture_v( + &self.texture, + Vector2::new(right_tile_x, origin.y), + Color::WHITE, + ); + } +}