O TEMA DO FÓRUM ESTÁ EM MANUTENÇÃO. FEEDBACKS AQUI: ACESSAR

Minigame - Quicar a Bola

Iniciado por RD12, 15/02/2013 às 14:34

Minigame de Quicar a Bola
Esse minigame é de quicar a bola com o mouse, se a bola cair no chão, você perde, quanto mais tempo quicando ela, mais pontos você consegue. No final os pontos são convertidos em moedas ou experiência.
Foi usado um script de mouse feito por mim.


Imagens

Spoiler


[close]

Mouse

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#|Autor: RD12|              Mouse System
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#$Mouse.icon_drag = "Picture" #Poe um icone em baixo do mouse
#como se estivesse arrastando.
#$Mouse.icon_cursor = "Picture" #Muda o cursor do mouse

class Game_Mouse
  
  attr_accessor :x
  attr_accessor :y
  attr_accessor :icon_cursor
  attr_accessor :icon_drag
  attr_accessor :left
  attr_accessor :map_x
  attr_accessor :map_y
  def initialize
    Win32API.new("user32", "ShowCursor", "i", "i" ).call(0)
    @x = 0
    @y = 0
    @map_x = 0
    @map_y = 0
    @pos = 0
    @icon_cursor = "Cursor"
    @icon_drag = ""
    @cursor = Sprite.new
    @cursor.z = 999999999
    @cursor_drag = Sprite.new
    @cursor_drag.z = 999999998
    @left_up = false
    @click_count = 0
    #Windows API's
    @GetCursorPos = Win32API.new("user32", "GetCursorPos", ['P'], 'V')
    @ScrToClt = Win32API.new('user32', 'ScreenToClient', ['l','p'], 'i')
    @GPPS = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
    @FindWindow = Win32API.new('user32', 'FindWindowA', ['p', 'p'], 'l')
    @x_count = 0
  end
  
  def update
    @x_count += 1
    if @x_count == 3
     @old_x = @x
     @old_y = @y
     @x_count = 0
   end
    @cursor.bitmap = RPG::Cache.icon(@icon_cursor)
    @cursor_drag.z = 1
    @cursor_drag.bitmap = RPG::Cache.icon(@icon_drag)
    @x, @y = scr_to_cl(*global_pos)
    return if @x.nil? or @y.nil?
    @cursor.x, @cursor.y = @x, @y
  end
      
  def left_press
   if Win32API.new("user32", "GetAsyncKeyState", "i", "i").call(1) != 0
     return true
   else
     return false
   end
  end
  
  def right_press
   if Win32API.new("user32", "GetAsyncKeyState", "i", "i").call(2) != 0
     return true
   else
     return false
   end
  end

  def global_pos
    lpp = " " * 8
    @GetCursorPos.Call(lpp)
    x, y = lpp.unpack("LL")
    return x, y
  end
  
   def scr_to_cl(x, y)
    return nil unless x and y
    pos = [x, y].pack('ll')
    if @ScrToClt.call(win_h, pos) != 0
      return pos.unpack('ll')
    else
      return nil
    end
  end
  
  def win_h
    game_name = "\0" * 256
    @GPPS.call('Game','Title','',game_name,255,".\\Game.ini")
    game_name.delete!("\0")
    return @FindWindow.call('RGSS Player',game_name)
  end
     
  def in_area?(x, y, w, h)
    return if @x.nil? or @y.nil?
    if ($Mouse.x >= x and $Mouse.x <= (x+w)) and ($Mouse.y >= y and $Mouse.y <= (y+h))
      return true
    else
      return false
    end
  end
  
end


Minigame

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#Author: RD12           Minigame de quicar a bola
#------------------------------------------------------------------
#Para iniciar o jogo chame o script: $scene = Scene_BallGame.new
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

module Config_BallGame
  #==O valor que irá ganhar é igual ao número vezes a pontuação==
  Ganhar_Moedas = [true,10]#true para ganhar, número
  Ganhar_XP = [true,5]#true para ganhar, número
  #Tempo para aumentar o ponto
  Time_Ponto = 60
  Fundo = "001-Title01"
  #Física
  Gravidade = 12
  Atrito = 0.9
