~jheckt/TextEscape

13e0b6325eec2055cfe086837ce2bc6b2ab73956 — Jeremy Heckt 5 months ago 572fee4
starting game ending, adding shaders to text, and baddie soon
M Scripts/Commands.gd => Scripts/Commands.gd +25 -12
@@ 44,8 44,18 @@ func handle_look():
		return_text = info.DarkLookText + "\n" + "Noticed doorways: " + doors_info

	if GameState.is_light_on || info.Light == "Yes" || GameState.lit_rooms.has(GameState.current_room):

		## IF the light is on the the start room have the blood effect on the writing on the wall
		if GameState.current_room == "startroom": 
			return_text = info.LightLookText + "\n" + "Noticed doorways: " + doors_info
			get_tree().call_group("DisplayArea", "display_text", return_text)
			get_tree().call_group("DisplayArea", "display_text", "")
			get_tree().call_group("DisplayArea", "display_text_effect", "Climb Out Of The Basement!", "blood")
			return

		return_text = info.LightLookText + "\n" + "Noticed doorways: " + doors_info
		return return_text
		get_tree().call_group("DisplayArea", "display_text", return_text)
		return

	return_text = info.DarkLookText + "\n" + "Noticed doorways: " + doors_info



@@ 53,7 63,8 @@ func handle_look():
	for item in GameState.inventory:
		return_text = Utils.remove_item_text(return_text, item)

	return return_text
	get_tree().call_group("DisplayArea", "display_text", return_text)
	return


func handle_examine(target):


@@ 67,6 78,7 @@ func handle_examine(target):
		## Ensure the file exists
		if FileAccess.file_exists(filename):
			var info = Utils.read_file(filename)
			text_to_display = info.DarkLookText

			## If we have light then handle that first
			if GameState.is_light_on || info.Light == "Yes" || GameState.lit_rooms.has(GameState.current_room):


@@ 79,15 91,15 @@ func handle_examine(target):
						if info.LightLookInteractedText:
							text_to_display = info.LightLookInteractedText

						text_to_display =  info.LightLookText
					text_to_display =  info.LightLookText


			## Check if we have already interacted with the target before
			if GameState.room_items_interacted[GameState.current_room].has(target):

				## If the item has special text for after interacting, show it here
				## Otherwise return standard text
				if info.DarkLookInteractedText:
				## Otherwise return standard text (dark)
				if info.DarkLookInteractedText && !GameState.is_light_on:
					text_to_display = info.DarkLookInteractedText

			## If there is an inventory item, add it to inventory


@@ 98,7 110,8 @@ func handle_examine(target):
					if GameState.is_crate_open:
						for i in info.InventoryItems:
							GameState.inventory.append(i)

						get_tree().call_group("DisplayArea", "display_text", "You reach inside and grab a battery out of the pile inside of the crate.")
						return
				else:
					for i in info.InventoryItems:
						GameState.inventory.append(i)


@@ 106,17 119,11 @@ func handle_examine(target):
			## Add to the list of interacted items found in the room
			GameState.room_items_interacted[GameState.current_room].append(target)

			## If there is an inventory item, add it to inventory
			text_to_display = info.DarkLookText

			print("Examine2")

			if info.Effects != "None":
				print("effects")
				get_tree().call_group("DisplayArea", "display_text_effect", text_to_display, info.Effects)
				return
			
			print("examine3")
			get_tree().call_group("DisplayArea", "display_text", text_to_display)
			return



@@ 166,6 173,12 @@ func handle_use(item):
	if GameState.all_items_used.has(item):
		get_tree().call_group("DisplayArea", "display_text", "You have already used the " + item + ".")
		return


	### You can use the battery anywhere
	if item == "battery":
		Interactions.interactions_map[item].call()
		return
	
	## See if this item is in the list of UseItems for the room
	var room_info = Utils.get_current_room_info()

