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 / 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 / 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
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 / 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:
@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 / 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 / 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 / text-overlay.gd
Created November 30, 2020 10:02
Add a Line2D above tagged ranges of text in a Label in Godot
extends Control
# Scene structure:
# Main (Control Node)
# - HBox
# -- Multi-line Text label of 400px min width containing a bunch of text
# -- Control node that expands horizontally
# c (canvas node)
export var token = "#" # Marks start and end points of text to draw a line over
@andrew-wilkes
andrew-wilkes / computer.c
Created December 13, 2020 10:25
Arduino Cycling Computer
/*
* Bicyle computer Arduino Uno code
* Author: Andrew M Wilkes
* 2016-08-12
*/
/*
* Notes
* Switch/sensor debounce is implemented by assigning an INT value to the switch variable that is set on the initial falling edge of the switch.
* The switch action is then ignored until the value has been counted down to zero.
@andrew-wilkes
andrew-wilkes / winsize.gd
Last active December 19, 2020 10:47
Godot in Windows set window size and position
func _ready():
if OS.get_name() == "Windows":
var screen_size = OS.get_screen_size()
var window_size = OS.get_window_size()
OS.set_window_position(Vector2((screen_size.x - window_size.x) * 0.5, 0))
OS.set_window_size(Vector2(window_size.x, screen_size.y - 75)) # Allow for the tray bar