yeah was thinking of something like that but wasnt sure how to implement. would i be possible rotate each piece in a matrix, i will be looking into a shape factory though this is my current code
ps. my code is a little bit neater but the codebox shifts things around a bit
Import mojo
Global gcube:Image
global rcube:Image
global bcube:Image
global pkcube:Image
Global ycube:Image
Class shape
Field piece:Int[][]
Field color:int
Field img:Image
Field x:Int ,y:Int
Field rowmax:Int
Field colmax:Int
Field gravity:Int
Method New(img:Image,x:Int,y:Int,
rowmax:Int,colmax:Int,piece:int[][])
Self.rowmax = rowmax
Self.colmax =colmax
Self.img= img
Self.x = x
Self.y = y
Self.piece = piece
End
Method Draw()
For Local i:Int = 0 To rowmax
For Local j:Int = 0 To colmax
If piece[j][i] = 1
DrawImage(img,x+i*26,y+j*25,0,.5,.5)
End
End
End
End
' Method t()
' [[1,1,1],
' [0,1,0]]
'End
Method move(gravity:Int)
Self.gravity = gravity
If KeyHit(KEY_RIGHT)
x+=26
Elseif KeyHit(KEY_LEFT)
x-=26
End
' y+=gravity
End
End class
Class drop
Field size:float
Field gravity:Float
Field droplet:Image
Field x:Int,y:Int
Method New(x:Int,y:Int,droplet:Image)
Self.droplet = droplet
Self.x = x
Self.y = y
Self.size = size
gravity = Rnd(5.0,8.0)
size = Rnd(0.2,.5)
End
Method fall()
Self.gravity = gravity
y+= gravity
End
Method Draw()
DrawImage(droplet,x,y,0,size,size)
End
End Class
Class bg
Field x:Int
Field y:Int
Field speed:Int
Field bg1:Image
Field name:String
Method New(x:Int,y:Int,bg1:Image)
Self.x = x
Self.y = y
Self.bg1 = bg1
End
Method scroll(speed:Int)
Self.speed = speed
x = x + speed
End
Method create(name:String)
Self.name = name
bg1 = LoadImage("bg.png ")
End
Method Draw()
DrawImage (bg1, x,y)
End
End Class
Class test2 Extends App
Field ScreenHeight = 480
Field ScreenWidth = 640
Field shapePicker:Int = 2
Field background:bg
Field bg1:Image
Field bg2:bg
Field droplet:Image
Field rain:drop
Field bgList:List<bg> = New List<bg>()
Field dropList:List<drop> = New List<drop>()
Field L:shape
Field I:shape
Field T:shape
Field Z:shape
Field O:shape
Field shapeList:List<shape> = New List<shape>()
Method OnCreate()
SetUpdateRate(60)
ycube = LoadImage("yellowcubesmall.png")
pkcube = LoadImage("pinkcubesmall.png")
rcube = LoadImage("redcubesmall.png")
bcube = LoadImage("bluecubesmall.png")
gcube = LoadImage("greencubesmall.png")
For Local i:Int = 0 To 4
End
If shapePicker = 1
shapeList.AddLast(New shape(gcube,150, 150,2,1,[[1,1,1],[0,1,0]])) 'T
Elseif shapePicker = 2
shapeList.AddLast(New shape(ycube,ScreenWidth/2, 0,2,1,[[1,1,0],[0,1,1]])) 'Z
Elseif shapePicker = 3
shapeList.AddLast(New shape(bcube,250, 250,0,3,[[1],[1],[1],[1]])) 'I
Elseif shapePicker = 4
shapeList.AddLast(New shape(pkcube,250, 250,1,1,[[1,1],[1,1]])) 'O
Elseif shapePicker = 5
shapeList.AddLast(New shape(rcube,250, 250,1,2,[[1,0],[1,0],[1,1]]))'L
End
'PlayMusic ("rain.mp3",1)
rain = New drop
droplet = LoadImage("drop.png")
background = New bg
bg1 = LoadImage("bg2.png")
' background.create("bg.png")
bg2 = New bg(0,0,bg1)
bgList.AddLast(New bg(0,0,bg1))
End Method
Method OnUpdate()
For Local i:= Eachin shapeList
i.move(2)
End
dropList.AddLast(New drop(Rnd(ScreenWidth),0,droplet))
For Local rain:drop = Eachin dropList
rain.fall()
End
For Local rain:drop = Eachin dropList
If rain.y > 520
dropList.RemoveFirst()
End
End
End
Method OnRender()
Cls(0,0,0)
'bg2.Draw()
For Local rain:drop = Eachin dropList
rain.Draw()
End
For Local shape:= Eachin shapeList
shape.Draw()
End
SetColor(255,66,255)
SetAlpha .7
DrawRect(10,10,222,222)
DrawOval(34,13,30,34)
T.Draw()
Z.Draw()
O.Draw()
I.Draw()
L.Draw()
'nothing renders past here???
End
End
Function Main()
New test2()
End
quick thing, the bottom i couldnt render anything after the x.Draw's i had to put the DrawRect before them, is there a reason why???
|