Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[modpack] Adds pixel shifting #197

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion code/modules/mob/living/carbon/human/update_icons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,12 @@ Please contact me on #coderbus IRC. ~Carn x
// Scale/translate/rotate and apply the transform.
var/matrix/M = matrix()
if(lying)
M.Turn(pick(90, -90))
var/turn_angle = pick(-90, 90)
if(dir == WEST)
turn_angle = -90
if(dir == EAST)
turn_angle = 90
M.Turn(turn_angle)
M.Scale(desired_scale_y, desired_scale_x)
M.Translate(1, -6-default_pixel_z)
else
Expand Down
9 changes: 8 additions & 1 deletion code/modules/mob/living/living.dm
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,16 @@ default behaviour is:
if(affecting_mob)
affecting_mob.handle_grab_damage()

/mob/living/Move(a, b, flag)
/mob/living/Move(newloc, direct, flag)
if (buckled)
return
// Modpack edit - pixel shifting
if(shifting)
pixel_shift(direct)
return FALSE
else if(is_shifted)
unpixel_shift()
// end modpack edit
Comment on lines +507 to +513
Copy link
Contributor

@quardbreak quardbreak Dec 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This edit will conflict with upstream.
You probably want to move it to modpack as well, since those functions work only if you include it.

I used this code in my downstream to separate from core to modpack:

/mob/living/Move()
	. = ..()

	if(is_shifted && !buckled)
		is_shifted = FALSE
		pixel_x = default_pixel_x
		pixel_y = default_pixel_y

After some tweaks for you, it will look like this:
I use this code to separate from core to modpack:

/mob/living/Move()
	if(shifting)
		pixel_shift(direct)
		return FALSE
	else if((is_shifted && !buckled)
		unpixel_shift()

	. = ..()

. = ..()
handle_grabs_after_move()
if (s_active && !( s_active in contents ) && get_turf(s_active) != get_turf(src)) //check !( s_active in contents ) first so we hopefully don't have to call get_turf() so much.
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/mob.dm
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@

// facing verbs
/mob/proc/canface()
return !incapacitated()
return !incapacitated(INCAPACITATION_UNRESISTING)

// Not sure what to call this. Used to check if humans are wearing an AI-controlled exosuit and hence don't need to fall over yet.
/mob/proc/can_stand_overridden()
Expand Down
1 change: 1 addition & 0 deletions maps/modpack_testing/modpack_testing.dm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "../../mods/content/psionics/_psionics.dme"
#include "../../mods/content/shards/_shards.dme"
#include "../../mods/content/xenobiology/_xenobiology.dme"
#include "../../mods/content/pixel_shifting/_pixel_shifting.dme"

#include "../../mods/mobs/dionaea/_dionaea.dme"
#include "../../mods/mobs/borers/_borers.dme"
Expand Down
1 change: 1 addition & 0 deletions maps/torch/torch.dm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "..\..\mods\content\genemodding\_genemodding.dme"
#include "..\..\mods\content\hearthfoods\_hearthfoods.dme"
#include "..\..\mods\content\shards\_shards.dme"
#include "..\..\mods\content\pixel_shifting\_pixel_shifting.dme"

#include "..\..\mods\verbs\antighost\_subtle_antighost.dme"

Expand Down
14 changes: 14 additions & 0 deletions mods/content/pixel_shifting/_pixel_shifting.dme
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef MODPACK_PIXELSHIFTING
#define MODPACK_PIXELSHIFTING
#include "pixel_shifting.dm"
#include "keybindings\mob.dm"
#endif
// BEGIN_INTERNALS
// END_INTERNALS
// BEGIN_FILE_DIR
#define FILE_DIR .
// END_FILE_DIR
// BEGIN_PREFERENCES
// END_PREFERENCES
// BEGIN_INCLUDE
// END_INCLUDE
15 changes: 15 additions & 0 deletions mods/content/pixel_shifting/keybindings/mob.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/datum/keybinding/mob/pixel_shift
hotkey_keys = list("Alt")
name = "pixel_shifting"
full_name = "Pixel shift"
description = "Hold this down to pixel shift the icon of your current mob."

/datum/keybinding/mob/pixel_shift/down(client/user)
var/mob/client_mob = user.mob
client_mob.shifting = TRUE
return TRUE

/datum/keybinding/mob/pixel_shift/up(client/user)
var/mob/client_mob = user.mob
client_mob.shifting = FALSE
return TRUE
44 changes: 44 additions & 0 deletions mods/content/pixel_shifting/pixel_shifting.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/mob
/// Wether the mob is currently pixel shifted or not
var/is_shifted
/// If the mob is currently pixel shifting
var/shifting

/mob/proc/unpixel_shift()
return

/mob/living/unpixel_shift()
if(is_shifted)
is_shifted = FALSE
pixel_x = initial(pixel_x)
pixel_y = initial(pixel_y)
Comment on lines +13 to +14
Copy link
Contributor

@quardbreak quardbreak Dec 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

	pixel_x = default_pixel_x
	pixel_y = default_pixel_y

Some species/mobs have their own default pixel. Use them.


/mob/proc/pixel_shift(direction)
return

/mob/living/pixel_shift(direction)
switch(direction)
if(NORTH)
if(!canface())
Copy link
Contributor

@quardbreak quardbreak Dec 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the first check inside this function. No need to duplicate it for every direction.
Use this:

/mob/proc/can_pixel_shift()
	return !(incapacitated() || buckled || LAZYLEN(grabbed_by))

/mob/proc/pixel_shift(direction)
	return

/mob/living/pixel_shift(direction)
	if(!canface() || !can_shift())
		return FALSE
	
	(...)

return FALSE
if(pixel_y <= 16)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace magic numbers like 16 with define like DEFAULT_SHIFT_MAX.
I use 8 at this moment, but would like to change it to 16 if this visually better.

pixel_y++
is_shifted = TRUE
if(EAST)
if(!canface())
return FALSE
if(pixel_x <= 16)
pixel_x++
is_shifted = TRUE
if(SOUTH)
if(!canface())
return FALSE
if(pixel_y >= -16)
pixel_y--
is_shifted = TRUE
if(WEST)
if(!canface())
return FALSE
if(pixel_x >= -16)
pixel_x--
is_shifted = TRUE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you can just copypaste my proc:

#define SHIFT_MAX 8

/mob/proc/pixel_shift(dir)
	if(!canface() || !can_shift())
		return FALSE

	switch(dir)
		if(NORTH)
			if(pixel_y <= SHIFT_MAX)
				pixel_y++
		if(EAST)
			if(pixel_x <= SHIFT_MAX)
				pixel_x++
		if(SOUTH)
			if(pixel_y >= -SHIFT_MAX)
				pixel_y--
		if(WEST)
			if(pixel_x >= -SHIFT_MAX)
				pixel_x--
		else
			CRASH("Invalid argument supplied!")

	is_shifted = TRUE
	UPDATE_OO_IF_PRESENT

#undef SHIFT_MAX

Note about the UPDATE_OO_IF_PRESENT. It will update a openspace overlay above you (so people above will see your character is shifted).