end

class Scene_BallGame
   def main
     @sprite = Sprite.new
     @sprite.bitmap = RPG::Cache.title(Config_BallGame::Fundo)
     @Ball = Ball_Minigame.new
     @Hud_Ball = Hud_Ball.new
     $Mouse = Game_Mouse.new
     @count = 0
    Graphics.transition
    loop do
      $Mouse.update
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @sprite.bitmap.dispose
    @sprite.dispose
    @Hud_Ball.dispose
    @Ball.dispose
   end
   
   def update
    @count += 1
    if !$perdeu and @count == Config_BallGame::Time_Ponto
      $pontos += 1
      @count = 0
    end
     @Hud_Ball.refresh
    if Input.trigger?(Input::C)
      $start_ball = true
      $scene = Scene_Map.new if $perdeu
    end
    
    @Ball.update
   end
end
class Ball_Minigame < Sprite
  def initialize
    super()
    self.bitmap = Bitmap.new(92,92)
    self.x = 640/2-45
    self.y = 50
    self.z = 10
    @grav = Config_BallGame::Gravidade
    @atrito = Config_BallGame::Atrito
    @vel_y = 0
    @vel_x = 0
    @ball = RPG::Cache.picture("Ball")
    $start_ball = false
  end
  
  def update
    self.bitmap.clear
    self.bitmap.blt(0, 0, @ball, Rect.new(0, 0, @ball.width, @ball.height))
    return unless $start_ball
    fisica
    if $Mouse.left_press and !$perdeu
      if $Mouse.in_area?(self.x,self.y, 44, 92)
        @vel_x = 5 * @grav
        @vel_y = -15 * @grav
      end
      if $Mouse.in_area?(self.x+45,self.y+40, 40, 40)
        @vel_x = -5 * @grav
        @vel_y = -15 * @grav
      end 
    end 
  end
  
  def fisica
    @vel_y += @grav
    @vel_x += 0
    self.x += @vel_x/10
    self.y += @vel_y/10
    if self.y >= 480-90
      return if @vel_y < 0
      @vel_y *= -@atrito
      $perdeu = true
    end
    if self.y <= 0
      @vel_y = 20
    end
    if self.x >= 640-90
      return if @vel_x < 0
      @vel_x *= -@atrito
    end
    if self.x <= 0
      @vel_x *= -@atrito
    end
  end
end

class Hud_Ball < Sprite
  
  def initialize
    super()
    self.bitmap = Bitmap.new(640,100)
    self.x = 0
    self.y = 10
    self.z = 10
    $pontos = 0
    @count = 0
   end
  
  def refresh
    self.bitmap.clear
    unless $start_ball
      self.bitmap.draw_text(0,0,640,25,"Aperte Enter para começar",1)
    else
      self.bitmap.draw_text(0,0,640,25,"Pontuação: #{$pontos}",1)
    end
    if $perdeu
      self.bitmap.draw_text(0,40,640,25,"Você deixou a bola cair - Enter para voltar",1)
      @ganhou = ""
      if Config_BallGame::Ganhar_Moedas[0]
        @ganhou += " #{$pontos*Config_BallGame::Ganhar_Moedas[1]} Moedas e"
      end
      if Config_BallGame::Ganhar_XP[0]
        @ganhou += " #{$pontos*Config_BallGame::Ganhar_XP[1]} Exp"
      end
      self.bitmap.draw_text(0,60,640,25,"Ganhou: #{@ganhou}",1)
      
    end
  end 
end


Imagens necessários:
Ball - Pasta Pictures

http://i.imgur.com/agCfGDv.png
Cursor - Pasta Icons

http://i.imgur.com/GvrQBHd.png

Créditos: RD12

Oh esse é um mini-game interessante xD, o único tenso é que é RMXP a única engine que estou sem aqui no momento D:, vou baixar assim que der, eu me lembro desse joguinho em vários sites cujo tem que esperar carregar algo u_u, pelo code você usou umas coisas de gravidade e talz, parece interessante.