赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 1 |
经验 | 2860 |
最后登录 | 2016-6-18 |
在线时间 | 8 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 8 小时
- 注册时间
- 2008-5-1
- 帖子
- 236
|
4楼

楼主 |
发表于 2008-8-13 18:32:16
|
只看该作者
- #==============================================================================
- # ** Game_Player
- #------------------------------------------------------------------------------
- # This class handles the player. Its functions include event starting
- # determinants and map scrolling. Refer to "$game_player" for the one
- # instance of this class.
- #==============================================================================
- def pbAddDependency(event)
- $game_player.addDependentEvent(event)
- end
- def pbRemoveDependency(event)
- $game_player.removeDependentEvent(event)
- end
- def pbTurnTowardEvent(event,otherEvent)
- sx = event.x - otherEvent.x
- sy = event.y - otherEvent.y
- if sx == 0 and sy == 0
- return
- end
- if sx.abs > sy.abs
- sx > 0 ? event.turn_left : event.turn_right
- else
- sy > 0 ? event.turn_up : event.turn_down
- end
- if event.is_a?(Game_Event)
- $PokemonMap.addMovedEvent(event.id)
- end
- end
- def pbMoveBehindEvent(leader,follower)
- d=leader.direction
- newX = leader.x + (d == 6 ? -1 : d == 4 ? 1 : 0)
- newY = leader.y + (d == 2 ? -1 : d == 8 ? 1 : 0)
- if follower.x!=newX || follower.y!=newY
- follower.moveto(newX,newY)
- end
- case leader.direction
- when 2 # down
- follower.turn_down
- when 4 # left
- follower.turn_left
- when 6 # right
- follower.turn_right
- when 8 # up
- follower.turn_up
- end
- if follower.is_a?(Game_Event)
- $PokemonMap.addMovedEvent(follower.id)
- end
- end
- def pbFollowEvent(leader,follower)
- d=leader.direction
- newX = leader.x + (d == 6 ? -1 : d == 4 ? 1 : 0)
- newY = leader.y + (d == 2 ? -1 : d == 8 ? 1 : 0)
- posX = newX + (d == 6 ? -1 : d == 4 ? 1 : 0)
- posY = newY + (d == 2 ? -1 : d == 8 ? 1 : 0)
- if follower.x-newX==-1 && follower.y==newY
- follower.move_right
- elsif follower.x-newX==1 && follower.y==newY
- follower.move_left
- elsif follower.y-newY==-1 && follower.x==newX
- follower.move_down
- elsif follower.y-newY==1 && follower.x==newX
- follower.move_up
- elsif follower.x!=posX || follower.y!=posY
- follower.moveto(posX,posY)
- case leader.direction
- when 2 # down
- follower.move_down
- when 4 # left
- follower.move_left
- when 6 # right
- follower.move_right
- when 8 # up
- follower.move_up
- end
- end
- if follower.is_a?(Game_Event)
- $PokemonMap.addMovedEvent(follower.id)
- end
- end
- def pbFollowEventJumping(leader,follower)
- d=leader.direction
- newX = leader.x + (d == 6 ? -1 : d == 4 ? 1 : 0)
- newY = leader.y + (d == 2 ? -1 : d == 8 ? 1 : 0)
- posX = newX + (d == 6 ? -1 : d == 4 ? 1 : 0)
- posY = newY + (d == 2 ? -1 : d == 8 ? 1 : 0)
- if follower.x-newX==-1 && follower.y==newY
- follower.jump(1,0)
- return
- elsif follower.x-newX==1 && follower.y==newY
- follower.jump(-1,0)
- return
- elsif follower.y-newY==-1 && follower.x==newX
- follower.jump(0,1)
- return
- elsif follower.y-newY==1 && follower.x==newX
- follower.jump(0,-1)
- return
- elsif follower.x!=posX || follower.y!=posY
- follower.moveto(posX,posY)
- end
- case leader.direction
- when 2 # down
- follower.jump(0,1)
- when 4 # left
- follower.jump(-1,0)
- when 6 # right
- follower.jump(1,0)
- when 8 # up
- follower.jump(0,-1)
- end
- if follower.is_a?(Game_Event)
- $PokemonMap.addMovedEvent(follower.id)
- end
- end
- class Game_Player < Game_Character
- def map
- @map=nil
- return $game_map
- end
- #--------------------------------------------------------------------------
- # * Invariables
- #--------------------------------------------------------------------------
- def initialize(*arg)
- super(*arg)
- @lastdir=0
- @lastdirframe=0
- end
- def pbHasDependentEvents?
- return @dependentEvents && (@dependentEvents.length>0)
- end
- def addDependentEvent(event)
- @dependentEvents=[] if !@dependentEvents
- for i in [email protected]
- if @dependentEvents[i][0]==$game_map.map_id&&
- @dependentEvents[i][1]==event.id
- # Already exists
- return
- end
- end
- @dependentEvents.push([$game_map.map_id,event.id,event.through])
- event.through=true
- end
- def removeDependentEvent(event)
- if @dependentEvents
- mapid=$game_map.map_id
- for i in [email protected]
- if @dependentEvents[i][0]==mapid &&
- @dependentEvents[i][1]==event.id
- event.through=@dependentEvents[i][2]
- @dependentEvents[i]=nil
- end
- end
- @dependentEvents.compact!
- end
- end
- def updateDependentEvents
- if @dependentEvents
- for i in [email protected]
- @dependentEvents[i]=nil if @dependentEvents[i][0]!=$game_map.map_id
- end
- @dependentEvents.compact!
- end
- end
- def getDependentEvent(evt)
- event=$game_map.events[evt[1]]
- if event
- event.through=true
- end
- return event
- end
- def move_down(turn_enabled = true)
- if turn_enabled
- turn_down
- end
- pbBridgeCheck(2)
- if passable?(@x, @y, 2)
- return if pbLedge(0,1)
- return if pbEndSurf(0,1)
- turn_down
- @y += 1
- pbMoveDependentEvents
- increase_steps
- else
- if !check_event_trigger_touch(@x, @y+1)
- Audio.se_play("Audio/SE/bump.wav")
- end
- end
- end
- def move_left(turn_enabled = true)
- if turn_enabled
- turn_left
- end
- pbBridgeCheck(4)
- if passable?(@x, @y, 4)
- return if pbLedge(-1,0)
- return if pbEndSurf(-1,0)
- turn_left
- @x -= 1
- pbMoveDependentEvents
- increase_steps
- else
- if !check_event_trigger_touch(@x-1, @y)
- Audio.se_play("Audio/SE/bump.wav")
- end
- end
- end
- def move_right(turn_enabled = true)
- if turn_enabled
- turn_right
- end
- pbBridgeCheck(6)
- if passable?(@x, @y, 6)
- return if pbLedge(1,0)
- return if pbEndSurf(1,0)
- turn_right
- @x += 1
- pbMoveDependentEvents
- increase_steps
- else
- if !check_event_trigger_touch(@x+1, @y)
- Audio.se_play("Audio/SE/bump.wav")
- end
- end
- end
- def move_up(turn_enabled = true)
- if turn_enabled
- turn_up
- end
- pbBridgeCheck(8)
- if passable?(@x, @y, 8)
- return if pbLedge(0,-1)
- return if pbEndSurf(0,-1)
- turn_up
- @y -= 1
- pbMoveDependentEvents
- increase_steps
- else
- if !check_event_trigger_touch(@x, @y-1)
- Audio.se_play("Audio/SE/bump.wav")
- end
- end
- end
- def pbMoveDependentEvents
- return if !@dependentEvents
- updateDependentEvents
- leader=self
- for evt in @dependentEvents
- event=getDependentEvent(evt)
- if event
- pbFollowEvent(leader,event)
- leader=event
- end
- end
- end
- def pbJumpDependentEvents
- return if !@dependentEvents
- updateDependentEvents
- leader=self
- for evt in @dependentEvents
- event=getDependentEvent(evt)
- if event
- pbFollowEventJumping(leader,event)
- leader=event
- end
- end
- end
- def pbTurnDependentEvents
- return if !@dependentEvents
- updateDependentEvents
- leader=self
- for evt in @dependentEvents
- event=getDependentEvent(evt)
- if event
- pbTurnTowardEvent(event,leader)
- leader=event
- end
- end
- end
- def pbTriggeredTrainerEvents(triggers,checkIfRunning=true)
- result = []
- # If event is running
- if checkIfRunning && $game_system.map_interpreter.running?
- return result
- end
- # All event loops
- for event in $game_map.events.values
- next if !event.name[/^Trainer\((\d+)\)$/]
- distance=$~[1].to_i
- # If event coordinates and triggers are consistent
- if pbEventCanReachPlayer?(event,self,distance) and triggers.include?(event.trigger)
- # If starting determinant is front event (other than jumping)
- if not event.jumping? and not event.over_trigger?
- result.push(event)
- end
- end
- end
- return result
- end
- def pbTriggeredCounterEvents(triggers,checkIfRunning=true)
- result = []
- # If event is running
- if checkIfRunning && $game_system.map_interpreter.running?
- return result
- end
- # All event loops
- for event in $game_map.events.values
- next if !event.name[/^Counter\((\d+)\)$/]
- distance=$~[1].to_i
- # If event coordinates and triggers are consistent
- if pbEventFacesPlayer?(event,self,distance) and triggers.include?(event.trigger)
- # If starting determinant is front event (other than jumping)
- if not event.jumping? and not event.over_trigger?
- result.push(event)
- end
- end
- end
- return result
- end
- def pbCheckEventTriggerAfterTurning
- end
- def pbCheckEventTriggerFromDistance(triggers)
- ret=pbTriggeredTrainerEvents(triggers)
- ret.concat(pbTriggeredCounterEvents(triggers))
- return false if ret.length==0
- for event in ret
- event.start
- end
- return true
- end
- def pbFacingEvent
- if $game_system.map_interpreter.running?
- return nil
- end
- new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
- new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
- for event in $game_map.events.values
- if event.x == new_x and event.y == new_y
- if not event.jumping? and not event.over_trigger?
- return event
- end
- end
- end
- if $game_map.counter?(new_x, new_y)
- new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
- new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
- for event in $game_map.events.values
- if event.x == new_x and event.y == new_y
- if not event.jumping? and not event.over_trigger?
- return event
- end
- end
- end
- end
- return nil
- end
- #--------------------------------------------------------------------------
- # * Passable Determinants
- # x : x-coordinate
- # y : y-coordinate
- # d : direction (0,2,4,6,8)
- # * 0 = Determines if all directions are impassable (for jumping)
- #--------------------------------------------------------------------------
- def passable?(x, y, d)
- # Get new coordinates
- new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
- new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
- # If coordinates are outside of map
- unless $game_map.validLax?(new_x, new_y)
- # Impassable
- return false
- end
- if !$game_map.valid?(new_x, new_y)
- return false if !$MapFactory
- return $MapFactory.isPassableFromEdge?(new_x, new_y)
- end
- # If debug mode is ON and ctrl key was pressed
- if $DEBUG and Input.press?(Input::CTRL)
- # Passable
- return true
- end
- super
- end
- #--------------------------------------------------------------------------
- # * Set Map Display Position to Center of Screen
- #--------------------------------------------------------------------------
- def center(x, y)
- center_x = (Graphics.width/2 - 16) * 4 # Center screen x-coordinate * 4
- center_y = (Graphics.height/2 - 16) * 4 # Center screen y-coordinate * 4
- max_x = ($game_map.width - Graphics.width/32.0) * 128
- max_y = ($game_map.height - Graphics.height/32.0) * 128
- $game_map.display_x = [0, [x * 128 - center_x, max_x].min].max
- $game_map.display_y = [0, [y * 128 - center_y, max_y].min].max
- end
- #--------------------------------------------------------------------------
- # * Move to Designated Position
- # x : x-coordinate
- # y : y-coordinate
- #--------------------------------------------------------------------------
- def moveto(x, y)
- super
- # Centering
- center(x, y)
- # Make encounter count
- make_encounter_count
- end
- #--------------------------------------------------------------------------
- # * Increase Steps
- #--------------------------------------------------------------------------
- def increase_steps
- super
- end
- #--------------------------------------------------------------------------
- # * Get Encounter Count
- #--------------------------------------------------------------------------
- def encounter_count
- return @encounter_count
- end
- #--------------------------------------------------------------------------
- # * Make Encounter Count
- #--------------------------------------------------------------------------
- def make_encounter_count
- # Image of two dice rolling
- if $game_map.map_id != 0
- n = $game_map.encounter_step
- @encounter_count = rand(n) + rand(n) + 1
- end
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- @opacity = 255
- @blend_type = 0
- end
- #--------------------------------------------------------------------------
- # * Same Position Starting Determinant
- #--------------------------------------------------------------------------
- def check_event_trigger_here(triggers,keypress=false)
- result = false
- # If event is running
- if $game_system.map_interpreter.running?
- return result
- end
- # All event loops
- for event in $game_map.events.values
- # If event coordinates and triggers are consistent
- if event.x == @x and event.y == @y and triggers.include?(event.trigger)
- # If starting determinant is same position event (other than jumping)
- if not event.jumping? and event.over_trigger?
- event.start(keypress)
- result = true
- end
- end
- end
- return result
- end
- #--------------------------------------------------------------------------
- # * Front Envent Starting Determinant
- #--------------------------------------------------------------------------
- def check_event_trigger_there(triggers,keypress=false)
- result = false
- # If event is running
- if $game_system.map_interpreter.running?
- return result
- end
- # Calculate front event coordinates
- new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
- new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
- # All event loops
- for event in $game_map.events.values
- # If event coordinates and triggers are consistent
- if event.x == new_x and event.y == new_y and
- triggers.include?(event.trigger)
- # If starting determinant is front event (other than jumping)
- if not event.jumping? and (keypress || !event.over_trigger?)
- event.start(keypress)
- result = true
- end
- end
- end
- # If fitting event is not found
- if result == false
- # If front tile is a counter
- if $game_map.counter?(new_x, new_y)
- # Calculate 1 tile inside coordinates
- new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
- new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
- # All event loops
- for event in $game_map.events.values
- # If event coordinates and triggers are consistent
- if event.x == new_x and event.y == new_y and
- triggers.include?(event.trigger)
- # If starting determinant is front event (other than jumping)
- if not event.jumping? and (keypress || !event.over_trigger?)
- event.start
- result = true
- end
- end
- end
- end
- end
- return result
- end
- #--------------------------------------------------------------------------
- # * Touch Event Starting Determinant
- #--------------------------------------------------------------------------
- def check_event_trigger_touch(x, y)
- result = false
- # If event is running
- if $game_system.map_interpreter.running?
- return result
- end
- # All event loops
- for event in $game_map.events.values
- if event.name[/^Trainer\((\d+)\)$/]
- distance=$~[1].to_i
- next if !pbEventCanReachPlayer?(event,self,distance)
- end
- if event.name[/^Counter\((\d+)\)$/]
- distance=$~[1].to_i
- next if !pbEventFacesPlayer?(event,self,distance)
- end
- # If event coordinates and triggers are consistent
- if event.x == x and event.y == y and [1,2].include?(event.trigger)
- # If starting determinant is front event (other than jumping)
- if not event.jumping? and not event.over_trigger?
- event.start
- result = true
- end
- end
- end
- return result
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- updateDependentEvents
- # Remember whether or not moving in local variables
- last_moving = moving?
- # If moving, event running, move route forcing, and message window
- # display are all not occurring
- dir=Input.dir4
- unless moving? or $game_system.map_interpreter.running? or
- @move_route_forcing or $game_temp.message_window_showing or
- $PokemonTemp.miniupdate
- # Move player in the direction the directional button is being pressed
- if dir==@lastdir && Graphics.frame_count-@lastdirframe>2
- case dir
- when 2
- move_down
- when 4
- move_left
- when 6
- move_right
- when 8
- move_up
- end
- elsif dir!=@lastdir
- case dir
- when 2
- turn_down
- when 4
- turn_left
- when 6
- turn_right
- when 8
- turn_up
- end
- end
- end
- if dir!=@lastdir
- @lastdirframe=Graphics.frame_count
- end
- @lastdir=dir
- # Remember coordinates in local variables
- last_real_x = @real_x
- last_real_y = @real_y
- super
- center_x = (Graphics.width/2 - 16) * 4 # Center screen x-coordinate * 4
- center_y = (Graphics.height/2 - 16) * 4 # Center screen y-coordinate * 4
- # If character moves down and is positioned lower than the center
- # of the screen
- if @real_y > last_real_y and @real_y - $game_map.display_y > center_y
- # Scroll map down
- $game_map.scroll_down(@real_y - last_real_y)
- end
- # If character moves left and is positioned more let on-screen than
- # center
- if @real_x < last_real_x and @real_x - $game_map.display_x < center_x
- # Scroll map left
- $game_map.scroll_left(last_real_x - @real_x)
- end
- # If character moves right and is positioned more right on-screen than
- # center
- if @real_x > last_real_x and @real_x - $game_map.display_x > center_x
- # Scroll map right
- $game_map.scroll_right(@real_x - last_real_x)
- end
- # If character moves up and is positioned higher than the center
- # of the screen
- if @real_y < last_real_y and @real_y - $game_map.display_y < center_y
- # Scroll map up
- $game_map.scroll_up(last_real_y - @real_y)
- end
- # If not moving
- unless moving?
- # If player was moving last time
- if last_moving
- pbTurnDependentEvents
- result = pbCheckEventTriggerFromDistance([2])
- # Event determinant is via touch of same position event
- result |= check_event_trigger_here([1,2])
- # If event which started does not exist
- Kernel.pbOnStepTaken(result) # *Added function call
- if result == false
- # Disregard if debug mode is ON and ctrl key was pressed
- unless $DEBUG and Input.press?(Input::CTRL)
- # Encounter countdown
- if @encounter_count > 0
- @encounter_count -= 1
- end
- end
- end
- end
- # If C button was pressed
- if Input.trigger?(Input::C) && !$PokemonTemp.miniupdate
- # Same position and front event determinant
- check_event_trigger_here([0],true)
- check_event_trigger_there([0,2],true) # *Modified to prevent unnecessary triggers
- end
- end
- end
- end
复制代码 |
|