赞 | 154 |
VIP | 0 |
好人卡 | 0 |
积分 | 245 |
经验 | 0 |
最后登录 | 2024-5-15 |
在线时间 | 5077 小时 |
Lv5.捕梦者
- 梦石
- 0
- 星屑
- 24479
- 在线时间
- 5077 小时
- 注册时间
- 2016-3-8
- 帖子
- 1623
|
1000星屑
本帖最后由 alexncf125 于 2022-5-16 12:08 编辑
有大神可以帮忙看看171行跟243行的算法该怎样地改良才能正常么
三张图片放置于Graphics/Breakout_Clone之內
$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 Sprite_Breakout_Clone_Paddle < Sprite def initialize super init_members create_bitmap end def init_members @slide_speed = 8 end def create_bitmap self.bitmap = Cache.breakout_clone("paddle") self.x = (Graphics.width - paddle_width) / 2 self.y = Graphics.height - paddle_height end def slide_speed; @slide_speed; end def paddle_width; self.bitmap.width; end def paddle_height; self.bitmap.height; end def paddle_x; self.x + paddle_width; end def paddle_y; self.y + paddle_height; end def dispose self.bitmap.dispose super end def update super update_position end def update_position slide_left if Input.press?(:LEFT) slide_right if Input.press?(:RIGHT) end def slide_left result = self.x - slide_speed return self.x = 0 if result <= 0 self.x -= slide_speed end def slide_right result = self.x + slide_speed block = Graphics.width - paddle_width return self.x = block if result >= block self.x += slide_speed end end class Sprite_Breakout_Clone_Ball < Sprite attr_accessor :route_x attr_accessor :route_y attr_accessor :ball_last_touch def initialize(viewport, paddle = nil) super(viewport) @paddle = paddle init_members create_bitmap end def init_members @move_speed = 4 @route_x = [-(rand(@move_speed) + 1), rand(@move_speed) + 1][rand(2)] @route_y = -(@move_speed + 1) @ball_last_touch = :paddle end def create_bitmap self.bitmap = Cache.breakout_clone("ball") self.x = (Graphics.width - ball_width) / 2 self.y = Graphics.height - @paddle.bitmap.height - ball_height end def move_speed; @move_speed; end def route_x; @route_x; end def route_y; @route_y; end def ball_width; self.bitmap.width; end def ball_height; self.bitmap.height; end def ball_x; self.x + ball_width; end def ball_y; self.y + ball_height; end def dispose self.bitmap.dispose super end def update super update_position update_ball_touch end def update_position if $game_temp.breakout_clone_start? self.x = (@paddle.x + @paddle.bitmap.width) / 2 - ball_width / 2 self.y = Graphics.height - @paddle.bitmap.height - ball_height else self.x += route_x self.y += route_y end end def update_ball_touch return if $game_temp.breakout_clone_gameover? update_touch_paddle update_touch_wall end def update_touch_paddle return if @ball_last_touch == :paddle if ball_x.between?(@paddle.x, @paddle.x + @paddle.bitmap.width + ball_width) && ball_y.between?(@paddle.y, @paddle.y + @paddle.bitmap.height) if (ball_x.between?(@paddle.x, @paddle.x + (ball_width / 2)) && route_x > 0) || (self.x.between?(@paddle.x + @paddle.bitmap.width - (ball_width / 2), @paddle.x + @paddle.bitmap.width) && route_x < 0) if Input.press?(:RIGHT) && route_x < 0 @route_x = rand(move_speed) + 1 elsif Input.press?(:LEFT) && route_x > 0 @route_x = -(rand(move_speed) + 1) else @route_x = -(route_x) end else @route_x = rand(move_speed) + 1 if Input.press?(:RIGHT) @route_x = -(rand(move_speed) + 1) if Input.press?(:LEFT) end @route_y = -(move_speed) unless self.y > @paddle.y @ball_last_touch = :paddle end end def update_touch_wall if self.x <= 0 || ball_x >= Graphics.width @route_x = -(route_x) @ball_last_touch = :wall end if self.y <= 0 @route_y = -(route_y) @ball_last_touch = :wall end end end class Sprite_Breakout_Clone_Brick < Sprite def initialize(viewport, balls = nil, brick = nil) super(viewport) @ball = balls @brick = brick init_members create_bitmap end def init_members @brick_life = @brick[0] end def create_bitmap self.bitmap = Cache.breakout_clone("brick") self.x = @brick[1] self.y = @brick[2] end def dispose self.bitmap.dispose super end def update super update_src_rect update_brick_touch update_brick_visible end def update_src_rect return if @brick_life.zero? index = @brick_life sy = (index - 1) * 24 self.src_rect.set(0, sy, 68, 24) end def update_brick_touch return if self.visible == false @ball.each do |b| return if b.ball_last_touch == self if b.ball_x.between?(self.x, self.x + self.bitmap.width + b.ball_width) && b.ball_y.between?(self.y, self.y + self.bitmap.height / 7 + b.ball_height) if (b.x).between?(self.x - b.bitmap.width + 1, self.x + self.bitmap.width - 1) b.route_y = -(b.route_y) end if (b.y).between?(self.y - b.bitmap.height + 1, self.y + self.bitmap.height / 7 - 1) b.route_x = -(b.route_x) end @brick_life -= 1 if @brick_life > 0 b.ball_last_touch = self end end end def update_brick_visible self.visible = !@brick_life.zero? end end class Scene_Breakout_Clone < Scene_Base include BREAKOUT_CLONE def start super create_breakout_clone_paddle create_breakout_clone_ball create_breakout_clone_brick end def create_breakout_clone_paddle @breakout_clone_paddle_sprite = Sprite_Breakout_Clone_Paddle.new end def create_breakout_clone_ball @breakout_clone_ball_sprite ||= [] @breakout_clone_ball_sprite.push(Sprite_Breakout_Clone_Ball.new(@viewport1, @breakout_clone_paddle_sprite)) end def create_breakout_clone_brick @breakout_clone_brick_sprite ||= [] STAGE[0].each do |brick| @breakout_clone_brick_sprite.push(Sprite_Breakout_Clone_Brick.new(@viewport1, @breakout_clone_ball_sprite, brick)) end end def terminate super dispose_breakout_clone_paddle dispose_breakout_clone_ball dispose_breakout_clone_brick end def dispose_breakout_clone_paddle @breakout_clone_paddle_sprite.bitmap.dispose @breakout_clone_paddle_sprite.dispose end def dispose_breakout_clone_ball @breakout_clone_ball_sprite.each do |sprite| sprite.bitmap.dispose sprite.dispose end end def dispose_breakout_clone_brick @breakout_clone_brick_sprite.each do |sprite| sprite.bitmap.dispose sprite.dispose end end def update super @breakout_clone_paddle_sprite.update @breakout_clone_ball_sprite.each {|sprite| sprite.update} @breakout_clone_brick_sprite.each {|sprite| sprite.update} 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 Sprite_Breakout_Clone_Paddle < Sprite
def initialize
super
init_members
create_bitmap
end
def init_members
@slide_speed = 8
end
def create_bitmap
self.bitmap = Cache.breakout_clone("paddle")
self.x = (Graphics.width - paddle_width) / 2
self.y = Graphics.height - paddle_height
end
def slide_speed; @slide_speed; end
def paddle_width; self.bitmap.width; end
def paddle_height; self.bitmap.height; end
def paddle_x; self.x + paddle_width; end
def paddle_y; self.y + paddle_height; end
def dispose
self.bitmap.dispose
super
end
def update
super
update_position
end
def update_position
slide_left if Input.press?(:LEFT)
slide_right if Input.press?(:RIGHT)
end
def slide_left
result = self.x - slide_speed
return self.x = 0 if result <= 0
self.x -= slide_speed
end
def slide_right
result = self.x + slide_speed
block = Graphics.width - paddle_width
return self.x = block if result >= block
self.x += slide_speed
end
end
class Sprite_Breakout_Clone_Ball < Sprite
attr_accessor :route_x
attr_accessor :route_y
attr_accessor :ball_last_touch
def initialize(viewport, paddle = nil)
super(viewport)
@paddle = paddle
init_members
create_bitmap
end
def init_members
@move_speed = 4
@route_x = [-(rand(@move_speed) + 1), rand(@move_speed) + 1][rand(2)]
@route_y = -(@move_speed + 1)
@ball_last_touch = :paddle
end
def create_bitmap
self.bitmap = Cache.breakout_clone("ball")
self.x = (Graphics.width - ball_width) / 2
self.y = Graphics.height - @paddle.bitmap.height - ball_height
end
def move_speed; @move_speed; end
def route_x; @route_x; end
def route_y; @route_y; end
def ball_width; self.bitmap.width; end
def ball_height; self.bitmap.height; end
def ball_x; self.x + ball_width; end
def ball_y; self.y + ball_height; end
def dispose
self.bitmap.dispose
super
end
def update
super
update_position
update_ball_touch
end
def update_position
if $game_temp.breakout_clone_start?
self.x = (@paddle.x + @paddle.bitmap.width) / 2 - ball_width / 2
self.y = Graphics.height - @paddle.bitmap.height - ball_height
else
self.x += route_x
self.y += route_y
end
end
def update_ball_touch
return if $game_temp.breakout_clone_gameover?
update_touch_paddle
update_touch_wall
end
def update_touch_paddle
return if @ball_last_touch == :paddle
if ball_x.between?(@paddle.x, @paddle.x + @paddle.bitmap.width + ball_width) && ball_y.between?(@paddle.y, @paddle.y + @paddle.bitmap.height)
if (ball_x.between?(@paddle.x, @paddle.x + (ball_width / 2)) && route_x > 0) || (self.x.between?(@paddle.x + @paddle.bitmap.width - (ball_width / 2), @paddle.x + @paddle.bitmap.width) && route_x < 0)
if Input.press?(:RIGHT) && route_x < 0
@route_x = rand(move_speed) + 1
elsif Input.press?(:LEFT) && route_x > 0
@route_x = -(rand(move_speed) + 1)
else
@route_x = -(route_x)
end
else
@route_x = rand(move_speed) + 1 if Input.press?(:RIGHT)
@route_x = -(rand(move_speed) + 1) if Input.press?(:LEFT)
end
@route_y = -(move_speed) unless self.y > @paddle.y
@ball_last_touch = :paddle
end
end
def update_touch_wall
if self.x <= 0 || ball_x >= Graphics.width
@route_x = -(route_x)
@ball_last_touch = :wall
end
if self.y <= 0
@route_y = -(route_y)
@ball_last_touch = :wall
end
end
end
class Sprite_Breakout_Clone_Brick < Sprite
def initialize(viewport, balls = nil, brick = nil)
super(viewport)
@ball = balls
@brick = brick
init_members
create_bitmap
end
def init_members
@brick_life = @brick[0]
end
def create_bitmap
self.bitmap = Cache.breakout_clone("brick")
self.x = @brick[1]
self.y = @brick[2]
end
def dispose
self.bitmap.dispose
super
end
def update
super
update_src_rect
update_brick_touch
update_brick_visible
end
def update_src_rect
return if @brick_life.zero?
index = @brick_life
sy = (index - 1) * 24
self.src_rect.set(0, sy, 68, 24)
end
def update_brick_touch
return if self.visible == false
@ball.each do |b|
return if b.ball_last_touch == self
if b.ball_x.between?(self.x, self.x + self.bitmap.width + b.ball_width) && b.ball_y.between?(self.y, self.y + self.bitmap.height / 7 + b.ball_height)
if (b.x).between?(self.x - b.bitmap.width + 1, self.x + self.bitmap.width - 1)
b.route_y = -(b.route_y)
end
if (b.y).between?(self.y - b.bitmap.height + 1, self.y + self.bitmap.height / 7 - 1)
b.route_x = -(b.route_x)
end
@brick_life -= 1 if @brick_life > 0
b.ball_last_touch = self
end
end
end
def update_brick_visible
self.visible = !@brick_life.zero?
end
end
class Scene_Breakout_Clone < Scene_Base
include BREAKOUT_CLONE
def start
super
create_breakout_clone_paddle
create_breakout_clone_ball
create_breakout_clone_brick
end
def create_breakout_clone_paddle
@breakout_clone_paddle_sprite = Sprite_Breakout_Clone_Paddle.new
end
def create_breakout_clone_ball
@breakout_clone_ball_sprite ||= []
@breakout_clone_ball_sprite.push(Sprite_Breakout_Clone_Ball.new(@viewport1, @breakout_clone_paddle_sprite))
end
def create_breakout_clone_brick
@breakout_clone_brick_sprite ||= []
STAGE[0].each do |brick|
@breakout_clone_brick_sprite.push(Sprite_Breakout_Clone_Brick.new(@viewport1, @breakout_clone_ball_sprite, brick))
end
end
def terminate
super
dispose_breakout_clone_paddle
dispose_breakout_clone_ball
dispose_breakout_clone_brick
end
def dispose_breakout_clone_paddle
@breakout_clone_paddle_sprite.bitmap.dispose
@breakout_clone_paddle_sprite.dispose
end
def dispose_breakout_clone_ball
@breakout_clone_ball_sprite.each do |sprite|
sprite.bitmap.dispose
sprite.dispose
end
end
def dispose_breakout_clone_brick
@breakout_clone_brick_sprite.each do |sprite|
sprite.bitmap.dispose
sprite.dispose
end
end
def update
super
@breakout_clone_paddle_sprite.update
@breakout_clone_ball_sprite.each {|sprite| sprite.update}
@breakout_clone_brick_sprite.each {|sprite| sprite.update}
end
end
|
|