Arcanoid game on CorelSCRIPT

This game is very similar to Catch Me! game by its functional structure. The ball (an option button) is moved using its MOVE function. Each time the timer event is generated. If the ball is about to cross the bottom edge of the game field (the dialog area above the slider), a conditional operator IF is used to determine whether the slider index is in the same position as the ball. If not, the ball is missed and the game finished. If not, the ball is bounced and returned to the game. To determine the slider's index position, the slider is assigned a value range equal to its width (200 dialog units). Therefore each unit of the slider value corresponds to the horizontal position of the index in terms of dialog units. Thus, reading the slider value we can immediately determine the slider index position.

arcanoid.gif (21632 bytes)

GLOBAL sx&,sy&,x&,y&,cx&,cy&,vx&,vy&
GLOBAL Score&,HiScore&
GLOBAL CONST BallSize&=15

BEGIN DIALOG OBJECT FunDialog 200, 122, "Arcanoid", SUB FunHandler
	TEXT  68, 45, 65, 8, .Text1, "Don't miss the ball !!"
	OPTIONGROUP .Dummy%
		OPTIONBUTTON  15, 4, 10, 10, .Ball, ""
	HSLIDER 0, 96, 200, 12, .Slider
	STATUS .Status
END DIALOG

SUB FunHandler(BYVAL CtrlID%, BYVAL Event%)
SELECT CASE Event
	CASE 0 ' Initializing
		sx&=FunDialog.GetWidth()
		sy&=FunDialog.Slider.GetTopPosition()
		cx&=FunDialog.Ball.GetWidth()
		cy&=FunDialog.Ball.GetHeight()
		x&=FunDialog.Ball.GetLeftPosition()
		y&=FunDialog.Ball.GetTopPosition()
		vx=5
		vy=5
		FunDialog.Slider.SetMinRange 0  ' Set the slider value
		FunDialog.Slider.SetMaxRange 200' range to its width 
		FunDialog.Slider.SetIncrement 1
		FunDialog.Slider.SetValue 100
		Score=0
		HiScore=0
		FunDialog.SETTIMER 70 ' Initialize timer
	CASE 5 ' Timer event
		if x+vx+cx>sx or x+vx<0 then vx=-vx ' Bounce from left
						    ' or right edge
		if y+vy<0 then vy=-vy ' Bounce from the top edge
		if y+vy+cy>sy then ' Check whether the slider is in
				   ' a proper position
		   rx&=FunDialog.Slider.GetValue()
		   if (x<rx-BallSize or x>rx+BallSize) then
			' If the ball is not at the slider position,
			' then display message and ask whether the user
			' wants to play again
		      rx=messagebox("You have missed the ball"+ \\
				CHR(13)+"Do you want to try again?", \\
				"You lost!",20)
		      if rx=6 then
			x=0:y=0:vx=5:vy=-5:Score=0 ' If yes, reset the
						' ball position and speed
		      else
			FunDialog.CloseDialog 2 ' If no, close the dialog
		      endif
		   endif
		   vy=-vy
		endif
		x=x+vx
		y=y+vy
		FunDialog.Ball.Move x,y ' Move the ball
		Score=Score+1
		if Score>HiScore then HiScore=Score
		FunDialog.Status.SetText "Your Score:"+STR(Score\10)+\\
		  "   Hi-Score:"+STR(HiScore\10)' Display current score 
						' in the status bar
END SELECT
END SUB

DIALOG FunDialog

Click here to download the script ready to run.


[ Fun Hour with CorelSCRIPT | Learning CorelSCRIPT | Oberon Home Page ]

Copyright 2000 by Alex Vakulenko. All rights reserved.
This page was last revised on 01/13/00.