Go Back   The PokéCommunity Forums > Creative Discussions > Game Development > Scripts & Tutorials
Reload this Page [Essentials script] Egg Hatch Animation

Notices
For all updates, view the main page.

Scripts & Tutorials This forum is for scripts and code, as well as all kinds of tutorials, software, tools and so forth. Remember to give credit!
The thread revival limit does not apply here.



Reply
 
Thread Tools
  #1    
Old August 20th, 2014 (05:23 AM).
FL's Avatar
FL
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Code:
#===============================================================================
# * Egg Hatch Animation - by FL (Credits will be apreciated)
#===============================================================================
#
# This script is for Pokémon Essentials. It's a egg hatch animation that
# works even with special eggs like Manaphy egg.
#
#===============================================================================
#
# To this script works, put it above main and put a picture (a 5 frames
# sprite sheet) with egg sprite height and 5 times the egg sprite width at
# Graphics/Pictures/hatchsheet.
#
#===============================================================================

class PokemonEggHatchScene
  def pbStartScene(pokemon)
    @sprites={} 
    @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
    @viewport.z=99999
    @pokemon=pokemon
    @pokemon.eggsteps=1 # Just for drawing the egg
    addBackgroundOrColoredPlane(@sprites,"background","evolutionbg",
       Color.new(248,248,248),@viewport)
    @sprites["pokemon"]=PokemonSprite.new(@viewport)
    @sprites["pokemon"].setPokemonBitmap(@pokemon)
    @sprites["pokemon"].x=Graphics.width/2-@sprites["pokemon"].bitmap.width/2
    @sprites["pokemon"].y=Graphics.height/2-@sprites["pokemon"].bitmap.height/2
    @sprites["hatch"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
    @sprites["msgwindow"]=Kernel.pbCreateMessageWindow(@viewport)
    @sprites["overlay"]=BitmapSprite.new(
        Graphics.width,Graphics.height,@viewport)
    @sprites["overlay"].z=200
    @sprites["overlay"].bitmap = Bitmap.new(Graphics.width,Graphics.height)
    @sprites["overlay"].bitmap.fill_rect(0,0,Graphics.width,Graphics.height,
        Color.new(255,255,255))
    @sprites["overlay"].opacity = 0
    # Initialize the pokémon
    @pokemon.eggsteps=0
    @pokemon.name=PBSpecies.getName(@pokemon.species)
    @pokemon.trainerID=$Trainer.id
    @pokemon.ot=$Trainer.name
    @pokemon.happiness=120
    @pokemon.timeEggHatched=pbGetTimeNow
    @pokemon.obtainMode=1 # hatched from egg
    @pokemon.hatchedMap=$game_map.map_id
    pbFadeInAndShow(@sprites)
  end

  def pbMain
    hatchSheet=AnimatedBitmap.new(_INTL("Graphics/Pictures/hatchsheet"))
    pbBGMPlay("evolv")
    # Egg animation
    updateScene(60)
    pbPositionHatchMask(hatchSheet,0)
    pbSEPlay("ballshake")
    swingEgg(2)
    updateScene(12)
    pbPositionHatchMask(hatchSheet,1)
    pbSEPlay("ballshake")
    swingEgg(2)
    updateScene(24)
    pbPositionHatchMask(hatchSheet,2)
    pbSEPlay("ballshake")
    swingEgg(4,2)
    updateScene(6)
    pbPositionHatchMask(hatchSheet,3)
    pbSEPlay("ballshake")
    swingEgg(8,4)
    updateScene(6)
    pbPositionHatchMask(hatchSheet,4)
    pbSEPlay("recall")
    # Fade and change the sprite
    fadeSpeed=15
    for i in 1..(255/fadeSpeed)
      @sprites["overlay"].opacity=i*fadeSpeed
      updateScene
    end  
    updateScene(40)
    @sprites["pokemon"].setPokemonBitmap(@pokemon)
    @sprites["hatch"].visible=false
    for i in 1..(255/fadeSpeed)
      @sprites["overlay"].opacity=255-i*fadeSpeed
      updateScene
    end
    # Finish scene
    frames=pbCryFrameLength(@newspecies)
    pbBGMStop()
    pbPlayCry(@pokemon)
    frames.times do
      Graphics.update
    end
    pbMEPlay("004-Victory04")
    speciesname = @pokemon.name
    Kernel.pbMessageDisplay(@sprites["msgwindow"],
       _INTL("\\se[]{1} hatched from the Egg!\\wt[80]",speciesname))
    $Trainer.seen[@pokemon.species]=true
    $Trainer.owned[@pokemon.species]=true
    pbSeenForm(@pokemon)
    if Kernel.pbConfirmMessage(
        _INTL("Would you like to nickname the newly hatched {1}?",speciesname))
      nickname=pbEnterText(_INTL("{1}'s nickname?",speciesname),0,10)
      pokemon.name=nickname if nickname!=""
    end
    @sprites["msgwindow"].text=""
  end
  
  def pbPositionHatchMask(hatchSheet,index)
    frames = 5
    frameWidth = hatchSheet.width/frames
    rect = Rect.new(frameWidth*index,0,frameWidth,hatchSheet.height)
    @sprites["hatch"].bitmap.blt(@sprites["pokemon"].x,@sprites["pokemon"].y,
        hatchSheet.bitmap,rect)
  end  
      
  def swingEgg(speed,swingTimes=1) # Only accepts 2, 4 or 8 for speed.
    limit = 8
    targets = [@sprites["pokemon"].x-limit,@sprites["pokemon"].x+limit,
        @sprites["pokemon"].x]
    swingTimes.times do   
      usedSpeed=speed
      for target in targets
        usedSpeed*=-1    
        while(target != @sprites["pokemon"].x)
          @sprites["pokemon"].x+=usedSpeed
          @sprites["hatch"].x+=usedSpeed
          updateScene
        end  
      end
    end
  end  

  def updateScene(frames=1) # Can be used for "wait" effect
    frames.times do
      Graphics.update
      Input.update
      self.update
    end
  end  
  
  def update
    pbUpdateSpriteHash(@sprites)
  end
  
  def pbEndScene
    Kernel.pbDisposeMessageWindow(@sprites["msgwindow"])
    pbFadeOutAndHide(@sprites) { update }
    pbDisposeSpriteHash(@sprites)
    @viewport.dispose
  end
end

class PokemonEggHatchScreen
  def initialize(scene)
    @scene=scene
  end

  def pbStartScreen(pokemon)
    @scene.pbStartScene(pokemon)
    @scene.pbMain
    @scene.pbEndScene
  end
end

def pbHatch(pokemon)
  Kernel.pbMessage(_INTL("Huh?\1"))
  pbFadeOutIn(99999) {
    scene=PokemonEggHatchScene.new
    screen=PokemonEggHatchScreen.new(scene)
    screen.pbStartScreen(pokemon)
  }
end
Attached Thumbnails
hatchsheet.png‎   egghatchscreen.png‎  
__________________
Reply With Quote
  #2    
Old August 20th, 2014 (12:33 PM).
Lexxilion's Avatar
Lexxilion
 
Join Date: Jul 2014
Gender: Male
Nature: Careful
I'm looking forward to using this and testing it out =] You are better equipped for this than me =]
Reply With Quote
  #3    
Old September 27th, 2014 (08:07 AM).
xTHx
 
Join Date: Dec 2013
Gender: Male
Hey FL!
You script have an error on the line 51, and that makes the game end.
Reply With Quote
  #4    
Old September 27th, 2014 (08:30 AM).
mej71's Avatar
mej71
 
Join Date: Mar 2014
Location: Omnipresence
Gender: Male
Quote originally posted by xTHx:
Hey FL!
You script have an error on the line 51, and that makes the game end.
Nope, that'd be the forum's formatting that messes up code. Click Thread Tools, and then Show Printable Version, and copy that instead.
Reply With Quote
  #5    
Old September 28th, 2014 (01:16 PM).
Drimer's Avatar
Drimer
Admón
 
Join Date: Aug 2014
Location: In my house :b
Gender: Male
Nature: Calm
Send a message via Skype™ to Drimer
Pokémon Essentials does not include a hatch anim?
When i test ur code i'll edit my message
Reply With Quote
  #6    
Old October 2nd, 2014 (04:12 AM).
FL's Avatar
FL
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Quote originally posted by Drimer:
Pokémon Essentials does not include a hatch anim?
When i test ur code i'll edit my message
Few hours after your post, Essentials v14 came with this script integrated.
__________________
Reply With Quote
  #7    
Old December 30th, 2014 (04:10 AM).
Jacopo Mii
 
Join Date: May 2014
Gender: Male
How can I change the script to use a different image for the egg?
Reply With Quote
  #8    
Old December 30th, 2014 (07:14 AM).
Savordez's Avatar
Savordez
Life? Interesting, tell me more
 
Join Date: Dec 2013
Location: dunno
Gender: Male
Nature: Relaxed
If you're using essentials v14, the egg sprite can be found in Battlers\egg.png.
__________________
Reply With Quote
  #9    
Old December 30th, 2014 (10:38 AM).
Jacopo Mii
 
Join Date: May 2014
Gender: Male
Yes, I already know this
But I would like to use a different egg image only for this script, because my egg sprite is an animated gif and it is bad for this animation...
How can I do?
Reply With Quote
  #10    
Old January 12th, 2015 (06:50 AM).
Jacopo Mii
 
Join Date: May 2014
Gender: Male
Up (I am violating the rules of the forum? If yes, sorry )
Reply With Quote
  #11    
Old January 13th, 2015 (03:08 PM).
FL's Avatar
FL
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Quote originally posted by Jacopo Mii:
Yes, I already know this
But I would like to use a different egg image only for this script, because my egg sprite is an animated gif and it is bad for this animation...
How can I do?
Change first line '@sprites["pokemon"].setPokemonBitmap(@pokemon)' into '@sprites["pokemon"].bitmap=BitmapCache.load_bitmap("Graphics/Battlers/490egg")' (change for your egg path). You can change the image loaded checking @pokemon variable attributes (like @pokemon.species).
__________________
Reply With Quote
  #12    
Old January 18th, 2015 (04:09 AM).
Enigmatic Emolga's Avatar
Enigmatic Emolga
L'énigmatique
 
Join Date: Oct 2012
Location: Somewhere in England
Gender: Male
Nature: Naive
After an egg hatches, the BGM of the map the player is in doesn't start playing again unless the player leaves and re-enters the map. Any way to fix this?
__________________
Emolga: The Sky Squirrel Pokémon

Black: The energy made in its cheeks' electric pouches is stored inside its membranes and released while it is gliding.
White: They live on treetops and glide using the inside of a cape-like membrane while discharging electricity.

Youtube
deviantArt
Reply With Quote
  #13    
Old January 18th, 2015 (04:36 AM).
FL's Avatar
FL
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
Quote originally posted by Enigmatic Emolga:
After an egg hatches, the BGM of the map the player is in doesn't start playing again unless the player leaves and re-enters the map. Any way to fix this?
After line 'def pbEndScene' add line '$game_map.autoplay'.
__________________
Reply With Quote
Reply
Quick Reply

Sponsored Links
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are UTC -8. The time now is 10:58 PM.