├── se ├── move.ogg ├── accept.ogg └── buzzer.ogg ├── database └── objects.txt ├── music └── background.ogg ├── graphics ├── background.png ├── charasets │ ├── npc.png │ ├── Thumbs.db │ ├── hero.png │ ├── npc2.png │ └── npc3.png ├── gosu-splash.png └── tilesets │ ├── Thumbs.db │ └── tileset.png ├── events ├── event1.txt ├── event2.txt └── event3.txt ├── Temp.rb ├── Window_Gold.rb ├── Timer.rb ├── Window_Steps.rb ├── Scene_Item.rb ├── Window_Location.rb ├── maps ├── Test Map2.txt-2 ├── Test Map.txt-2 ├── Test Map.txt └── Test Map2.txt ├── FPSCounter.rb ├── Window.rb ├── Main.rb ├── Hero.rb ├── Window_Command.rb ├── Window_PlayTime.rb ├── Initial.rb ├── Database.rb ├── Scene_Intro.rb ├── readme.txt ├── Window_Item.rb ├── Window_MenuStatus.rb ├── Effects.rb ├── Scene_Title.rb ├── Party.rb ├── Window_Selectable.rb ├── Map.rb ├── Scene_Menu.rb ├── Tileset.rb ├── Scene_Map.rb ├── Character_Hero.rb ├── Window_Base.rb └── Character.rb /se/move.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dahrkael/RPG-Template-for-Ruby-Gosu/HEAD/se/move.ogg -------------------------------------------------------------------------------- /database/objects.txt: -------------------------------------------------------------------------------- 1 | 001;Potion;Recover 100 HP 2 | 002;Key;Open a door 3 | 003;Rock;A normal rock -------------------------------------------------------------------------------- /se/accept.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dahrkael/RPG-Template-for-Ruby-Gosu/HEAD/se/accept.ogg -------------------------------------------------------------------------------- /se/buzzer.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dahrkael/RPG-Template-for-Ruby-Gosu/HEAD/se/buzzer.ogg -------------------------------------------------------------------------------- /music/background.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dahrkael/RPG-Template-for-Ruby-Gosu/HEAD/music/background.ogg -------------------------------------------------------------------------------- /graphics/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dahrkael/RPG-Template-for-Ruby-Gosu/HEAD/graphics/background.png -------------------------------------------------------------------------------- /graphics/charasets/npc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dahrkael/RPG-Template-for-Ruby-Gosu/HEAD/graphics/charasets/npc.png -------------------------------------------------------------------------------- /graphics/gosu-splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dahrkael/RPG-Template-for-Ruby-Gosu/HEAD/graphics/gosu-splash.png -------------------------------------------------------------------------------- /graphics/charasets/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dahrkael/RPG-Template-for-Ruby-Gosu/HEAD/graphics/charasets/Thumbs.db -------------------------------------------------------------------------------- /graphics/charasets/hero.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dahrkael/RPG-Template-for-Ruby-Gosu/HEAD/graphics/charasets/hero.png -------------------------------------------------------------------------------- /graphics/charasets/npc2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dahrkael/RPG-Template-for-Ruby-Gosu/HEAD/graphics/charasets/npc2.png -------------------------------------------------------------------------------- /graphics/charasets/npc3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dahrkael/RPG-Template-for-Ruby-Gosu/HEAD/graphics/charasets/npc3.png -------------------------------------------------------------------------------- /graphics/tilesets/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dahrkael/RPG-Template-for-Ruby-Gosu/HEAD/graphics/tilesets/Thumbs.db -------------------------------------------------------------------------------- /graphics/tilesets/tileset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Dahrkael/RPG-Template-for-Ruby-Gosu/HEAD/graphics/tilesets/tileset.png -------------------------------------------------------------------------------- /events/event1.txt: -------------------------------------------------------------------------------- 1 | First line is ignored --- To use correctly X and Y use tiles, not pixels, for example x:5 not x:176 2 | x:4 3 | y:4 4 | filename:npc2 5 | movement:static 6 | face:down 7 | solid:true 8 | route: 9 | commands: -------------------------------------------------------------------------------- /events/event2.txt: -------------------------------------------------------------------------------- 1 | First line is ignored --- To use correctly X and Y use tiles, not pixels, for example x:5 not x:176 2 | x:10 3 | y:10 4 | filename:npc3 5 | movement:static 6 | face:left 7 | solid:true 8 | route: 9 | commands: -------------------------------------------------------------------------------- /events/event3.txt: -------------------------------------------------------------------------------- 1 | First line is ignored --- To use correctly X and Y use tiles, not pixels, for example x:5 not x:176 2 | x:6 3 | y:6 4 | filename:npc 5 | movement:random 6 | face:down 7 | solid:false 8 | route: 9 | commands: -------------------------------------------------------------------------------- /Temp.rb: -------------------------------------------------------------------------------- 1 | 2 | 3 | class Temp 4 | attr_accessor :actual_map 5 | attr_accessor :actual_map_tileset 6 | attr_accessor :actual_position 7 | def initialize 8 | @actual_map = nil 9 | @actual_map_tileset = nil 10 | @actual_position = nil 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /Window_Gold.rb: -------------------------------------------------------------------------------- 1 | 2 | 3 | class Window_Gold < Window_Base 4 | 5 | def initialize(window, x, y, z) 6 | super(window, x, y, 160, 70, 10) 7 | @font = Font.new(window ,@window.initial.font_name, @window.initial.font_size) 8 | colors 9 | end 10 | 11 | def update 12 | self.draw 13 | end 14 | 15 | def draw 16 | self.drawBox(@x, @y, @width, @height, @z) 17 | @font.draw("Money:", self.x+20, self.y+10, @z, 1, 1, @blue_text) 18 | draw_gold(@font, self.x+ @width - 15, self.y + 50) 19 | end 20 | end 21 | 22 | -------------------------------------------------------------------------------- /Timer.rb: -------------------------------------------------------------------------------- 1 | 2 | 3 | class Timer 4 | attr_reader :hours 5 | attr_reader :minutes 6 | attr_reader :seconds 7 | 8 | def initialize(window) 9 | @hours = 0 10 | @minutes = 0 11 | @seconds = 0 12 | @last_time = Gosu::milliseconds() 13 | end 14 | 15 | def update 16 | if (Gosu::milliseconds - @last_time) / 1000 == 1 17 | @seconds += 1 18 | @last_time = Gosu::milliseconds() 19 | end 20 | if @seconds > 59 21 | @seconds = 0 22 | @minutes += 1 23 | end 24 | if @minutes > 59 25 | @hours += 1 26 | @minutes = 0 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /Window_Steps.rb: -------------------------------------------------------------------------------- 1 | 2 | 3 | class Window_Steps < Window_Base 4 | 5 | def initialize(window, x, y, z) 6 | super(window, x, y, 160, 70, 10) 7 | @window = window 8 | @font = Font.new(window ,@window.initial.font_name, @window.initial.font_size) 9 | colors 10 | end 11 | 12 | def update 13 | self.draw 14 | end 15 | 16 | def draw 17 | self.drawBox(@x, @y, @width, @height, @z) 18 | @font.draw("Steps:", self.x+20, self.y+10, @z, 1, 1, @blue_text) 19 | @font.draw_rel($party.steps.to_s, self.x + @width - 15, self.y + 50, @z, 1.0, 0.5) 20 | end 21 | end 22 | 23 | -------------------------------------------------------------------------------- /Scene_Item.rb: -------------------------------------------------------------------------------- 1 | 2 | 3 | class Scene_Item 4 | def initialize(window) 5 | @window = window 6 | @item_window = Window_Item.new(window) 7 | @item_window.x = 240 8 | @item_window.active = true 9 | end 10 | 11 | def button_down(id) 12 | if @item_window.active == true 13 | @item_window.button_down(id) 14 | if id == Button::KbEscape 15 | @window.scene = Scene_Menu.new(@window) 16 | end 17 | if id == Button::KbReturn 18 | #case @item_window.index 19 | #end 20 | end 21 | end 22 | end 23 | 24 | def update 25 | @item_window.update 26 | self.draw 27 | end 28 | 29 | def draw 30 | end 31 | end -------------------------------------------------------------------------------- /Window_Location.rb: -------------------------------------------------------------------------------- 1 | 2 | 3 | class Window_Location < Window_Base 4 | 5 | def initialize(window, x, y, z) 6 | super(window, x, y, 160, 70, 10) 7 | @window = window 8 | @font = Font.new(window ,@window.initial.font_name, @window.initial.font_size) 9 | @name = $temp.actual_map.gsub(".txt","") 10 | @name.gsub!("maps/","") 11 | colors 12 | end 13 | 14 | def update 15 | self.draw 16 | end 17 | 18 | def draw 19 | self.drawBox(@x, @y, @width, @height, @z) 20 | @font.draw("Location:", self.x+20, self.y+10, @z, 1, 1, @blue_text) 21 | @font.draw_rel(@name, self.x + @width - 15, self.y + 50, @z, 1.0, 0.5) 22 | end 23 | end 24 | 25 | -------------------------------------------------------------------------------- /maps/Test Map2.txt-2: -------------------------------------------------------------------------------- 1 | ################1###################1### 2 | #####1##############################1### 3 | ##############56####################1### 4 | ###7################################1### 5 | ###f#######1#########################1### 6 | ####################################1### 7 | ##############%#####################1### 8 | #####1##############################1### 9 | ####################################1### 10 | ############1#######################1### 11 | ####################################1### 12 | ####################################1### 13 | ###########1########################1### 14 | ####1###############################1### 15 | ####################################1### -------------------------------------------------------------------------------- /maps/Test Map.txt-2: -------------------------------------------------------------------------------- 1 | 2 | ################1###################1### 3 | #####1##############################1### 4 | ##############56####################1### 5 | ###7################################1### 6 | ###f#######1#########################1### 7 | ####################################1### 8 | ##############%#####################1### 9 | #####1##############################1### 10 | ####################################1### 11 | ############1#######################1### 12 | ####################################1### 13 | ####################################1### 14 | ###########1########################1### 15 | ####1###############################1### 16 | ####################################1### -------------------------------------------------------------------------------- /FPSCounter.rb: -------------------------------------------------------------------------------- 1 | 2 | # FPS Counter based in fguillens fpscounter 3 | class FPSCounter 4 | 5 | attr_accessor :show_fps 6 | attr_reader :fps 7 | 8 | def initialize(window) 9 | @font = Font.new(window,window.initial.font_name, window.initial.font_size) 10 | @frames_counter = 0 11 | @milliseconds_before = Gosu::milliseconds 12 | @show_fps = false 13 | @fps = 0 14 | end 15 | 16 | def update 17 | @frames_counter += 1 18 | if Gosu::milliseconds - @milliseconds_before >= 1000 19 | @fps = @frames_counter.to_f / ((Gosu::milliseconds - @milliseconds_before) / 1000.0) 20 | @frames_counter = 0 21 | @milliseconds_before = Gosu::milliseconds 22 | end 23 | @font.draw("FPS: "+@fps.to_s, 0, 0, 20) if @show_fps 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /Window.rb: -------------------------------------------------------------------------------- 1 | include Gosu 2 | class Game_Window < Window 3 | attr_reader :screen_x 4 | attr_reader :screen_y 5 | attr_reader :timer 6 | attr_reader :initial 7 | attr_accessor :scene 8 | def initialize 9 | super(640, 480, false) 10 | self.caption = "RPG Template using Gosu" 11 | @initial = Initial_Settings.new 12 | @fpscounter = FPSCounter.new(self) 13 | @timer = Timer.new(self) 14 | @scene = Scene_Intro.new(self) 15 | end 16 | 17 | def button_down(id) 18 | @scene.button_down(id) 19 | if id == Button::KbF 20 | @fpscounter.show_fps = !@fpscounter.show_fps 21 | end 22 | end 23 | 24 | 25 | def update 26 | @fpscounter.update 27 | @timer.update 28 | @scene.update 29 | end 30 | 31 | def draw 32 | end 33 | 34 | end 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /maps/Test Map.txt: -------------------------------------------------------------------------------- 1 | event1;event2;event3 2 | 0000000000000000000000000000000000000000 3 | 0000000000000000000000000000000000000000 4 | 0000000000000000000000000000000000000000 5 | 0000000000000000000000000000000000000000 6 | 0000000000000000000000000000000000000000 7 | 0000000000000000000000000000000000000000 8 | 0000000000000000000000000000000000000000 9 | 0000000000000000000000000000000000000000 10 | 0000000000000000000000000000000000000000 11 | 0000000000000000000000000000000000000000 12 | 0000000000000000000000000000000000000000 13 | 0000000000000000000000000000000000000000 14 | 0000000000000000000000000000000000000000 15 | 0000000000000000000000000000000000000000 16 | 0000000000000000000000000000000000000000 17 | 0000000000000000000000000000000000000000 18 | 0000000000000000000000000000000000000000 19 | 0000000000000000000000000000000000000000 -------------------------------------------------------------------------------- /maps/Test Map2.txt: -------------------------------------------------------------------------------- 1 | event1;event2;event3 2 | 1111111111111111111111111111111111111111 3 | 1111111111111111111111111111111111111111 4 | 1111111111111111111111111111111111111111 5 | 1111111111111111111111111111111111111111 6 | 1111111111111111111111111111111111111111 7 | 1111111111111111111111111111111111111111 8 | 1111111111111111111111111111111111111111 9 | 1111111111111111111111111111111111111111 10 | 1111111111111111111111111111111111111111 11 | 1111111111111111111111111111111111111111 12 | 1111111111111111111111111111111111111111 13 | 1111111111111111111111111111111111111111 14 | 1111111111111111111111111111111111111111 15 | 1111111111111111111111111111111111111111 16 | 1111111111111111111111111111111111111111 17 | 1111111111111111111111111111111111111111 18 | 1111111111111111111111111111111111111111 19 | 1111111111111111111111111111111111111111 -------------------------------------------------------------------------------- /Main.rb: -------------------------------------------------------------------------------- 1 | begin 2 | # In case you use Gosu via rubygems. 3 | require 'rubygems' 4 | rescue LoadError 5 | # In case you don't. 6 | end 7 | begin 8 | require 'lib/gosu' 9 | rescue LoadError 10 | require 'gosu' 11 | end 12 | 13 | require 'FPSCounter.rb' 14 | require 'Timer.rb' 15 | require 'Database.rb' 16 | require 'Initial.rb' 17 | require 'Temp.rb' 18 | require 'Hero.rb' 19 | require 'Party.rb' 20 | require 'Effects.rb' 21 | require 'Window.rb' 22 | require 'Character.rb' 23 | require 'Character_Hero.rb' 24 | require 'Tileset.rb' 25 | require 'Map.rb' 26 | require 'Window_Base.rb' 27 | require 'Window_Selectable' 28 | require 'Window_Command.rb' 29 | require 'Window_Item.rb' 30 | require 'Window_MenuStatus.rb' 31 | require 'Window_Gold.rb' 32 | require 'Window_Steps.rb' 33 | require 'Window_PlayTime.rb' 34 | require 'Window_Location.rb' 35 | require 'Scene_Intro.rb' 36 | require 'Scene_Title.rb' 37 | require 'Scene_Map.rb' 38 | require 'Scene_Menu.rb' 39 | require 'Scene_Item.rb' 40 | 41 | 42 | 43 | 44 | include Gosu 45 | 46 | @window = Game_Window.new 47 | @window.show -------------------------------------------------------------------------------- /Hero.rb: -------------------------------------------------------------------------------- 1 | class Hero 2 | attr_accessor :name 3 | attr_accessor :job 4 | attr_accessor :chara_filename 5 | attr_accessor :chara 6 | attr_accessor :LVL 7 | attr_accessor :HP 8 | attr_accessor :MAX_HP 9 | attr_accessor :MP 10 | attr_accessor :MAX_MP 11 | attr_accessor :attack 12 | attr_accessor :defense 13 | attr_accessor :m_attack 14 | attr_accessor :m_defense 15 | attr_accessor :state 16 | attr_accessor :EXP 17 | attr_accessor :NXT_EXP 18 | 19 | def initialize(name, job, filename, max_hp=100, max_mp=50, attack=10, defense=10, m_attack=10, m_defense=10) 20 | @name = name 21 | @job = job 22 | @chara_filename = filename 23 | @chara = nil 24 | @LVL = 1 25 | @MAX_HP = max_hp 26 | @HP = @MAX_HP 27 | @MAX_MP = max_mp 28 | @MP = @MAX_MP 29 | @attack = attack 30 | @defense = defense 31 | @m_attack = m_attack 32 | @m_defense = m_defense 33 | @state = "Normal" 34 | @EXP = 0 35 | @NXT_EXP = 100 36 | end 37 | 38 | def up_level 39 | if @EXP >= @NXT_EXP 40 | @LVL += 1 41 | @EXP = 0 42 | @NXT_EXP *= 1.1 43 | @NXT_EXP.to_i 44 | end 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /Window_Command.rb: -------------------------------------------------------------------------------- 1 | 2 | class Window_Command < Window_Selectable 3 | attr_accessor :index 4 | 5 | def initialize(window,width=192, options=[], index=0) 6 | super(window, width, options.size * 32, 32, index) 7 | @window = window 8 | @commands = options 9 | @font = Font.new(window, @window.initial.font_name, @window.initial.font_size) 10 | end 11 | 12 | def draw_commands 13 | spacing = 32 14 | for i in 0...@commands.size 15 | position = spacing * i+1 16 | adjust = @font.text_width(@commands[i], 1) 17 | @font.draw(@commands[i], @x+((@width/2)-(adjust/2)), @y+8 + position, @z+1) 18 | end 19 | end 20 | 21 | def button_down(id) 22 | if id == Button::KbDown and not @index == @commands.size - 1 23 | Sample.new(@window, @window.initial.move_se).play 24 | @index += 1 25 | end 26 | if id == Button::KbUp and not @index == 0 27 | Sample.new(@window, @window.initial.move_se).play 28 | @index -= 1 29 | end 30 | end 31 | 32 | def update 33 | super 34 | self.draw 35 | end 36 | 37 | def draw 38 | super 39 | self.draw_commands 40 | self.draw_index if @active == true 41 | end 42 | 43 | end 44 | -------------------------------------------------------------------------------- /Window_PlayTime.rb: -------------------------------------------------------------------------------- 1 | 2 | 3 | class Window_PlayTime < Window_Base 4 | 5 | def initialize(window, x, y, z) 6 | super(window, x, y, 160, 70, 10) 7 | @window = window 8 | @font = Font.new(window ,@window.initial.font_name, @window.initial.font_size) 9 | colors 10 | end 11 | 12 | def adapt_time 13 | if @window.timer.hours < 10 14 | @hours_display = "0" + @window.timer.hours.to_s 15 | else 16 | @hours_display = @window.timer.hours.to_s 17 | end 18 | if @window.timer.minutes < 10 19 | @minutes_display = "0" + @window.timer.minutes.to_s 20 | else 21 | @minutes_display = @window.timer.minutes.to_s 22 | end 23 | if @window.timer.seconds < 10 24 | @seconds_display = "0" + @window.timer.seconds.to_s 25 | else 26 | @seconds_display = @window.timer.seconds.to_s 27 | end 28 | end 29 | 30 | def update 31 | adapt_time 32 | self.draw 33 | end 34 | 35 | def draw 36 | self.drawBox(@x, @y, @width, @height, @z) 37 | @font.draw("Play Time:", self.x+20, self.y+10, @z, 1, 1, @blue_text) 38 | @font.draw_rel(@hours_display+":"+@minutes_display+":"+@seconds_display, self.x + @width - 15, self.y + 50, @z, 1.0, 0.5) 39 | end 40 | end 41 | 42 | -------------------------------------------------------------------------------- /Initial.rb: -------------------------------------------------------------------------------- 1 | class Initial_Settings 2 | attr_reader :font_name 3 | attr_reader :font_size 4 | attr_reader :title_background_picture 5 | attr_reader :title_background_music 6 | attr_reader :title_commands 7 | attr_reader :move_se 8 | attr_reader :accept_se 9 | attr_reader :buzzer_se 10 | attr_reader :player_start 11 | attr_reader :map_start 12 | attr_reader :map_tileset_start 13 | attr_reader :party 14 | attr_reader :gold 15 | 16 | def initialize 17 | @font_size = 18 18 | @font_name = "Verdana" 19 | @title_background_picture = "graphics/background.png" 20 | @title_background_music = "music/background.ogg" 21 | @title_commands = ["New Game", "Load Game", "Exit Game"] 22 | @move_se = "se/move.ogg" 23 | @accept_se = "se/accept.ogg" 24 | @buzzer_se = "se/buzzer.ogg" 25 | @player_start = [7, 3] 26 | @map_start = "maps/Test Map.txt" 27 | @map_tileset_start = "graphics/tilesets/tileset.png" 28 | @party = [Hero.new("Ryan", "Fighter", "graphics/charasets/hero.png"), 29 | Hero.new("Mr. Unnamed", "Mage", "graphics/charasets/npc3.png"), 30 | Hero.new("Sally", "NekoGirl", "graphics/charasets/npc.png"), 31 | Hero.new("Little George", "Killer", "graphics/charasets/npc2.png")] 32 | @gold = 100 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /Database.rb: -------------------------------------------------------------------------------- 1 | 2 | module Database 3 | 4 | def self.load_items 5 | $data_items = Array.new(1) 6 | items = File.readlines("database/objects.txt").map { |line| line.chomp } 7 | #@items = [] 8 | for i in 0...items.size 9 | $data_items.push(items[i].split(';')) 10 | end 11 | end 12 | 13 | def self.load_npcs(npc) 14 | npc_load = File.readlines("events/"+npc+".txt").map { |line| line.chomp } 15 | 16 | x = npc_load[1] 17 | x.gsub!('x:', '') 18 | 19 | y = npc_load[2] 20 | y.gsub!('y:', '') 21 | 22 | filename = npc_load[3] 23 | filename.gsub!('filename:', '') 24 | 25 | movement = npc_load[4] 26 | movement.gsub!('movement:', '') 27 | movement = eval(':'+movement) 28 | 29 | face = npc_load[5] 30 | face.gsub!('face:', '') 31 | face = eval(':'+face) 32 | 33 | solid = npc_load[6] 34 | solid.gsub!('solid:', '') 35 | solid = eval(solid) 36 | 37 | route = npc_load[7] 38 | route.gsub!('route:', '') 39 | 40 | commands = [] 41 | for i in 0...npc_load.size 42 | next if (0...8).include?(i) 43 | commands.push(npc_load[i]) 44 | end 45 | commands.to_s.gsub!('commands:', '') 46 | return x.to_i,y.to_i,filename,movement,face,solid,route,commands 47 | end 48 | 49 | end -------------------------------------------------------------------------------- /Scene_Intro.rb: -------------------------------------------------------------------------------- 1 | include Gosu 2 | 3 | class Scene_Intro 4 | def initialize(window) 5 | #@font = Font.new(window, "Verdana", 18) 6 | @window = window 7 | @background = Image.new(window, "graphics/gosu-splash.png", true) 8 | @time = 0 9 | @fading = :in 10 | @fade_time = 255 11 | @color = Color.new(@fade_time, 0, 0 ,0) 12 | end 13 | 14 | def button_down(id) 15 | end 16 | 17 | def update 18 | @color = Color.new(@fade_time, 0, 0 ,0) 19 | case @fading 20 | 21 | when :in 22 | if @fade_time <= 0 23 | @fading = :wait 24 | else 25 | @fade_time -= 15 # 15 is cool 26 | end 27 | when :wait 28 | @time += 1 29 | if @time >= 200 30 | @fading = :out 31 | end 32 | when :out 33 | if @fade_time >= 255 34 | @window.scene = Transition.new(@window, Scene_Title.new(@window), :in, false)#Scene_Title.new(@window) 35 | else 36 | @fade_time += 15 # 15 is cool 37 | end 38 | end 39 | 40 | self.draw 41 | end 42 | def draw 43 | @background.draw(0,0,0) 44 | @window.draw_quad(0, 0, @color, 640, 0, @color, 0, 480, @color, 640, 480, @color, 500) 45 | #@font.draw("fade time: "+@fade_time.to_s, 0, 0, 600) 46 | #@font.draw("wait time: "+@time.to_s, 0, 30, 600) 47 | #@font.draw(@fading.to_s, 0, 60, 600) 48 | end 49 | 50 | end 51 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | 2 | ##### RPG Template for Ruby/Gosu ##### 3 | 4 | Alpha version, so dont expect too much =) 5 | 6 | This is a template to make you own jRPG easily! 7 | You dont need to worry about the basic things like maps engine, menus, etc 8 | All you need is edit the options, design your own maps, heros, npc, monster, items, etc and click play! 9 | 10 | All the code is structured in the best way i can to give more flexibility to make edits in the code. 11 | 12 | Some features for now are: 13 | 14 | -Pixel movement 15 | -Collisions (hero with npcs and objects, and npcs with objects and the hero) 16 | -Cool menu (H) 17 | -Scenes based system to make your own menus 18 | -Windows structured to make your own windows easily 19 | -Initial settings to make things easier 20 | -etc 21 | 22 | -- Controls (for now): 23 | 24 | ---- Return (Enter): Choose options in the menus. 25 | ---- Arrows: Move the hero in the map and move the index in the menus. 26 | ---- Escape: Go back to the map from the menu, go back from the menu status to the options. 27 | 28 | 29 | All improves/fixes/adviced/etc are welcome! 30 | 31 | you can use the bug tracker: 32 | http://github.com/Dahrkael/RPG-Template-for-Ruby-Gosu/issues 33 | 34 | or contact me at gosu forum =) 35 | 36 | 37 | ##### RPG Template for Ruby/Gosu ##### -------------------------------------------------------------------------------- /Window_Item.rb: -------------------------------------------------------------------------------- 1 | 2 | 3 | class Window_Item < Window_Selectable 4 | def initialize(window) 5 | super(window,400, 473, 32, 0) 6 | @window = window 7 | @font = Font.new(window,@window.initial.font_name, @window.initial.font_size) 8 | load_items 9 | end 10 | 11 | def button_down(id) 12 | if id == Button::KbDown and not @index == @item_max - 1 13 | Sample.new(@window, @window.initial.move_se).play 14 | @index += 1 15 | end 16 | if id == Button::KbUp and not @index == 0 17 | Sample.new(@window, @window.initial.move_se).play 18 | @index -= 1 19 | end 20 | end 21 | 22 | def load_items 23 | @data = [] 24 | for i in 1...$data_items.size 25 | if $party.item_number($data_items[i][0].to_i) > 0 26 | @data.push([$data_items[i][0], $data_items[i][1]]) 27 | end 28 | end 29 | 30 | end 31 | 32 | def draw_items 33 | if @data.size != 0 34 | @item_max = @data.size 35 | for i in 0...@item_max 36 | y = @y + (32 * i) + 10 37 | @font.draw(@data[i][1].to_s+" : "+$party.item_number(@data[i][0].to_i).to_s, @x + 20, y, @z + 5, 1, 1, @white) 38 | end 39 | else 40 | @item_max = 1 41 | end 42 | 43 | end 44 | 45 | def update 46 | super 47 | draw_items 48 | self.draw 49 | end 50 | 51 | def draw 52 | super 53 | draw_index if self.active == true 54 | end 55 | 56 | end 57 | -------------------------------------------------------------------------------- /Window_MenuStatus.rb: -------------------------------------------------------------------------------- 1 | class Window_MenuStatus < Window_Selectable 2 | 3 | def initialize(window, index=0) 4 | super(window,482, 473, 118, 0) 5 | @window = window 6 | @font = Font.new(window,@window.initial.font_name, @window.initial.font_size) 7 | @item_max = $party.main_party.size - 1 8 | end 9 | 10 | def draw_characters 11 | for i in 0...$party.main_party.size 12 | x = self.x + 64 13 | y = i * 120 14 | draw_hero_graphic(i, x - 40, y + 50) 15 | draw_hero_name(i, @font, x - 40, y + 20) 16 | draw_hero_level(i, @font, x + 10, y + 60) 17 | draw_hero_state(i, @font, x + 100, y + 60) 18 | draw_hero_class(i, @font, x + 100, y + 20) 19 | draw_hero_hp(i, @font, x + 250, y + 20) 20 | draw_hero_mp(i, @font, x + 250, y + 60) 21 | draw_hero_exp(i, @font, x + 10, y + 90) 22 | next if i == 0 23 | @window.draw_line(x, y, 0xffffffff, x+400, y, 0xffffffff, @z) 24 | end 25 | end 26 | 27 | def button_down(id) 28 | if id == Button::KbDown and not @index == @item_max 29 | Sample.new(@window, @window.initial.move_se).play 30 | @index += 1 31 | end 32 | if id == Button::KbUp and not @index == 0 33 | Sample.new(@window, @window.initial.move_se).play 34 | @index -= 1 35 | end 36 | end 37 | 38 | def update 39 | super 40 | draw_characters 41 | end 42 | def draw 43 | super 44 | draw_index if self.active == true 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /Effects.rb: -------------------------------------------------------------------------------- 1 | 2 | include Gosu 3 | 4 | class Transition 5 | attr_reader :screen_x 6 | attr_reader :screen_y 7 | attr_reader :mapa 8 | def initialize(window, scene, type, map) 9 | @window = window 10 | @next_scene = scene 11 | @map = map 12 | @time = 0 13 | @fading = type 14 | @fade_time = 255 if @fading == :in 15 | @fade_time = 0 if @fading == :out 16 | @color = Color.new(@fade_time, 0, 0 ,0) 17 | 18 | if @map == true 19 | @mapa = @next_scene.mapa 20 | @screen_x = [[@next_scene.hero.x - 320, 0].max, @next_scene.mapa.width * 32 - 640].min 21 | @screen_y = [[@next_scene.hero.y - 240, 0].max, @next_scene.mapa.height * 32 - 480].min 22 | end 23 | end 24 | 25 | def button_down(id) 26 | end 27 | 28 | def solid_event_infront?(character) 29 | end 30 | 31 | def update 32 | @color = Color.new(@fade_time, 0, 0 ,0) 33 | case @fading 34 | 35 | when :in 36 | if @fade_time <= 0 37 | @window.scene = @next_scene 38 | else 39 | @fade_time -= 15 # 15 is cool 40 | end 41 | when :out 42 | if @fade_time >= 255 43 | @window.scene = @next_scene 44 | else 45 | @fade_time += 15 # 15 is cool 46 | end 47 | end 48 | 49 | self.draw 50 | end 51 | 52 | def draw 53 | @next_scene.update 54 | @window.draw_quad(0, 0, @color, 640, 0, @color, 0, 480, @color, 640, 480, @color, 500) 55 | end 56 | 57 | end 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /Scene_Title.rb: -------------------------------------------------------------------------------- 1 | 2 | 3 | class Scene_Title 4 | def initialize(window) 5 | @window = window 6 | @background = Image.new(window, @window.initial.title_background_picture, true) 7 | @command_window = Window_Command.new(window, 192, @window.initial.title_commands, 0) 8 | @command_window.x = @background.width/2 - 192/2 9 | @command_window.y = 360 10 | @command_window.active = true 11 | @bgm = Song.new(window, @window.initial.title_background_music) 12 | @bgm.play(true) 13 | end 14 | def button_down(id) 15 | if @command_window.active == true 16 | @command_window.button_down(id) 17 | if id == Button::KbReturn 18 | case @command_window.index 19 | when 0 # New Game 20 | @bgm.stop 21 | Sample.new(@window, @window.initial.accept_se).play 22 | $temp = Temp.new 23 | $party = Party.new(@window) 24 | Database.load_items 25 | $party.setup_initial_party 26 | @window.scene = Transition.new(@window, Scene_Map.new(@window, @window.initial.map_start, @window.initial.map_tileset_start, @window.initial.player_start), :in, true) 27 | when 1 # Load Game 28 | Sample.new(@window, @window.initial.buzzer_se).play 29 | # load game 30 | when 2 # Exit Game 31 | Sample.new(@window, @window.initial.accept_se).play 32 | @window.close 33 | end 34 | end 35 | end 36 | end 37 | 38 | def update 39 | @command_window.update 40 | self.draw 41 | end 42 | def draw 43 | @background.draw(0,0,0) 44 | end 45 | 46 | end 47 | -------------------------------------------------------------------------------- /Party.rb: -------------------------------------------------------------------------------- 1 | class Party 2 | attr_accessor :main_party 3 | attr_accessor :reserve_party 4 | attr_accessor :steps 5 | attr_accessor :gold 6 | attr_reader :items 7 | def initialize(window) 8 | @window = window 9 | @main_party = [] 10 | @reserve_party = [] 11 | @gold = @window.initial.gold 12 | @steps = 0 13 | @items = {} 14 | @weapons = {} 15 | @armors = {} 16 | end 17 | 18 | def setup_initial_party 19 | for i in @window.initial.party 20 | @main_party.push(i) 21 | i.chara = Image.load_tiles(@window, i.chara_filename, 32, 48, false) 22 | end 23 | end 24 | 25 | def add_hero(name, job, filename) 26 | if @main_party.size < 4 27 | @main_party.push(Hero.new(name, job, filename)) 28 | elsif @main_party >= 4 29 | @reserve_party.push(Hero.new(name, job, filename)) 30 | end 31 | end 32 | 33 | def move_hero(from, position, where) 34 | where.push(from[position]) 35 | from.slice!(position) 36 | end 37 | 38 | def delete_hero(from, position) 39 | from.slice!(position) 40 | end 41 | 42 | def gain_gold(n) 43 | @gold = [[@gold + n, 0].max, 9999999].min 44 | end 45 | 46 | def lose_gold(n) 47 | gain_gold(-n) 48 | end 49 | 50 | def increase_steps 51 | @steps = [@steps + 1, 9999999].min 52 | end 53 | 54 | def item_number(item_id) 55 | if @items.include?(item_id) 56 | return @items[item_id] 57 | else 58 | return 0 59 | end 60 | end 61 | 62 | def gain_item(item_id, n) 63 | @items[item_id] = [[item_number(item_id) + n, 0].max, 99].min 64 | end 65 | end 66 | -------------------------------------------------------------------------------- /Window_Selectable.rb: -------------------------------------------------------------------------------- 1 | 2 | class Window_Selectable < Window_Base 3 | attr_accessor :index 4 | 5 | def initialize(window,width, height, space, index=0) 6 | super(window, 0, 0, width, 0) 7 | @window = window 8 | @index = index 9 | @x = 0 10 | @y = 0 11 | @z = 10 12 | @width = width 13 | @height = height 14 | @space = space 15 | @cursor_x = @x 16 | @cursor_y = @y 17 | @cursor_x_plus = 3 18 | @cursor_y_plus = 4 19 | @cursor_opacity = 200 20 | @fading_type = :IN 21 | colors 22 | end 23 | 24 | def draw_index 25 | blue_border = Color.new(@cursor_opacity, 192, 224, 255) 26 | blue1 = Color.new(@cursor_opacity, 66, 68, 120) 27 | blue2 = Color.new(@cursor_opacity, 44, 45, 85) 28 | 29 | @window.draw_quad(@cursor_x + 1, @cursor_y, blue_border, @cursor_x + @width - 7, @cursor_y, blue_border, 30 | @cursor_x + 1, @cursor_y+@space, blue_border, @cursor_x + @width - 7, @cursor_y+@space, blue_border, @z) 31 | 32 | @window.draw_quad(@cursor_x + 2, @cursor_y + 1, blue2, @cursor_x + @width - 8, @cursor_y + 1, blue1, 33 | @cursor_x + 2, @cursor_y+@space-1, blue2, @cursor_x + @width - 8, @cursor_y+@space-1, blue1, @z) 34 | 35 | @cursor_opacity += 5 if @fading_type == :IN 36 | @cursor_opacity -= 5 if @fading_type == :OUT 37 | 38 | @fading_type = :IN if @cursor_opacity <= 20 39 | @fading_type = :OUT if @cursor_opacity >= 160 40 | 41 | end 42 | 43 | def update 44 | @cursor_x = @x + @cursor_x_plus 45 | @cursor_y = @y + @cursor_y_plus + @space * @index 46 | self.draw 47 | end 48 | 49 | def draw 50 | self.drawBox(@x, @y, @width, @height+(@cursor_y_plus*2), @z) 51 | end 52 | 53 | end 54 | -------------------------------------------------------------------------------- /Map.rb: -------------------------------------------------------------------------------- 1 | 2 | include Gosu 3 | 4 | class Map 5 | attr_reader :width 6 | attr_reader :height 7 | attr_reader :npcs 8 | attr_reader :filename 9 | attr_reader :tileset_filename 10 | def initialize(window, filename, tileset) 11 | @window = window 12 | @filename = filename 13 | @tileset_filename = tileset 14 | @tileset = Image.load_tiles(window, tileset, 32, 32, true) 15 | @data_1 = Tileset::load_map(window, filename) 16 | @width = @data_1[1] 17 | @height = @data_1[2] 18 | @capa_1 = @data_1[0] 19 | @npcs = @data_1[3] 20 | @data_2 = Tileset::load_map(window, filename+"-2") 21 | @width_2 = @data_2[1] 22 | @height_2 = @data_2[2] 23 | @capa_2 = @data_2[0] 24 | end 25 | 26 | def update 27 | @height.times do |y| 28 | @width.times do |x| 29 | tile = @capa_1[x][y] 30 | next if x * 32 > @window.scene.screen_x + 640 31 | next if x * 32 < @window.scene.screen_x - 32 32 | next if y * 32 > @window.scene.screen_y + 480 33 | next if y * 32 < @window.scene.screen_y - 32 34 | if tile 35 | @tileset[tile].draw(x * 32 - @window.scene.screen_x, y * 32- @window.scene.screen_y, 1) 36 | end 37 | end 38 | end 39 | @height_2.times do |y| 40 | @width_2.times do |x| 41 | tile = @capa_2[x][y] 42 | next if x * 32 > @window.scene.screen_x + 640 43 | next if x * 32 < @window.scene.screen_x - 32 44 | next if y * 32 > @window.scene.screen_y + 480 45 | next if y * 32 < @window.scene.screen_y - 32 46 | if tile 47 | @tileset[tile].draw(x * 32 - @window.scene.screen_x, y * 32 - @window.scene.screen_y, 1) 48 | end 49 | end 50 | end 51 | end 52 | def solid(x, y) 53 | begin 54 | return true if @capa_2[x/32][y/32] 55 | rescue 56 | end 57 | return false 58 | end 59 | end 60 | 61 | -------------------------------------------------------------------------------- /Scene_Menu.rb: -------------------------------------------------------------------------------- 1 | 2 | 3 | class Scene_Menu 4 | def initialize(window) 5 | @window = window 6 | main 7 | end 8 | 9 | def main 10 | s1 = "Items" 11 | s2 = "Skills" 12 | s3 = "Equip" 13 | s4 = "State" 14 | s5 = "Save" 15 | s6 = "Exit" 16 | @command_window = Window_Command.new(@window, 160, [s1,s2,s3,s4,s5,s6], 0) 17 | @command_window.active = true 18 | @status_window = Window_MenuStatus.new(@window, 0) 19 | @status_window.active = false 20 | @status_window.x = 159 21 | @gold_window = Window_Gold.new(@window, 0, 200, 0) 22 | @steps_window = Window_Steps.new(@window, 0, 270, 0) 23 | @location_window = Window_Location.new(@window, 0, 410, 0) 24 | @playtime_window = Window_PlayTime.new(@window, 0, 340, 0) 25 | end 26 | 27 | def button_down(id) 28 | if @command_window.active == true 29 | @command_window.button_down(id) 30 | if id == Button::KbEscape 31 | @window.scene = Transition.new(@window, Scene_Map.new(@window, $temp.actual_map, $temp.actual_map_tileset, $temp.actual_position), :in, true) 32 | end 33 | if id == Button::KbReturn 34 | case @command_window.index 35 | when 0 36 | # Inventory 37 | @window.scene = Scene_Item.new(@window) 38 | when 1 39 | @command_window.active = false 40 | @status_window.active = true 41 | when 2 42 | @command_window.active = false 43 | @status_window.active = true 44 | when 3 45 | @command_window.active = false 46 | @status_window.active = true 47 | when 4 48 | # Save 49 | when 5 50 | @window.scene = Transition.new(Scene_Title.new(@window), :in, false) 51 | end 52 | end 53 | end 54 | if @status_window.active == true 55 | @status_window.button_down(id) 56 | if id == Button::KbEscape 57 | @status_window.active = false 58 | @command_window.active = true 59 | end 60 | end 61 | 62 | end 63 | 64 | def update 65 | @command_window.update 66 | @status_window.update 67 | @gold_window.update 68 | @steps_window.update 69 | @playtime_window.update 70 | @location_window.update 71 | self.draw 72 | end 73 | 74 | def draw 75 | end 76 | end -------------------------------------------------------------------------------- /Tileset.rb: -------------------------------------------------------------------------------- 1 | 2 | 3 | module Tileset 4 | def self.load_map(window, filename) 5 | 6 | @capa = File.readlines(filename).map { |line| line.chomp } 7 | @height = @capa.size - 1 8 | @width = @capa[1].size 9 | @tiles = Array.new(@width) do |x| 10 | Array.new(@height) do |y| 11 | case @capa[y+1][x, 1] 12 | when '0' 13 | 0 14 | when '1' 15 | 1 16 | when '2' 17 | 2 18 | when '3' 19 | 3 20 | when '4' 21 | 4 22 | when '5' 23 | 5 24 | when '6' 25 | 6 26 | when '7' 27 | 7 28 | when '8' 29 | 8 30 | when '9' 31 | 9 32 | when 'a' 33 | 10 34 | when 'b' 35 | 11 36 | when 'c' 37 | 12 38 | when 'd' 39 | 13 40 | when 'e' 41 | 14 42 | when 'f' 43 | 15 44 | when 'g' 45 | 16 46 | when 'h' 47 | 17 48 | when 'i' 49 | 18 50 | when 'j' 51 | 19 52 | when 'k' 53 | 20 54 | when 'l' 55 | 21 56 | when 'm' 57 | 22 58 | when 'n' 59 | 23 60 | when 'o' 61 | 24 62 | when 'p' 63 | 25 64 | when 'q' 65 | 26 66 | when 'r' 67 | 27 68 | when 's' 69 | 28 70 | when 't' 71 | 29 72 | when 'u' 73 | 30 74 | when 'v' 75 | 31 76 | when 'w' 77 | 32 78 | when 'x' 79 | 33 80 | when 'y' 81 | 34 82 | when 'z' 83 | 35 84 | when 'A' 85 | 36 86 | when 'B' 87 | 37 88 | when 'C' 89 | 38 90 | when 'D' 91 | 39 92 | when 'E' 93 | 40 94 | when 'F' 95 | 41 96 | when 'G' 97 | 42 98 | when 'H' 99 | 43 100 | when 'I' 101 | 44 102 | when 'J' 103 | 45 104 | when 'K' 105 | 46 106 | when 'L' 107 | 47 108 | when 'M' 109 | 48 110 | when 'N' 111 | 49 112 | when 'O' 113 | 50 114 | when 'P' 115 | 51 116 | when 'Q' 117 | 52 118 | when 'R' 119 | 53 120 | when 'S' 121 | 54 122 | when 'T' 123 | 55 124 | when 'U' 125 | 56 126 | when 'V' 127 | 57 128 | when 'W' 129 | 58 130 | when 'X' 131 | 59 132 | when 'Y' 133 | 60 134 | when 'Z' 135 | 61 136 | #when '%' 137 | # '%' 138 | else 139 | nil 140 | end #case 141 | end # y 142 | end # x 143 | @npcs = @capa[0].to_s.split(';') 144 | @data = [@tiles, @width, @height, @npcs] 145 | return @data 146 | end # def 147 | end #module 148 | -------------------------------------------------------------------------------- /Scene_Map.rb: -------------------------------------------------------------------------------- 1 | class Scene_Map 2 | attr_reader :mapa 3 | attr_reader :hero 4 | attr_reader :screen_x 5 | attr_reader :screen_y 6 | def initialize(window, map, tileset, position) 7 | @window = window 8 | @screen_x = 0 9 | @screen_y = 0 10 | @mapa = Map.new(@window, map, tileset) 11 | @hero = Character_Hero.new(@window, position[0], position[1]) 12 | @npcs = [] 13 | for npc in @mapa.npcs 14 | x,y,filename,movement,face,solid,route,commands = *Database.load_npcs(npc) 15 | @npcs.push(Character.new(@window, x, y, filename, movement, face, solid, route, commands)) 16 | end 17 | 18 | #@npcs.push(Character.new(@window, 800, 200, 2, "npc3.png", 'static', 'left')) 19 | #@npcs.push(Character.new(@window, 600, 300, 2, "npc3.png", 'static', 'right')) 20 | #@npcs.push(Character.new(@window, 700, 350, 2, "npc3.png", 'static', 'up')) 21 | 22 | end 23 | 24 | def button_down(id) 25 | if id == Button::KbEscape 26 | $temp.actual_map = @mapa.filename 27 | $temp.actual_map_tileset = @mapa.tileset_filename 28 | $temp.actual_position = [(@hero.x/32+1),((@hero.y+24)/32+1)] 29 | @window.scene = Transition.new(@window, Scene_Menu.new(@window), :in, false) 30 | end 31 | end 32 | 33 | def solid_event_infront?(character) 34 | case character.direccion 35 | when :left 36 | for i in 0...@npcs.size 37 | return true if @npcs[i].solid == true and @npcs[i].x == character.x - 24 and character.y >= @npcs[i].y - 20 and character.y <= @npcs[i].y + 20 38 | end 39 | return true if @hero.x == character.x - 24 and character.y >= @hero.y and character.y <= @hero.y + 20 40 | return false 41 | when :right 42 | for i in 0...@npcs.size 43 | return true if @npcs[i].solid == true and @npcs[i].x == character.x + 24 and character.y >= @npcs[i].y - 20 and character.y <= @npcs[i].y + 20 44 | end 45 | return true if @hero.x == character.x + 24 and character.y >= @hero.y - 20 and character.y <= @hero.y + 20 46 | return false 47 | when :up 48 | for i in 0...@npcs.size 49 | return true if @npcs[i].solid == true and @npcs[i].y == character.y - 16 and character.x >= @npcs[i].x - 20 and character.x <= @npcs[i].x + 20 50 | end 51 | return true if @hero.y == character.y - 16 and character.x >= @hero.x - 20 and character.x <= @hero.x + 20 52 | return false 53 | when :down 54 | for i in 0...@npcs.size 55 | return true if @npcs[i].solid == true and @npcs[i].y == character.y + 16 and character.x >= @npcs[i].x - 20 and character.x <= @npcs[i].x + 20 56 | end 57 | return true if @hero.y == character.y + 16 and character.x >= @hero.x - 20 and character.x <= @hero.x + 20 58 | return false 59 | end 60 | end 61 | 62 | def update 63 | @screen_x = [[@hero.x - 320, 0].max, @mapa.width * 32 - 640].min 64 | @screen_y = [[@hero.y - 240, 0].max, @mapa.height * 32 - 480].min 65 | @npcs.each { |npc| if @hero.y > npc.y then npc.z = 2 else npc.z = 4 end } 66 | @hero.update 67 | @npcs.each { |npc|npc.update } 68 | @mapa.update 69 | end 70 | 71 | def draw 72 | end 73 | end 74 | -------------------------------------------------------------------------------- /Character_Hero.rb: -------------------------------------------------------------------------------- 1 | 2 | include Gosu 3 | 4 | class Character_Hero 5 | attr_accessor :x 6 | attr_accessor :y 7 | attr_accessor :z 8 | attr_accessor :direccion 9 | def initialize(window, x, y) 10 | @window = window 11 | @x = ((x-1)*32) 12 | @y = ((y-1)*32)-24 13 | @z = 3 14 | @poses = $party.main_party[0].chara 15 | @pose = @poses[0] 16 | @direccion = :down 17 | @speed = 4 18 | @step = 0 19 | @walking = false 20 | end 21 | def walk 22 | case @direccion 23 | when :up 24 | for i in 0...@speed 25 | @y -= 1 if not @window.scene.solid_event_infront?(self) 26 | end 27 | when :down 28 | for i in 0...@speed 29 | @y += 1 if not @window.scene.solid_event_infront?(self) 30 | end 31 | when :left 32 | for i in 0...@speed 33 | @x -= 1 if not @window.scene.solid_event_infront?(self) 34 | end 35 | when :right 36 | for i in 0...@speed 37 | @x += 1 if not @window.scene.solid_event_infront?(self) 38 | end 39 | end 40 | return [@x, @y] 41 | end 42 | 43 | def draw 44 | if @direccion == :left and @window.button_down?(Button::KbLeft) 45 | if milliseconds / 175 % 4 == 0 46 | @pose = @poses[4] 47 | elsif milliseconds / 175 % 4 == 1 48 | @pose = @poses[5] 49 | elsif milliseconds / 175 % 4 == 2 50 | @pose = @poses[6] 51 | elsif milliseconds / 175 % 4 == 3 52 | @pose = @poses[7] 53 | end 54 | elsif @direccion == :right and @window.button_down?(Button::KbRight) 55 | if milliseconds / 175 % 4 == 0 56 | @pose = @poses[8] 57 | elsif milliseconds / 175 % 4 == 1 58 | @pose = @poses[9] 59 | elsif milliseconds / 175 % 4 == 2 60 | @pose = @poses[10] 61 | elsif milliseconds / 175 % 4 == 3 62 | @pose = @poses[11] 63 | end 64 | elsif @direccion == :up and @window.button_down?(Button::KbUp) 65 | if milliseconds / 175 % 4 == 0 66 | @pose = @poses[12] 67 | elsif milliseconds / 175 % 4 == 1 68 | @pose = @poses[13] 69 | elsif milliseconds / 175 % 4 == 2 70 | @pose = @poses[14] 71 | elsif milliseconds / 175 % 4 == 3 72 | @pose = @poses[15] 73 | end 74 | elsif @direccion == :down and @window.button_down?(Button::KbDown) 75 | if milliseconds / 175 % 4 == 0 76 | @pose = @poses[0] 77 | elsif milliseconds / 175 % 4 == 1 78 | @pose = @poses[1] 79 | elsif milliseconds / 175 % 4 == 2 80 | @pose = @poses[2] 81 | elsif milliseconds / 175 % 4 == 3 82 | @pose = @poses[3] 83 | end 84 | end 85 | @pose.draw(@x - @window.scene.screen_x,@y - @window.scene.screen_y, @z) 86 | end 87 | 88 | def update 89 | @x_pies = @x + (@pose.width/2) 90 | @y_pies = @y + @pose.height 91 | if @window.button_down?(Button::KbLeft) and @x > 0 - @window.scene.screen_x 92 | @direccion = :left 93 | if not @window.scene.mapa.solid(@x_pies-16, @y_pies) and not @window.scene.solid_event_infront?(self) 94 | walk 95 | end 96 | elsif @window.button_down?(Button::KbRight) and @x < (@window.scene.mapa.width * 32) - @pose.width 97 | @direccion = :right 98 | if not @window.scene.mapa.solid(@x_pies+16, @y_pies) and not @window.scene.solid_event_infront?(self) 99 | walk 100 | end 101 | elsif @window.button_down?(Button::KbUp) and @y > 0 - @window.scene.screen_y 102 | @direccion = :up 103 | if not @window.scene.mapa.solid(@x_pies, @y_pies-16) and not @window.scene.solid_event_infront?(self) 104 | walk 105 | end 106 | elsif @window.button_down?(Button::KbDown) and @y < (@window.scene.mapa.height * 32) - @pose.height 107 | @direccion = :down 108 | if not @window.scene.mapa.solid(@x_pies, @y_pies+6) and not @window.scene.solid_event_infront?(self) 109 | walk 110 | end 111 | else 112 | case @direccion 113 | when :left 114 | @pose = @poses[4] 115 | when :right 116 | @pose = @poses[8] 117 | when :up 118 | @pose = @poses[12] 119 | when :down 120 | @pose = @poses[0] 121 | end 122 | end 123 | self.draw 124 | end 125 | end -------------------------------------------------------------------------------- /Window_Base.rb: -------------------------------------------------------------------------------- 1 | 2 | class Window_Base 3 | attr_accessor :x 4 | attr_accessor :y 5 | attr_accessor :z 6 | attr_accessor :active 7 | def initialize(window, x, y, width, height, z = 10) 8 | @window = window 9 | if x != 0 then @x = x else @x = 0 end 10 | @z = z 11 | if y != 0 then @y = y else @y = 0 end 12 | if width != 0 then @width = width else @width = 0 end 13 | if height != 0 then @height = height else @height = 0 end 14 | @active = false 15 | end 16 | 17 | def colors 18 | @white = Color.new(255, 255, 255, 255) 19 | @blueBorder = Color.new(255, 33, 35, 79) 20 | @blue1 = Color.new(255, 66, 68, 120) 21 | @blue2 = Color.new(255, 56,58, 110) 22 | @blue3 = Color.new(255, 40, 41, 81) 23 | @blue_text = Color.new(255, 192, 224, 255) 24 | 25 | @green_light = Color.new(255, 0, 255, 0) 26 | @green_dark = Color.new(255, 0, 100, 0) 27 | @blue_light = Color.new(255, 0, 0, 255) 28 | @blue_dark = Color.new(255, 0, 0, 100) 29 | @black = Color.new(255, 0, 0, 0) 30 | @grey = Color.new(255, 50, 50, 50) 31 | end 32 | 33 | def drawBox(x, y, w, h, z = 1) 34 | # blue border 35 | @window.draw_quad(x, y, @blueBorder, x + w, y, @blueBorder, x, y + h, @blueBorder, x + w, y + h, @blueBorder, z) 36 | # white border 37 | @window.draw_quad(x + 1, y + 1, @white, x + w - 1, y + 1, @white, x + 1, y + h - 1, @white, x + w - 1, y + h - 1, @white, z) 38 | # blue gradient 39 | @window.draw_quad(x + 3, y + 3, @blue1, x + w - 3, y + 3, @blue2, x + 3, y + h - 3, @blue2, x + w - 3, y + h - 3, @blue3, z) 40 | end 41 | 42 | def drawHPBar(i, x, y, w, h, color1, color2, z=1) 43 | # white border 44 | @window.draw_quad(x, y, @white, x + w, y, @white, x, y + h, @white, x + w, y + h, @white, z) 45 | @window.draw_quad(x + 1, y + 1, @black, x + w - 1, y + 1, @black, x + 1, y + h - 1, @black, x + w - 1, y + h - 1, @black, z) 46 | # gradient 47 | max_hp = $party.main_party[i].MAX_HP 48 | hp = $party.main_party[i].HP 49 | pre = (hp*w)/100 50 | lenght = (pre * 100) / max_hp 51 | @window.draw_quad(x + 1, y + 1, color1, x + lenght - 1, y + 1, color1, x + 1, y + h - 1, color2, x + lenght - 1, y + h - 1, color2, z) 52 | end 53 | def drawMPBar(i, x, y, w, h, color1, color2, z=1) 54 | # white border 55 | @window.draw_quad(x, y, @white, x + w, y, @white, x, y + h, @white, x + w, y + h, @white, z) 56 | @window.draw_quad(x + 1, y + 1, @black, x + w - 1, y + 1, @black, x + 1, y + h - 1, @black, x + w - 1, y + h - 1, @black, z) 57 | # gradient 58 | max_mp = $party.main_party[i].MAX_MP 59 | mp = $party.main_party[i].MP 60 | pre = (mp*w)/100 61 | lenght = (pre * 100) / max_mp 62 | @window.draw_quad(x + 1, y + 1, color1, x + lenght - 1, y + 1, color1, x + 1, y + h - 1, color2, x + lenght - 1, y + h - 1, color2, z) 63 | end 64 | 65 | def draw_hero_graphic(i, x, y) 66 | chara = $party.main_party[i].chara 67 | pose = chara[0] 68 | pose.draw(x, y, @z) 69 | end 70 | 71 | def draw_hero_name(i, font, x, y) 72 | name = $party.main_party[i].name 73 | font.draw(name, x, y, @z) 74 | end 75 | 76 | def draw_hero_state(i, font, x, y) 77 | state = $party.main_party[i].state 78 | font.draw("State: ", x, y, @z, 1, 1, @blue_text) 79 | font.draw(state, x + 55, y, @z) 80 | end 81 | 82 | def draw_hero_class(i, font, x, y) 83 | job = $party.main_party[i].job 84 | font.draw("Class: ", x, y, @z, 1, 1, @blue_text) 85 | font.draw(job, x + 55, y, @z) 86 | end 87 | 88 | def draw_hero_level(i, font, x, y) 89 | level = $party.main_party[i].LVL 90 | font.draw("Lvl: ", x, y, @z, 1, 1, @blue_text) 91 | font.draw(level.to_s, x+ 35, y, @z) 92 | end 93 | 94 | def draw_hero_hp(i, font, x, y) 95 | hp = $party.main_party[i].HP 96 | maxhp = $party.main_party[i].MAX_HP 97 | self.drawHPBar(i,x+35, y, 120, 20, @green_light, @green_dark, @z) 98 | font.draw("HP:", x, y, @z, 1, 1, @blue_text) 99 | font.draw_rel(hp.to_s+"/"+maxhp.to_s, x + 95, y, @z, 0.5, 0.0) 100 | end 101 | 102 | def draw_hero_mp(i, font, x, y) 103 | mp = $party.main_party[i].MP 104 | maxmp = $party.main_party[i].MAX_MP 105 | self.drawMPBar(i, x+35, y, 120, 20, @blue_light, @blue_dark, @z) 106 | font.draw("MP:", x, y, @z, 1, 1, @blue_text) 107 | font.draw_rel(mp.to_s+"/"+maxmp.to_s, x + 95, y, @z, 0.5, 0.0) 108 | end 109 | 110 | def draw_hero_exp(i, font, x, y) 111 | exp = $party.main_party[i].EXP 112 | nxtexp = $party.main_party[i].NXT_EXP 113 | font.draw("Exp:", x, y, @z, 1, 1, @blue_text) 114 | font.draw(exp.to_s, x+40, y, @z) 115 | font.draw("Next Lvl:", x + 195, y, @z, 1, 1, @blue_text) 116 | font.draw(nxtexp.to_s, x + 280, y, @z) 117 | end 118 | 119 | def draw_gold(font, x, y) 120 | gold = $party.gold 121 | font.draw_rel(gold.to_s+" Gold", x, y, @z, 1.0, 0.5) 122 | end 123 | 124 | end 125 | -------------------------------------------------------------------------------- /Character.rb: -------------------------------------------------------------------------------- 1 | class Character 2 | attr_accessor :x 3 | attr_accessor :y 4 | attr_accessor :z 5 | attr_accessor :direccion 6 | attr_reader :solid 7 | def initialize(window, x, y, filename, movement=:static, face=:down, solid=true, route='', commands='') 8 | @window = window 9 | @x = (x*32) 10 | @y = (y*32)-24 11 | @z = 2 12 | @movement_type = movement 13 | @face = face 14 | @poses = Image.load_tiles(window, "graphics/charasets/"+filename+".png", 32, 48, false) 15 | @pose = @poses[0] 16 | @direccion = :down 17 | @solid = solid 18 | @route = route 19 | @commands = commands 20 | @speed = 2 21 | @step = 15 22 | end 23 | def walk 24 | case @direccion 25 | when :up 26 | for i in 0...@speed 27 | @y -= 1 if not @window.scene.solid_event_infront?(self) 28 | end 29 | when :down 30 | for i in 0...@speed 31 | @y += 1 if not @window.scene.solid_event_infront?(self) 32 | end 33 | when :left 34 | for i in 0...@speed 35 | @x -= 1 if not @window.scene.solid_event_infront?(self) 36 | end 37 | when :right 38 | for i in 0...@speed 39 | @x += 1 if not @window.scene.solid_event_infront?(self) 40 | end 41 | end 42 | @step+=1 43 | return [@x, @y] 44 | end 45 | 46 | def face 47 | case @movement_type 48 | when :static 49 | case @face 50 | when :left 51 | @pose = @poses[4] 52 | when :right 53 | @pose = @poses[8] 54 | when :up 55 | @pose = @poses[12] 56 | when :down 57 | @pose = @poses[0] 58 | end 59 | 60 | when :random 61 | direccion = rand(4) 62 | case direccion 63 | when 0 64 | @direccion = :left 65 | when 1 66 | @direccion = :right 67 | when 2 68 | @direccion = :up 69 | when 3 70 | @direccion = :down 71 | end 72 | end 73 | end 74 | 75 | def draw 76 | if @direccion == :left 77 | if milliseconds / 175 % 4 == 0 78 | @pose = @poses[4] 79 | elsif milliseconds / 175 % 4 == 1 80 | @pose = @poses[5] 81 | elsif milliseconds / 175 % 4 == 2 82 | @pose = @poses[6] 83 | elsif milliseconds / 175 % 4 == 3 84 | @pose = @poses[7] 85 | end 86 | elsif @direccion == :right 87 | if milliseconds / 175 % 4 == 0 88 | @pose = @poses[8] 89 | elsif milliseconds / 175 % 4 == 1 90 | @pose = @poses[9] 91 | elsif milliseconds / 175 % 4 == 2 92 | @pose = @poses[10] 93 | elsif milliseconds / 175 % 4 == 3 94 | @pose = @poses[11] 95 | end 96 | elsif @direccion == :up 97 | if milliseconds / 175 % 4 == 0 98 | @pose = @poses[12] 99 | elsif milliseconds / 175 % 4 == 1 100 | @pose = @poses[13] 101 | elsif milliseconds / 175 % 4 == 2 102 | @pose = @poses[14] 103 | elsif milliseconds / 175 % 4 == 3 104 | @pose = @poses[15] 105 | end 106 | elsif @direccion == :down 107 | if milliseconds / 175 % 4 == 0 108 | @pose = @poses[0] 109 | elsif milliseconds / 175 % 4 == 1 110 | @pose = @poses[1] 111 | elsif milliseconds / 175 % 4 == 2 112 | @pose = @poses[2] 113 | elsif milliseconds / 175 % 4 == 3 114 | @pose = @poses[3] 115 | end 116 | end 117 | @pose.draw(@x - @window.scene.screen_x,@y - @window.scene.screen_y, @z) 118 | end 119 | 120 | def update 121 | @x_pies = @x + (@pose.width/2) 122 | @y_pies = @y + @pose.height 123 | if @step >= 15 124 | face 125 | @step = 0 126 | end 127 | if @direccion == :left and not @window.scene.mapa.solid(@x_pies-16, @y_pies) and @x > 0 - @window.scene.screen_x and not @window.scene.solid_event_infront?(self) 128 | walk 129 | elsif @direccion == :left and @window.scene.mapa.solid(@x_pies-16, @y_pies) or @window.scene.solid_event_infront?(self) 130 | face 131 | elsif @direccion == :left and @x <= 0 - @window.scene.screen_x 132 | face 133 | end 134 | if @direccion == :right and not @window.scene.mapa.solid(@x_pies+16, @y_pies) and @x < (@window.scene.mapa.width * 32) - @pose.width and not @window.scene.solid_event_infront?(self) 135 | walk 136 | elsif @direccion == :right and @window.scene.mapa.solid(@x_pies+16, @y_pies) or @window.scene.solid_event_infront?(self) 137 | face 138 | elsif @direccion == :right and @x >= (@window.scene.mapa.width * 32) - @pose.width 139 | face 140 | end 141 | if @direccion == :up and not @window.scene.mapa.solid(@x_pies, @y_pies-16) and @y > 0 - @window.scene.screen_y and not @window.scene.solid_event_infront?(self) 142 | walk 143 | elsif @direccion == :up and @window.scene.mapa.solid(@x_pies, @y_pies-16) or @window.scene.solid_event_infront?(self) 144 | face 145 | elsif @direccion == :up and @y <= 0 - @window.scene.screen_y 146 | face 147 | end 148 | if @direccion == :down and not @window.scene.mapa.solid(@x_pies, @y_pies+6) and @y < (@window.scene.mapa.height * 32) - @pose.height and not @window.scene.solid_event_infront?(self) 149 | walk 150 | elsif @direccion == :down and @window.scene.mapa.solid(@x_pies, @y_pies+6) or @window.scene.solid_event_infront?(self) 151 | face 152 | elsif @direccion == :down and @y >= (@window.scene.mapa.height * 32) - @pose.height 153 | face 154 | end 155 | case @direccion 156 | when :left 157 | @pose = @poses[4] 158 | when :right 159 | @pose = @poses[8] 160 | when :up 161 | @pose = @poses[12] 162 | when :down 163 | @pose = @poses[0] 164 | end 165 | if @x > @window.scene.screen_x - 32 and @x < @window.scene.screen_x + 640 and @y > @window.scene.screen_y - 32 and @y < @window.scene.screen_y + 480 166 | self.draw 167 | end 168 | end 169 | end --------------------------------------------------------------------------------