On-map Bullet System
Version: 1.0
Type: Misc Add-on
PengenalanThis script enables you to spawn a bullet that can trigger using event's self switch or switch (for hitting player).
You may use this for creating your own ABS (action battle system) because this is also used as a part of ABS.
NB: Script ini termasuk yang digunakan dalam game
The Mystery House
Petunjuk & Pemasangan - Just place the script above Main.
- To create a bullet, use code:
@bullet = $scene.createbullet(name, source, speed, dir, atk[, target])
where
@bullet = last created bullet object
name = picture name for created bullet
source = Game_Character object from which the bullet is spawned
($game_player or $game_map.events[@event_id])
speed = bullet speed
dir = 1: down
2: left
3: right
4: up
5: Southwest
6: Northwest
7: Northeast
8: Southeast
9: Toward target
10: Toward target (homing)
11: Angled direction (use @bullet.bullet_angle to determine angle)
atk = bullet attack value
target = Game_Character object to which the bullet move
(if use dir = 9 or 10)
- Accessible bullet properties:
@bullet.speed
@bullet.bullet_dir
@bullet.bullet_angle (in degrees, CCW from east)
@bullet.source (read-only)
@bullet.atk
and all attributes inherited from Game_Picture
- Global variables:
$scene.bullet_hitting = bullet that just hit an object
- Script configurations: see and edit at module BulletMod.
Screenshot- Spoiler:
http://www.indojpg.com/images/105ut_.png
(Usage on The Mystery House)
- Spoiler:
http://www.indojpg.com/images/939ut_.png
- Spoiler:
http://www.indojpg.com/images/113ut_.png
Demohttp://dl.dropbox.com/u/39428704/Bullet%20System.zip
Script - Code:
-
#==============================================================================
# On-map Bullet System
#==============================================================================
# Information:
# This script enables you to spawn a bullet that can trigger using event's
# self switch or switch (for hitting player).
#
# Usage:
# - To create a bullet, use code:
# @bullet = $scene.createbullet(name, source, speed, dir, atk[, target])
# where
# @bullet = last created bullet object
# name = picture name for created bullet
# source = Game_Character object from which the bullet is spawned
# ($game_player or $game_map.events[@event_id])
# speed = bullet speed
# dir = 1: down
# 2: left
# 3: right
# 4: up
# 5: Southwest
# 6: Northwest
# 7: Northeast
# 8: Southeast
# 9: Toward target
# 10: Toward target (homing)
# 11: Angled direction (use @bullet.bullet_angle to determine angle)
# atk = bullet attack value
# target = Game_Character object to which the bullet move
# (if use dir = 9 or 10)
#
# - Accessible bullet properties:
# @bullet.speed
# @bullet.bullet_dir
# @bullet.bullet_angle (in degrees, CCW from east)
# @bullet.source (read-only)
# @bullet.atk
# and all attributes inherited from Game_Picture
#
# - Global variables:
# $scene.bullet_hitting = bullet that just hit an object
#
# - Script configurations at module BulletMod.
#
# Installation:
# Just place above Main.
#
# Credits
# Alissa Liu
#
#==============================================================================
#---------------------------------------------------------------------------
# ** BulletMod Module
#---------------------------------------------------------------------------
module BulletMod
FromPicID = 31 # Min Picture ID
ToPicID = 61 # Max Picture ID
PlayerHit = 16 # Player Hit Switch
TriggerSS = "D" # Target's Self Switch triggered when touching
# the bullet
end
#==============================================================================
# ** Game_Character
#------------------------------------------------------------------------------
# This class deals with characters. It's used as a superclass of the
# Game_Player and Game_Event classes.
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# * Determine Character Collision
# x : x-coordinate
# y : y-coordinate
# Detects normal character collision, including the player and vehicles.
#--------------------------------------------------------------------------
def collide_with_characters2?(x, y)
if self != $game_player && x==$game_player.x && y==$game_player.y
return $game_player
end
for event in $game_map.events_xy(x, y) # Matches event position
unless event.through # Passage OFF?
if event!=self
return event if event.priority_type == 1 # Target is normal char
end
end
end
return nil
end
end
#==============================================================================
# ** Bullet
#------------------------------------------------------------------------------
#
#==============================================================================
class Bullet < Game_Picture
attr_accessor :speed
attr_accessor :bullet_dir
attr_accessor :bullet_angle
attr_reader :source
attr_accessor :atk
alias bulletinit initialize unless method_defined?('bulletinit')
alias bulletshow show unless method_defined?('bulletshow')
alias bulletupdate update unless method_defined?('bulletupdate')
#--------------------------------------------------------------------------
# * Object Initialization
# number : picture index
#--------------------------------------------------------------------------
def initialize(number)
bulletinit(number)
@bullet_dir = -1
@bullet_angle = 0
@speed = 0
end
#--------------------------------------------------------------------------
# * Show Picture
#--------------------------------------------------------------------------
def show(name, source, speed, dir, target=nil)
bulletshow(name,1,source.screen_x,source.screen_y-16,100,100,255,0)
@real_x = source.real_x.to_f
@real_y = source.real_y.to_f
@real_xo = @real_x
@real_yo = @real_y
@speed = speed
@bullet_dir = dir
@source = source
@target = target
if source==target
erase
else
if dir==9
@dx = speed/Math::sqrt((target.real_x-source.real_x)*(target.real_x-source.real_x)+
(target.real_y-source.real_y)*(target.real_y-source.real_y))*(target.real_x-source.real_x)
@dy = speed/Math::sqrt((target.real_x-source.real_x)*(target.real_x-source.real_x)+
(target.real_y-source.real_y)*(target.real_y-source.real_y))*(target.real_y-source.real_y)
end
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
if @name != ""
x_last = @real_x
y_last = @real_y
case @bullet_dir
when 1
@real_y += @speed # Down
when 2
@real_x -= @speed # Left
when 3
@real_x += @speed # Right
when 4
@real_y -= @speed # Up
when 5
# Southwest
@real_y += @speed*0.707
@real_x -= @speed*0.707
when 6
# Northwest
@real_y -= @speed*0.707
@real_x -= @speed*0.707
when 7
# Northeast
@real_y -= @speed*0.707
@real_x += @speed*0.707
when 8
# Southeast
@real_y += @speed*0.707
@real_x += @speed*0.707
when 9
# Towards target
@real_x += @dx
@real_y += @dy
when 10
# Homing
@dx = speed/Math::sqrt((@target.real_x-@real_x)*(@target.real_x-@real_x)+
(@target.real_y-@real_y)*(@target.real_y-@real_y))*(@target.real_x-@real_x)
@dy = speed/Math::sqrt((@target.real_x-@real_x)*(@target.real_x-@real_x)+
(@target.real_y-@real_y)*(@target.real_y-@real_y))*(@target.real_y-@real_y)
@real_x += @dx
@real_y += @dy
when 11
# Angled direction
@dx = @speed*Math::cos(@bullet_angle*Math::PI/180)
@dy = -@speed*Math::sin(@bullet_angle*Math::PI/180)
@real_x += @dx
@real_y += @dy
end
@x = (($game_map.adjust_x(@real_x) + 8007) / 8 - 1000 + 16).round
@y = (($game_map.adjust_y(@real_y) + 8007) / 8 - 1000 + 16).round
if ((x_last/256).round!=(@real_xo/256).round || (y_last/256).round!=(@real_yo/256).round)
if !$game_map.passable?($game_map.round_x(@real_x/256).round,$game_map.round_y(@real_y/256).round) &&
!$game_map.ship_passable?($game_map.round_x(@real_x/256).round,$game_map.round_y(@real_y/256).round)
erase
else
coli = @source.collide_with_characters2?($game_map.round_x(@real_x/256).round,$game_map.round_y(@real_y/256).round)
if (coli != nil)
if coli == $game_player || coli.id<=0
$game_switches[BulletMod::PlayerHit] = true
else
key = [$game_map.map_id,coli.id,BulletMod::TriggerSS]
$game_self_switches[key] = true
end
$scene.bullet_source = @source
$scene.bullet_hitting = self
$scene.bullet_hitting_name = name
erase
end
end
end
if @x<=0 || @x>=544 || @y<=0 || @y>=416
erase
end
bulletupdate
end
end
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
# This class performs the map screen processing.
#==============================================================================
class Scene_Map < Scene_Base
attr_accessor :bullet_source
attr_accessor :bullet_hitting
attr_accessor :bullet_hitting_name
# Alias things
alias bulletinit initialize unless method_defined?('bulletinit')
alias bulletupdate update unless method_defined?('bulletupdate')
alias bulletterminate terminate unless method_defined?('bulletterminate')
#--------------------------------------------------------------------------
# * Initialize
#--------------------------------------------------------------------------
def initialize
$bullet_sprite = []
for i in BulletMod::FromPicID..BulletMod::ToPicID
$bullet_sprite[i-BulletMod::FromPicID] = Bullet.new(i)
end
bulletinit
end
#--------------------------------------------------------------------------
# * createbullet
#--------------------------------------------------------------------------
def createbullet(name, source, speed, dir, atk, target=nil)
ret_id = BulletMod::FromPicID
while $bullet_sprite[ret_id-BulletMod::FromPicID].name != "" && ret_id<BulletMod::ToPicID
ret_id += 1
end
if $bullet_sprite[ret_id-BulletMod::FromPicID].name == ""
$bullet_sprite[ret_id-BulletMod::FromPicID].show(name, source, speed, dir, target)
$bullet_sprite[ret_id-BulletMod::FromPicID].atk = atk
return $bullet_sprite[ret_id-BulletMod::FromPicID]
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
bulletupdate
for bulletspr in $bullet_sprite
if bulletspr.name != ""
if $game_player.transfer?
bulletspr.erase
else
bulletspr.update
end
end
end
end
#--------------------------------------------------------------------------
# * Termination Processing
#--------------------------------------------------------------------------
def terminate
for bulletspr in $bullet_sprite
bulletspr.erase
end
bulletterminate
end
end
class Spriteset_Map
alias bulletcreatepic create_pictures unless method_defined?('bulletcreatepic')
#--------------------------------------------------------------------------
# * Create Picture Sprite
#--------------------------------------------------------------------------
def create_pictures(*args);bulletcreatepic(*args)
for bulletspr in $bullet_sprite
@picture_sprites.push(Sprite_Picture.new(@viewport1,bulletspr))
end
end
end
class Sprite_Picture < Sprite
alias bulletpic_upd update unless method_defined?('bulletpic_upd')
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update(*args);bulletpic_upd(*args)
if @picture.number >= BulletMod::FromPicID && @picture.number <= BulletMod::ToPicID
self.z = $game_player.screen_z+50+@picture.number-BulletMod::FromPicID
end
end
end
Credit