M Scripts/DisplayArea.gd => Scripts/DisplayArea.gd +1 -3
@@ 84,10 84,8 @@ func handle_command(text):
		return

	if command == "look":
		var look_result = Commands.handle_look()
		display_command(command, args)
		display_text(look_result)
		return
		Commands.handle_look()

	if command == "examine":
		display_command(command, args)

M Scripts/GameState.gd => Scripts/GameState.gd +9 -2
@@ 54,7 54,7 @@ var room_connection_map = {
}


var inventory = ["bkey"]
var inventory = ["battery"]
var all_items_grabbed = [] # For knowing which items to remove from descriptions
var all_items_used = [] # All items SUCCESSFULLY used so as to not be used again



@@ 67,7 67,11 @@ var all_items_can_pickup = {
	"restroom": ["crampons", "wire"],
	"closet": ["bkey"],
	"hallway": [""],
	"kitchen": ["ckey"]
	"kitchen": ["ckey"],
	"basementcloset": [""],
	"basementhallway": [""],
	"toolroom": ["crowbar"],
	"chemicalstore": [""]
}

## Are certain items open?


@@ 81,6 85,9 @@ var lit_rooms = []
var is_basement_door_unlocked = false
var is_closet_unlocked = false

## Baddie
var is_baddie_spawned = false


###############################################################################
## Mains

M Scripts/Interactions.gd => Scripts/Interactions.gd +19 -3
@@ 6,9 6,11 @@ extends Node
## "Global" variables
###############################################################################
var interactions_map = {
	"can":  Callable(self, "use_can_on_scale"),
	"ckey": Callable(self, "use_closet_key"),
	"bkey": Callable(self, "use_basement_key")
	"can"	 : Callable(self, "use_can_on_scale"),
	"ckey"	 : Callable(self, "use_closet_key"),
	"bkey"	 : Callable(self, "use_basement_key"),
	"crowbar": Callable(self, "use_crowbar"),
	"battery": Callable(self, "use_battery"),
}

###############################################################################


@@ 29,6 31,20 @@ func use_basement_key():
	GameState.is_basement_door_unlocked = true
	GameState.all_items_used.append("bkey")

func use_crowbar():
	get_tree().call_group("DisplayArea", "display_text", "You use the crowbar to pry open the wooden crate. The crowbar breaks in the process, making a loud noise.")
	GameState.is_crate_open = true
	GameState.all_items_used.append("crowbar")
	GameState.is_baddie_spawned = true

func use_battery():
	get_tree().call_group("DisplayArea", "display_text", "You place the battery in your headlamp. Everything is illuminated.")
	GameState.is_light_on = true
	GameState.all_items_used.append("battery")

func use_crampons():
	get_tree().quit()


###############################################################################
## Mains

M Scripts/Utils.gd => Scripts/Utils.gd +1 -1
@@ 20,7 20,7 @@ class GameFile:
	var UseItem: String


var valid_effects = ["shake"]
var valid_effects = ["shake", "blood"]

###############################################################################
## Functions

M Scripts/text_line.gd => Scripts/text_line.gd +9 -0
@@ 4,13 4,22 @@ extends Node2D
@export var text: String = ""
@export var effect: String = ""

var blood_shader = preload("res://Scripts/text_line.gdshader")

var is_shader_set = false

func handle_effect():
	if effect.to_lower() == "shake":
		var rng = RandomNumberGenerator.new()
		position.y = position.y + rng.randf_range(-1, 1)

	if effect.to_lower() == "blood":
		if not is_shader_set:
			$TextArea.material = ShaderMaterial.new()
			$TextArea.material.shader = blood_shader
			is_shader_set = true



# Called when the node enters the scene tree for the first time.
func _ready():

A Scripts/text_line.gdshader => Scripts/text_line.gdshader +20 -0
@@ 0,0 1,20 @@
shader_type canvas_item;

uniform sampler2D flowMap; //Displacement map
uniform float strength;    //Force of the effect
uniform float speed;       //Speed of the effect
uniform int frames : hint_range(1, 10); //Frames of the effect

//Returns a value between 0 and 1 depending of the frames -> exemple: frames = 4, frame 1 = 0.25
float clock(float time){
	float fframes = float(frames);
	return floor(mod(time * speed, fframes)) / fframes;
}

