Created
August 27, 2021 07:55
-
-
Save drusepth/b26b523376ef3c686ea861d596164fb8 to your computer and use it in GitHub Desktop.
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 'ruby2d' | |
BUILD = :DEVELOPMENT | |
set title: 'Tiamat', | |
background: 'blue', | |
width: 640, viewport_width: 640, | |
height: 480, viewport_height: 480, | |
resizable: false, | |
borderless: BUILD == :PRODUCTION, | |
fullscreen: BUILD == :PRODUCTION, | |
diagnostics: BUILD != :PRODUCTION | |
TILE_WIDTH = TILE_HEIGHT = 64 | |
TILE_PADDING = 1 | |
def sanitize_config | |
if get(:height) % TILE_HEIGHT > 0 | |
puts "[Debug] Resizing window height" | |
new_height = get(:height) - (get(:height) % TILE_HEIGHT) | |
set height: new_height, | |
viewport_height: new_height | |
end | |
if get(:width) % TILE_WIDTH > 0 | |
puts "[Debug] Resizing window width" | |
new_width = get(:height) - (get(:height) % TILE_HEIGHT) | |
set height: new_width, | |
viewport_width: new_width | |
end | |
end | |
def draw_grid | |
(TILE_PADDING..(get :height)).step(TILE_HEIGHT).each do |y| | |
(TILE_PADDING..(get :width)).step(TILE_WIDTH).each do |x| | |
s = Square.new(x: x, y: y, size: TILE_WIDTH - TILE_PADDING) | |
s.color = 'random' | |
end | |
end | |
end | |
def draw_ui | |
end | |
def initial_setup | |
sanitize_config | |
draw_grid | |
draw_ui | |
end | |
def every_second(tick) | |
yield if tick % 60 == 0 | |
end | |
tick = 0 | |
# Game loop | |
initial_setup | |
update do | |
every_second(tick) do | |
set background: 'random' | |
end | |
clear | |
draw_grid | |
tick += 1 | |
end | |
on :key_down do |event| | |
if %w(up down left right).include?(event.key) | |
# move | |
end | |
end | |
# Gettables: | |
# - :window (obj), :frames (since start), :fps, :mouse_x, :mouse_y | |
# Other interesting methods | |
# - close: close the window | |
show | |
# Triangle.new( | |
# x1: 320, y1: 50, | |
# x2: 540, y2: 430, | |
# x3: 100, y3: 430, | |
# color: ['red', 'green', 'blue'] | |
# ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment