Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =begin
- -- Зрение противника
- -- Автор: ну наверное Paranoid. Хотя по сути это просто куча копипаста
- -- Версия: 1.0
- -- Лицензия: Свободная для коммерческих и некоммерческих проектов. Только в титрах укажите ник.
- Этот скрипт позволяет ивентам видеть игрока по прямой. Даже если вы используете
- пиксельное движение. Его можно настроить в блоке "Смотрит" заменив число 0.75
- на нужное вам или вообще убрав его. Числа 12 и 16 позволяют ивенту смотреть
- на расстояние всего экрана 12 клеток по Y и 16 по X. Если хотите уменьшить поле
- зрения до определеной длинны, то просто измените эти числа.
- Ивент так же не может видеть игрока, если он за непроходимыми тайлами.
- Так же игрок может прятаться в коробку аля Солид Снейк. За это отвечает свитч
- SW_IN_BOX, у меня он 3, можете поменять. Как работает: если вы в коробке (свитч)
- включен, то ивент не будет обращать на вас внимание, пока вы не двигаетесь.
- Чтобы просто проверить видимость используйте event_see?(event_id), дает true
- если игрока видно.
- P.S.: скрипт полукопипаста зрения от DeadElf79 с изменением принципа зрения
- =end
- ###########################################################################
- ################################# Настройки ###############################
- ###########################################################################
- module EnemyEvent
- EVENT_NAME = /see/i # Здесь "see" это имя зрячего ивента
- SSW_IF_SEE = 'A' # Свитч, который сработает в случае если героя увидят
- SW_IN_BOX = 3 # Свитч, который позволяет вам быть невидимым,
- # если вы не двигаетесь
- end
- ###########################################################################
- ############################# Конец настроек ##############################
- ###########################################################################
- def event_see?(event_id)
- $game_map.events[event_id].can_see?($game_player.x,$game_player.y)
- end
- class Game_Event
- def enemy?
- self.name =~ EnemyEvent::EVENT_NAME
- end
- def set_seen
- @seen_once = true
- end
- def seen_once?
- @seen_once
- end
- def can_see?(px,py)
- # Смотрит
- case @direction
- when 8
- return true if py.between?(self.y-12, self.y) && px.between?(self.x-0.75, self.x+0.75) and for fy in (py.to_i..self.y)
- return false if $game_map.passable?(self.x, fy, 8)!=true or $game_map.passable?(self.x, fy, 2)!=true
- end
- when 4
- return true if px.between?(self.x-16, self.x) && py.between?(self.y-0.75, self.y+0.75) and for fx in px.to_i..self.x
- return false if $game_map.passable?(fx, self.y, 4)!=true or $game_map.passable?(fx, self.y, 6)!=true
- end
- when 6
- return true if px.between?(self.x, self.x+16) && py.between?(self.y-0.75, self.y+0.75) and for fx in self.x.to_i..px
- return false if $game_map.passable?(fx, self.y, 4)!=true or $game_map.passable?(fx, self.y, 6)!=true
- end
- when 2
- return true if py.between?(self.y, self.y+12) && px.between?(self.x-0.75, self.x+0.75) and for fy in self.y.to_i..py
- return false if $game_map.passable?(self.x, fy, 8)!=true or $game_map.passable?(self.x, fy, 2)!=true
- end
- end
- false
- end
- end
- class Game_Map
- attr_accessor :enemies
- alias enemy_event_setup setup
- def setup(map_id)
- enemy_event_setup(map_id)
- setup_enemies
- end
- def setup_enemies
- @enemies = []
- @events.each_value do |event|
- @enemies.push event if event.enemy?
- end
- end
- end
- class Scene_Map < Scene_Base
- alias enemy_event_update update
- def update
- enemy_event_update
- update_enemies
- end
- def update_enemies
- $game_map.enemies.each do |enemy|
- next unless enemy_on_screen?(enemy)
- x, y = $game_player.x, $game_player.y
- see_now = false
- if enemy.can_see?(x,y)
- if $game_switches[ EnemyEvent::SW_IN_BOX ]
- # player is in box
- if $game_player.moving?
- see_now = true
- end
- else
- # player is not in box
- see_now = true
- end
- end
- if see_now
- $game_map.events[enemy.id].balloon_id = 1
- end
- # Видел ли хотя бы раз?
- if see_now
- enemy.set_seen
- else
- if enemy.seen_once?
- see_now = true
- end
- end
- # Реакция на игрока
- key = [$game_map.map_id, enemy.id, EnemyEvent::SSW_IF_SEE]
- $game_self_switches[key] = see_now
- enemy.refresh
- end
- end
- def enemy_on_screen?(event)
- stx = $game_map.screen_tile_x
- sty = $game_map.screen_tile_y
- sx = $game_map.modw($game_player.x)*stx
- sy = $game_map.modh($game_player.y)*sty
- if (sx..sx+stx).include? event.x
- if (sy..sy+sty).include? event.y
- return true
- end
- end
- false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement