Rancang Bangun Game Wirausaha Muda Berbasis RPG Maker VX

  LAMPIRAN : LISTING PROGRAM

  a. module Vocab

  Modul ini mendefinisikan persyaratan dan pesan dari beberapa data sebagai konstan Variabel.

  SaveMessage = "Simpan dislot mana?" LoadMessage = "Lanjutkan game di slot mana?" File = "Data" def self.save return $data_system.terms.save end def self.game_end return $data_system.terms.game_end end def self.new_game return $data_system.terms.new_game end def self.continue return $data_system.terms.continue end def self.shutdown return $data_system.terms.shutdown end end

  b. module Sound

  Modul ini memainkan efek suara. Diperoleh dengan efek suara yang ditentukan dalam Database dari $ data_system, dan memainkan mereka. def self.play_cursor $data_system.sounds[0].play end def self.play_decision $data_system.sounds[1].play end def self.play_cancel $data_system.sounds[2].play end def self.play_buzzer $data_system.sounds[3].play end def self.play_save $data_system.sounds[5].play end def self.play_load $data_system.sounds[6].play end def self.play_shop $data_system.sounds[17].play end end

  c. module Cache

  Modul ini memuat masing-masing grafis, membuat objek Bitmap, dan mempertahankannya. Modul ini dibuat untuk mempercepat load dan menghemat memori. def self.animation(filename, hue) load_bitmap("Graphics/Animations/", filename, hue) end def self.character(filename) load_bitmap("Graphics/Characters/", filename) end def self.face(filename) load_bitmap("Graphics/Faces/", filename) end def self.parallax(filename) load_bitmap("Graphics/Parallaxes/", filename) end def self.picture(filename) load_bitmap("Graphics/Pictures/", filename) end def self.system(filename) load_bitmap("Graphics/System/", filename) end def self.clear @cache = {} if @cache == nil @cache.clear GC.start end

def self.load_bitmap(folder_name, filename, hue = 0) @cache = {} if @cache == nil path = folder_name + filename if not @cache.include?(path) or @cache[path].disposed? if filename.empty? @cache[path] = Bitmap.new(32, 32) else @cache[path] = Bitmap.new(path) end end if hue == 0 return @cache[path] else key = [path, hue] if not @cache.include?(key) or @cache[key].disposed? @cache[key] = @cache[path].clone @cache[key].hue_change(hue) end return @cache[key] end end end

  a. class Game_Temp

  Kelas ini menangani data sementara yang tidak termasuk dengan data simpan. Contoh kelas ini direferensikan oleh $ game_temp. attr_accessor :next_scene attr_accessor :map_bgm attr_accessor :map_bgs attr_accessor :common_event_id attr_accessor :in_battle attr_accessor :battle_proc attr_accessor :shop_goods attr_accessor :shop_purchase_only attr_accessor :name_actor_id attr_accessor :name_max_char attr_accessor :menu_beep attr_accessor :last_file_index attr_accessor :debug_top_row attr_accessor :debug_index attr_accessor :background_bitmap def initialize @next_scene = nil @map_bgm = nil @map_bgs = nil @common_event_id = 0 @in_battle = false @battle_proc = nil @shop_goods = nil @shop_purchase_only = false @name_actor_id = 0 @name_max_char = 0 @menu_beep = false @last_file_index = 0 @debug_top_row = 0 @debug_index = 0 @background_bitmap = Bitmap.new(1, 1) end end

  b. class Game_Switches Kelas ini menangani Switch yang disusun berdasarkan ‘Array’.

  def initialize @data = [] end def [](switch_id) if @data[switch_id] == nil return false else return @data[switch_id] end end def []=(switch_id, value) if switch_id <= 5000 @data[switch_id] = value end end end

  c. class Game_Variables Kelas ini menangani variable yang disusun berdasarkan ‘Array’.

  def initialize @data = [] end def [](variable_id) if @data[variable_id] == nil return 0 else return @data[variable_id] end end def []=(variable_id, value) if variable_id <= 5000 @data[variable_id] = value end end end

  a. class Sprite_Base Kelas untuk menambahkan animasi sprite.

  class Sprite_Base < Sprite @@animations = [] @@_reference_count = {} def initialize(viewport = nil) super(viewport)

  @use_sprite = true @animation_duration = 0 end def dispose super dispose_animation end def update super if @animation != nil @animation_duration -= 1 if @animation_duration % 4 == 0 update_animation end end @@animations.clear end def animation? return @animation != nil end def start_animation(animation, mirror = false) dispose_animation @animation = animation return if @animation == nil @animation_mirror = mirror @animation_duration = @animation.frame_max * 4 + 1 load_animation_bitmap @animation_sprites = [] if @animation.position != 3 or not @@animations.include?(animation) if @use_sprite for i in 0..15 sprite = ::Sprite.new(viewport) sprite.visible = false @animation_sprites.push(sprite) end unless @@animations.include?(animation) @@animations.push(animation) end end end if @animation.position == 3 if viewport == nil

  @animation_ox = 544 / 2 @animation_oy = 416 / 2 else @animation_ox = viewport.rect.width / 2 @animation_oy = viewport.rect.height / 2 end else @animation_ox = x - ox + width / 2 @animation_oy = y - oy + height / 2 if @animation.position == 0 @animation_oy -= height / 2 elsif @animation.position == 2 @animation_oy += height / 2 end end end def load_animation_bitmap animation1_name = @animation.animation1_name animation1_hue = @animation.animation1_hue animation2_name = @animation.animation2_name animation2_hue = @animation.animation2_hue @animation_bitmap1 = Cache.animation(animation1_name, animation1_hue) @animation_bitmap2 = Cache.animation(animation2_name, animation2_hue) if @@_reference_count.include?(@animation_bitmap1) @@_reference_count[@animation_bitmap1] += 1 else @@_reference_count[@animation_bitmap1] = 1 end if @@_reference_count.include?(@animation_bitmap2) @@_reference_count[@animation_bitmap2] += 1 else @@_reference_count[@animation_bitmap2] = 1 end Graphics.frame_reset end def dispose_animation if @animation_bitmap1 != nil @@_reference_count[@animation_bitmap1] -= 1 if @@_reference_count[@animation_bitmap1] == 0 @animation_bitmap1.dispose end end if @animation_bitmap2 != nil @@_reference_count[@animation_bitmap2] -= 1 if @@_reference_count[@animation_bitmap2] == 0 @animation_bitmap2.dispose end end

