Added decent spacing to all scripts thanks to Rubocop

This commit is contained in:
Maruno17
2021-12-18 15:25:40 +00:00
parent f7b76ae62e
commit d17fc40a47
207 changed files with 18577 additions and 18587 deletions

View File

@@ -22,60 +22,60 @@ class TilePuzzleCursor < BitmapSprite
attr_accessor :selected
attr_accessor :holding
def initialize(game,position,tilewidth,tileheight,boardwidth,boardheight)
@viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
@viewport.z=99999
super(Graphics.width,Graphics.height,@viewport)
@game=game
@position=position
@tilewidth=tilewidth
@tileheight=tileheight
@boardwidth=boardwidth
@boardheight=boardheight
@arrows=[]
@selected=false
@holding=false
@cursorbitmap=AnimatedBitmap.new(_INTL("Graphics/Pictures/Tile Puzzle/cursor"))
def initialize(game, position, tilewidth, tileheight, boardwidth, boardheight)
@viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
@viewport.z = 99999
super(Graphics.width, Graphics.height, @viewport)
@game = game
@position = position
@tilewidth = tilewidth
@tileheight = tileheight
@boardwidth = boardwidth
@boardheight = boardheight
@arrows = []
@selected = false
@holding = false
@cursorbitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/Tile Puzzle/cursor"))
update
end
def update
self.bitmap.clear
x=(Graphics.width-(@tilewidth*@boardwidth))/2
if @position>=@boardwidth*@boardheight
x=(x-(@tilewidth*(@boardwidth/2).ceil))/2-10
if (@position%@boardwidth)>=(@boardwidth/2).ceil
x=Graphics.width-x-@tilewidth*@boardwidth
x = (Graphics.width - (@tilewidth * @boardwidth)) / 2
if @position >= @boardwidth * @boardheight
x = (x - (@tilewidth * (@boardwidth / 2).ceil)) / 2 - 10
if (@position % @boardwidth) >= (@boardwidth / 2).ceil
x = Graphics.width - x - @tilewidth * @boardwidth
end
end
x+=@tilewidth*(@position%@boardwidth)
y=(Graphics.height-(@tileheight*@boardheight))/2-32
y+=@tileheight*((@position%(@boardwidth*@boardheight))/@boardwidth)
self.tone=Tone.new(0,(@holding ? 64 : 0),(@holding ? 64 : 0),0)
x += @tilewidth * (@position % @boardwidth)
y = (Graphics.height - (@tileheight * @boardheight)) / 2 - 32
y += @tileheight * ((@position % (@boardwidth * @boardheight)) / @boardwidth)
self.tone = Tone.new(0, (@holding ? 64 : 0), (@holding ? 64 : 0), 0)
# Cursor
if @game!=3
expand=(@holding) ? 0 : 4
if @game != 3
expand = (@holding) ? 0 : 4
for i in 0...4
self.bitmap.blt(x+(i%2)*(@tilewidth-@cursorbitmap.width/4)+expand*(((i%2)*2)-1),
y+(i/2)*(@tileheight-@cursorbitmap.height/2)+expand*(((i/2)*2)-1),
@cursorbitmap.bitmap,Rect.new(
(i%2)*@cursorbitmap.width/4,(i/2)*@cursorbitmap.height/2,
@cursorbitmap.width/4,@cursorbitmap.height/2))
self.bitmap.blt(x + (i % 2) * (@tilewidth - @cursorbitmap.width / 4) + expand * (((i % 2) * 2) - 1),
y + (i / 2) * (@tileheight - @cursorbitmap.height / 2) + expand * (((i / 2) * 2) - 1),
@cursorbitmap.bitmap, Rect.new(
(i % 2) * @cursorbitmap.width / 4, (i / 2) * @cursorbitmap.height / 2,
@cursorbitmap.width / 4, @cursorbitmap.height / 2))
end
end
# Arrows
if @selected || @game==3
expand=(@game==3) ? 0 : 4
xin=[(@tilewidth-@cursorbitmap.width/4)/2,-expand,
@tilewidth-@cursorbitmap.width/4+expand,(@tilewidth-@cursorbitmap.width/4)/2]
yin=[@tileheight-@cursorbitmap.height/2+expand,(@tileheight-@cursorbitmap.height/2)/2,
(@tileheight-@cursorbitmap.height/2)/2,-expand]
if @selected || @game == 3
expand = (@game == 3) ? 0 : 4
xin = [(@tilewidth - @cursorbitmap.width / 4) / 2, -expand,
@tilewidth - @cursorbitmap.width / 4 + expand, (@tilewidth - @cursorbitmap.width / 4) / 2]
yin = [@tileheight - @cursorbitmap.height / 2 + expand, (@tileheight - @cursorbitmap.height / 2) / 2,
(@tileheight - @cursorbitmap.height / 2) / 2, -expand]
for i in 0...4
if @arrows[i]
self.bitmap.blt(x+xin[i],y+yin[i],@cursorbitmap.bitmap,Rect.new(
@cursorbitmap.width/2+(i%2)*(@cursorbitmap.width/4),
(i/2)*(@cursorbitmap.height/2),
@cursorbitmap.width/4,@cursorbitmap.height/2))
self.bitmap.blt(x + xin[i], y + yin[i], @cursorbitmap.bitmap, Rect.new(
@cursorbitmap.width / 2 + (i % 2) * (@cursorbitmap.width / 4),
(i / 2) * (@cursorbitmap.height / 2),
@cursorbitmap.width / 4, @cursorbitmap.height / 2))
end
end
end
@@ -85,49 +85,49 @@ end
class TilePuzzleScene
def initialize(game,board,width,height)
@game=game
@board=board
@boardwidth=(width>0) ? width : 4
@boardheight=(height>0) ? height : 4
def initialize(game, board, width, height)
@game = game
@board = board
@boardwidth = (width > 0) ? width : 4
@boardheight = (height > 0) ? height : 4
end
def update
xtop=(Graphics.width-(@tilewidth*@boardwidth))/2
ytop=(Graphics.height-(@tileheight*@boardheight))/2+@tileheight/2-32
for i in 0...@boardwidth*@boardheight
pos=-1
xtop = (Graphics.width - (@tilewidth * @boardwidth)) / 2
ytop = (Graphics.height - (@tileheight * @boardheight)) / 2 + @tileheight / 2 - 32
for i in 0...@boardwidth * @boardheight
pos = -1
for j in 0...@tiles.length
pos=j if @tiles[j]==i
pos = j if @tiles[j] == i
end
@sprites["tile#{i}"].z=0
@sprites["tile#{i}"].tone=Tone.new(0,0,0,0)
if @heldtile==i
pos=@sprites["cursor"].position
@sprites["tile#{i}"].z=1
@sprites["tile#{i}"].tone=Tone.new(64,0,0,0) if @tiles[pos]>=0
@sprites["tile#{i}"].z = 0
@sprites["tile#{i}"].tone = Tone.new(0, 0, 0, 0)
if @heldtile == i
pos = @sprites["cursor"].position
@sprites["tile#{i}"].z = 1
@sprites["tile#{i}"].tone = Tone.new(64, 0, 0, 0) if @tiles[pos] >= 0
end
thisx=xtop
if pos>=0
if pos>=@boardwidth*@boardheight
thisx=(xtop-(@tilewidth*(@boardwidth/2).ceil))/2-10
if (pos%@boardwidth)>=(@boardwidth/2).ceil
thisx=Graphics.width-thisx-@tilewidth*@boardwidth
thisx = xtop
if pos >= 0
if pos >= @boardwidth * @boardheight
thisx = (xtop - (@tilewidth * (@boardwidth / 2).ceil)) / 2 - 10
if (pos % @boardwidth) >= (@boardwidth / 2).ceil
thisx = Graphics.width - thisx - @tilewidth * @boardwidth
end
end
@sprites["tile#{i}"].x=thisx+@tilewidth*(pos%@boardwidth)+@tilewidth/2
@sprites["tile#{i}"].y=ytop+@tileheight*((pos%(@boardwidth*@boardheight))/@boardwidth)
next if @game==3
rotatebitmaps=[@tilebitmap,@tilebitmap1,@tilebitmap2,@tilebitmap3]
@sprites["tile#{i}"].x = thisx + @tilewidth * (pos % @boardwidth) + @tilewidth / 2
@sprites["tile#{i}"].y = ytop + @tileheight * ((pos % (@boardwidth * @boardheight)) / @boardwidth)
next if @game == 3
rotatebitmaps = [@tilebitmap, @tilebitmap1, @tilebitmap2, @tilebitmap3]
@sprites["tile#{i}"].bitmap.clear
if rotatebitmaps[@angles[i]]
@sprites["tile#{i}"].bitmap.blt(0,0,rotatebitmaps[@angles[i]].bitmap,
Rect.new(@tilewidth*(i%@boardwidth),@tileheight*(i/@boardwidth),@tilewidth,@tileheight))
@sprites["tile#{i}"].angle=0
@sprites["tile#{i}"].bitmap.blt(0, 0, rotatebitmaps[@angles[i]].bitmap,
Rect.new(@tilewidth * (i % @boardwidth), @tileheight * (i / @boardwidth), @tilewidth, @tileheight))
@sprites["tile#{i}"].angle = 0
else
@sprites["tile#{i}"].bitmap.blt(0,0,@tilebitmap.bitmap,
Rect.new(@tilewidth*(i%@boardwidth),@tileheight*(i/@boardwidth),@tilewidth,@tileheight))
@sprites["tile#{i}"].angle=@angles[i]*90
@sprites["tile#{i}"].bitmap.blt(0, 0, @tilebitmap.bitmap,
Rect.new(@tilewidth * (i % @boardwidth), @tileheight * (i / @boardwidth), @tilewidth, @tileheight))
@sprites["tile#{i}"].angle = @angles[i] * 90
end
end
end
@@ -136,100 +136,100 @@ class TilePuzzleScene
end
def updateCursor
arrows=[]
arrows = []
for i in 0...4
arrows.push(pbCanMoveInDir?(@sprites["cursor"].position,(i+1)*2,@game==6))
arrows.push(pbCanMoveInDir?(@sprites["cursor"].position, (i + 1) * 2, @game == 6))
end
@sprites["cursor"].arrows=arrows
@sprites["cursor"].arrows = arrows
end
def pbStartScene
@sprites={}
@viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
@viewport.z=99999
@sprites = {}
@viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
@viewport.z = 99999
if pbResolveBitmap("Graphics/Pictures/Tile Puzzle/bg#{@board}")
addBackgroundPlane(@sprites,"bg","Tile Puzzle/bg#{@board}",@viewport)
addBackgroundPlane(@sprites, "bg", "Tile Puzzle/bg#{@board}", @viewport)
else
addBackgroundPlane(@sprites,"bg","Tile Puzzle/bg",@viewport)
addBackgroundPlane(@sprites, "bg", "Tile Puzzle/bg", @viewport)
end
@tilebitmap=AnimatedBitmap.new("Graphics/Pictures/Tile Puzzle/tiles#{@board}")
@tilebitmap1=nil
@tilebitmap2=nil
@tilebitmap3=nil
@tilebitmap = AnimatedBitmap.new("Graphics/Pictures/Tile Puzzle/tiles#{@board}")
@tilebitmap1 = nil
@tilebitmap2 = nil
@tilebitmap3 = nil
if pbResolveBitmap("Graphics/Pictures/Tile Puzzle/tiles#{@board}_1")
@tilebitmap1=AnimatedBitmap.new("Graphics/Pictures/Tile Puzzle/tiles#{@board}_1")
@tilebitmap1 = AnimatedBitmap.new("Graphics/Pictures/Tile Puzzle/tiles#{@board}_1")
end
if pbResolveBitmap("Graphics/Pictures/Tile Puzzle/tiles#{@board}_2")
@tilebitmap2=AnimatedBitmap.new("Graphics/Pictures/Tile Puzzle/tiles#{@board}_2")
@tilebitmap2 = AnimatedBitmap.new("Graphics/Pictures/Tile Puzzle/tiles#{@board}_2")
end
if pbResolveBitmap("Graphics/Pictures/Tile Puzzle/tiles#{@board}_3")
@tilebitmap3=AnimatedBitmap.new("Graphics/Pictures/Tile Puzzle/tiles#{@board}_3")
@tilebitmap3 = AnimatedBitmap.new("Graphics/Pictures/Tile Puzzle/tiles#{@board}_3")
end
@tilewidth=@tilebitmap.width/@boardwidth
@tileheight=@tilebitmap.height/@boardheight
for i in 0...@boardwidth*@boardheight
@sprites["tile#{i}"]=BitmapSprite.new(@tilewidth,@tileheight,@viewport)
@sprites["tile#{i}"].ox=@tilewidth/2
@sprites["tile#{i}"].oy=@tileheight/2
break if @game==3 && i>=@boardwidth*@boardheight-1
@sprites["tile#{i}"].bitmap.blt(0,0,@tilebitmap.bitmap,
Rect.new(@tilewidth*(i%@boardwidth),@tileheight*(i/@boardwidth),@tilewidth,@tileheight))
@tilewidth = @tilebitmap.width / @boardwidth
@tileheight = @tilebitmap.height / @boardheight
for i in 0...@boardwidth * @boardheight
@sprites["tile#{i}"] = BitmapSprite.new(@tilewidth, @tileheight, @viewport)
@sprites["tile#{i}"].ox = @tilewidth / 2
@sprites["tile#{i}"].oy = @tileheight / 2
break if @game == 3 && i >= @boardwidth * @boardheight - 1
@sprites["tile#{i}"].bitmap.blt(0, 0, @tilebitmap.bitmap,
Rect.new(@tilewidth * (i % @boardwidth), @tileheight * (i / @boardwidth), @tilewidth, @tileheight))
end
@heldtile=-1
@angles=[]
@tiles=pbShuffleTiles
@sprites["cursor"]=TilePuzzleCursor.new(@game,pbDefaultCursorPosition,
@tilewidth,@tileheight,@boardwidth,@boardheight)
@heldtile = -1
@angles = []
@tiles = pbShuffleTiles
@sprites["cursor"] = TilePuzzleCursor.new(@game, pbDefaultCursorPosition,
@tilewidth, @tileheight, @boardwidth, @boardheight)
update
pbFadeInAndShow(@sprites)
end
def pbShuffleTiles
ret=[]
for i in 0...@boardwidth*@boardheight
ret = []
for i in 0...@boardwidth * @boardheight
ret.push(i)
@angles.push(0)
end
if @game==6
@tiles=ret
if @game == 6
@tiles = ret
5.times do
pbShiftLine([2,4,6,8][rand(4)],rand(@boardwidth*@boardheight),false)
pbShiftLine([2, 4, 6, 8][rand(4)], rand(@boardwidth * @boardheight), false)
end
return @tiles
elsif @game==7
@tiles=ret
elsif @game == 7
@tiles = ret
5.times do
pbRotateTile(rand(@boardwidth*@boardheight),false)
pbRotateTile(rand(@boardwidth * @boardheight), false)
end
else
ret.shuffle!
if @game==3 # Make sure only solvable Mystic Squares are allowed.
num=0
blank=-1
for i in 0...ret.length-1
blank=i if ret[i]==@boardwidth*@boardheight-1
if @game == 3 # Make sure only solvable Mystic Squares are allowed.
num = 0
blank = -1
for i in 0...ret.length - 1
blank = i if ret[i] == @boardwidth * @boardheight - 1
for j in i...ret.length
num+=1 if ret[j]<ret[i] && ret[i]!=@boardwidth*@boardheight-1 &&
ret[j]!=@boardwidth*@boardheight-1
num += 1 if ret[j] < ret[i] && ret[i] != @boardwidth * @boardheight - 1 &&
ret[j] != @boardwidth * @boardheight - 1
end
end
if @boardwidth%2==1
ret=pbShuffleTiles if num%2==1
if @boardwidth % 2 == 1
ret = pbShuffleTiles if num % 2 == 1
else
ret=pbShuffleTiles if !((num%2==0 && (@boardheight-(blank/@boardwidth))%2==1) ||
(num%2==1 && (@boardheight-(blank/@boardwidth))%2==0))
ret = pbShuffleTiles if !((num % 2 == 0 && (@boardheight - (blank / @boardwidth)) % 2 == 1) ||
(num % 2 == 1 && (@boardheight - (blank / @boardwidth)) % 2 == 0))
end
end
if @game==1 || @game==2
ret2=[]
for i in 0...@boardwidth*@boardheight
if @game == 1 || @game == 2
ret2 = []
for i in 0...@boardwidth * @boardheight
ret2.push(-1)
end
ret=ret2+ret
ret = ret2 + ret
end
if @game==2 || @game==5
if @game == 2 || @game == 5
for i in 0...@angles.length
@angles[i]=rand(4)
@angles[i] = rand(4)
end
end
end
@@ -237,9 +237,9 @@ class TilePuzzleScene
end
def pbDefaultCursorPosition
if @game==3
for i in 0...@boardwidth*@boardheight
return i if @tiles[i]==@boardwidth*@boardheight-1
if @game == 3
for i in 0...@boardwidth * @boardheight
return i if @tiles[i] == @boardwidth * @boardheight - 1
end
return 0
else
@@ -247,73 +247,73 @@ class TilePuzzleScene
end
end
def pbMoveCursor(pos,dir)
if dir==2
pos+=@boardwidth
elsif dir==4
if pos>=@boardwidth*@boardheight
if pos%@boardwidth==(@boardwidth/2).ceil
pos=((pos%(@boardwidth*@boardheight))/@boardwidth)*@boardwidth+@boardwidth-1
def pbMoveCursor(pos, dir)
if dir == 2
pos += @boardwidth
elsif dir == 4
if pos >= @boardwidth * @boardheight
if pos % @boardwidth == (@boardwidth / 2).ceil
pos = ((pos % (@boardwidth * @boardheight)) / @boardwidth) * @boardwidth + @boardwidth - 1
else
pos-=1
pos -= 1
end
else
if (pos%@boardwidth)==0
pos=(((pos/@boardwidth)+@boardheight)*@boardwidth)+(@boardwidth/2).ceil-1
if (pos % @boardwidth) == 0
pos = (((pos / @boardwidth) + @boardheight) * @boardwidth) + (@boardwidth / 2).ceil - 1
else
pos-=1
pos -= 1
end
end
elsif dir==6
if pos>=@boardwidth*@boardheight
if pos%@boardwidth==(@boardwidth/2).ceil-1
pos=((pos%(@boardwidth*@boardheight))/@boardwidth)*@boardwidth
elsif dir == 6
if pos >= @boardwidth * @boardheight
if pos % @boardwidth == (@boardwidth / 2).ceil - 1
pos = ((pos % (@boardwidth * @boardheight)) / @boardwidth) * @boardwidth
else
pos+=1
pos += 1
end
else
if pos%@boardwidth>=@boardwidth-1
pos=(((pos/@boardwidth)+@boardheight)*@boardwidth)+(@boardwidth/2).ceil
if pos % @boardwidth >= @boardwidth - 1
pos = (((pos / @boardwidth) + @boardheight) * @boardwidth) + (@boardwidth / 2).ceil
else
pos+=1
pos += 1
end
end
elsif dir==8
pos-=@boardwidth
elsif dir == 8
pos -= @boardwidth
end
return pos
end
def pbCanMoveInDir?(pos,dir,swapping)
return true if @game==6 && swapping
if dir==2
return false if (pos/@boardwidth)%@boardheight>=@boardheight-1
elsif dir==4
if @game==1 || @game==2
return false if pos>=@boardwidth*@boardheight && pos%@boardwidth==0
def pbCanMoveInDir?(pos, dir, swapping)
return true if @game == 6 && swapping
if dir == 2
return false if (pos / @boardwidth) % @boardheight >= @boardheight - 1
elsif dir == 4
if @game == 1 || @game == 2
return false if pos >= @boardwidth * @boardheight && pos % @boardwidth == 0
else
return false if pos%@boardwidth==0
return false if pos % @boardwidth == 0
end
elsif dir==6
if @game==1 || @game==2
return false if pos>=@boardwidth*@boardheight && pos%@boardwidth>=@boardwidth-1
elsif dir == 6
if @game == 1 || @game == 2
return false if pos >= @boardwidth * @boardheight && pos % @boardwidth >= @boardwidth - 1
else
return false if pos%@boardwidth>=@boardwidth-1
return false if pos % @boardwidth >= @boardwidth - 1
end
elsif dir==8
return false if (pos/@boardwidth)%@boardheight==0
elsif dir == 8
return false if (pos / @boardwidth) % @boardheight == 0
end
return true
end
def pbRotateTile(pos,anim = true)
if @heldtile>=0
def pbRotateTile(pos, anim = true)
if @heldtile >= 0
if anim
@sprites["cursor"].visible=false
@sprites["cursor"].visible = false
@sprites["tile#{@heldtile}"].z = 1
oldAngle = @sprites["tile#{@heldtile}"].angle
rotateTime = Graphics.frame_rate/4
angleDiff = 90.0/rotateTime
rotateTime = Graphics.frame_rate / 4
angleDiff = 90.0 / rotateTime
rotateTime.times do
@sprites["tile#{@heldtile}"].angle -= angleDiff
pbUpdateSpriteHash(@sprites)
@@ -321,23 +321,23 @@ class TilePuzzleScene
Input.update
end
@sprites["tile#{@heldtile}"].z = 0
@sprites["tile#{@heldtile}"].angle = oldAngle-90
@sprites["cursor"].visible=true if !pbCheckWin
@sprites["tile#{@heldtile}"].angle = oldAngle - 90
@sprites["cursor"].visible = true if !pbCheckWin
end
@angles[@heldtile]-=1
@angles[@heldtile]+=4 if @angles[@heldtile]<0
@angles[@heldtile] -= 1
@angles[@heldtile] += 4 if @angles[@heldtile] < 0
else
return if @tiles[pos]<0
group=pbGetNearTiles(pos)
return if @tiles[pos] < 0
group = pbGetNearTiles(pos)
if anim
@sprites["cursor"].visible=false
@sprites["cursor"].visible = false
oldAngles = []
for i in group
@sprites["tile#{@tiles[i]}"].z = 1
oldAngles[i] = @sprites["tile#{@tiles[i]}"].angle
end
rotateTime = Graphics.frame_rate/4
angleDiff = 90.0/rotateTime
rotateTime = Graphics.frame_rate / 4
angleDiff = 90.0 / rotateTime
rotateTime.times do
for i in group
@sprites["tile#{@tiles[i]}"].angle -= angleDiff
@@ -348,114 +348,114 @@ class TilePuzzleScene
end
for i in group
@sprites["tile#{@tiles[i]}"].z = 0
@sprites["tile#{@tiles[i]}"].angle = oldAngles[i]-90
@sprites["tile#{@tiles[i]}"].angle = oldAngles[i] - 90
end
@sprites["cursor"].visible=true if !pbCheckWin
@sprites["cursor"].visible = true if !pbCheckWin
end
for i in group
tile=@tiles[i]
@angles[tile]-=1
@angles[tile]+=4 if @angles[tile]<0
tile = @tiles[i]
@angles[tile] -= 1
@angles[tile] += 4 if @angles[tile] < 0
end
end
end
def pbGetNearTiles(pos)
ret=[pos]
if @game==7
for i in [2,4,6,8]
ret.push(pbMoveCursor(pos,i)) if pbCanMoveInDir?(pos,i,true)
ret = [pos]
if @game == 7
for i in [2, 4, 6, 8]
ret.push(pbMoveCursor(pos, i)) if pbCanMoveInDir?(pos, i, true)
end
end
return ret
end
def pbSwapTiles(dir)
cursor=@sprites["cursor"].position
return pbShiftLine(dir,cursor) if @game==6
movetile=pbMoveCursor(cursor,dir)
@sprites["cursor"].visible=false
@sprites["tile#{@tiles[cursor]}"].z=1
if dir==2 || dir==8 # Swap vertically
swapTime = Graphics.frame_rate*3/10
distancePerFrame = (@tileheight.to_f/swapTime).ceil
dist = (dir/4).floor-1
cursor = @sprites["cursor"].position
return pbShiftLine(dir, cursor) if @game == 6
movetile = pbMoveCursor(cursor, dir)
@sprites["cursor"].visible = false
@sprites["tile#{@tiles[cursor]}"].z = 1
if dir == 2 || dir == 8 # Swap vertically
swapTime = Graphics.frame_rate * 3 / 10
distancePerFrame = (@tileheight.to_f / swapTime).ceil
dist = (dir / 4).floor - 1
swapTime.times do
@sprites["tile#{@tiles[movetile]}"].y += dist*distancePerFrame
@sprites["tile#{@tiles[cursor]}"].y -= dist*distancePerFrame
@sprites["tile#{@tiles[movetile]}"].y += dist * distancePerFrame
@sprites["tile#{@tiles[cursor]}"].y -= dist * distancePerFrame
pbUpdateSpriteHash(@sprites)
Graphics.update
Input.update
end
else # Swap horizontally
swapTime = Graphics.frame_rate*3/10
distancePerFrame = (@tilewidth.to_f/swapTime).ceil
dist = dir-5
swapTime = Graphics.frame_rate * 3 / 10
distancePerFrame = (@tilewidth.to_f / swapTime).ceil
dist = dir - 5
swapTime.times do
@sprites["tile#{@tiles[movetile]}"].x -= dist*distancePerFrame
@sprites["tile#{@tiles[cursor]}"].x += dist*distancePerFrame
@sprites["tile#{@tiles[movetile]}"].x -= dist * distancePerFrame
@sprites["tile#{@tiles[cursor]}"].x += dist * distancePerFrame
pbUpdateSpriteHash(@sprites)
Graphics.update
Input.update
end
end
@tiles[cursor], @tiles[movetile]=@tiles[movetile], @tiles[cursor]
@sprites["tile#{@tiles[cursor]}"].z=0
@sprites["cursor"].position=movetile
@sprites["cursor"].selected=false
@sprites["cursor"].visible=true if !pbCheckWin
@tiles[cursor], @tiles[movetile] = @tiles[movetile], @tiles[cursor]
@sprites["tile#{@tiles[cursor]}"].z = 0
@sprites["cursor"].position = movetile
@sprites["cursor"].selected = false
@sprites["cursor"].visible = true if !pbCheckWin
return true
end
def pbShiftLine(dir,cursor,anim = true)
def pbShiftLine(dir, cursor, anim = true)
# Get tiles involved
tiles=[]
dist=0
if dir==2 || dir==8
dist=(dir/4).floor-1
while (dist>0 && cursor<(@boardwidth-1)*@boardheight) ||
(dist<0 && cursor>=@boardwidth)
cursor+=(@boardwidth*dist)
tiles = []
dist = 0
if dir == 2 || dir == 8
dist = (dir / 4).floor - 1
while (dist > 0 && cursor < (@boardwidth - 1) * @boardheight) ||
(dist < 0 && cursor >= @boardwidth)
cursor += (@boardwidth * dist)
end
for i in 0...@boardheight
tiles.push(cursor-i*dist*@boardwidth)
tiles.push(cursor - i * dist * @boardwidth)
end
else
dist=dir-5
while (dist>0 && cursor%@boardwidth>0) ||
(dist<0 && cursor%@boardwidth<@boardwidth-1)
cursor-=dist
dist = dir - 5
while (dist > 0 && cursor % @boardwidth > 0) ||
(dist < 0 && cursor % @boardwidth < @boardwidth - 1)
cursor -= dist
end
for i in 0...@boardwidth
tiles.push(cursor+i*dist)
tiles.push(cursor + i * dist)
end
end
# Shift tiles
fadeTime = Graphics.frame_rate*4/10
fadeDiff = (255.0/fadeTime).ceil
fadeTime = Graphics.frame_rate * 4 / 10
fadeDiff = (255.0 / fadeTime).ceil
if anim
@sprites["cursor"].visible=false
@sprites["cursor"].visible = false
fadeTime.times do
@sprites["tile#{@tiles[tiles[tiles.length-1]]}"].opacity-=fadeDiff
@sprites["tile#{@tiles[tiles[tiles.length - 1]]}"].opacity -= fadeDiff
Graphics.update
Input.update
end
shiftTime = Graphics.frame_rate*3/10
if dir==2 || dir==8
distancePerFrame = (@tileheight.to_f/shiftTime).ceil
shiftTime = Graphics.frame_rate * 3 / 10
if dir == 2 || dir == 8
distancePerFrame = (@tileheight.to_f / shiftTime).ceil
shiftTime.times do
for i in tiles
@sprites["tile#{@tiles[i]}"].y -= dist*distancePerFrame
@sprites["tile#{@tiles[i]}"].y -= dist * distancePerFrame
end
pbUpdateSpriteHash(@sprites)
Graphics.update
Input.update
end
else
distancePerFrame = (@tilewidth.to_f/shiftTime).ceil
distancePerFrame = (@tilewidth.to_f / shiftTime).ceil
shiftTime.times do
for i in tiles
@sprites["tile#{@tiles[i]}"].x += dist*distancePerFrame
@sprites["tile#{@tiles[i]}"].x += dist * distancePerFrame
end
pbUpdateSpriteHash(@sprites)
Graphics.update
@@ -463,36 +463,36 @@ class TilePuzzleScene
end
end
end
temp=[]
temp = []
for i in tiles
temp.push(@tiles[i])
end
for i in 0...temp.length
@tiles[tiles[(i+1)%(temp.length)]]=temp[i]
@tiles[tiles[(i + 1) % (temp.length)]] = temp[i]
end
if anim
update
fadeTime.times do
@sprites["tile#{@tiles[tiles[0]]}"].opacity+=fadeDiff
@sprites["tile#{@tiles[tiles[0]]}"].opacity += fadeDiff
Graphics.update
Input.update
end
@sprites["cursor"].selected=false
@sprites["cursor"].visible=true if !pbCheckWin
@sprites["cursor"].selected = false
@sprites["cursor"].visible = true if !pbCheckWin
end
return true
end
def pbGrabTile(pos)
@heldtile, @tiles[pos] = @tiles[pos], @heldtile
@sprites["cursor"].holding=(@heldtile>=0)
@sprites["cursor"].visible=false if pbCheckWin
@sprites["cursor"].holding = (@heldtile >= 0)
@sprites["cursor"].visible = false if pbCheckWin
end
def pbCheckWin
for i in 0...@boardwidth*@boardheight
return false if @tiles[i]!=i
return false if @angles[i]!=0
for i in 0...@boardwidth * @boardheight
return false if @tiles[i] != i
return false if @angles[i] != 0
end
return true
end
@@ -504,23 +504,23 @@ class TilePuzzleScene
Input.update
# Check end conditions
if pbCheckWin
@sprites["cursor"].visible=false
if @game==3
extratile=@sprites["tile#{@boardwidth*@boardheight-1}"]
@sprites["cursor"].visible = false
if @game == 3
extratile = @sprites["tile#{@boardwidth * @boardheight - 1}"]
extratile.bitmap.clear
extratile.bitmap.blt(0,0,@tilebitmap.bitmap,
Rect.new(@tilewidth*(@boardwidth-1),@tileheight*(@boardheight-1),
@tilewidth,@tileheight))
extratile.opacity=0
appearTime = Graphics.frame_rate*8/10
opacityDiff = (255.0/appearTime).ceil
extratile.bitmap.blt(0, 0, @tilebitmap.bitmap,
Rect.new(@tilewidth * (@boardwidth - 1), @tileheight * (@boardheight - 1),
@tilewidth, @tileheight))
extratile.opacity = 0
appearTime = Graphics.frame_rate * 8 / 10
opacityDiff = (255.0 / appearTime).ceil
appearTime.times do
extratile.opacity += opacityDiff
Graphics.update
Input.update
end
else
pbWait(Graphics.frame_rate/2)
pbWait(Graphics.frame_rate / 2)
end
loop do
Graphics.update
@@ -530,29 +530,29 @@ class TilePuzzleScene
return true
end
# Input
@sprites["cursor"].selected=(Input.press?(Input::USE) && @game>=3 && @game<=6)
dir=0
dir=2 if Input.trigger?(Input::DOWN) || Input.repeat?(Input::DOWN)
dir=4 if Input.trigger?(Input::LEFT) || Input.repeat?(Input::LEFT)
dir=6 if Input.trigger?(Input::RIGHT) || Input.repeat?(Input::RIGHT)
dir=8 if Input.trigger?(Input::UP) || Input.repeat?(Input::UP)
if dir>0
if @game==3 || (@game!=3 && @sprites["cursor"].selected)
if pbCanMoveInDir?(@sprites["cursor"].position,dir,true)
@sprites["cursor"].selected = (Input.press?(Input::USE) && @game >= 3 && @game <= 6)
dir = 0
dir = 2 if Input.trigger?(Input::DOWN) || Input.repeat?(Input::DOWN)
dir = 4 if Input.trigger?(Input::LEFT) || Input.repeat?(Input::LEFT)
dir = 6 if Input.trigger?(Input::RIGHT) || Input.repeat?(Input::RIGHT)
dir = 8 if Input.trigger?(Input::UP) || Input.repeat?(Input::UP)
if dir > 0
if @game == 3 || (@game != 3 && @sprites["cursor"].selected)
if pbCanMoveInDir?(@sprites["cursor"].position, dir, true)
pbSEPlay("Tile Game cursor")
pbSwapTiles(dir)
end
else
if pbCanMoveInDir?(@sprites["cursor"].position,dir,false)
if pbCanMoveInDir?(@sprites["cursor"].position, dir, false)
pbSEPlay("Tile Game cursor")
@sprites["cursor"].position=pbMoveCursor(@sprites["cursor"].position,dir)
@sprites["cursor"].position = pbMoveCursor(@sprites["cursor"].position, dir)
end
end
elsif (@game==1 || @game==2) && Input.trigger?(Input::USE)
elsif (@game == 1 || @game == 2) && Input.trigger?(Input::USE)
pbGrabTile(@sprites["cursor"].position)
elsif (@game==2 && Input.trigger?(Input::ACTION)) ||
(@game==5 && Input.trigger?(Input::ACTION)) ||
(@game==7 && Input.trigger?(Input::USE))
elsif (@game == 2 && Input.trigger?(Input::ACTION)) ||
(@game == 5 && Input.trigger?(Input::ACTION)) ||
(@game == 7 && Input.trigger?(Input::USE))
pbRotateTile(@sprites["cursor"].position)
elsif Input.trigger?(Input::BACK)
return false
@@ -571,12 +571,12 @@ end
class TilePuzzle
def initialize(scene)
@scene=scene
@scene = scene
end
def pbStartScreen
@scene.pbStartScene
ret=@scene.pbMain
ret = @scene.pbMain
@scene.pbEndScene
return ret
end
@@ -584,10 +584,10 @@ end
def pbTilePuzzle(game,board,width = 0,height = 0)
def pbTilePuzzle(game, board, width = 0, height = 0)
ret = false
pbFadeOutIn {
scene = TilePuzzleScene.new(game,board,width,height)
scene = TilePuzzleScene.new(game, board, width, height)
screen = TilePuzzle.new(scene)
ret = screen.pbStartScreen
}