Skip to content

Commit

Permalink
Menu with useless buttons. Spritesheets.
Browse files Browse the repository at this point in the history
  • Loading branch information
victords committed Mar 26, 2022
1 parent 39bfb98 commit c70492c
Show file tree
Hide file tree
Showing 21 changed files with 139 additions and 0 deletions.
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0.1
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source 'https://rubygems.org'

ruby '~> 3.0'

gem 'minigl', '~> 2.3.9'
18 changes: 18 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
Binary file added data/img/interface/button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed data/img/interface/buttonClicked.png
Binary file not shown.
Binary file removed data/img/interface/buttonDefault.png
Binary file not shown.
Binary file removed data/img/interface/buttonHover.png
Binary file not shown.
Binary file modified data/img/interface/confirmDialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/img/interface/keyCursor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed data/img/interface/keyCursor1.png
Binary file not shown.
Binary file removed data/img/interface/keyCursor2.png
Binary file not shown.
Binary file removed data/img/interface/keyCursor3.png
Binary file not shown.
Binary file added data/img/interface/lineConverterCursor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed data/img/interface/lineConverterCursor1.png
Binary file not shown.
Binary file removed data/img/interface/lineConverterCursor2.png
Binary file not shown.
Binary file removed data/img/interface/lineConverterCursor3.png
Binary file not shown.
19 changes: 19 additions & 0 deletions src/button.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions src/constants.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
33 changes: 33 additions & 0 deletions src/game.rb
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions src/main.rb
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions src/menu.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c70492c

Please sign in to comment.