Dodge (b3d)

Miscellaneous Forums/Blitz Showcase/Dodge (b3d)

Eurythmia , that is the crazyest thing I have ever seen!

thanks everyone


Thats pretty great Coorrae, did you see the concept somewhere else or did you come up with it?


Thanks, I origionally came up with it the idea when I was 14 or 15 when all I had was QBasic. I made it at school.
I didn't know how to use speed variables or Floats so they would just move diagnally based on a direction number. Then I remade the idea in Darkbasic and recently copyied it in blitz3d


I came up with at the same time.
you have to get to the right with the ball
;ARROW KEYS
Const scx=600,scy=300
Graphics scx,scy,16,2
SetBuffer BackBuffer()

SeedRnd MilliSecs()

Type guy
	Field x#,y#,xsp#,ysp#,xspmax#,yspmax#,move#
	Field xsize,ysize,tarx,tary,targuy.guy
End Type

Const powam=2
Dim px(powam),py(powam),pxsize(powam),pysize(powam),boost(powam)
For p=1 To powam
	pxsize(p)=Rand(5,20)
	pysize(p)=Rand(5,20)
	px(p)=Rand(0,scx-pxsize(p))
	py(p)=Rand(0,scy-pysize(p))
Next

Global guyball.guy,g.guy,you.guy

Global level
Const move#=.08
you=New guy

levelup()
timer=CreateTimer(40)
;#########################################################################
Repeat
	wait=WaitTimer(timer)
	For updates=1 To wait	
		updatepows()
		updateguys()
	Next
	drawpows()
	drawguys()
	Text 1,1,"level: "+level
	Flip
	Cls
	If KeyHit(1) Then End
Forever
;#########################################################################
Function updatepows()
	For p=1 To 2
		For g=Each guy
			If RectsOverlap(px(p),py(p),pxsize(p),pysize(p),g\x,g\y,g\xsize,g\ysize) Then
				If g=you Then
					boost(p)=254
					pxsize(p)=Rand(5,20)
					pysize(p)=Rand(5,20)
					px(p)=Rand(0,scx-100)
					py(p)=Rand(0,scy-pysize(p))
					Exit
				Else
					px(p)=curve(px(p),g\x,g\xsize,1)
					py(p)=curve(py(p),g\y,g\ysize,1)
					px(p)=keepin(px(p),0,scx-pxsize(p))
					py(p)=keepin(py(p),0,scy-pysize(p))
				EndIf
			EndIf
		Next
	Next
End Function
;#########################################################################
Function updateguys()
	For g=Each guy
		For g2.guy=Each guy
			If g<>g2 If RectsOverlap(g\x,g\y,g\xsize,g\ysize,g2\x,g2\y,g2\xsize,g2\ysize) Then
				;steal ball
				stole=0
				If guyball=g And (g=you Or g2=you) Then 
					guyball=g2
					stole=1
				EndIf
				;smaller guys bounce off
				If g\xsize>=g2\xsize Then
					g2\x=curve(g2\x,g\x,g2\xsize/(2-stole),1)
				Else
					g\x=curve(g\x,g2\x,g\xsize/(2-stole),1)
				EndIf
				If g\ysize>=g2\ysize Then
					g2\y=curve(g2\y,g\y,g2\ysize/(2-stole),1)
				Else
					g\y=curve(g\y,g2\y,g\ysize/(2-stole),1)
				EndIf
			EndIf
		Next
		g\x=g\x+g\xsp
		;guys coming at begining dont go to the y middle as fast
		If g<>you And guyball=you And g\x>scx/2 And guyball\x<scx/2 Then
			g\y=g\y+g\ysp/2
		Else
			g\y=g\y+g\ysp
		EndIf
		oldy#=g\y
		g\y=keepin(g\y,0,scy-g\ysize)
		If oldy<>g\y Then g\ysp=0
		If g=you Then
			If KeyDown(205) Then you\xsp=you\xsp+move+(boost(2)>0)
			If KeyDown(203) Then you\xsp=you\xsp-move-(boost(2)>0)
			If KeyDown(208) Then you\ysp=you\ysp+move+(boost(2)>0)
			If KeyDown(200) Then you\ysp=you\ysp-move-(boost(2)>0)
			If boost(1)>0 Then boost(1)=boost(1)-2
			If boost(2)>0 Then boost(2)=boost(2)-2
		Else
			g\tarx=you\x
			g\tary=you\y
			If guyball=g Then g\tarx=0
			g\xsp=curve(g\xsp,g\tarx-g\x,move)
			g\ysp=curve(g\ysp,g\tary-g\y,move)
		EndIf
		xspmax=g\xspmax-(guyball=g)*(1+(g<>you)*.5)+((boost(1)>0) And g=you)
		yspmax=g\xspmax-(guyball=g)*(1+(g<>you)*.5)+((boost(1)>0) And g=you)
		g\xsp=keepin(g\xsp,-xspmax,+xspmax)
		g\ysp=keepin(g\ysp,-yspmax,+yspmax)
	Next
	If guyball=you And you\x>=scx Then levelup(1)
	If guyball<>you And guyball\x<=0 Then levelup(0)
End Function
;#########################################################################
Function drawguys()
	For g=Each guy
		Color 0,0,255
		If g=you Then 
			Color 255,boost(1),boost(2)
		EndIf
		Rect g\x,g\y,g\xsize,g\ysize
	Next
	Color 0,255,0
	Oval guyball\x,guyball\y,8,6
End Function
;#########################################################################
Function drawpows()
	For p=1 To powam
		If p=1 Then Color 255,255,0
		If p=2 Then Color 255,0,255
		Rect px(p),py(p),pxsize(p),pysize(p)
	Next
End Function
;#########################################################################
Function levelup(done=1)
	For p=1 To powam
		boost(p)=0
	Next
	If done=1 Then 
		level=level+1
		g=New guy
		you\targuy=g
	Else
		If level>1 Then
			level=level-1
			Delete Last guy
		EndIf
	EndIf
	For g=Each guy
		If g=you Then
			g\x=10
			g\y=scy/2
			g\xsize=10
			g\ysize=10
		Else
			g\xsize=Rand(6,15)
			g\ysize=Rand(6,15)
			g\x=Rand(scx/2,scx)
			g\y=Rand(0,scy-g\ysize)
		EndIf
		g\xspmax=4-g\xsize/10.0
		g\yspmax=4-g\ysize/10.0
		g\xsp=0
		g\ysp=0
	Next
	guyball=you
End Function
;#########################################################################
Function keepin#(num#,min,max,wrap=0)
	If wrap=0 Then
		If num<min Then 
			num=min
		ElseIf num>max
			num=max
		EndIf
	Else
		While num<min: num=num+(max-min): Wend
		While num>max: num=mun-(max-min): Wend
	EndIf
	Return num
End Function
;#########################################################################
Function curve#(num#,dest#,speed#,away=0)
	If away=0 Then
		If num<dest Then num=num+speed
		If num>dest Then num=num-speed
		If Abs(dest-num)<speed Then num=dest
	Else
		If num<dest Then num=num-speed
		If num>dest Then num=num+speed
	EndIf
	Return num
End Function
;#########################################################################