Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

DNS events.

Code:
#=======================================#
# class Game_Title                                                                 #
#     Written by Deke
#     Rewiten by Near Fantastica
#=======================================#
class Game_Time

attr_accessor :minute_length

def initialize
 @minute_length= 0.1#0.325     #length of game minute in real seconds
 @hour_length= 60.0      #minute in an hour
 @day_length= 24.0        #hours in a day
 @month_length=30.0    #days in a month
 @year_length=12.0       #months in a year
 @minutes=0                 #starting minute count
 start_minute=0
 add_minutes(start_minute)
 start_hour=23           #starting hour count
 add_hours(start_hour)
 start_day=20                #starting day count
 add_days(start_day)
 start_month=6             #starting month count
 add_months(start_month-1)
 start_year= 2000         #starting year count
 add_years(start_year)
end

def add_minutes(minutes)
 @minutes +=minutes
end

def add_hours(hours)
 @minutes +=hours*@hour_length
end

def add_days(days)
 @minutes += days*@hour_length*@day_length
end

def add_months(months)
 @minutes +=months * @hour_length*@day_length*@month_length
end

def add_years(years)
 @minutes += years * @hour_length*@day_length*@month_length * @year_length
end
 

def get_year
  minutes=get_total_minutes
  year=minutes / @hour_length / @day_length / @month_length  / @year_length
  return year
end
 
def get_month
  minutes=get_total_minutes
  month=minutes / @hour_length / @day_length /  @month_length % @year_length + 1
  return month
end
 
def get_day
  minutes=get_total_minutes
  day=minutes / @hour_length / @day_length % @month_length
  return day
end  
 
def get_hour
  minutes=get_total_minutes
  hour=minutes / @hour_length % @day_length
  return hour
end
 
def get_total_minutes
  total_sec=Graphics.frame_count / Graphics.frame_rate
  minute=(total_sec/@minute_length+@minutes)
  return minute
end

def get_minute
 minutes=get_total_minutes % @hour_length
 return minutes
end

def get_tone
 period_length=Math::PI*(get_hour / @day_length)
 red_shift=  -100+ 115*Math.sin(period_length)
 green_shift=  -140+ 155*Math.sin(period_length)
 blue_shift=  -150+ 165*Math.sin(period_length)
 return Tone.new(red_shift, green_shift, blue_shift, 0)
end

end # of class Game_Time  

#=======================================#
# â–  class Window_Time
# written by Deke
#=======================================#
class Window_PlayTime < Window_Base

#--------------------------------------------------------------------------
def initialize
  super(0, 0, 160, 96)
  self.contents = Bitmap.new(width - 32, height - 32)
  self.contents.font.name = $fontface  # "Time" window font
  self.contents.font.size = $fontsize
  refresh
end

#--------------------------------------------------------------------------
def refresh
  self.contents.clear
  @total_sec = Graphics.frame_count / Graphics.frame_rate
  @minute=$game_time.get_minute.floor
  hour = $game_time.get_hour
  pm_flag= hour >=12 ? true : false
  hour= hour >= 12 ? hour-12 : hour
  day=$game_time.get_day
  month=$game_time.get_month
  year=$game_time.get_year
  if hour.floor==0
    text=sprintf("%02d:%02d",12,@minute)
  else
    text=sprintf("%02d:%02d",hour,@minute)
  end
  if pm_flag
    text += " PM"
  else
    text += " AM"
  end
  self.contents.font.color = normal_color
  self.contents.draw_text(0, 32, 120, 32, text)
  text = sprintf("%02d-%02d-%02d", month, day, year)
  self.contents.font.color=system_color
  self.contents.draw_text(4,0,120,32,'Time')
end

#--------------------------------------------------------------------------
def update
  if $game_time.get_minute.floor != @minute
    refresh
  end
end
end # of class

#=======================================
class Game_Temp
 #--------------------------------------------------------------------------
 # â—
 
Okay, you see where it says "def get_year" and "def get_day" and so on? Those can be used to find the current year, day, etc.

So how do you use this in events?

Well, on the fourth page of Conditional Branch, there's the script field. You want to use this to check the current time. Here's an example of how you'd check if it was the 4th year.
Code:
$game_time.get_year == 4

So basically, it's
$game_time.xxx == y
where xxx is get_minute, get_hour, get_day, get_month, or get_year.
and y is the number you're checking against. You can also use >, <, >=, <=, !=.

Let me know if you understand.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top