This file contains 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
from functools import wraps | |
from typing import Any, Callable, TypeVar, Type, cast, get_type_hints | |
T = TypeVar('T') | |
class AppContext: | |
def __init__(self) -> None: | |
self.dependencies: dict[type, dict[Any, Any]] = {} | |
self.cache: dict[type, Any] = {} |
This file contains 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
require 'rainbow' | |
RULES = { | |
coast: [:land, :coast, :sea], | |
sea: [:sea, :coast], | |
land: [:land, :coast], | |
} | |
DISPLAY = { | |
land: Rainbow("-").bg(:orange), |
This file contains 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
# Ideal choice of fixed-point equivalent to 1.0 that can almost perfectly represent sqrt(2) and (sqrt(2) - 1) in whole numbers | |
# 1.000000000 = 2378 | |
# 0.414213624 = 985 / 2378 | |
# 1.414213625 = 3363 / 2378 | |
# 1.414213562 = Actual sqrt(2) | |
# 0.00000006252 = Difference between actual sqrt(2) and fixed-point sqrt(2) | |
COST_STRAIGHT = 2378 | |
COST_DIAG = 3363 | |
class Node |
This file contains 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
$: << '../lib' | |
require_relative '../lib/game_ecs' | |
require 'pry' | |
require 'gosu' | |
include Gosu | |
Q = GameEcs::Query | |
# Components | |
class GenerateNewCoinEvent; end |
This file contains 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
module GameEcs | |
class EcsSystem | |
def self.system_for_query(query, &block) | |
new(query, &block) | |
end | |
def initialize(query=Query.none, &block) | |
@query = query | |
@system_block = block | |
end |
This file contains 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 the primary element in an AABBTree. | |
# It acts as both containing elements and leaf elements. Leaves have an @object, | |
# containers have @a and @b nodes. All leaf nodes have a cached list of | |
# collisions that contain references to other nodes in the tree. | |
class AABBNode | |
include AABBNodeDebugHelpers | |
attr_accessor :bb, :a, :b, :parent, :object, :cached_collisions | |
def initialize(parent, object, bb) | |
@parent = parent |
This file contains 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
Foo = {} | |
Object.defineProperty(Foo, 'blah', {get: function(){ return 'yo'}}); | |
Foo.blah | |
=> 'yo' |
This file contains 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
Pry-remote: | |
[7] pry(#<GameboxApp>)> f = actors(:foxy).first; | |
[31:0:736875] [debug] found 2 actors | |
[8] pry(#<GameboxApp>)> f.x += 10 | |
=> 120.0 | |
[9] pry(#<GameboxApp>)> watch :time do Time.now end |
This file contains 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
# Using group-by | |
# no extra step definition is required | |
PiecePipe::Pipeline.new. | |
source([{region: region}]). | |
step(FetchPowerPlantsByRegion). | |
group_by(:region). | |
to_enum | |
This file contains 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
# CURRENT | |
has_behavior animated: {:frame_update_time => 900} | |
has_behavior collidable: {shape: :polygon, cw_local_points: [[4,4],[44,4],[44,44],[4,44]]} | |
has_behavior projectile: {speed: 0.01, direction: vec2(1,0)} | |
has_behavior :reversable_direction | |
has_behavior increasing_speed: { accel: 0.001 } | |
has_behavior drops: { fall_amount: 25} | |
has_behavior shooter: {shoots: :alien_missile, direction: vec2(0,-1)} |
NewerOlder