help me please

BlitzMax Forums/BlitzMax Beginners Area/help me please

cloned(Posted 2006) [#1]
i am wokring on a simple pong game to get used to BMAX and OOP

when i run it all i get is a blank screen, can someone help me?

 Graphics 640,480

'this is a pong clone and my first game in BMAX

Global num_players = 1'the number of players
Global phase = 0'the current phase of the game
Global sup_phase = 0
Global paused = False
Global player_1_score
Global player_2_score

Type thing'this is the basic type for all objects in this game

	Field X,Y'my referrence for where the objects are
	Field speed_X,speed_Y
	Field dir
	Field width,height
	Field true_X,true_Y'ths drawing point of the rects

	Method draw()

		SetColor 255,255,255

		DrawRect(X,Y,width,height)

	End Method

End Type

Type bar Extends thing

	Field player
	Field speed

	Method controls()

		If num_players = 1

			If player = 1

				If KeyDown(KEY_UP)

					dir = 0

				ElseIf KeyDown(KEY_DOWN)

					dir = 1

				Else

					dir = 2

				EndIf

			ElseIf player = 2

				AI()

			EndIf

		ElseIf num_players = 2

			If player = 1'checks which player are you and sets up the controls

				If KeyDown(KEY_W)

					dir = 0

				ElseIf KeyDown(KEY_S)

					dir = 1

				Else

					dir = 2

				EndIf

			ElseIf player = 2

				If KeyDown(KEY_UP)

					dir = 0

				ElseIf KeyDown(KEY_DOWN)

					dir = 1

				Else

					dir = 2

				EndIf

			EndIf

		EndIf

	End Method

	Method move()'moves the bars

		If dir = 0

			X:+ speed

		ElseIf dir = 1

			X:- speed

		EndIf

	End Method

	Method AI()'this is for the AI of a pong padle

		If dot.X >= GraphicsWidth() / 3'makes sure the dut is close enough to care

			If dot.Y > Y - height - 15'then moves accordingly

				dir = 1

			ElseIf dot.Y < Y + height + 15

				dir = 0

			Else

				dir = 2

			EndIf

		EndIf

	End Method

	Function create_bar(which)'this function creates a new player bar

		Local newbar:bar
		newbar = New bar

		If which = 1

			newbar.player = 1
			newbar.X = 10

		ElseIf which = 2

			newbar.player = 2
			newbar.X = GraphicsWidth() - 10

		EndIf

		newbar.Y = GraphicsHeight() / 2
		newbar.speed = 5
		newbar.dir = 2
		newbar.width = 10
		newbar.height = 35
		newbar.true_X = newbar.X - (newbar.width / 2)
		newbar.true_Y = newbar.Y - (newbar.height / 2)

		ListAddLast(player_list,newbar)
	End Function

End Type

Type ball Extends thing

	Field RED,BLUE,GREEN

	Method physics()'this will check when the dot hits either a horizontail wall or a paddle and then move it

		X:+ speed_X
		Y:+ speed_Y

		If Y <= height + 3

			If speed_X >= 2

				speed_Y = Rand(2,6)

				speed_X = 8 - speed_Y

				speed_Y = -speed_Y

			ElseIf speed_X <= -2

				speed_Y = Rand(2,6)

				speed_X = 8 - speed_Y

				speed_X = -speed_X

				speed_Y = -speed_Y

			EndIf

		ElseIf Y >= GraphicsHeight() - height + 3

			If speed_X >= 2

				speed_Y = Rand(2,6)

				speed_X = 8 - speed_Y

			ElseIf speed_X <= -2

				speed_Y = Rand(2,6)

				speed_X = 8 - speed_Y

				speed_X = -speed_X

			EndIf

		EndIf

			For Local players:bar = EachIn player_list

				If RectsOverlap(X,Y,width,height,players.X,players.Y,players.width,players.height)

					If players.player = 1

						If speed_Y >= 2

							speed_X = Rand(2,6)

							speed_Y = 8 - speed_X

						ElseIf speed_Y <= -2

							speed_X = Rand(2,6)

							speed_Y = 8 - speed_X

							speed_Y = -speed_Y

						EndIf

					EndIf

				EndIf

			Next

	End Method

	Method score()

		If X <= -height

			player_1_score:+ 1

		ElseIf X >= GraphicsWidth() + height

			player_2_score:+ 1

		EndIf

	End Method

End Type

Global player_list:TList = CreateList()

For num = 1 To 2
	bar.create_bar(num)'this loop creates the 2 player bars
Next

Global dot:ball

dot = New ball
dot.X = GraphicsWidth() / 2
dot.Y = GraphicsHeight() / 2
dot.speed_Y = Rand(2,6)
dot.speed_X = 8 - dot.speed_Y
dot.width = 10
dot.height = 10
dot.true_X = dot.X - dot.width
dot.true_Y = dot.Y - dot.height

While Not KeyHit(KEY_ESCAPE)

		If paused = False

			If KeyHit(KEY_P) Then paused = True

			For Local player:bar = EachIn player_list

				player.move()
				player.controls()
				player.draw()

			Next

			dot.physics()
			dot.score()
			dot.draw()

		ElseIf paused = True

			If KeyHit(KEY_P) Then paused = False

			For Local player_B:bar = EachIn player_list

				player_B.draw()

			Next

			dot.draw()
			dot.score()

		EndIf
Wend

Function RectsOverlap:Int(x0, y0, w0, h0, x2, y2, w2, h2)
    If x0 > (x2 + w2) Or (x0 + w0) < x2 Then Return False
    If y0 > (y2 + h2) Or (y0 + h0) < y2 Then Return False
    Return True
End Function



Yan(Posted 2006) [#2]
Flip!


cloned(Posted 2006) [#3]
crap i can't believe that i forgot that