赞 | 451 |
VIP | 56 |
好人卡 | 75 |
积分 | 424 |
经验 | 124650 |
最后登录 | 2024-11-21 |
在线时间 | 7601 小时 |
Lv5.捕梦者 (管理员) 老黄鸡
- 梦石
- 0
- 星屑
- 42387
- 在线时间
- 7601 小时
- 注册时间
- 2009-7-6
- 帖子
- 13506
|
做了一点小重构方便自己理解
基本功能看上去是没问题了,细节没考虑,代码也未优化
楼主参考参考就行了
$imported ||= {} $imported["AI-BreakoutClone"] = true module BREAKOUT_CLONE STAGE = {} STAGE[0] = [ [7, 15, 0], [7, 91, 0], [7, 167, 0], [7, 242, 0], [7, 317, 0], [7, 393, 0], [7, 469, 0], [6, 15, 40], [6, 91, 40], [6, 167, 40], [6, 242, 40], [6, 317, 40], [6, 393, 40], [6, 469, 40], [3, 15, 80], [1, 91, 80], [1, 167, 80], [1, 242, 80], [1, 317, 80], [1, 393, 80], [1, 469, 80], [4, 15, 120], [2, 91, 120], [1, 167, 120], [1, 242, 120], [1, 317, 120], [2, 393, 120], [4, 469, 120], [5, 15, 160], [3, 91, 160], [1, 167, 160], [1, 242, 160], [1, 317, 160], [3, 393, 160], [5, 469, 160], [6, 15, 200], [4, 91, 200], [2, 167, 200], [1, 242, 200], [2, 317, 200], [4, 393, 200], [6, 469, 200], [7, 15, 240], [6, 91, 240], [4, 167, 240], [1, 242, 240], [4, 317, 240], [6, 393, 240], [7, 469, 240] ] end module Cache def self.breakout_clone(filename) load_bitmap("Graphics/Breakout_Clone/", filename) end end module SceneManager class << self; alias :breakout_clone_first_scene_class :first_scene_class; end def self.first_scene_class if $imported["AI-BreakoutClone"] && !$BTEST Graphics.resize_screen(544, 480) return Scene_Breakout_Clone end breakout_clone_first_scene_class end end class Game_Temp attr_accessor :breakout_clone_start attr_accessor :breakout_clone_gameover alias breakout_clone_initialize initialize def initialize breakout_clone_initialize @breakout_clone_start = false @breakout_clone_gameover = false end def set_breakout_clone_start(flag); @breakout_clone_start = flag; end def reset_breakout_clone_start; @breakout_clone_start = false; end def breakout_clone_start?; @breakout_clone_start == true; end def set_breakout_clone_gameover(flag); @breakout_clone_gameover = flag; end def reset_breakout_clone_gameover; @breakout_clone_gameover = false; end def breakout_clone_gameover?; @breakout_clone_gameover == true; end end class Breakout_Object include Math Vector2 = Struct.new(:x, :y) do include Math def magnitude sqrt(x*x+y*y) end def normalized return Vector2.new(0.0,0.0) if y == 0 && x == 0 a = atan2(y,x) Vector2.new(cos(a),sin(a)) end def *(rate) Vector2.new(x*rate,y*rate) end end Segment = Struct.new(:x1,:y1,:x2,:y2,:vertical,:hoster,:offset) Ray = Struct.new(:x1,:y1,:x2,:y2,:hoster,:offset) do include Math def vector Vector2.new(x2-x1,y2-y1) end end attr_accessor :name attr_accessor :x attr_accessor :y attr_accessor :width attr_accessor :height attr_accessor :force attr_accessor :bounce attr_accessor :mass def initialize init_members_internal init_members end def init_members_internal @name = '' @x = 0.0 @y = 0.0 @width = 0.0 @height = 0.0 @force = Vector2.new(0.0,0.0) @bounce = 1.0 @mass = 0 @alive = true @static = true end def next_x @x + @force.x end def next_y @y + @force.y end def x=(v) @x = v.to_f end def y=(v) @y = v.to_f end def ox @x + @width / 2 end def oy @y + @height / 2 end def init_members # end def update # end def take_damage(source) # end def is_alive? @alive end def is_static? @static end def bitmap end def collide(target, info) self.force.x *= -1.0 * target.bounce * self.bounce if info.seg.vertical self.force.y *= -1.0 * target.bounce * self.bounce unless info.seg.vertical end def on_collide(source, info) # end def push(target, vertical) self.force.x = 0.0 self.force.y = 0.0 target.force.x += self.force.x * target.bounce * self.bounce if vertical target.force.y += self.force.y * target.bounce * self.bounce unless vertical end def get_segments result = Array.new(4) result[0] = Segment.new(@x,@y+@height,@x,@y,true,self,[0,0]) result[1] = Segment.new(@x,@y,@x+@width,@y,false,self,[-1,0]) result[2] = Segment.new(@x+@width,@y,@x+@width,@y+@height,true,self,[0,-1]) result[3] = Segment.new(@x+@width,@y+@height,@x,@y+@height,false,self,[-1,-1]) result end def get_raycastor(power) af = @force.normalized * power result = Array.new(4) result[0] = Ray.new(@x,@y,@x+af.x,@y+af.y,self,[0,0]) result[1] = Ray.new(@x+@width,@y,@x+@width+af.x,@y+af.y,self,[-1,0]) result[2] = Ray.new(@x,@y+@height,@x+af.x,@y+@height+af.y,self,[0,-1]) result[3] = Ray.new(@x+@width,@y+@height,@x+@width+af.x,@y+@height+af.y,self,[-1,-1]) result end end class Breakout_World < Breakout_Object def init_members @name = 'world' @mass = 10 end end class Breakout_Paddle < Breakout_Object def init_members @name = 'paddle' @static = false @mass = 5 end def collide(target, vertical) self.force.x = 0 if vertical self.force.y = 0 unless vertical end def on_collide(source, info) if source.name == 'world' self.force.x = 0 if info.seg.vertical self.force.y = 0 unless info.seg.vertical end end def update if Input.press?(:LEFT) @force.x = -8 elsif Input.press?(:RIGHT) @force.x = 8 else @force.x = 0 end @force.y = 0 end def bitmap Cache.breakout_clone("paddle") end end class Breakout_Ball < Breakout_Object def init_members @name = 'ball' @static = false @speed = 4 @force.x = ([-(rand(@speed) + 1), rand(@speed) + 1][rand(2)]).to_f @force.y = -(@speed + 1).to_f @mass = 1 end def on_collide(source, info) if source.name == 'paddle' dir_force = self.force.magnitude a = atan2(self.oy - source.oy,self.ox - source.ox) self.force.x = cos(a) * dir_force self.force.y = sin(a) * dir_force elsif source.name == 'world' if self.y > Graphics.height die else collide(source, info) end else collide(source, info) end end def die p 'game over' @static = true end def bitmap Cache.breakout_clone("ball") end end class Breakout_Brick < Breakout_Object attr_accessor :life def init_members @name = 'brick' @life = 0 @mass = 5 end def take_damage(source) if @life > 1 @life-=1 else @life = 0 @alive = false end end def on_collide(source, info) take_damage(source) if source.name == 'ball' end def bitmap Cache.breakout_clone("brick") end end class Sprite_Breakout_Single < Sprite def initialize(object) super() @target = object refresh end def refresh self.bitmap = @target.bitmap end def update return unless is_alive? self.x = @target.x.to_i self.y = @target.y.to_i end def is_alive? @target.is_alive? end end class Sprite_Breakout_Block < Sprite_Breakout_Single def initialize(object) super @life = @target.life end def update super return unless is_alive? if @life != @target.life @life = @target.life refresh end end def refresh super sy = (@target.life - 1) * 24 self.src_rect.set(0, sy, 68, 24) end end class Breakout_Manager include Math IntersectionInfo = Struct.new(:x,:y,:t,:distance,:ray,:seg) def initialize(objects) @objects = objects end def get_objects_inrect(x01,x02,y01,y02,hoster) @objects.find_all do |obj| if hoster == obj false else x11,x12,y11,y12 = obj.x,obj.x+obj.width,obj.y,obj.y+obj.height zx = (x01 + x02 -x11 - x12).abs x = (x01 - x02).abs + (x11 - x12).abs zy = (y01 + y02 - y11 - y12).abs y = (y01 - y02).abs + (y11 - y12).abs zx <= x && zy <= y end end end def intersection(ox,oy,x,y,ray,segment) dx = x - ox dy = y - oy distance = sqrt(dx*dx+dy*dy) return IntersectionInfo.new(x,y,0,distance,ray,segment) end def get_intersection(ray,segment) ax,ay,bx,by = ray.x1,ray.y1,ray.x2,ray.y2 cx,cy,dx,dy = segment.x1,segment.y1,segment.x2,segment.y2 area_abc = (ax - cx) * (by - cy) - (ay - cy) * (bx - cx) area_abd = (ax - dx) * (by - dy) - (ay - dy) * (bx - dx) return nil if area_abc*area_abd >= 0 area_cda = (cx - ax) * (dy - ay) - (cy - ay) * (dx - ax) area_cdb = area_cda + area_abc - area_abd return nil if area_cda*area_cdb >= 0 t = area_cda / (area_abd-area_abc) fdx= t*(bx - ax) fdy= t*(by - ay) x = ax+fdx y = ay+fdy distance = sqrt(fdx*fdx+fdy*fdy) return IntersectionInfo.new(x,y,t,distance,ray,segment) end def get_collide(obj,targets,power) segments = Array.new(targets.size * 4) targets.each_with_index do |target,i| target.get_segments.each_with_index do |seg,j| segments[i*4+j] = seg end end all_point = [] castor_list = obj.get_raycastor(power) castor_list.each do |castor| segments.each do |seg| info = get_intersection(castor,seg) all_point << info if info end end return [nil,0] if all_point.size == 0 all_point.sort!{|a,b| a.distance - b.distance} result = all_point.first [result,power - result.distance] end def get_fix_x(speed,seg) return 0.0 if speed.x == 0 || !seg.vertical speed.x > 0 ? -0.5 : 0.5 end def get_fix_y(speed,seg) return 0.0 if speed.y == 0 || seg.vertical speed.y > 0 ? -0.5 : 0.5 end def update @objects = @objects.find_all do |obj| obj.update unless obj.is_static? nx = obj.next_x ny = obj.next_y xlist = [obj.x,obj.x+obj.width,nx,nx+obj.width] ylist = [obj.y,obj.y+obj.height,ny,ny+obj.height] targets = get_objects_inrect(xlist.min,xlist.max,ylist.min,ylist.max,obj) power = obj.force.magnitude base_power = power count = 0 while(power > 0) collide_info = get_collide(obj,targets,power) if collide_info[0] info = collide_info[0] seg = info.seg ray = info.ray speed = ray.vector obj.x = info.x + ray.offset[0]*obj.width + get_fix_x(speed,seg) obj.y = info.y + ray.offset[1]*obj.height + get_fix_y(speed,seg) obj.on_collide(seg.hoster, info) seg.hoster.on_collide(obj, info) else obj.x += obj.force.x * power / base_power obj.y += obj.force.y * power / base_power end count+=1 power = collide_info[1] power = 0 if count > 2 end end obj.is_alive? end end end class Scene_Breakout_Clone < Scene_Base include BREAKOUT_CLONE def start super init_members create_breakout_clone_paddle create_breakout_clone_ball create_breakout_clone_brick create_breakout_clone_worldbox create_manager end def init_members @objects = [] @sprites = [] @cache_bitmaps = { 'paddle'=>Cache.breakout_clone("paddle"), 'ball'=>Cache.breakout_clone("ball"), 'brick'=>Cache.breakout_clone("brick") } end def create_breakout_clone_paddle bitmap = @cache_bitmaps['paddle'] @paddle = Breakout_Paddle.new @paddle.width = bitmap.width @paddle.height = bitmap.height @paddle.x = Graphics.width / 2 - @paddle.width / 2 @paddle.y = Graphics.height - @paddle.height @objects << @paddle @sprites << Sprite_Breakout_Single.new(@paddle) end def create_breakout_clone_ball bitmap = @cache_bitmaps['ball'] ball = Breakout_Ball.new $tests = ball ball.width = bitmap.width ball.height = bitmap.height ball.x = Graphics.width / 2 - ball.width / 2 ball.y = @paddle.y - (@paddle.height + ball.height) / 2 @objects << ball @sprites << Sprite_Breakout_Single.new(ball) end def create_breakout_clone_brick STAGE[0].each do |brick| brick_obj = Breakout_Brick.new brick_obj.width = 68 brick_obj.height = 24 brick_obj.life = brick[0] brick_obj.x = brick[1] brick_obj.y = brick[2] @objects << brick_obj @sprites << Sprite_Breakout_Block.new(brick_obj) end end def create_breakout_clone_worldbox worldbox = Breakout_World.new worldbox.width = Graphics.width worldbox.height = Graphics.height + 32 @objects << worldbox end def create_manager @manager = Breakout_Manager.new(@objects) end def terminate super dispose_all end def dispose_all @sprites.each{|spr| spr.dispose} end def update super @manager.update @sprites = @sprites.find_all do |spr| spr.update ret = spr.is_alive? spr.dispose unless ret ret end end end
$imported ||= {}
$imported["AI-BreakoutClone"] = true
module BREAKOUT_CLONE
STAGE = {}
STAGE[0] = [
[7, 15, 0], [7, 91, 0], [7, 167, 0], [7, 242, 0], [7, 317, 0], [7, 393, 0], [7, 469, 0],
[6, 15, 40], [6, 91, 40], [6, 167, 40], [6, 242, 40], [6, 317, 40], [6, 393, 40], [6, 469, 40],
[3, 15, 80], [1, 91, 80], [1, 167, 80], [1, 242, 80], [1, 317, 80], [1, 393, 80], [1, 469, 80],
[4, 15, 120], [2, 91, 120], [1, 167, 120], [1, 242, 120], [1, 317, 120], [2, 393, 120], [4, 469, 120],
[5, 15, 160], [3, 91, 160], [1, 167, 160], [1, 242, 160], [1, 317, 160], [3, 393, 160], [5, 469, 160],
[6, 15, 200], [4, 91, 200], [2, 167, 200], [1, 242, 200], [2, 317, 200], [4, 393, 200], [6, 469, 200],
[7, 15, 240], [6, 91, 240], [4, 167, 240], [1, 242, 240], [4, 317, 240], [6, 393, 240], [7, 469, 240]
]
end
module Cache
def self.breakout_clone(filename)
load_bitmap("Graphics/Breakout_Clone/", filename)
end
end
module SceneManager
class << self; alias :breakout_clone_first_scene_class :first_scene_class; end
def self.first_scene_class
if $imported["AI-BreakoutClone"] && !$BTEST
Graphics.resize_screen(544, 480)
return Scene_Breakout_Clone
end
breakout_clone_first_scene_class
end
end
class Game_Temp
attr_accessor :breakout_clone_start
attr_accessor :breakout_clone_gameover
alias breakout_clone_initialize initialize
def initialize
breakout_clone_initialize
@breakout_clone_start = false
@breakout_clone_gameover = false
end
def set_breakout_clone_start(flag); @breakout_clone_start = flag; end
def reset_breakout_clone_start; @breakout_clone_start = false; end
def breakout_clone_start?; @breakout_clone_start == true; end
def set_breakout_clone_gameover(flag); @breakout_clone_gameover = flag; end
def reset_breakout_clone_gameover; @breakout_clone_gameover = false; end
def breakout_clone_gameover?; @breakout_clone_gameover == true; end
end
class Breakout_Object
include Math
Vector2 = Struct.new(:x, :y) do
include Math
def magnitude
sqrt(x*x+y*y)
end
def normalized
return Vector2.new(0.0,0.0) if y == 0 && x == 0
a = atan2(y,x)
Vector2.new(cos(a),sin(a))
end
def *(rate)
Vector2.new(x*rate,y*rate)
end
end
Segment = Struct.new(:x1,:y1,:x2,:y2,:vertical,:hoster,:offset)
Ray = Struct.new(:x1,:y1,:x2,:y2,:hoster,:offset) do
include Math
def vector
Vector2.new(x2-x1,y2-y1)
end
end
attr_accessor :name
attr_accessor :x
attr_accessor :y
attr_accessor :width
attr_accessor :height
attr_accessor :force
attr_accessor :bounce
attr_accessor :mass
def initialize
init_members_internal
init_members
end
def init_members_internal
@name = ''
@x = 0.0
@y = 0.0
@width = 0.0
@height = 0.0
@force = Vector2.new(0.0,0.0)
@bounce = 1.0
@mass = 0
@alive = true
@static = true
end
def next_x
@x + @force.x
end
def next_y
@y + @force.y
end
def x=(v)
@x = v.to_f
end
def y=(v)
@y = v.to_f
end
def ox
@x + @width / 2
end
def oy
@y + @height / 2
end
def init_members
#
end
def update
#
end
def take_damage(source)
#
end
def is_alive?
@alive
end
def is_static?
@static
end
def bitmap
end
def collide(target, info)
self.force.x *= -1.0 * target.bounce * self.bounce if info.seg.vertical
self.force.y *= -1.0 * target.bounce * self.bounce unless info.seg.vertical
end
def on_collide(source, info)
#
end
def push(target, vertical)
self.force.x = 0.0
self.force.y = 0.0
target.force.x += self.force.x * target.bounce * self.bounce if vertical
target.force.y += self.force.y * target.bounce * self.bounce unless vertical
end
def get_segments
result = Array.new(4)
result[0] = Segment.new(@x,@y+@height,@x,@y,true,self,[0,0])
result[1] = Segment.new(@x,@y,@x+@width,@y,false,self,[-1,0])
result[2] = Segment.new(@x+@width,@y,@x+@width,@y+@height,true,self,[0,-1])
result[3] = Segment.new(@x+@width,@y+@height,@x,@y+@height,false,self,[-1,-1])
result
end
def get_raycastor(power)
af = @force.normalized * power
result = Array.new(4)
result[0] = Ray.new(@x,@y,@x+af.x,@y+af.y,self,[0,0])
result[1] = Ray.new(@x+@width,@y,@x+@width+af.x,@y+af.y,self,[-1,0])
result[2] = Ray.new(@x,@y+@height,@x+af.x,@y+@height+af.y,self,[0,-1])
result[3] = Ray.new(@x+@width,@y+@height,@x+@width+af.x,@y+@height+af.y,self,[-1,-1])
result
end
end
class Breakout_World < Breakout_Object
def init_members
@name = 'world'
@mass = 10
end
end
class Breakout_Paddle < Breakout_Object
def init_members
@name = 'paddle'
@static = false
@mass = 5
end
def collide(target, vertical)
self.force.x = 0 if vertical
self.force.y = 0 unless vertical
end
def on_collide(source, info)
if source.name == 'world'
self.force.x = 0 if info.seg.vertical
self.force.y = 0 unless info.seg.vertical
end
end
def update
if Input.press?(:LEFT)
@force.x = -8
elsif Input.press?(:RIGHT)
@force.x = 8
else
@force.x = 0
end
@force.y = 0
end
def bitmap
Cache.breakout_clone("paddle")
end
end
class Breakout_Ball < Breakout_Object
def init_members
@name = 'ball'
@static = false
@speed = 4
@force.x = ([-(rand(@speed) + 1), rand(@speed) + 1][rand(2)]).to_f
@force.y = -(@speed + 1).to_f
@mass = 1
end
def on_collide(source, info)
if source.name == 'paddle'
dir_force = self.force.magnitude
a = atan2(self.oy - source.oy,self.ox - source.ox)
self.force.x = cos(a) * dir_force
self.force.y = sin(a) * dir_force
elsif source.name == 'world'
if self.y > Graphics.height
die
else
collide(source, info)
end
else
collide(source, info)
end
end
def die
p 'game over'
@static = true
end
def bitmap
Cache.breakout_clone("ball")
end
end
class Breakout_Brick < Breakout_Object
attr_accessor :life
def init_members
@name = 'brick'
@life = 0
@mass = 5
end
def take_damage(source)
if @life > 1
@life-=1
else
@life = 0
@alive = false
end
end
def on_collide(source, info)
take_damage(source) if source.name == 'ball'
end
def bitmap
Cache.breakout_clone("brick")
end
end
class Sprite_Breakout_Single < Sprite
def initialize(object)
super()
@target = object
refresh
end
def refresh
self.bitmap = @target.bitmap
end
def update
return unless is_alive?
self.x = @target.x.to_i
self.y = @target.y.to_i
end
def is_alive?
@target.is_alive?
end
end
class Sprite_Breakout_Block < Sprite_Breakout_Single
def initialize(object)
super
@life = @target.life
end
def update
super
return unless is_alive?
if @life != @target.life
@life = @target.life
refresh
end
end
def refresh
super
sy = (@target.life - 1) * 24
self.src_rect.set(0, sy, 68, 24)
end
end
class Breakout_Manager
include Math
IntersectionInfo = Struct.new(:x,:y,:t,:distance,:ray,:seg)
def initialize(objects)
@objects = objects
end
def get_objects_inrect(x01,x02,y01,y02,hoster)
@objects.find_all do |obj|
if hoster == obj
false
else
x11,x12,y11,y12 = obj.x,obj.x+obj.width,obj.y,obj.y+obj.height
zx = (x01 + x02 -x11 - x12).abs
x = (x01 - x02).abs + (x11 - x12).abs
zy = (y01 + y02 - y11 - y12).abs
y = (y01 - y02).abs + (y11 - y12).abs
zx <= x && zy <= y
end
end
end
def intersection(ox,oy,x,y,ray,segment)
dx = x - ox
dy = y - oy
distance = sqrt(dx*dx+dy*dy)
return IntersectionInfo.new(x,y,0,distance,ray,segment)
end
def get_intersection(ray,segment)
ax,ay,bx,by = ray.x1,ray.y1,ray.x2,ray.y2
cx,cy,dx,dy = segment.x1,segment.y1,segment.x2,segment.y2
area_abc = (ax - cx) * (by - cy) - (ay - cy) * (bx - cx)
area_abd = (ax - dx) * (by - dy) - (ay - dy) * (bx - dx)
return nil if area_abc*area_abd >= 0
area_cda = (cx - ax) * (dy - ay) - (cy - ay) * (dx - ax)
area_cdb = area_cda + area_abc - area_abd
return nil if area_cda*area_cdb >= 0
t = area_cda / (area_abd-area_abc)
fdx= t*(bx - ax)
fdy= t*(by - ay)
x = ax+fdx
y = ay+fdy
distance = sqrt(fdx*fdx+fdy*fdy)
return IntersectionInfo.new(x,y,t,distance,ray,segment)
end
def get_collide(obj,targets,power)
segments = Array.new(targets.size * 4)
targets.each_with_index do |target,i|
target.get_segments.each_with_index do |seg,j|
segments[i*4+j] = seg
end
end
all_point = []
castor_list = obj.get_raycastor(power)
castor_list.each do |castor|
segments.each do |seg|
info = get_intersection(castor,seg)
all_point << info if info
end
end
return [nil,0] if all_point.size == 0
all_point.sort!{|a,b| a.distance - b.distance}
result = all_point.first
[result,power - result.distance]
end
def get_fix_x(speed,seg)
return 0.0 if speed.x == 0 || !seg.vertical
speed.x > 0 ? -0.5 : 0.5
end
def get_fix_y(speed,seg)
return 0.0 if speed.y == 0 || seg.vertical
speed.y > 0 ? -0.5 : 0.5
end
def update
@objects = @objects.find_all do |obj|
obj.update
unless obj.is_static?
nx = obj.next_x
ny = obj.next_y
xlist = [obj.x,obj.x+obj.width,nx,nx+obj.width]
ylist = [obj.y,obj.y+obj.height,ny,ny+obj.height]
targets = get_objects_inrect(xlist.min,xlist.max,ylist.min,ylist.max,obj)
power = obj.force.magnitude
base_power = power
count = 0
while(power > 0)
collide_info = get_collide(obj,targets,power)
if collide_info[0]
info = collide_info[0]
seg = info.seg
ray = info.ray
speed = ray.vector
obj.x = info.x + ray.offset[0]*obj.width + get_fix_x(speed,seg)
obj.y = info.y + ray.offset[1]*obj.height + get_fix_y(speed,seg)
obj.on_collide(seg.hoster, info)
seg.hoster.on_collide(obj, info)
else
obj.x += obj.force.x * power / base_power
obj.y += obj.force.y * power / base_power
end
count+=1
power = collide_info[1]
power = 0 if count > 2
end
end
obj.is_alive?
end
end
end
class Scene_Breakout_Clone < Scene_Base
include BREAKOUT_CLONE
def start
super
init_members
create_breakout_clone_paddle
create_breakout_clone_ball
create_breakout_clone_brick
create_breakout_clone_worldbox
create_manager
end
def init_members
@objects = []
@sprites = []
@cache_bitmaps = {
'paddle'=>Cache.breakout_clone("paddle"),
'ball'=>Cache.breakout_clone("ball"),
'brick'=>Cache.breakout_clone("brick")
}
end
def create_breakout_clone_paddle
bitmap = @cache_bitmaps['paddle']
@paddle = Breakout_Paddle.new
@paddle.width = bitmap.width
@paddle.height = bitmap.height
@paddle.x = Graphics.width / 2 - @paddle.width / 2
@paddle.y = Graphics.height - @paddle.height
@objects << @paddle
@sprites << Sprite_Breakout_Single.new(@paddle)
end
def create_breakout_clone_ball
bitmap = @cache_bitmaps['ball']
ball = Breakout_Ball.new
$tests = ball
ball.width = bitmap.width
ball.height = bitmap.height
ball.x = Graphics.width / 2 - ball.width / 2
ball.y = @paddle.y - (@paddle.height + ball.height) / 2
@objects << ball
@sprites << Sprite_Breakout_Single.new(ball)
end
def create_breakout_clone_brick
STAGE[0].each do |brick|
brick_obj = Breakout_Brick.new
brick_obj.width = 68
brick_obj.height = 24
brick_obj.life = brick[0]
brick_obj.x = brick[1]
brick_obj.y = brick[2]
@objects << brick_obj
@sprites << Sprite_Breakout_Block.new(brick_obj)
end
end
def create_breakout_clone_worldbox
worldbox = Breakout_World.new
worldbox.width = Graphics.width
worldbox.height = Graphics.height + 32
@objects << worldbox
end
def create_manager
@manager = Breakout_Manager.new(@objects)
end
def terminate
super
dispose_all
end
def dispose_all
@sprites.each{|spr| spr.dispose}
end
def update
super
@manager.update
@sprites = @sprites.find_all do |spr|
spr.update
ret = spr.is_alive?
spr.dispose unless ret
ret
end
end
end
|
|