if @animation_sprites != nil for sprite in @animation_sprites sprite.dispose end @animation_sprites = nil @animation = nil end @animation_bitmap1 = nil @animation_bitmap2 = nil end def update_animation if @animation_duration > 0 frame_index = @animation.frame_max - (@animation_duration + 3) / 4 animation_set_sprites(@animation.frames[frame_index]) for timing in @animation.timings if timing.frame == frame_index animation_process_timing(timing) end end else dispose_animation end end def animation_set_sprites(frame) cell_data = frame.cell_data

for i in 0..15 sprite = @animation_sprites[i] next if sprite == nil pattern = cell_data[i, 0] if pattern == nil or pattern == -1 sprite.visible = false next end if pattern < 100 sprite.bitmap = @animation_bitmap1 else sprite.bitmap = @animation_bitmap2 end sprite.visible = true sprite.src_rect.set(pattern % 5 * 192, pattern % 100 / 5 * 192, 192, 192) if @animation_mirror sprite.x = @animation_ox - cell_data[i, 1] sprite.y = @animation_oy + cell_data[i, 2] sprite.angle = (360 - cell_data[i, 4]) sprite.mirror = (cell_data[i, 5] == 0) else sprite.x = @animation_ox + cell_data[i, 1] sprite.y = @animation_oy + cell_data[i, 2] sprite.angle = cell_data[i, 4]

sprite.mirror = (cell_data[i, 5] == 1) end sprite.z = self.z + 300 + i sprite.ox = 96 sprite.oy = 96 sprite.zoom_x = cell_data[i, 3] / 100.0 sprite.zoom_y = cell_data[i, 3] / 100.0 sprite.opacity = cell_data[i, 6] * self.opacity / 255.0 sprite.blend_type = cell_data[i, 7] end end def animation_process_timing(timing) timing.se.play case timing.flash_scope when 1 self.flash(timing.flash_color, timing.flash_duration * 4) when 2 if viewport != nil viewport.flash(timing.flash_color, timing.flash_duration * 4) end when 3 self.flash(nil, timing.flash_duration * 4) end end end

  b. class Sprite_Character

  kelas yang berfungsi untuk menampilkan sprite character dan secara otomatis mengubah kondisinya sesuai dengan event yang terjadi. class Sprite_Character < Sprite_Base attr_accessor :character def initialize(viewport, character = nil) super(viewport) @character = character @balloon_duration = 0 update end def dispose dispose_balloon super end def update super update_bitmap self.visible = (not @character.transparent) update_src_rect self.x = @character.screen_x self.y = @character.screen_y self.z = @character.screen_z self.opacity = @character.opacity self.blend_type = @character.blend_type self.bush_depth = @character.bush_depth update_balloon if @character.animation_id != 0 animation = $data_animations[@character.animation_id] start_animation(animation) @character.animation_id = 0 end if @character.balloon_id != 0 @balloon_id = @character.balloon_id start_balloon @character.balloon_id = 0 end end def tileset_bitmap(tile_id) set_number = tile_id / 256 return Cache.system("TileB") if set_number == 0 return Cache.system("TileC") if set_number == 1 return Cache.system("TileD") if set_number == 2 return Cache.system("TileE") if set_number == 3 return nil