void fragment(){
	float c = clock(TIME); //Get clock frame
	vec4 offset = texture(flowMap, vec2(UV.x + c, UV.y + c)) * strength; //Get offset 
	//COLOR = texture(TEXTURE, vec2(UV.x,UV.y) + normal.xy); //Apply offset
	//COLOR = texture(TEXTURE, vec2(UV.x,UV.y) + offset.xy - vec2(0.5,0.5)*strength); //We need to remove the displacement 
	COLOR = vec4(offset.xy, 0.5, 1.0); //Debug
}
\ No newline at end of file

A Texts/basementhallway.txt => Texts/basementhallway.txt +7 -0
@@ 0,0 1,7 @@
--Type: Location
--Effects: None
--Light: No
--Doors: Left,Right
--Items: 
--DarkLookText: You are in another hallway. You can feel what you think are dirt walls.
--LightLookText: You are in a dirt hallway carved into the back of a basement.
\ No newline at end of file

A Texts/chemicalstore.txt => Texts/chemicalstore.txt +8 -0
@@ 0,0 1,8 @@
--Type: Location
--Effects: None
--Light: No
--Doors: Left
--Items: 
--UseItems: crampons
--DarkLookText: You feel around a room full of glass beakers. It has a strong chemical stench, almost like a mixture of bleach and cat urine.
--LightLookText: You are in some sort of makeshift chemistry laboratory. You see jars full of liquids that are varying shades of yellow and brown. You can see a tunnel dug into the dirt in the ceiling. You may be able to climb out if you have some way to get a better grip with your shoes.
\ No newline at end of file

A Texts/sawblade.txt => Texts/sawblade.txt +5 -0
@@ 0,0 1,5 @@
--Type: Item
--Effects: None
--Light: No
--DarkLookText: What feels like a broken sawblade. You are careful not to cut yourself, this time.
--LightLookText: A broken sawblade. Do not touch, you may cut yourself.
\ No newline at end of file

M Texts/startroom.txt => Texts/startroom.txt +1 -1
@@ 5,4 5,4 @@
--Items: sack,crate
--UseItems: crowbar,bkey
--DarkLookText: You do not see much, but you can reach out and feel what you think is a wood [hint=examine][u]crate[/u][/hint]. Behind you can be felt a burlap [hint=examine][u]sack[/u][/hint].
--LightLookText: INSERT TEXT
--LightLookText: Looking around the room you see a wooden [hint=examine][u]crate[/u][/hint] with a red-stained lid. On the floor behind you is an empty burlap onion [hint=examine][u]sack[/u][/hint]. On the ground you see clothes from apparently several different people of different sizes. On the wall you notice blood-red lettering that reads....

A Texts/toolroom.txt => Texts/toolroom.txt +7 -0
@@ 0,0 1,7 @@
--Type: Location
--Effects: None
--Light: No
--Doors: Left,Right
--Items: crowbar,wood,sawblade
--DarkLookText: You feel around a dusty room full of planks of [hint=examine][u]wood[/u][/hint]. On the floor you can find a broken [hint=examine][u]sawblade[/u][/hint].{crowbar} You also find a [hint=pickup][u]crowbar[/u][/hint] on the only counter not covered in boxes of wood.{/crowbar}
--LightLookText: You see a room covered in sawdust and full of red-splattered planks of [hint=examine][u]wood[/u][/hint]. On the floor you can find a broken [hint=examine][u]sawblade[/u][/hint].{crowbar} You also find a [hint=pickup][u]crowbar[/u][/hint] on the only counter not covered in boxes of wood.{/crowbar}
\ No newline at end of file

A Texts/wood.txt => Texts/wood.txt +5 -0
@@ 0,0 1,5 @@
--Type: Item
--Effects: None
--Light: No
--DarkLookText: Feels like 2x4 planks of wood in boxes.
--LightLookText: An apparently blood-stained pile of 2x4 planks.
\ No newline at end of file