Created
April 21, 2026 02:03
-
-
Save KonnorRogers/5a80c114af45276e04e89c4a3f27bab4 to your computer and use it in GitHub Desktop.
simple-conveyor
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
| class Game | |
| attr_gtk # attr_gtk class macro | |
| SPRITES = { | |
| conveyor_belt: { | |
| source_x: 0, | |
| source_w: 16, | |
| source_h: 16, | |
| source_y: 0, | |
| animations: { | |
| frames: 16, | |
| frame_length: 60 * 6, | |
| repeat: true, | |
| }, | |
| angle: 270, | |
| path: "sprites/conveyor-1.png" | |
| } | |
| } | |
| def initialize(args) | |
| @tick_count = 0 | |
| @animations = {} # Basic map of running animations, keyed off an object_id. | |
| @entities = [] | |
| @conveyors = [] | |
| conveyor_size = 64 | |
| 16.times do |i| | |
| @conveyors << { | |
| x: 100 + conveyor_size * i, | |
| y: Grid.h / 2, | |
| w: conveyor_size, | |
| h: conveyor_size, | |
| **SPRITES[:conveyor_belt], | |
| primitive_marker: :sprite, | |
| } | |
| end | |
| end | |
| # Pass a tick count so we can sync them all if we add one. | |
| def animation_for_conveyor_belt(conveyor_belt) | |
| sprite = SPRITES[:conveyor_belt] | |
| animations = sprite.animations | |
| frame_index = Numeric.frame_index( | |
| count: animations.frames, | |
| hold_for: animations.frame_length / 60, | |
| repeat: animations.repeat, | |
| repeat_index: animations.repeat_index || 0, | |
| tick_count_override: @tick_count | |
| ) | |
| { | |
| **conveyor_belt, | |
| **sprite, | |
| source_x: frame_index * sprite.source_w, # only source_w increments. | |
| } | |
| end | |
| def tick | |
| defaults | |
| calc | |
| render | |
| @tick_count += 1 | |
| end | |
| def defaults | |
| end | |
| def calc | |
| if @tick_count % 120 == 0 | |
| @entities << { | |
| x: @conveyors[0].x , | |
| y: @conveyors[0].y + 16, | |
| w: 32, | |
| h: 32, | |
| path: "sprites/circle/red.png" | |
| } | |
| end | |
| # For obvious reasons, doing a many-to-many collision is really bad. But this is just an example. | |
| @entities.each do |spr| | |
| if Geometry.find_intersect_rect(spr, @conveyors) | |
| spr.x += (100 / 60) | |
| end | |
| end | |
| end | |
| def render | |
| @conveyors.each { |spr| spr.merge!(animation_for_conveyor_belt(spr)) } | |
| outputs.primitives | |
| .concat(@conveyors) | |
| .concat(@entities) # always render entities on top | |
| end | |
| end | |
| def boot(args) | |
| args.state = {} | |
| end | |
| def tick(args) | |
| $game ||= Game.new(args) | |
| $game.args = args # set args property on game | |
| $game.tick # call tick without passing in args | |
| end | |
| $game = nil |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
^ Sprite used
Video:
2026-04-20_22-04-09.remuxed.mp4