breakout clone problems

BlitzPlus Forums/BlitzPlus Beginners Area/breakout clone problems

lid(Posted 2009) [#1]
i figured this out already sorry people

hi every one im new to the forums

im making a breakout clone but every time i run it, it draws the pong constantly, i only wanted to draw it once

can some one give me a remedy

here's the code


;breakout attempt 1

;set screen width and height
Const gwidth=640
Const gheight=520

;set graphics mode
Graphics gwidth,gheight,16,2

;set the timer to run at 30 frames per second
timer=CreateTimer(30)

;toogle auto middle handle
AutoMidHandle True

;pong image
Global img_pong=LoadImage("C:\Program Files\blitzbasic\sprites/pong.bmp")

Global img_ball=LoadImage("C:\Program Files\blitzbasic\sprites/ball.bmp")

;pong type
Type pong
	Field x,y
End Type

;set starting coords
Global x=0
Global y=0

;number of pongs on the screen
Global nump=1

;set starting points
Global points=0

;set the radius(not gonna use this  yet)
radius=0

;set wich area the ground will be on the map(not gonna use this yet)
ground=0

;set ball speed(not gonna use this yet)
bspeed=0

;declare pong type as "GLOBAL"
Global p.pong

;set drawing buffer to the backbuffer
SetBuffer BackBuffer()

;main loop
While Not KeyDown(1)

	Cls

	;create a pong
	createpong(nump)

	For p.pong=Each pong
		;draw pong image to the screen with its coords
		DrawImage img_pong,p\x,p\y

		;update pongs coords
		If KeyDown(205) Then p\x=p\x+5
		If KeyDown(203) Then p\x=p\x-5
	Next

	WaitTimer(timer)

	Flip

Wend

End

;create pong function
Function createpong(nump)
	p.pong=New pong
	p\x=400
	p\y=200
End Function



GfK(Posted 2009) [#2]
Try putting createpong(nump) Before your while/wend loop (i.e. not inside it). That will cause it to only create one, instead of one every time it draws the screen.


GaryV(Posted 2009) [#3]
Global img_pong=LoadImage("C:\Program Files\blitzbasic\sprites/pong.bmp")

Global img_ball=LoadImage("C:\Program Files\blitzbasic\sprites/ball.bmp")


Just a tip, it is bad practice to hardcode file locations for things like images.

I do not have Blitz Plus, but I am pretty sure it will look for the images in the directory the exe is running from. You "should" be able to just use the filename for the load image command without having to use the file location.


lid(Posted 2009) [#4]
thanks :D