Skip to content

Instantly share code, notes, and snippets.

View andrew-wilkes's full-sized avatar

Andrew Wilkes andrew-wilkes

View GitHub Profile
@andrew-wilkes
andrew-wilkes / export-tool.gd
Last active November 16, 2020 12:37
Implementing a Tool script in Godot Engine to update a Label text in an Instantiated scene
tool
extends Control
# Set a default value and call the setter and getter functions as needed
# But this txt value IS NOT SAVED in an instantiated scene
export var txt = "Y0" setget set_text, get_text
# But this text value IS SAVED in an instantiated scene
# And it is displayed in the Inspector panel (we don't want that to happen)
export var text: String
@andrew-wilkes
andrew-wilkes / make-brighter-bg.shader
Created June 25, 2020 10:07
Godot make background brighter shader
shader_type canvas_item;
void fragment() {
vec3 c = textureLod(SCREEN_TEXTURE, SCREEN_UV, 0.0).rgb;
if (c.r < 0.3 || c.g < 0.3 || c.b < 0.3) c *= 1.2;
COLOR.rgb = c;
}
@andrew-wilkes
andrew-wilkes / tree-item-highlight.gd
Last active June 25, 2020 09:57
Godot TreeItem Highlight Code
func _on_Tree_gui_input(event):
if event is InputEventMouseMotion:
$Bar.rect_position = Vector2(2, get_y(event.position.y))
$Bar.rect_size = Vector2(rect_size.x - 12, 17)
func get_y(y):
var step = 22
var dy = tree.get_scroll().y
return floor(y / step) * step + 7 - dy + step * floor(dy / step)
@andrew-wilkes
andrew-wilkes / treeitem.gd
Created June 25, 2020 09:03
Scan Tree and save a list of collapsed TreeItems
func _on_Tree_item_collapsed(_item):
if ready:
g.state.ci[cid] = []
scan_children(tree.get_root())
g.save_state()
func scan_children(root):
var item = root.get_children()
while item:
shader_type spatial;
uniform vec3 target = vec3(1.0, 0.0, 0.0);
uniform float alpha = 1.0;
uniform vec4 globe_color : hint_color = vec4(0.1, 0.5, 0.99, 0.5);
uniform vec4 shield_color : hint_color = vec4(0.99, 0.0, 0.1, 1.0);
varying float ang;
void vertex() {
@andrew-wilkes
andrew-wilkes / side-scroll.gd
Created January 31, 2020 13:36
GDScript side scroll code
extends Node2D
const SPEED = 100
var max_x
var pos = 0
var terrain
var p_bg
var p_layer
@andrew-wilkes
andrew-wilkes / js-hit.php
Created January 26, 2020 11:06
Unique Website Visitor Logger
<?php
const TESTING = false;
const FILE_NAME = ".hits";
const DAYS = 10;
const PASSWORD = "YOUR PASSWORD HERE";
$user_agent = strip_tags($_SERVER['HTTP_USER_AGENT']);
$bots = ["bot", "slurp", "spider", "crawler"];
foreach ($bots as $bot) {
if (stripos($user_agent, $bot) !== false) exit();
@andrew-wilkes
andrew-wilkes / circular-progress.shader
Created January 16, 2020 11:41
Circular Progress Shader in Godot Engine
shader_type canvas_item;
uniform float value: hint_range(0, 100); // %
uniform float thickness: hint_range(0, 100) = 30.; // % thickness
uniform sampler2D fg: hint_albedo;
uniform sampler2D bg: hint_black_albedo;
uniform float offset: hint_range(0, 100); // %
uniform float smoothing: hint_range(0, 100) = 5.;
void fragment() {
@andrew-wilkes
andrew-wilkes / Italics.shader
Last active December 10, 2019 18:53
Italic Text Shader for Godot Engine Label
shader_type canvas_item;
void vertex() {
VERTEX.x -= VERTEX.y * 0.3;
}
@andrew-wilkes
andrew-wilkes / phonetic-alphabet-memorizer.gd
Last active December 1, 2019 11:39
Phonetic Alphabet Memorizer
extends CenterContainer
const words = "ALFA, BRAVO, CHARLIE, DELTA, ECHO, FOXTROT, GOLF, HOTEL, INDIA, JULIETT, KILO, LIMA, MIKE, NOVEMBER, OSCAR, PAPA, QUEBEC, ROMEO, SIERRA, TANGO, UNIFORM, VICTOR, WHISKEY, X-RAY, YANKEE, ZULU"
const words2 = "Amsterdam, Baltimore, Casablanca, Denmark, Edison, Florida, Gallipoli, Havana, Italia, Jerusalem, Kilogramme, Liverpool, Madagascar, New York, Oslo, Paris, Quebec, Roma, Santiago, Tripoli, Uppsala, Valencia, Washington, Xanthippe, Yokohama, Zurich"
const words3 = "Able, Baker, Charlie, Dog, Easy, Fox, George, How, Item, Jig, King, Love, Mike, Nan, Oboe, Peter, Queen, Roger, Sugar, Tare, Uncle, Victor, William, X-ray, Yoke, Zebra"
const words4 = "Alfa, Bravo, Coca, Delta, Echo, Foxtrot, Gold, Hotel, India, Juliett, Kilo, Lima, Metro, Nectar, Oscar, Papa, Quebec, Romeo, Sierra, Tango, Union, Victor, Whiskey, eXtra, Yankee, Zulu"
var list
var show_letter = true
var i = 0