Opis
Skrypt umożliwia nam wędkowanie - najpierw wybieramy oś poziomą, a potem zarzucamy wędkę z odpowiednią siłą. Jeśli trafimy w rybę - mamy ją!
Info
Autor: Omegas7
Tłmaczenie: Angius
Skrypt
Spoiler:
Kod:
# =============================================================================
# Fishing MiniGame
# Version: 1.0
# Author: Omegas7
# Blog: http://omegas7.blogspot.com || http://omegadev.biz
# -----------------------------------------------------------------------------
# Features:
# [1.0]
# > Background & water surface images
# > Water surface & fish have wave effect
# > Aim with cursor image right & left
# > Calculate strength with power meter & cursor
# > Throw hook, if a fish is on landing area, catch.
# > Multiple configurable sound effects
# > Multiple configurable images
# > Fish catching limit per session through variable (or infinite)
# > Caught fish listing on end of session
# > Configurable speed of power cursor & hook
# > Link fish objects in script with items from database
# > Receive items (fish)
# > Fish become available through a game switch
# > Edit chances of appearance for fish
# > Accurate movement speed (decimal numbers) for fish
# -----------------------------------------------------------------------------
# NOTES
# > When going to use the script, you need MINIMUN one fish available
# (it's game switch ON)
# =============================================================================
module OmegaX
module Fishing
SessionFishLimitVariableID = 1
# ID zmiennej przechowującej maksymalną ilość ryb do złowienia.
# Jeśli zmienna równa lub mniejsza 0, brak limitu.
# Fishes[ID] = ["Grafika",ID przedmiotu,SID switcha,Prędkość,Szansa]
# Chances = im wyżej, tym większa szansa
Fishes[0] = ["Fish01", 1, 1, 0.6, 3]
Fishes[1] = ["Fish02", 2, 2, 0.4, 3]
Fishes[2] = ["Fish03", 3, 3, 0.2, 2]
end
end
class OmegaFishing < Scene_Base
include OmegaX::Fishing
def initialize
createArea
createCursor
createPossibleList
@fishes = []
@timer = [0,SpawningIntervals[rand(SpawningIntervals.size)]]
@mode = "NOTHING"
@pointerGoing = "RIGHT"
@hookDistanceLeft = 0
@animation = Sprite_Base.new
@messages = []
@limit = $game_variables[SessionFishLimitVariableID]
executeSpawn
executeSpawn
@fix = false
@caught = []
@finished = false
end
def finish
@finished = true
@finishWindow = Window_Base.new(100,50,544 - 200,416 - 100)
@finishWindow.contents.font.size = 18
@finishWindow.contents.draw_text(0,0,344,20,"Caught fish:")
kinds = {}
for i in 0...@caught.size
if !kinds.keys.include?(@caught[i])
kinds[@caught[i]] = 0
end
kinds[@caught[i]] += 1
end
for i in 0...kinds.keys.size
@finishWindow.contents.draw_text(0,40 + (18 * i),344,20,$data_items[kinds.keys[i]].name + " x " + kinds[kinds.keys[i]].to_s)
end
end
def update
@animation.update if @animation.animation?
@water.update
updateFishMovement
for i in 0...@messages.size
@messages[i].y -= 2
@messages[i].opacity -= 2
if @messages[i].opacity <= 0
@messages[i].dispose
@messages[i] = nil
end
end
@messages.compact!
if !@finished
@timer[0] += 1
if @timer[0] >= @timer[1]
@timer[0] = 0
@timer[1] = SpawningIntervals[rand(SpawningIntervals.size)]
executeSpawn
end
updateCursor if @mode == "NOTHING"
updatePointer if @mode == "POWERING"
updateHook if @mode == "THROWING"
if Input.trigger?(Input::B)
finish
end
else
if Input.trigger?(Input::B)
@finishWindow.dispose
for i in 0...@messages.size
@messages[i].dispose
@messages[i] = nil
end
@messages.compact!
@water.dispose
@animation.dispose
for i in 0...@fishes.size
@fishes[i][0].dispose
@fishes[i] = nil
end
@fishes.compact!
@hook.dispose if @hook != nil
@powerBar.dispose if @powerBar != nil
@powerPointer.dispose if @powerPointer != nil
@cursor.dispose
@bg.dispose
for i in 0...@caught.size
$game_party.gain_item($data_items[@caught[i]], 1)
end
$scene = Scene_Map.new
end
end
end
def catch(obtained,x,y,fish = 0,id = 0)
@messages.push(Sprite_Base.new)
if obtained
Audio.se_play("Audio/SE/" + CatchSoundEffect)
@caught.push(id)
@messages[@messages.size - 1].bitmap = Cache.picture(CatchMessage)
@fishes[fish][0].dispose
@fishes[fish] = nil
else
Audio.se_play("Audio/SE/" + MissSoundEffect)
@messages[@messages.size - 1].bitmap = Cache.picture(MissMessage)
end
@fishes.compact!
@messages[@messages.size - 1].x = x
@messages[@messages.size - 1].y = y
@messages[@messages.size - 1].z = 20
@mode = "NOTHING"
@hook.dispose
@hook = nil
@powerPointer.dispose
@powerPointer = nil
@powerBar.dispose
@powerBar = nil
if @limit > 0 # Limited catchable fish
if @caught.size >= @limit
finish
end
end
end
def updateFishMovement
for i in 0...@fishes.size
@fishes[i][2] += Fishes[@fishes[i][1]][3]
while @fishes[i][2] >= 1.0
@fishes[i][2] -= 1.0
@fishes[i][0].x += 1
end
@fishes[i][0].update
end
end
def updateCursor
if Input.press?(Input::RIGHT)
@cursor.x += 3 if @cursor.x + @cursor.width < 544
end
if Input.press?(Input::LEFT)
@cursor.x -= 3 if @cursor.x > 0
end
if Input.trigger?(Input::C) && @mode == "NOTHING"
@mode = "POWERING"
@powerBar = Sprite_Base.new
@powerBar.bitmap = Cache.picture(PowerBar)
@powerBar.z = 10
@powerPointer = Sprite_Base.new
@powerPointer.bitmap = Cache.picture(PowerPointer)
@powerPointer.z = 11
@fix = false
return
end
end
def updatePointer
case @pointerGoing
when "RIGHT"
@powerPointer.x += PowerPointerSpeed
if @powerPointer.x + @powerPointer.width >= 544
@pointerGoing = "LEFT"
end
when "LEFT"
@powerPointer.x -= PowerPointerSpeed
if @powerPointer.x < 0
@pointerGoing = "RIGHT"
end
end
if Input.trigger?(Input::C) && @mode == "POWERING" && @fix
Audio.se_play("Audio/SE/" + ThrowSoundEffect)
@mode = "THROWING"
@hook = Sprite_Base.new
@hook.bitmap = Cache.picture(ThrowHook)
@hook.z = 12
@hook.x = (@cursor.x + (@cursor.width/2)) - @hook.width/2
@hook.y = @cursor.y
@hookDistanceLeft = (416.0 * (@powerPointer.x/544.0)).abs
return
end
@fix = true
end
def updateHook
if @hookDistanceLeft > 0
@hook.y -= HookThrownSpeed
@hookDistanceLeft -= HookThrownSpeed
else
playSplash(@hook.x,@hook.y)
hookRect = Rect.new(@hook.x,@hook.y,@hook.width,@hook.height)
for i in 0...@fishes.size
fishRect = Rect.new(@fishes[i][0].x,@fishes[i][0].y,@fishes[i][0].width,@fishes[i][0].height)
if hookRect.intersects?(fishRect)
catch(true,@hook.x,@hook.y,i,Fishes[@fishes[i][1]][1])
return
end
end
catch(false,@hook.x,@hook.y)
end
end
def playSplash(x,y)
@animation.x = x
@animation.y = y
@animation.start_animation($data_animations[WaterSplashAnimationID])
end
def executeSpawn
@fishes.push([Sprite_Base.new,@possibleFishes[rand(@possibleFishes.size)],0.0])
id = @fishes.size - 1
@fishes[id][0].bitmap = Cache.picture(Fishes[@fishes[id][1]][0])
@fishes[id][0].z = 1
@fishes[id][0].x = -(@fishes[id][0].width)
@fishes[id][0].y = rand(416) - 100
@fishes[id][0].wave_amp = 8
@fishes[id][0].wave_length = 300
@fishes[id][0].wave_speed = 200
end
def createArea
@bg = Sprite_Base.new
@bg.bitmap = Cache.picture(FishingBackground)
@bg.z = 0
@water = Sprite_Base.new
@water.bitmap = Cache.picture(WaterSurface)
@water.z = 2
@water.x = (544/2) - (@water.width/2)
@water.wave_amp = 8
@water.wave_length = 240
@water.wave_speed = 120
end
def createCursor
@cursor = Sprite_Base.new
@cursor.bitmap = Cache.picture(FishingAim)
@cursor.z = 10
@cursor.x = (544/2) - (@cursor.width/2)
@cursor.y = 416 - (@cursor.height/2)
end
def createPossibleList
@possibleFishes = []
for i in 0...Fishes.size
if $game_switches[Fishes[i][2]]
chances = Fishes[i][4]
while chances > 0
@possibleFishes.push(i)
chances -= 1
end
end
end
end
end
# Lol I still have this snippet BigEd did once :P
class Rect
def intersects?( rect )
return ((((rect.x < (self.x + self.width)) && (self.x < (rect.x + rect.width))) && (rect.y < (self.y + self.height))) && (self.y < (rect.y + rect.height)))
end
end
Konfig
To opiszę chyba tylko dodawanie ryb. Są to linijki od 56-tej:
ID - numer porządkowy ryby
Grafika - ścieżka dio graphics/pictures gdzie grafika ryby się znajduje
ID przedmiotu - ID przedmiotu, który dostajemy po złowieni ryby
ID switcha - ID switcha aktywowanego po złowieniu
Prędkość - prędkość z jaką płynie ryba
Szansa - szansa z jaką pojawi się na łowisku
Skriny:
Z tego co widzę w demie, można także ustawić zmienną na ile można złowić maksymalnie ryb przy jednym połowie ryb.
Numer zmiennej jest w skrypcie pod komendą:
SessionFishLimitVariableID = 1
Nie możesz pisać nowych tematów Nie możesz odpowiadać w tematach Nie możesz zmieniać swoich postów Nie możesz usuwać swoich postów Nie możesz głosować w ankietach Nie możesz załączać plików na tym forum Możesz ściągać załączniki na tym forum