]> git.seodisparate.com - LudumDare45_StartWithNothing/commitdiff
Add "origin" to draw calls with a transform
authorStephen Seo <seo.disparate@gmail.com>
Sun, 19 Feb 2023 08:05:30 +0000 (17:05 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Sun, 19 Feb 2023 08:05:30 +0000 (17:05 +0900)
src/agnostic_interface.rs
src/agnostic_interface/raylib_impl.rs
src/original_impl.rs

index 0c09bda5e4d12b0b27e556e3a5c8c97c96da846f..95a67fdf4be3288ac18db747d11bad88a6b351c1 100644 (file)
@@ -14,6 +14,7 @@ pub trait ImageInterface {
         y: f32,
         color: Color,
         transform: Transform,
+        origin: Vector,
     ) -> Result<(), String>;
     fn draw_sub_transform(
         &mut self,
@@ -22,6 +23,7 @@ pub trait ImageInterface {
         y: f32,
         color: Color,
         transform: Transform,
+        origin: Vector,
     ) -> Result<(), String>;
     fn get_w(&self) -> usize;
     fn get_h(&self) -> usize;
@@ -76,6 +78,7 @@ pub trait GameInterface {
         circle: Circle,
         color: Color,
         transform: Transform,
+        origin: Vector,
     ) -> Result<(), String>;
     fn draw_rect(&mut self, rect: Rectangle, color: Color) -> Result<(), String>;
     fn draw_rect_ex(
@@ -90,6 +93,7 @@ pub trait GameInterface {
         rect: Rectangle,
         color: Color,
         transform: Transform,
+        origin: Vector,
     ) -> Result<(), String>;
 
     fn load_image(&mut self, path: &Path) -> Result<Box<dyn ImageInterface>, String>;
index 9faa8928d1c6ffe41ce4921b7fdf4fbc15000c4f..e6f27df92207678b34101cacd199ec586683d1d0 100644 (file)
@@ -15,6 +15,8 @@ use std::{
     rc::Rc,
 };
 
+use crate::faux_quicksilver::Vector;
+
 use super::{FontInterface, GameInterface, ImageInterface, MusicInterface, SoundInterface};
 
 fn fqcolor_to_color(c: crate::faux_quicksilver::Color) -> ffi::Color {
@@ -62,6 +64,7 @@ impl ImageInterface for RaylibImageHandler {
         y: f32,
         color: crate::faux_quicksilver::Color,
         transform: crate::faux_quicksilver::Transform,
+        origin: Vector,
     ) -> Result<(), String> {
         todo!()
     }
@@ -73,6 +76,7 @@ impl ImageInterface for RaylibImageHandler {
         y: f32,
         color: crate::faux_quicksilver::Color,
         transform: crate::faux_quicksilver::Transform,
+        origin: Vector,
     ) -> Result<(), String> {
         todo!()
     }
@@ -328,6 +332,7 @@ impl GameInterface for RaylibGame {
         circle: crate::faux_quicksilver::Circle,
         color: crate::faux_quicksilver::Color,
         transform: crate::faux_quicksilver::Transform,
+        origin: Vector,
     ) -> Result<(), String> {
         todo!()
     }
@@ -364,6 +369,7 @@ impl GameInterface for RaylibGame {
         rect: crate::faux_quicksilver::Rectangle,
         color: crate::faux_quicksilver::Color,
         transform: crate::faux_quicksilver::Transform,
+        origin: Vector,
     ) -> Result<(), String> {
         todo!()
     }
index d37c8245b9e5f3a13cf3d716c874eb91c7c4d20c..3c5c8695bc2278edc0e8bc32fa67d6942987ca9a 100644 (file)
@@ -643,12 +643,28 @@ impl ParticleSystem {
                         * Transform::rotate(particle.r);
                 window
                     .get_gi_mut()
-                    .draw_rect_transform(particle.rect, self.color, transform * pre_transform)
+                    .draw_rect_transform(
+                        particle.rect,
+                        self.color,
+                        transform * pre_transform,
+                        Vector {
+                            x: particle.rect.x + particle.rect.w / 2.0,
+                            y: particle.rect.y + particle.rect.h / 2.0,
+                        },
+                    )
                     .ok();
             } else {
                 window
                     .get_gi_mut()
-                    .draw_circle_transform(particle.circle, self.color, transform)
+                    .draw_circle_transform(
+                        particle.circle,
+                        self.color,
+                        transform,
+                        Vector {
+                            x: particle.circle.x,
+                            y: particle.circle.y,
+                        },
+                    )
                     .ok();
             }
         }
@@ -761,6 +777,10 @@ impl RotatingParticleSystem {
                     transform
                         * Transform::translate(-moved_rect.x / 2.0, -moved_rect.y / 2.0)
                         * Transform::rotate(self.r * 1.3),
+                    Vector {
+                        x: moved_rect.x + moved_rect.w / 2.0,
+                        y: moved_rect.y + moved_rect.h / 2.0,
+                    },
                 )
                 .ok();
         } else {
@@ -770,7 +790,15 @@ impl RotatingParticleSystem {
             solid_color.a = (self.particle_system.opacity * 255.0) as u8;
             window
                 .get_gi_mut()
-                .draw_circle_transform(moved_cir, solid_color, transform)
+                .draw_circle_transform(
+                    moved_cir,
+                    solid_color,
+                    transform,
+                    Vector {
+                        x: moved_cir.x,
+                        y: moved_cir.y,
+                    },
+                )
                 .ok();
         }
     }
@@ -856,7 +884,15 @@ impl ExplConvParticleSystem {
                 * 255.0) as u8;
             window
                 .get_gi_mut()
-                .draw_circle_transform(particle.circle, self.color, transform)
+                .draw_circle_transform(
+                    particle.circle,
+                    self.color,
+                    transform,
+                    Vector {
+                        x: particle.circle.x,
+                        y: particle.circle.y,
+                    },
+                )
                 .ok();
         }
     }
