From 805ae65b8cd897cd2add6c18d77dcd91d33d2fbb Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sun, 3 Apr 2022 20:46:06 -0400 Subject: [PATCH] Cup pointer --- assets/ewpratten/prp_cupIcon/prp_cupIcon.xcf | Bin 0 -> 2427 bytes .../assets/prp/prp_cupIcon/prp_cupIcon.png | Bin 0 -> 1593 bytes .../src/rendering/utilities/map_render.rs | 156 +++++++++++------- .../src/scenes/player_interaction.rs | 20 ++- 4 files changed, 105 insertions(+), 71 deletions(-) create mode 100644 assets/ewpratten/prp_cupIcon/prp_cupIcon.xcf create mode 100644 game/dist/assets/prp/prp_cupIcon/prp_cupIcon.png diff --git a/assets/ewpratten/prp_cupIcon/prp_cupIcon.xcf b/assets/ewpratten/prp_cupIcon/prp_cupIcon.xcf new file mode 100644 index 0000000000000000000000000000000000000000..e82255602b2e936c613e7629a85a6214c5073d38 GIT binary patch literal 2427 zcmc&#-Af}^6d#=$>qfC#+XkVOX{(TZ5X@gts1Hqrg8xD`#%x+mB$>1u`XVje)^T3? zQjiKFRH4v?(nLy9u@Bmo{m>QNO~g#bm&MGJiDovL-1+LclbLa{?iN~Ddcv9WyT5zx zJ@=k-W)hCf%u+XlQ`D!UJ|6+{mZ=zj2YMB>qXQlTpf8UBg%#vA(3e0vLEkVj_In+) z2HF>ftw(~fnVC?OhB1LBUmc5w0(5AS`Yb}cbJ+VQ zZ-P!uhp0qsIx>0figzj;j7`Vll-DpL@$mHkHER5P*I@ekGp2o%@x#+M6SIL}BpRlC zqcBRfjm*JFG8&<&NHlmOl)x)uQ&Wi$O&R_U+=A`S_{ z<^k;hJP10bD-A(tbhnHPm@Zu@XVPV0%IQoQuXE`N&$2u)*!1a2iD61G!lqA0JbUX= z?X2^(S*cbYe1RQ+`h1%^An&7{`#(o9Q{~xYcJI&4&5d8z*S`<2#|A}b5B7F;{`ze_ z8F|8CFZivzhRhou5d^e&|x7L zXIgh_i{45Z5;BXovpF)0a@pI98KIRnBnfvH={QNFIK6mRkot8+$gm8_Dh!(uuIid3 zbn}`Z^%%vFH84hT@SeC>UHS_x8_R1NsUS_^7&D73ugau^no{9wvuc=;q(;5|MhaMViXZn;(w0 zSoWK=dZ);dMZ^{FtUBJLomFO@WY9dby7R2c31;Q~>1}cm)xq)9%2uh0P_?wRk{TcE zAq3Lx@%ocXx&0GSmc^6(+)~o-^|;9{Lg*dx)63gjxl)%kO|DnU-1aiMo zm`fkk-1=$lC_OhZ3?$(mnpoI47FD-iRmJ0tg^3~f!|?d$HXb+n_4CH#jXA%EAiQ+? zxS{szqS`o4(_UiGzkDPP=ymaE**`d*+^(qu@HW-9ljEr+&Z8r4DYcR-11RTKw)QIk zD*IcdlRALWcYX>4a#c)d&+jUm)jc}AtVT42Cf@{%_E7%k?aGXn+LY9 gRJE>jaq-iOi(jNjvQk7oKc|rH=T)NTa@}0S-w}KtEdT%j literal 0 HcmV?d00001 diff --git a/game/dist/assets/prp/prp_cupIcon/prp_cupIcon.png b/game/dist/assets/prp/prp_cupIcon/prp_cupIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..fe5a391168b6b43b2aa6cc99799f3d68d2090699 GIT binary patch literal 1593 zcmV-92FCe`P)EX>4Tx04R}tkv&MmKpe$i(@I4u9qb_DkfAz=1yK=4twIqhgj%6h2a`*`pot+# zad8w}3l4rPRvlcNb#-tR1i=pwM<*vm7b)?7NufoI2gm(*ckglc4iFkurdgpeK+|nA zlS+!Y{E8TUMF;|-7(rNOmN6?yY50z>dj$A;m*83c=l&eMYQbVaKqQ`FhG`S86Hjg0 z2Iqa^7%R&v@j3CRNf#u3VPEmlR0?T`!LFF$9Enfo9!tzK)BVfh)c3-)I2SpQP8@ zTKouzZUYzBZB5w&E_ZMDFsENW|e|@idfh&R7zoCf$AtC<0<&7MKUV2kO8oumqHVg1skWItun|3AhCMKv2~Za13;SR73_D zmP`T90?&XSffok4W@|+=Di7p<$X**5*g22_UElzC59|Q%fIol(5$Q~LY@Qa(;yUmO zcmq7Qwb@%v#E*HMNdcG!-uB*V}l*0Q;V!4pB_lsFj zfhN$+fM+eduMD&XETm}~x7%$1N~IEU9N&tTrYW}Hl}e>z9LJG?V@Hqzr$E=);=G;d z8}oDlm}#|IG#U*yH#cduT6enHYPHzh+@#THWcz1K*Q)7$VOV%8nJjysTX+1l{bS;|hufRK1ZF>uCmc2{kXR4}%5Jtc6l3Vs?iMs~8 z1e~|#uxiOQk-Z{^^&U8OB&%L)qS{lo| zE7Cdlrxl+VHkrd zm#TzeY&i^lPBmQZO#ew%wgqqXRozay8n;efVsbPKe#*r?qkvz6^fzQAPZ^W!`t+Qg~<*d^aLLi{X z*mX6jWONTf2?UrN62X%A0N4X|Jg{XC){U-IM}6Cdgd?DK4Uswa(Eu)~d@a&y`3DN#^MV zaF}@td=imnR=3B-24^j^bHGA*z8r6CZ18md3tPLp{QAomLKu2A5l35Ft1k1pR%4~Q zOu1an=F1WA0r<@@j>ma*$0%q#HXc{=`TSy~QYirLpZzAM`%MC27|MwQ9Ih?Tl~}1R zQ>j#fh4;`vw}7{X(HS+HyXfut`T1KL9-lBT&GQvA;E9d4{8%?Sv5s_Lb-HKS`{|}n7(Yc}24-;=_*+%mR?~ip roF_(Iu^!L^+7`+W=IQorA8r2v=B%jrPQUPw00000NkvXXu0mjfymHNk literal 0 HcmV?d00001 diff --git a/game/game_logic/src/rendering/utilities/map_render.rs b/game/game_logic/src/rendering/utilities/map_render.rs index b552a889..93708e60 100644 --- a/game/game_logic/src/rendering/utilities/map_render.rs +++ b/game/game_logic/src/rendering/utilities/map_render.rs @@ -80,6 +80,7 @@ pub struct MapRenderer { tile_textures: HashMap, world_objects: WorldObjectPackage, world_end: na::Vector2, + cup_icon: Texture2D, } impl MapRenderer { @@ -101,6 +102,14 @@ impl MapRenderer { let mut loader = Loader::with_cache(ProgramDataTileCache::new()); let map = loader.load_tmx_map_from(data.as_slice(), tmx_path)?; + // Load the cup icon + let cup_icon = load_texture_from_internal_data( + raylib, + raylib_thread, + "assets/prp/prp_cupIcon/prp_cupIcon.png", + ) + .unwrap(); + // Iterate over all images in the map let mut tile_textures = HashMap::new(); for tileset in map.tilesets() { @@ -132,6 +141,7 @@ impl MapRenderer { tile_textures, world_objects, world_end, + cup_icon, }) } @@ -490,79 +500,99 @@ impl MapRenderer { // Convert the position to a tile position let tile_x = (position.x / 128.0).floor() as i32; let tile_y = ((position.y * -1.0) / 128.0).floor() as i32; - debug!("Tile x: {}, y: {}", tile_x, tile_y); + // debug!("Tile x: {}, y: {}", tile_x, tile_y); // Check if the tile is inside the win zone tile_x == self.world_end.x && tile_y == self.world_end.y } - // /// Used to modify the player's velocity based on the effects of the world - // pub fn effect_velocity_with_collisions( - // &self, - // player_position: na::Vector2, - // player_velocity: na::Vector2, - // ) -> na::Vector2 { - // // If the player is not moving, we don't need to do anything - // if player_velocity.norm() == 0.0 { - // return player_velocity; - // } + pub fn get_screenspace_vector_to_win_zone( + &self, + draw: &mut RaylibDrawHandle, + screen_center: na::Vector2, + camera: &Camera2D, + ) -> na::Vector2 { + let win_zone_position_world_space = Vector2::new( + self.world_end.x as f32 * 128.0, + (self.world_end.y as f32 * -1.0) * 128.0, + ); + let win_zone_position_screenspace = + draw.get_world_to_screen2D(win_zone_position_world_space, camera); + na::Vector2::new( + win_zone_position_screenspace.x - screen_center.x, + win_zone_position_screenspace.y - screen_center.y, + ) + } - // // Get the velocity unit vector - // let player_velocity_unit_vector = player_velocity.normalize(); + pub fn render_hud_endgoal_arrow( + &self, + draw: &mut RaylibDrawHandle, + player_position: na::Vector2, + camera: &Camera2D, + ) { + // Get the center of the screen + let screen_center = na::Vector2::new( + draw.get_screen_width() as f32 / 2.0, + draw.get_screen_height() as f32 / 2.0, + ); - // // Find the position 1 pixel infront of the player - // let player_position_1_pixel_infront = player_position + player_velocity_unit_vector; - // let next_player_position = player_position + player_velocity; + // Get the vector to the win zone + let vector_to_win_zone = + self.get_screenspace_vector_to_win_zone(draw, screen_center, camera); + let unit_vector_to_win_zone = vector_to_win_zone.normalize(); - // // Check if this is in the collision zone of any objects - // for obj_ref in &self.world_objects.object_references { - // // Filter out anything more than 1000 pixels away - // if (obj_ref.position - player_position).norm() > 1000.0 { - // continue; - // } + // Get the screenspace position of the win zone + let win_zone_position_screenspace = draw.get_world_to_screen2D( + Vector2::new( + self.world_end.x as f32 * 128.0, + (self.world_end.y as f32 * -1.0) * 128.0, + ), + camera, + ); - // // Get the object definition - // let object_key = obj_ref.into_key(); - // let obj_def = self - // .world_objects - // .object_definitions - // .get(&object_key) - // .unwrap(); + // If the win zone is inside the camera's view, don't render the arrow + if !(win_zone_position_screenspace.x < 0.0 + || win_zone_position_screenspace.x > draw.get_screen_width() as f32 + || win_zone_position_screenspace.y < 0.0 + || win_zone_position_screenspace.y > draw.get_screen_height() as f32) + { + return; + } - // // Check if the player is about to be in a collision zone - // for collider in &obj_def.physics_colliders { - // // Handle a radius collider vs a size collider - // if let Some(radius) = collider.radius { - // // Check if we are about to collide with the circle - // if (next_player_position - obj_ref.position).norm() < radius { - // // Get the angle from the player to the center of the collider - // let angle_to_center = - // (obj_ref.position - player_position).angle(&na::Vector2::new(0.0, 0.0)); - // if angle_to_center.abs() <= std::f32::consts::FRAC_PI_2 { - // // Apply the inverse of the velocity to the player - // return na::Vector2::zeros(); - // } - // } - // } else if let Some(size) = collider.size { - // // TODO: make this work for regular and rotated objects - // } - // } - // } + // // Draw the line + // draw.draw_line( + // screen_center.x as i32, + // screen_center.y as i32, + // (win_zone_position_screenspace.x + unit_vector_to_win_zone.x * 32.0) as i32, + // (win_zone_position_screenspace.y + unit_vector_to_win_zone.y * 32.0) as i32, + // Color::RED, + // ); - // // Check if the player is about to leave the map - // let mut player_velocity = player_velocity; - // if next_player_position.x < 0.0 { - // player_velocity.x = 0.0; - // } else if next_player_position.x > self.map.width as f32 * 128.0 { - // player_velocity.x = 0.0; - // } - // if next_player_position.y > 0.0 { - // player_velocity.y = 0.0; - // } else if next_player_position.y < self.map.height as f32 * -128.0 { - // player_velocity.y = 0.0; - // } + // // Define the screen rect + // let screen_rect = Rectangle { + // x: 0.0, + // y: 0.0, + // width: draw.get_screen_width() as f32, + // height: draw.get_screen_height() as f32, + // }; - // // If we got here, the player is not in a collision zone - // player_velocity - // } + // Find the intersection of the line and the screen edge + let intersect = unit_vector_to_win_zone * (draw.get_screen_height() as f32 / 2.0); + + // Render the cup icon + draw.draw_texture( + &self.cup_icon, + (screen_center.x + intersect.x) as i32 - self.cup_icon.width as i32 / 2, + (screen_center.y + intersect.y) as i32 - self.cup_icon.height as i32 / 2, + Color::WHITE, + ); + + // Render a circle where the line meets the screen edge + draw.draw_circle_lines( + (screen_center.x + intersect.x) as i32, + (screen_center.y + intersect.y) as i32, + 16.0, + Color::BLACK, + ); + } } diff --git a/game/game_logic/src/scenes/player_interaction.rs b/game/game_logic/src/scenes/player_interaction.rs index 41374b14..29188e87 100644 --- a/game/game_logic/src/scenes/player_interaction.rs +++ b/game/game_logic/src/scenes/player_interaction.rs @@ -212,14 +212,18 @@ impl PlayableScene { ); } - draw.draw_rectangle(draw.get_screen_width() / 2 - 225, 0, 450, 40, Color::WHITE); - draw.draw_text( - "Unregistered HyperCam 2", - draw.get_screen_width() / 2 - 215, - 0, - 32, - Color::BLACK, - ); + // Draw the hint arrow + self.world_map + .render_hud_endgoal_arrow(draw, self.player.position, &self.camera); + + // draw.draw_rectangle(draw.get_screen_width() / 2 - 225, 0, 450, 40, Color::WHITE); + // draw.draw_text( + // "Unregistered HyperCam 2", + // draw.get_screen_width() / 2 - 215, + // 0, + // 32, + // Color::BLACK, + // ); } // Physics