end def update_bitmap if @tile_id != @character.tile_id or @character_name != @character.character_name or @character_index != @character.character_index @tile_id = @character.tile_id @character_name = @character.character_name @character_index = @character.character_index if @tile_id > 0 sx = (@tile_id / 128 % 2 * 8 + @tile_id % 8) * 32; sy = @tile_id % 256 / 8 % 16 * 32; self.bitmap = tileset_bitmap(@tile_id) self.src_rect.set(sx, sy, 32, 32) self.ox = 16 self.oy = 32 else self.bitmap = Cache.character(@character_name) sign = @character_name[/^[\!\$]./] if sign != nil and sign.include?('$') @cw = bitmap.width / 3 @ch = bitmap.height / 4 else @cw = bitmap.width / 12 @ch = bitmap.height / 8

end self.ox = @cw / 2 self.oy = @ch end end end def update_src_rect if @tile_id == 0 index = @character.character_index pattern = @character.pattern < 3 ? @character.pattern : 1 sx = (index % 4 * 3 + pattern) * @cw sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch self.src_rect.set(sx, sy, @cw, @ch) end end def start_balloon dispose_balloon @balloon_duration = 8 * 8 + BALLOON_WAIT @balloon_sprite = ::Sprite.new(viewport) @balloon_sprite.bitmap = Cache.system("Balloon") @balloon_sprite.ox = 16 @balloon_sprite.oy = 32 update_balloon end def update_balloon

if @balloon_duration > 0 @balloon_duration -= 1 if @balloon_duration == 0 dispose_balloon else @balloon_sprite.x = x @balloon_sprite.y = y - height @balloon_sprite.z = z + 200 if @balloon_duration < BALLOON_WAIT sx = 7 * 32 else sx = (7 - (@balloon_duration - BALLOON_WAIT) / 8) * 32 end sy = (@balloon_id - 1) * 32 @balloon_sprite.src_rect.set(sx, sy, 32, 32) end end end def dispose_balloon if @balloon_sprite != nil @balloon_sprite.dispose @balloon_sprite = nil end end end

  Module ini membuat tampilan energi yang digunakan sebagai tolak ukur masa aktif pemain per hari. module Gauge

  VARIABLE_ID = 20

  VISIBLE_SWITCH = 20 X = 0 Y = 0 GAUGE_WIDTH = 120 GAUGE_HEIGHT = 6 GAUGE_MAX = 100 COLOUR1 = Color.new( 0, 255, 100) COLOUR2 = Color.new( 0, 255, 0) SHOW_WINDOW = true TEXT ="Energi" end class Window_GaugeDisplay < Window_Base include Gauge def initialize super(X, Y, GAUGE_WIDTH + 16, GAUGE_HEIGHT + WLH + 32) self.visible = $game_switches[VISIBLE_SWITCH] self.opacity = 0 unless SHOW_WINDOW @old_var = $game_variables[VARIABLE_ID] self.contents.draw_text(-8, -7, self.contents.width, WLH, TEXT, 1) refresh end def refresh gw = GAUGE_WIDTH * $game_variables[VARIABLE_ID] / GAUGE_MAX gc1 = COLOUR1 gc2 = COLOUR2 self.contents.fill_rect(0, 0 + WLH - 8, GAUGE_WIDTH, GAUGE_HEIGHT, gauge_back_color) self.contents.gradient_fill_rect(0, 0 + WLH - 8, gw, GAUGE_HEIGHT, gc1, gc2) end def update self.visible = $game_switches[VISIBLE_SWITCH] var = $game_variables[VARIABLE_ID] refresh if var != @old_var @old_var = var end end class Scene_Map alias :var_guage_old_start :start unless $@ alias :var_guage_old_update :update unless $@ alias :var_guage_old_terminate :terminate unless $@

def start var_guage_old_start @var_guage = Window_GaugeDisplay.new end def update var_guage_old_update @var_guage.update end def terminate var_guage_old_terminate @var_guage.dispose end end

  b. module Gold_Map modul yang memunculkan jumlah uang di interface.

  Gold_disable = 1 Posision_X = 410 Posision_Y = 333 end class Window_Gold_map < Window_Base def initialize super(0, 0, 135, 85) self.opacity = 0 refresh end def refresh self.contents.clear cx = contents.text_size($data_system.terms.gold).width self.contents.font.color = normal_color self.contents.draw_text(-20, 30, 120, 32, $game_party.gold.to_s, 2) self.contents.font.color = system_color self.contents.draw_text(100-cx, -3, cx, 32, $data_system.terms.gold, 2) end def update refresh end end class Scene_Map include Gold_Map alias falcao_gold_main main def main @gold_map = Window_Gold_map.new @gold_map.x = Posision_X

  @gold_map.y = Posision_Y if $game_switches[Gold_disable] == false @gold_map.visible = true else @gold_map.visible = false end falcao_gold_main @gold_map.dispose end alias falcao_gold_update update def update @gold_map.update if $game_switches[Gold_disable] == false @gold_map.visible = true else @gold_map.visible = false end falcao_gold_update end end