@@ -932,7 +968,15 @@ impl Planet {
         self.particle_system.draw(window, transform);
         window
             .get_gi_mut()
-            .draw_circle_transform(self.circle, self.color, transform)
+            .draw_circle_transform(
+                self.circle,
+                self.color,
+                transform,
+                Vector {
+                    x: self.circle.x,
+                    y: self.circle.y,
+                },
+            )
             .ok();
         for moon in &mut self.moons {
             moon.draw(window, transform);
@@ -999,6 +1043,10 @@ impl Star {
                 image_rect.y,
                 self.color,
                 transform * Transform::rotate(self.r),
+                Vector {
+                    x: image_rect.x + image_rect.w / 2.0,
+                    y: image_rect.y + image_rect.h / 2.0,
+                },
             )
             .ok();
     }
@@ -1108,6 +1156,10 @@ impl Fish {
                 body_rect.y,
                 self.color,
                 transform * body_tr,
+                Vector {
+                    x: self.body_rect.x + self.body_rect.w / 2.0,
+                    y: self.body_rect.y + self.body_rect.h / 2.0,
+                },
             )
             .ok();
         let mut tail_rect = self.tail_rect;
@@ -1128,6 +1180,10 @@ impl Fish {
                 tail_rect.y,
                 self.color,
                 transform * tail_tr,
+                Vector {
+                    x: self.tail_rect.x + self.tail_rect.w / 2.0,
+                    y: self.tail_rect.y + self.tail_rect.h / 2.0,
+                },
             )
             .ok();
     }
@@ -1914,6 +1970,10 @@ impl GameState {
             Color::from_rgba(255, 255, 255, (self.player_particles.opacity * 255.0) as u8),
             Transform::translate(-self.player.x / 2.0, -self.player.y / 2.0)
                 * Transform::rotate(self.player_r as f32),
+            Vector {
+                x: self.player.x + self.player.w / 2.0,
+                y: self.player.y + self.player.h / 2.0,
+            },
         )?;
         self.joining_particles.draw(window, Transform::IDENTITY);
         for expl_conv_ps in &mut self.expl_conv_p_systems {