From 7fe182b6095419550ebe4cb10553cc0235fba7e2 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Sat, 6 Oct 2018 18:59:17 +0200 Subject: [PATCH] Better textured, better collisions --- assets/test-textures/mario.png | Bin 3794 -> 3798 bytes assets/textures/mario.png | Bin 2516 -> 3654 bytes src/engine/character/mod.rs | 2 +- src/engine/scene/mod.rs | 7 ++++++- src/engine/texture/mod.rs | 2 +- 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/assets/test-textures/mario.png b/assets/test-textures/mario.png index 52a20c45694ee9746e4c4f1b20c0f29c2670ce70..a5f72f8afc676f89ede9aedbd06f384574050371 100644 GIT binary patch delta 3539 zcmV;^4J`7~9o8L?BmruXB_MyY8gdIo|zkOVz)coF~Qn_ZyKlfeumGge(yXdce`RuW&$!AGzDq(ArFE1O9I0)j@R?=mtkY(jefr8v7W7|rSy*lL z~(DkDYe<@ekBqsD4K+{eaw`qn2K%UBt>W&OTA2+w6Uc zbmc@ZW+0YJ0&%+t5YYKz7F#MMU*s-kv1dr38Pt+qa8`f1h=E|)DeFle*nJ}Rr?>?z ze+#$#E9An3?*D;YxX`_j`y*~YL2dbyQRD&Wvheye%0bu|u$$*$QpSnfPVKw5WrLTN zR~_oH9k=C4okxS3+%dk`DS$*#xEDVmnkD42CF5S)$osr)E^A?y&^>Znj;{1vsx&RBPdhzIcQWqALtaL& z(f9O_iq^5m<@3rFW3uT|f?zC+iqq)BA_75Xm5rNJ=eCAPMcQm$I@ov$Wyg)1K%Xg7 znS}A(8@b}|wc#%eJVgOP*Fm(6P>ADpV7?Guvtxe^4}+J6+tOOV(dRJI!f=vh>8Zy( zu?|nk+&)$wGb$N==%Pn}k_fN;R2dr?(J_Io1Lo333_^`K3p9aXIUe{a?J&lpTPmyi zUiI=NP2|istZ9Q37D!JWaHQx+S0kMTI=PehS?vnzgmE)_TeEahB0<_fdaW^&3^=jH z$0&a%GywM95*ODRkEeAXy9|xPYPqvk$TW%lGN7W#*=1QWpkXU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0{&8Zr~LV zK6g&o9iAbgc~x`Q+^K0a081Gy5D&9xIqn>uy}7OJuB6kVVQaYL&HqDK`!>U!x~cCm zZe}H4=2$;_U06gOo1A?Kk{X^}h)+N&%#<;@MG;y!^OVwH( z%E*k$(H7ReCOaW0mx#4^t~B&V4UGAt9$jWph#F=X6lfsb`f- z-PqK9bwhSSS5CRHGj{a8Tjk|c)PZSJMNb?|f)g@%G?NHnZsG<242VC!5EiBl3u^O< Q1SmuMzMguys#VDU0A@tt%m4rY diff --git a/assets/textures/mario.png b/assets/textures/mario.png index 296341ab436c9ae4471b82ecd42e0db902e27a09..343a39f0a1b557546cdb41f2f8685b2fa38600f0 100644 GIT binary patch delta 3428 zcmV-q4V&`R6UH2nBLWA7kvbcHc-rlkTaw*44n+UCidh0l5Cpj#KER0CK`(y}RoCUR zUG8W*=C6GfC8;QikIX~@3jWuBPxueN+)55bt<_#@d2rL>+wbj~VtLMAe(81o zraiphX0F0j-X2tcy)|gpuP<16wa;(cgRQrl++G8HnfW!K+?g{suYT=+HIU@D_VoHc z^w)c%eAv$GPwW}uz4Q0~7Xyr~G)fNHB}wF5?<~R!q{+B#oTJqIrA4JaXZswx@H6m! zhFu)5cKH^H5bLW${SKp7d(zLbdl34#qV#pX_y?9SQk9Dm#0C>5k?cx~#- zR-QXLPDYaFwaQ`qDfjk&9G#;v%>wido0DUO)Kdo8lSmjAwBb{v0Wd|6^vS3YU&hKkU&%FJaZ>7e}JJB;I21~s0!x27f{GH={pmVNt zQ;O{!E7p~-09nRm?w;udA?ds@)d%0_2p@D4KM*UhrVq@G4URZ}--ei)zG_Pzo`rrI zONeiBPqtqJ01D{RV=WMIL&Tt_%Ydv>6#ZCfXlSTt394Gvv}xB-rIxC-R;$;ehKUtZt7g`$+i22C z(^i|c)_NN~cfrDcwAXH-x8D00Ogb2P@b;j`7&A|qW$LWcW}AJEg?v_7y6UpkR$pW1 zEt~M)bz9hN_dPs0Qu5;J)yrNv zbN7|GzvV4x`6b@+&zK9By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Wt@wKHU9R&#zf6 zM*BFo3<| FloatRect { - FloatRect::new(self.position.x, self.position.y, 32.0, 32.0) + FloatRect::new(self.position.x + 8.0, self.position.y + 16.0, 16.0, 16.0) } } diff --git a/src/engine/scene/mod.rs b/src/engine/scene/mod.rs index b47e01b..7b2c3bd 100644 --- a/src/engine/scene/mod.rs +++ b/src/engine/scene/mod.rs @@ -1,5 +1,6 @@ use std::time::Duration; +use sfml::system::Vector2; use sfml::window::Event; use sfml::graphics::View; @@ -76,10 +77,14 @@ impl Scene { for c in &mut self.characters { let old = c.bbox(); + + // Compute the offset between position and bbox + let offset = Vector2::new(old.left, old.top) - c.position; + c.update(duration); if let Some((axis, position)) = self.map.collides_bbox(old, c.bbox()) { - c.position = position; + c.position = position - offset; if axis.is_x() { c.speed.x = 0.0; } diff --git a/src/engine/texture/mod.rs b/src/engine/texture/mod.rs index 3d554e1..3d63099 100644 --- a/src/engine/texture/mod.rs +++ b/src/engine/texture/mod.rs @@ -57,7 +57,7 @@ macro_rules! make_textures { } make_textures!( - Mario, mario, make_mario_texture, "../../../assets/test-textures/mario.png", + Mario, mario, make_mario_texture, "../../../assets/textures/mario.png", Overworld, overworld, make_overworld_texture, "../../../assets/textures/overworld.png", );