Last active
August 8, 2024 10:02
-
-
Save tonytins/49dc9076af0ab141307681550426e76c to your computer and use it in GitHub Desktop.
GDScript reference implementations by ChatGPT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node2D | |
var dragging: bool = false | |
func _input(event): | |
if dragging and event is InputEventMouseMotion: | |
position += event.relative | |
elif event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and not event.pressed: | |
dragging = false | |
func start_drag(): | |
dragging = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Button | |
# Reference to the scene to be instanced | |
@export var item_scene: PackedScene | |
func _on_Button_pressed(): | |
var item = item_scene.instantiate() | |
get_tree().root.add_child(item) | |
item.position = get_viewport().get_mouse_position() | |
item.start_drag() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is free and unencumbered software released into the public domain. | |
Anyone is free to copy, modify, publish, use, compile, sell, or | |
distribute this software, either in source code form or as a compiled | |
binary, for any purpose, commercial or non-commercial, and by any | |
means. | |
In jurisdictions that recognize copyright laws, the author or authors | |
of this software dedicate any and all copyright interest in the | |
software to the public domain. We make this dedication for the benefit | |
of the public at large and to the detriment of our heirs and | |
successors. We intend this dedication to be an overt act of | |
relinquishment in perpetuity of all present and future rights to this | |
software under copyright law. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
OTHER DEALINGS IN THE SOFTWARE. | |
For more information, please refer to <https://unlicense.org> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node | |
# Dictionary to store needs with their integer values | |
var needs: Dictionary = { | |
"hunger": 100, | |
"energy": 100 | |
} | |
# Decrease rates for each need | |
var decrease_rates: Dictionary = { | |
"hunger": 1, | |
"energy": 1 | |
} | |
# Function to update all needs every frame | |
func _process(delta): | |
for need_name in needs.keys(): | |
update_need(need_name, delta) | |
display_needs() | |
# Example process call | |
if needs["hunger"] <= 0: | |
print("The Sim is starving!") | |
if needs["energy"] <= 0: | |
print("The Sim is exhausted!") | |
# Function to update a specific need | |
func update_need(need_name: String, delta: float): | |
if needs[need_name] >= 0: | |
needs[need_name] -= delta * decrease_rates[need_name] | |
# Function to display all needs | |
func display_needs(): | |
for need_name in needs.keys(): | |
print_debug("%s: %d" % [need_name, needs[need_name]]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node | |
# Define registers | |
var registers = [] | |
var program_counter = 0 | |
# Define a simple set of RISC-V instructions | |
const ADD = 0 | |
const SUB = 1 | |
const LOAD = 2 | |
const STORE = 3 | |
# A simple program in our custom RISC-V-like assembly language | |
var program = [ | |
[LOAD, 0, 5], # Load the value 5 into register 0 | |
[LOAD, 1, 10], # Load the value 10 into register 1 | |
[ADD, 2, 0, 1], # Add register 0 and register 1, store result in register 2 | |
[SUB, 3, 1, 0], # Subtract register 0 from register 1, store result in register 3 | |
[STORE, 2, 100], # Store the value of register 2 at memory address 100 (simulated) | |
] | |
# Initialize registers and memory | |
func _ready(): | |
registers.resize(4) | |
for i in range(4): | |
registers[i] = 0 | |
# Run the program | |
run_program() | |
# Simulate the execution of the program | |
func run_program(): | |
while program_counter < program.size(): | |
var instruction = program[program_counter] | |
match instruction[0]: | |
ADD: | |
registers[instruction[1]] = registers[instruction[2]] + registers[instruction[3]] | |
SUB: | |
registers[instruction[1]] = registers[instruction[2]] - registers[instruction[3]] | |
LOAD: | |
registers[instruction[1]] = instruction[2] | |
STORE: | |
# Simulate storing the value (in a real system this would write to memory) | |
print("Stored value", registers[instruction[1]], "at address", instruction[2]) | |
program_counter += 1 | |
print("Final register values:", registers) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node | |
# Dictionary to store wants and fears with true/false values | |
var wants: Dictionary = { | |
"Eat a meal": false | |
} | |
var fears: Dictionary = { | |
"Burn food": false | |
} | |
# Function to check and set wants and fears | |
func _process(delta): | |
check_wants_and_fears("Eat a meal") | |
check_wants_and_fears("Burn food") | |
# Example process call | |
if wants["Eat a meal"]: | |
print("Sim wants to eat a meal.") | |
if fears["Burn food"]: | |
print("Sim fears burning food.") | |
func check_wants_and_fears(action: String): | |
if action in wants: | |
if action == action: | |
fulfill_want(action) | |
if action in fears: | |
if action == action: | |
experience_fear(action) | |
# Function to fulfill a want | |
func fulfill_want(want: String): | |
print("Want fulfilled: %s" % want) | |
wants[want] = false | |
# Additional logic for fulfilling want | |
# Function to experience a fear | |
func experience_fear(fear: String): | |
print("Fear realized: %s" % fear) | |
fears[fear] = false | |
# Additional logic for experiencing fear |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment