;---------------------------------------------------------------------------
; Initialization is called in WM_CREATE
;---------------------------------------------------------------------------
Initialization	proc	uses ebx esi hWnd:DWORD
LOCAL	TempRect:RECT
	invoke	GetClientRect, hWnd, ADDR TempRect
	xor		ebx, ebx
	
     ; This loop will crate MAX_SMILES unique objects of CSprite Objects..
     ; and then initialize each with the Instance handle, a drawing DC, and 
     ; the drawing rect to draw within, and lastly a random speed is set to each
     ; sprite object.
	.WHILE	ebx < MAX_SMILIES
		newobject CSprite
		mov		esi, eax
		mov		dword ptr [offset SmileyArray + 4 * ebx], eax
		invoke	RAND32, 3
		add		eax, 200 ; base of smiley resources (200, 201, 202 etc) 
		invoke	LoadBitmap, hInstance, eax
		method	esi, CSprite, setBitmap, eax
		method	esi, CSprite, setDrawingDC, hBackDC
		method	esi, CSprite, setScreenSize, TempRect.right,TempRect.bottom
		invoke	RAND32, 25
		add		eax, 5
		method	esi, CSprite, setSpeed, eax
	inc ebx
	.ENDW
ret
Initialization endp


; This proc will step thu the array and destroy each object created.
Cleanup proc
	xor		ebx, ebx
	.WHILE	ebx < MAX_SMILIES
		newobject CSprite
		mov		eax, [offset SmileyArray + 4 * ebx]
		destroy eax    ; DESTROY IT!
		inc ebx
	.ENDW
ret
Cleanup endp