Last active
October 8, 2023 16:11
-
-
Save katsuyoshi/7cf6ced16d52996ae81d98097d4d5095 to your computer and use it in GitHub Desktop.
DXOpalのテスト
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 'dxopal' | |
| include DXOpal | |
| class ScreenBuffer | |
| attr_reader :width, :height | |
| def initialize(width, height) | |
| @width = width | |
| @height = height | |
| @buffer_size = @width / 8 * @height | |
| @buffer = Array.new(@buffer_size, 0) | |
| end | |
| def draw(w) | |
| height.times do |y| | |
| (width / 8).times do |x_8| | |
| v = @buffer[y * height + x_8] || 0 | |
| 8.times do |i| | |
| x = x_8 * 8 + i | |
| if v & 1 == 0 | |
| w.draw_pixel(x, y, C_BLACK) | |
| else | |
| w.draw_pixel(x, y, C_WHITE) | |
| end | |
| v >>= 1 | |
| end | |
| end | |
| end | |
| end | |
| end | |
| Window.load_resources do | |
| @vram = ScreenBuffer.new(256, 244) | |
| Window.bgcolor = C_BLACK | |
| Window.width = @vram.width | |
| Window.height = @vram.height | |
| #Window.scale = 2 | |
| #Window.caption = "Space Invaders" | |
| Window.loop do | |
| Window.draw_font(0, 0, "Hello!", Font.default, color: C_WHITE) | |
| @vram.draw(Window) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment