Jump to content
Sign in to follow this  
efeberk

Circular Gauges for RGSS3

Recommended Posts

Circular Gauges

by efeberk

 

 

Introduction
 
Hello guyz :D After a long time, I had time for ruby and I coded a simple system for you. I am studying at school and I don't have much time for rgss :( Let me tell you about this script. This script draws circular progress bars by given image. This script can be used by a maker who knows about scripting. I have used Bresenham's line algorithm for this script. You can google it. I accept suggestions & requests ;)

 

zy80eh.png

 

 

Demo : http://www.mediafire.com/download/vacy3098crqxbl2/Project1.zip (Windowskin by RPGMakerSource)

 

Scripts :

 

 

 

=begin
===============================================================================
 Circular Gauges by efeberk
 Date : 21.03.2015 01:47
 Version: RGSS3
===============================================================================
 This script draws circular progress bars. This script can be used by a maker who
 knows about scripting. I have used Bresenham's line algorithm for this script.
 You can google it.
 
How to use: 

First of all, you need to create bitmap of the circular bar:

@circular_bitmap = BerksCircularBar.new([path of bar image], [start value], [max value], [start angle])

after that, you can draw this bitmap to contents : 

contents.blt(x, y, @circular_bitmap, @circular_bitmap.rect)

contact skype if you have trouble or something like that : oceanjack35
--------------------------------------------------------------------------------

=end


module BERK
  
end

class BerksCircularBar < Bitmap
  
  
  def initialize(filename, v, m, s)
    super(filename)
    radial_reactive(v, m, s)
  end
  
  def radial_reactive(value, max_value, start_aci)
    value = max_value if value > max_value
    if value < max_value && value >= 0
      v = value.to_f * 100.0 / max_value.to_f
      aci = start_aci
      tane = 108 * (100 - v) / 100
      for i in 0..(tane.to_i - 1)
        nx = self.width / 2 + ((self.width / 2 + 1) * Math.cos(aci * Math::PI / 180.0)).to_i
        ny = self.height / 2 - 1 - ((self.height / 2 + 1) * Math.sin(aci * Math::PI / 180.0)).to_i
        draw_line(self.width / 2, self.height / 2, nx, ny)
        aci -= 3.33
      end
    end
  end

  def draw_point(x, y)
    self.fill_rect(x, y, 2, 2, Color.new(255, 0, 0, 0))
  end
  
  # Bresenham's line algorithm
  def draw_line(x1, y1, x2, y2)
    steep = (y2 - y1).abs > (x2 - x1).abs
 
    if steep
      x1, y1 = y1, x1
      x2, y2 = y2, x2
    end
 
    if x1 > x2
      x1, x2 = x2, x1
      y1, y2 = y2, y1
    end
 
    deltax = x2 - x1
    deltay = (y2 - y1).abs
    error = deltax / 2
    ystep = y1 < y2 ? 1 : -1
 
    y = y1
    for x in x1..x2
      pixel = steep ? [y,x] : [x,y]
      draw_point(pixel[0], pixel[1])
      error -= deltay
      if error < 0
        y += ystep
        error += deltax
      end
    end
  end
end



 

 

 

 

 

Circular Menu HP & MP Bars Script

 

 

 

class Window_Base < Window
  
  def draw_actor_simple_status(actor, x, y)
    draw_actor_name(actor, x, y)
    draw_actor_level(actor, x, y + line_height * 1)
    draw_actor_icons(actor, x, y + line_height * 2)
    draw_actor_class(actor, x + 120, y)
    @circular_hp = BerksCircularBar.new("Graphics/Pictures/circular_hp", actor.hp, actor.mhp, 90)
    @circular_mp = BerksCircularBar.new("Graphics/Pictures/circular_mp", actor.mp, actor.mmp, 90)
    @circular_back = Bitmap.new("Graphics/Pictures/back")
    contents.blt(x + 84, y + 28, @circular_back, @circular_back.rect)
    contents.blt(x + 84, y + 28, @circular_hp, @circular_hp.rect)
    draw_text(x + 96, y + 48, 42, line_height, actor.hp, 1)
    
    contents.blt(x + 164, y + 28, @circular_back, @circular_back.rect)
    contents.blt(x + 164, y + 28, @circular_mp, @circular_mp.rect)
    draw_text(x + 176, y + 48, 42, line_height, actor.mp, 1)
  end
  
end 

 

 

Edited by efeberk

Share this post


Link to post
Share on other sites

Looks interesting. A little plain but that should be easy to fix later on. If you could code these gauges into a battle system and add some cosmetic appeal, I could certainly see using this.

Share this post


Link to post
Share on other sites

Looks interesting. A little plain but that should be easy to fix later on. If you could code these gauges into a battle system and add some cosmetic appeal, I could certainly see using this.

 

Yes I will improve this script but I made this script just yesterday. I have exams for my school, after exams I will start to work with this script about battle, timer, animated changes, mini games etc. :)

Share this post


Link to post
Share on other sites

Hi efeberk! Awesome script! Thank you for making the circular gauges code. Just want you to know that your script has been used in our IGMC contest game Blacksword Chronicles. You can check it out here:

 

http://contest.gamedevfort.com/submission/258#.VcRzifmqqko

 

Your code is a critical part of the battle system, and you are in the Credits under scripts. If you like our game please vote for it too.

 

Thanks again!

Edited by watermark

Share this post


Link to post
Share on other sites

Hey! Just want to say, great script. I visited that Bresenham tech, and sad life, I really understood nothing. 

 

So I'm having problems in converting it to 180 degrees version: where the point of origin (0%/100%) is reversed  meaning not based on the circle's top, but at the circle's direct bottom instead. Is there a neat trick like ".angle" code that I can use for this?

 

Please and thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×