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
| 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 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
| require 'rainbow' | |
| RULES = { | |
| coast: [:land, :coast, :sea], | |
| sea: [:sea, :coast], | |
| land: [:land, :coast], | |
| } | |
| DISPLAY = { | |
| land: Rainbow("-").bg(:orange), |
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
| # 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 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
| $: << '../lib' | |
| require_relative '../lib/game_ecs' | |
| require 'pry' | |
| require 'gosu' | |
| include Gosu | |
| Q = GameEcs::Query | |
| # Components | |
| class GenerateNewCoinEvent; end |
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
| 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 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
| define_behavior :faded do | |
| requires :timer_manager | |
| setup do | |
| actor.has_attributes shadows: [], shadows_to_render: opts[:shadows_to_render] | |
| timer_manager.add_timer timer_name, 100 do | |
| new_shadow = {x: actor.x, y: actor.y} | |
| actor.shadows << new_shadow | |
| actor.shadows.shift if actor.shadows.size > actor.shadows_to_render | |
| end |
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
| define_stage :demo do | |
| requires :tween_manager | |
| curtain_up do | |
| @player = spawn :player, x: 10, y:30 | |
| tween = tween_manager.tween_properties @player, {x: 600, y:750}, 6_000, Tween::Sine::InOut | |
| # tweens can be canceled if need be, or they will clean themselves up when finished | |
| timer_manager.add_timer :foo, 3_000, false do | |
| tween.cancel! | |
| end |
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
| define_behavior :fades do | |
| requires :director | |
| setup do # |opts| | |
| fade_out_time = 3_000 | |
| actor.has_attributes total_fade_time: fade_out_time, fade_time: fade_out_time | |
| director.when :update do |time_ms, secs| | |
| actor.fade_time -= time_ms | |
| alpha = 255 * actor.fade_time / actor.total_fade_time | |
| actor.remove if actor.fade_time <= 0 |
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
| Foo = {} | |
| Object.defineProperty(Foo, 'blah', {get: function(){ return 'yo'}}); | |
| Foo.blah | |
| => 'yo' |
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
| 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 |
NewerOlder