じ☆ve冰风 发表于 5 天前

KLotto VX

KLotto VX

by Kyonides Arkanthes​


Introduction

Do you recall my script Gem Roulette?

Yes, the one with the spinning wheel made out of gems!

Well, here's an interesting variant of it, this time is about the lotto!



This script can be customize up to a certain point, still, it can be used as a plug & play script as well, if you don't edit anything.

Yes, the spheres do fly!



Screenshot




NOTES

You'll need a picture that includes all the different colored spheres distributed in a single horizontal strip.
The width and the height of each individual frame cell should be identical, making it an actual square.

VX Script
                Code:       
# * KLotto VX#   Scripter : Kyonides Arkanthes#   v1.0.6 - 2019-11-19# This scriptlet will let you partake in raffles. Once the raffles are over, the# scene will change back to the current map.# * Script Calls *# $scene = KLottoShop.new#   Opens the shop with default values.# $scene = KLottoShop.new(SOME_HASH)# The following options you can use to replace SOME_HASH are optional.#   :id => 1                   - Changes the shop ID.#   :name => 'Claudia's Lotto' - Changes the shop's name.#   :cost => 25                - Changes the ticket cost.#   :prizes =>    - Changes the amount of the prize.#   :max => 5                  - Changes the number of columns aka digits.# $game_system.winner_tickets#   Array of Strings - List of previous winner tickets.# $game_party.winner_tickets#   Array of Strings - List of winner tickets the party has ever purchased.# $game_party.purchase_lotto_tickets# $game_party.purchase_lotto_tickets(Total)#   Yes, via a script call you can let the player buy some tickets.#   The Total number can be omitted, its default value is 1.# $game_party.has_lotto_ticket?(String)#   String should be a Number converted to a String by calling Number.to_s# $game_party.discard_lotto_tickets#   Forces the player to dispose of every single lotto ticket.module KLottoTICKET_ITEM_ID = 31PREVIOUS_TICKETS_MAX = 10TICKET_PRICE = 10DEFAULT_GOLD = SPHERES_MIN = 3SPHERE_WIDTH = 32 # In PixelsFIRST_SPHERE_X = 280DISCARD_AFTER_ONE_RAFFLE = true # Discard Tickets after a raffle?FILENAME = 'spheres32'SE_STARTUP = '056-Right02'GENERIC_NAME = 'Generic Lotto'PRIZES = 'Current Prizes'PARTY_GOLD = 'Your Money'WINNING_TICKET_LABEL = 'Winning Ticket'PAST_WINNING_TICKETS_LABEL = 'Past Winning Tickets'NAME_FONT_SIZE = 32WINNING_LABEL_FONT_SIZE = 24WINNING_NUMBER_FONT_SIZE = 32PREVIOUS_TICKETS_FONT_SIZE = 24PRIZE_LABEL_FONT_SIZE = 24PRIZE_FONT_SIZES = endmodule LottoSpriteModattr_accessor :numberendclass KLottoTicketdef initialize(number=nil)    @number = number || rand(10).to_s + rand(10).to_s + rand(10).to_sendattr_reader :numberendclass Game_Systemalias :kyon_lotto_gm_sys_init :initializedef initialize    kyon_lotto_gm_sys_init    @winner_tickets = []enddef tickets_maintenance    length = @winner_tickets.size - KLotto::PREVIOUS_TICKETS_MAX    length.times{ @winner_tickets.shift }endattr_reader :winner_ticketsendclass Game_Partyalias :kyon_lotto_gm_party_init :initializedef initialize    kyon_lotto_gm_party_init    @lotto_tickets = []    @winner_tickets = []enddef purchase_lotto_tickets(total=1)    return 0 if total < 1    gain_item($data_items, total)    total.times{ @lotto_tickets << KLottoTicket.new }enddef discard_lotto_tickets    gain_item(KLotto::TICKET_ITEM_ID, -@lotto_tickets.size)    @lotto_tickets.clearenddef has_lotto_ticket?(number) @lotto_tickets.include?(number) endattr_reader :lotto_tickets, :winner_ticketsendclass KLottoShopinclude KLottodef initialize(hsh={})    @id = hsh.delete(:id) || 0    @name = hsh.delete(:name) || GENERIC_NAME    @cost = hsh.delete(:cost) || TICKET_PRICE    @prizes = hsh.delete(:prizes) || DEFAULT_GOLD    @spheres_max = hsh.delete(:total) || SPHERES_MIN    @raffles_max = @prizes.size    @raffles = 0    @spheres = {}    @indexes = Array.new(@spheres_max, 0)    @radius_x = 24    @radius_y = 64    @d = 2.0 * Math::PI / @spheres_max    @moving_frames = 15    @cy = 208    @x_offset = []    @sprites = []    @gold_label = $data_system.terms.gold    @stage = :mainenddef main    @width = $HIDDENCHEST ? Graphics.width : 640    h = 36    @bg = Spriteset_Map.new    @sprites << @shop_label = Sprite.new    @shop_label.x = 120    @shop_label.y = 4    b = Bitmap.new(@width - 240, NAME_FONT_SIZE + 4)    b.font.size = NAME_FONT_SIZE    b.draw_text(b.rect, @name, 1)    @shop_label.bitmap = b    h = PRIZE_LABEL_FONT_SIZE + 4    @sprites << @prize_label = Sprite.new    @prize_label.x = @plx = @width - 208    @prize_label.y = @ply = 32    @prize_label.bitmap = b = Bitmap.new(200, h)    b.font.size = PRIZE_LABEL_FONT_SIZE    b.draw_text(b.rect, PRIZES, 1)    make_prize_labels    sprite = @sprites[-1]    @sprites << @party_gold_label = Sprite.new    @party_gold_label.x = sprite.x    @party_gold_label.y = sprite.y + h + 8    @party_gold_label.bitmap = b = Bitmap.new(200, h)    b.font.size = PRIZE_LABEL_FONT_SIZE    b.draw_text(b.rect, PARTY_GOLD, 1)    @sprites << @gold_sprite = Sprite.new    @gold_sprite.x = @party_gold_label.x    @gold_sprite.y = @party_gold_label.y + h    @gold_bitmap = Bitmap.new(200, h)    refresh_party_gold    @gold_sprite.bitmap = @gold_bitmap    @sprites << @winner_label = Sprite.new    @winner_label.x = 4    @winner_label.y = 32    @winner_label.bitmap = b = Bitmap.new(208, WINNING_LABEL_FONT_SIZE + 4)    b.font.size = WINNING_LABEL_FONT_SIZE    b.draw_text(b.rect, WINNING_TICKET_LABEL, 1)    @sprites << @winner_ticket = Sprite.new    @winner_ticket.x = 8    @winner_ticket.y = 58    @winner_bitmap = Bitmap.new(200, WINNING_NUMBER_FONT_SIZE + 4)    @winner_bitmap.font.size = WINNING_NUMBER_FONT_SIZE    @winner_ticket.bitmap = @winner_bitmap    make_past_tickets    refresh_past_tickets_list    make_spheres    Graphics.transition    loop do      Graphics.update      Input.update      update      break if $scene != self    end    Graphics.freeze    terminateenddef terminate    @spheres_max.times do |n|      @spheres.each{|s| s.dispose }    end    @spheres.clear    @sprites.each{|s| s.dispose }    @sprites.clear    @bg.dispose    $game_party.discard_lotto_ticketsenddef make_prize_labels    @raffles_max.times do |n|      h = PRIZE_FONT_SIZES      @sprites << sprite = Sprite.new      sprite.x = @plx      sprite.y = @ply - 4 + h + n * 4 + 24 * n      sprite.bitmap = bit = Bitmap.new(200, h)      bit.font.size = h      bit.draw_text(bit.rect, DEFAULT_GOLD.to_s, 1)    endenddef make_spheres    spheres = Cache.picture(FILENAME)    sh = spheres.height    @spheres_max.times do |m|      @spheres = slot = []      w = SPHERE_WIDTH * m      @x_offset << offset = m * 36      10.times do |n|      sprite = Sprite.new      sprite.extend(LottoSpriteMod)      sprite.number = n.to_s      rand(4) % 2 == 0 ? slot.push(sprite) : slot.unshift(sprite)      sprite.x = FIRST_SPHERE_X + offset - 8      sprite.y = @cy      sprite.z = 1000      sprite.bitmap = spheres.dup      sprite.bitmap.draw_text(w, 0, SPHERE_WIDTH, 24, sprite.number, 1)      sprite.src_rect.set(w, 0, SPHERE_WIDTH, sh)      end      @indexes = slot[-1].number.to_i    end    spheres.disposeenddef make_past_tickets    @sprites << @past_tickets_label = Sprite.new    @past_tickets_label.x = 8    @past_tickets_label.y = @winner_ticket.y + PREVIOUS_TICKETS_FONT_SIZE + 16    h = PREVIOUS_TICKETS_FONT_SIZE + 4    @past_tickets_label.bitmap = b = Bitmap.new(200, h)    b.draw_text(b.rect, PAST_WINNING_TICKETS_LABEL, 1)    @sprites << @past_tickets = Sprite.new    @past_tickets.x = 8    @past_tickets.y = @past_tickets_label.y + 28    @past_bitmap = Bitmap.new(200, PREVIOUS_TICKETS_MAX * 24 + 4)    @past_tickets.bitmap = @past_bitmapenddef refresh_past_tickets_list    @past_bitmap.clear    tickets = $game_system.winner_tickets    max = tickets.size    w = @past_bitmap.width    max.times{|n| @past_bitmap.draw_text(0, n * 24, w, 24, tickets, 1) }enddef refresh_party_gold    @gold_bitmap.clear    @gold_bitmap.font.size = PRIZE_LABEL_FONT_SIZE    @gold_bitmap.draw_text(@gold_bitmap.rect, $game_party.gold.to_s, 1)enddef update    if @stage == :main      update_start    elsif @stage == :spin      update_spheres    elsif @stage == :fall      update_fall    elsif @stage == :standby      update_stand_by    else      update_exit    endenddef update_start    if Input.trigger?(Input::B)      update_exit      return    elsif Input.trigger?(Input::C)      Sound.play_decision      @raffles += 1      @digits = ''      @steps = 60 + rand(40)      @stage = :spin    endenddef update_spheres    d1 = -@d / @moving_frames * 2    @spheres_max.times do |m|      col = @spheres      10.times do |n|      o = n - @indexes      d = @d * o + d1 * @steps      sx = FIRST_SPHERE_X + @x_offset - 20      sphere = col      sphere.x = sx - (@radius_x * Math.sin(d)).round      sphere.y = @cy - 60 + (@radius_y * Math.cos(d)).round      end    end    @steps -= 1    @stage = :fall if @steps == 0enddef update_fall    Audio.se_play("Audio/SE/" + SE_STARTUP, 80, 100)    @spheres_max.times do |m|      offset = @x_offset      col = @spheres      z_pos = []      10.times do |n|      z_order = rand(100)      random = rand(50) % 3      sprite = col      sprite.x = FIRST_SPHERE_X + offset - 8      sprite.y = @cy      sprite.z = 1000 + (rand(160) % 3 == 0 ? z_order : -z_order)      z_pos = sprite.z      end      sprite = col.sort{|a,b| b.z <=> a.z }      @digits += sprite.number    end    @winner_bitmap.font.size = WINNING_NUMBER_FONT_SIZE    @winner_bitmap.draw_text(@winner_bitmap.rect, @digits, 1)    @stage = :standbyenddef update_stand_by    return unless Input.trigger?(Input::B) or Input.trigger?(Input::C)    Sound.play_decision    $game_system.winner_tickets << @digits    $game_system.tickets_maintenance    refresh_past_tickets_list    @winner_bitmap.clear    if $game_party.has_lotto_ticket?(@digits)      $game_party.winning_tickets << KLottoTicket.new(@digits)      $game_party.gain_gold(@prizes[@raffles - 1])      refresh_party_gold      if DISCARD_AFTER_ONE_RAFFLE      $game_party.discard_lotto_tickets      return @stage = nil      end    end    @stage = @raffles_max > @raffles ? :main : nilenddef update_exit    Sound.play_cancel    $scene = Scene_Map.newendend


Terms & Conditions

You must include my nickname and the current website's URL in your game credits. Do not repost it anywhere else!
Free for non commercial games.


本贴来自国际rpgmaker官方论坛作者:kyonides处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/klotto-vx.115419/
页: [1]
查看完整版本: KLotto VX