simply and bugged arkanoid
Monkey Forums/Monkey Code/simply and bugged arkanoid
| ||
| ehi guys i made a simply and bugged arkanoid portet on my old blitzmax try. I use for test desktop output because im trying free version of monkey-x. Dont insult me if its bugged, its just a test of some functions. Maybe usefull for someone! here the code!
' Basic Monkey game structure:
Import mojo
Class Color
Field red:Byte
Field green:Byte
Field blue:Byte
End
Class Paddle
Field x:Float
Field y:Float
Field SizeX:Float
Field SizeY:Float
End
Class Ball
Field x:Float
Field y:Float
Field DirX:Float
Field DirY:Float
Field Size:Int
End
Function AllocateArray:Int[][]( i:Int, j:Int)
Local arr:Int[][] = New Int[i][]
For Local ind = 0 Until i
arr[ind] = New Int[j]
Next
Return arr
End
Class Game Extends App
Field PADDLEX:Int = 20
Field PADDLEY:Int = 10
Field BlockXOrigin:Int = 25
Field BlockYOrigin:Int = 10
Field Speed:Float = 0.5
Field colonne:Int = 5
Field righe:Int = 10
Field Seed : Int
Field pallina:Ball
Field giocatore:Paddle
Field score:Int
Field level:Int
Field total:Int
'Field Grid:Int[colonne][righe]
Field Grid:Int[][]
Method OnCreate:Int ()
'Seed = Millisecs()
ResetLevel()
SetUpdateRate 60
Return 0
End
Method OnUpdate:Int()
' Check the cursor keys (arrows) and adjust the x and y
' positions according to which keys are being held:
If KeyDown (KEY_LEFT) Then giocatore.x = giocatore.x-10
if KeyDown (KEY_RIGHT) Then giocatore.x = giocatore.x+10
If KeyDown (KEY_ESCAPE) Then EndApp()
Aggiorna()
PallinaControPaddle()
ControlloPallinaMattoni
Return 0
End
Method OnRender:Int ()
' Cls clears the screen:
Cls 0, 0, 0
' DrawRect draws a rectangle at our x and y co-ordinates, which
' were calculated in the OnUpdate method. The rectangle will
' be 8 pixels wide and 8 pixels high:
'DrawRect 10, 10, 8, 8
Disegna()
Return 0
End
' RESET LEVEL
Method ResetLevel()
total = 0
score = 0
level = 1
pallina = New Ball
giocatore = New Paddle
Grid = AllocateArray(righe, colonne)
For Local x = 0 To righe-1
For Local y = 0 To colonne-1
Grid[x][y] = 1
Next
Next
' Inizializzo il giocatore (in verita' inizializzo il paddle,posizione e grandezza)
giocatore.SizeX = 75
giocatore.SizeY = 15
giocatore.x = (DeviceWidth()- giocatore.SizeX)/2
giocatore.y = DeviceHeight()-50
' Inizializzo la pallina
pallina.x = DeviceWidth()/2
pallina.y = DeviceHeight() - 200
pallina.DirX = Rnd(1, 5) ' velocita' x
pallina.DirY = -5 ' velocita' y
pallina.Size = 10 ' grandezza della pallina
End ' ResetLevel
Method Disegna()
DrawRect(giocatore.x, giocatore.y, giocatore.SizeX, giocatore.SizeY)
DrawOval(pallina.x, pallina.y, pallina.Size, pallina.Size)
DisegnaMattoni()
HUD()
'DrawText ("Height " + DeviceHeight() , 10 ,10 )
'DrawText ("Width " + DeviceWidth() , 10 ,20 )
End
Method HUD()
If (score =5) Then
level=level+1
pallina.DirX = pallina.DirX+ (level/5)
score=0
Endif
DrawLine 0,455,640,455
SetColor 200,100,100
DrawText("Level: " + level,1,460)
DrawText("Total: " + total,100,460)
SetColor 255,255,255
End
Method DisegnaMattoni()
For Local x=0 To righe-1
For Local y=0 To colonne-1
If (Grid[x][y]=1) Then
SetColor 255,0,0
DrawRect((x*60+BlockXOrigin),(y*30+BlockYOrigin),50,18)
End If
Next
Next
SetColor 255,255,255
End
Method PallinaControPaddle()
If (pallina.x>=giocatore.x) And pallina.x<=(giocatore.x+giocatore.SizeX) And (pallina.y+pallina.Size)>= giocatore.y And pallina.y+pallina.Size<=giocatore.y+giocatore.SizeY Then
pallina.DirY=0-pallina.DirY
Endif
End
Method Aggiorna()
If ((pallina.x>=640-pallina.Size Or (pallina.x<=0))) Then
pallina.DirX=0-pallina.DirX
Endif
If (pallina.y<=0) Then
pallina.DirY=0-pallina.DirY
Endif
If ((giocatore.x>=640-giocatore.SizeX)) Then
giocatore.x = 640-giocatore.SizeX
End If
If ((giocatore.x<=0)) Then
giocatore.x = 0
End If
If (pallina.y>= (DeviceHeight()-pallina.Size-giocatore.SizeY )-15) Then
EndApp()
Endif
pallina.x= pallina.x + pallina.DirX
pallina.y= pallina.y + pallina.DirY
End
method ControlloPallinaMattoni()
Local mattoni=0
For Local x=0 To righe-1
For Local y=0 To colonne-1
If(Grid[x][y])=1 Then
mattoni=mattoni+1
If Collisione(pallina,(x*60+BlockXOrigin),(y*30+BlockYOrigin),50,18) Then
Grid[x][y]=0
pallina.DirY=0-pallina.DirY
score=score+1
total=total+1
End If
End If
Next
Next
End
Method Collisione:Bool(pallina:Ball , x , y , SizeX, SizeY)
Local left1, left2
Local right1, right2
Local top1, top2
Local bottom1, bottom2
left1 = pallina.x
left2 = x
right1 = pallina.x + pallina.Size
right2 = x + SizeX
top1 = pallina.y
top2 = y
bottom1 = pallina.y + pallina.Size
bottom2 = y + SizeY
If (bottom1 < top2) Return False
If (top1 > bottom2) Return False
If (right1 < left2) Return False
If (left1 > right2) Return False
Return True
End
Method HaiPerso()
Cls
DrawText "Mi dispiace hai perso!!!",300,250
DrawText "Il tuo punteggio e' stato: " + total , 300, 270
EndApp()
End
End ' class Game
Function Main ()
New Game
End
|