diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..13d683c --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.0.1 \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..1e25e98 --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +source 'https://rubygems.org' + +ruby '~> 3.0' + +gem 'minigl', '~> 2.3.9' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..d0a1671 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,18 @@ +GEM + remote: https://rubygems.org/ + specs: + gosu (1.4.1) + minigl (2.3.9) + gosu (>= 0.11, < 2.0) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + minigl (~> 2.3.9) + +RUBY VERSION + ruby 3.0.1p64 + +BUNDLED WITH + 2.2.15 diff --git a/data/img/interface/button.png b/data/img/interface/button.png new file mode 100644 index 0000000..20fc344 Binary files /dev/null and b/data/img/interface/button.png differ diff --git a/data/img/interface/buttonClicked.png b/data/img/interface/buttonClicked.png deleted file mode 100644 index 3e228d7..0000000 Binary files a/data/img/interface/buttonClicked.png and /dev/null differ diff --git a/data/img/interface/buttonDefault.png b/data/img/interface/buttonDefault.png deleted file mode 100644 index e492d82..0000000 Binary files a/data/img/interface/buttonDefault.png and /dev/null differ diff --git a/data/img/interface/buttonHover.png b/data/img/interface/buttonHover.png deleted file mode 100644 index 6c6d088..0000000 Binary files a/data/img/interface/buttonHover.png and /dev/null differ diff --git a/data/img/interface/confirmDialog.png b/data/img/interface/confirmDialog.png index fbcb7ea..6d02092 100644 Binary files a/data/img/interface/confirmDialog.png and b/data/img/interface/confirmDialog.png differ diff --git a/data/img/interface/keyCursor.png b/data/img/interface/keyCursor.png new file mode 100644 index 0000000..cfd284b Binary files /dev/null and b/data/img/interface/keyCursor.png differ diff --git a/data/img/interface/keyCursor1.png b/data/img/interface/keyCursor1.png deleted file mode 100644 index bbae52e..0000000 Binary files a/data/img/interface/keyCursor1.png and /dev/null differ diff --git a/data/img/interface/keyCursor2.png b/data/img/interface/keyCursor2.png deleted file mode 100644 index 7f205dc..0000000 Binary files a/data/img/interface/keyCursor2.png and /dev/null differ diff --git a/data/img/interface/keyCursor3.png b/data/img/interface/keyCursor3.png deleted file mode 100644 index cb1fe3e..0000000 Binary files a/data/img/interface/keyCursor3.png and /dev/null differ diff --git a/data/img/interface/lineConverterCursor.png b/data/img/interface/lineConverterCursor.png new file mode 100644 index 0000000..9e85a2d Binary files /dev/null and b/data/img/interface/lineConverterCursor.png differ diff --git a/data/img/interface/lineConverterCursor1.png b/data/img/interface/lineConverterCursor1.png deleted file mode 100644 index a106129..0000000 Binary files a/data/img/interface/lineConverterCursor1.png and /dev/null differ diff --git a/data/img/interface/lineConverterCursor2.png b/data/img/interface/lineConverterCursor2.png deleted file mode 100644 index c06da0a..0000000 Binary files a/data/img/interface/lineConverterCursor2.png and /dev/null differ diff --git a/data/img/interface/lineConverterCursor3.png b/data/img/interface/lineConverterCursor3.png deleted file mode 100644 index 86c8c46..0000000 Binary files a/data/img/interface/lineConverterCursor3.png and /dev/null differ diff --git a/src/button.rb b/src/button.rb new file mode 100644 index 0000000..8425948 --- /dev/null +++ b/src/button.rb @@ -0,0 +1,19 @@ +require 'minigl' + +class Button < MiniGL::Button + def initialize(x, y, text, back = false, &action) + super(x: x, y: y, img: :interface_button) + @_text = text + @action = lambda do |_| + action&.call + Game.play_sound(back ? :backButtonClick : :buttonClick) + end + @text_helper = MiniGL::TextHelper.new(Game.font) + end + + def draw + super + + @text_helper.write_line(@_text, @text_x, @text_y - Game.font.height / 2, :center, 0xffffff, 255, :border, 0x006666, 2, 127) + end +end diff --git a/src/constants.rb b/src/constants.rb new file mode 100644 index 0000000..2ee4d59 --- /dev/null +++ b/src/constants.rb @@ -0,0 +1,2 @@ +SCREEN_WIDTH = 800 +SCREEN_HEIGHT = 600 diff --git a/src/game.rb b/src/game.rb new file mode 100644 index 0000000..b922d69 --- /dev/null +++ b/src/game.rb @@ -0,0 +1,33 @@ +require_relative 'menu' + +class Game + class << self + attr_reader :font + + def initialize + @music_volume = 10 + @sound_volume = 10 + @font = Res.font(:arialRounded, 24) + @controller = Menu.new + end + + def play_song(id) + song = Res.song(id) + Gosu::Song.current_song&.stop unless Gosu::Song.current_song == song + song.volume = @music_volume * 0.1 + song.play(true) + end + + def play_sound(id) + Res.sound(id).play(@sound_volume * 0.1) + end + + def update + @controller.update + end + + def draw + @controller.draw + end + end +end diff --git a/src/main.rb b/src/main.rb new file mode 100644 index 0000000..0c8f60a --- /dev/null +++ b/src/main.rb @@ -0,0 +1,30 @@ +require 'minigl' +require_relative 'constants' +require_relative 'game' + +include MiniGL + +class Window < GameWindow + def initialize + super(SCREEN_WIDTH, SCREEN_HEIGHT, false) + self.caption = 'Spheres' + Res.prefix = File.expand_path(__FILE__).split('/')[0..-3].join('/') + '/data' + Game.initialize + end + + def needs_cursor? + true + end + + def update + KB.update + Mouse.update + Game.update + end + + def draw + Game.draw + end +end + +Window.new.show diff --git a/src/menu.rb b/src/menu.rb new file mode 100644 index 0000000..ee3bd94 --- /dev/null +++ b/src/menu.rb @@ -0,0 +1,31 @@ +require_relative 'button' + +class Menu + def initialize + @bg = Res.img(:other_bgStart) + + @buttons = { + main: [ + Button.new(305, 240, 'Play'), + Button.new(305, 290, 'Instructions'), + Button.new(305, 340, 'Options'), + Button.new(305, 390, 'High Scores'), + Button.new(305, 480, 'Exit') do + exit + end, + ] + } + + @state = :main + Game.play_song(:spheresTheme) + end + + def update + @buttons[@state]&.each(&:update) + end + + def draw + @bg.draw(0, 0, 0) + @buttons[@state]&.each(&:draw) + end +end