breakout in vb.net

loading and displaying bricks from an array

Page 1 of 1

7 Replies - 3857 Views - Last Post: 16 March 2009 - 06:02 PM Rate Topic: -----

#1 mrsh4dy1   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 12-February 09

breakout in vb.net

Posted 13 March 2009 - 09:14 PM

hiya im trying to do a breakout style game in vb.net using vs 2008 iv got my ball and bat with collitions working fine but cant figure out getting the bricks into an array and displayed onto the game area. this is what i have tryed and just get 1 brick displayed at the last coordinates enterd any help would be gratley appresated

Dim pBrick As Sprite
		Dim row1(4) As Sprite
		Dim i As Integer


		pBrick = Graphics.CreateSprite(GameImage("pBrick"))
		row1(0) = pBrick
		row1(0).X = 50
		row1(0).Y = 50
		row1(1) = pBrick
		row1(1).X = 150
		row1(1).Y = 50
		row1(2) = pBrick
		row1(2).X = 250
		row1(2).Y = 50
		row1(3) = pBrick
		row1(3).X = 350
		row1(3).Y = 50
		row1(4) = pBrick
		row1(4).X = 450
		row1(4).Y = 50



and then in my game loop i have

For i = 0 To 4
				Graphics.DrawSprite(row1(i))

			Next i



i am a beginer and can be slow at times :P anyway thx in advance

J

Is This A Good Question/Topic? 0
  • +

Replies To: breakout in vb.net

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5369
  • View blog
  • Posts: 14,283
  • Joined: 18-April 07

Re: breakout in vb.net

Posted 14 March 2009 - 11:07 AM

Well from what I can tell you are creating your pbrick and putting the same image into each item of the array, not its own new copy of the image. So when you do row1(0).X and row1(1).X you are in fact manipulating the same image, not two different bricks.

When you setup the array of bricks, try using a function that takes in an array (passed by reference) and then goes into a loop which will fill the array with new bricks. This will allow you to cut down your code, allow you to expand the array and its rows infinitely and will also give you a new brick for each array item.

What you want to avoid is creating pbrick and then using pbrick in assignments everywhere. You should be using several CreateSprite calls, one for each brick.

example...

' Create first brick...
row1(0) = Graphics.CreateSprite(GameImage("pBrick"))
row1(0).X = 50
row1(0).Y = 50

' Second brick...
row1(1) = Graphics.CreateSprite(GameImage("pBrick"))
row1(1).X = 150
row1(1).Y = 50



Or to load a full row....

For i = 0 to row1.length - 1
     row1(i) = Graphics.CreateSprite(GameImage("pBrick"))
     row1(i).X = (i * 100) + 50
     row1(i).Y = 50
Next i



Hopefully this code gives you an idea of where you can go from here.

"At DIC we be brick loading code ninjas... we come from a long line of brick layers. My uncle even threw them during the LA Riots" :snap:
Was This Post Helpful? 1
  • +
  • -

#3 mrsh4dy1   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 12-February 09

Re: breakout in vb.net

Posted 14 March 2009 - 01:33 PM

chears for the reply ill let you know where i get to :) bit stupid of me realy should of realised that i was just loading 1 image.

J



just an update works a treat thx just for the collition for the blocks now hehe


J

This post has been edited by mrsh4dy1: 14 March 2009 - 01:52 PM

Was This Post Helpful? 0
  • +
  • -

#4 Hyper   User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: breakout in vb.net

Posted 14 March 2009 - 03:22 PM

Post the working code so somebody else might see it/use it/learn from it?
Was This Post Helpful? 0
  • +
  • -

#5 mrsh4dy1   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 12-February 09

Re: breakout in vb.net

Posted 15 March 2009 - 03:36 AM

well here is the code so far I just have to get the brick to disapear when a collition is detected but shore someone can figure that out..
'populate the array with the brick sprite
Dim row1(14) As Sprite
		Dim i As Integer


		For i = 0 To row1.Length - 1
			row1(i) = Graphics.CreateSprite(GameImage("pBrick"))
			row1(i).X = (i * 50) + 45
			row1(i).Y = 50
		Next i



then to check for collition and display the brick to the screen
'check collition between the ball and the brick
			If Physics.HaveSpritesCollided(ball, row1(0)) Then
				performCollision(ball, row1(0))
			End If
'draw sprites to the game area
			Graphics.DrawBitmap(GameImage("BackGround"), 0, 0)
			Graphics.DrawSprite(ball)
			Graphics.DrawSprite(paddle)


			For i = 0 To row1.Length - 1
				Graphics.DrawSprite(row1(i))

			Next i



so hope this does help someome else
Was This Post Helpful? 1
  • +
  • -

#6 mrsh4dy1   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 12-February 09

Re: breakout in vb.net

Posted 16 March 2009 - 01:34 PM

hi sorry to pester again but i cant seem too get the brick to disaperre when hit iv tryd isvisable but that dont work this is whay differant to what iv doen befor so going bold a little :P anyway thanks for your pataince and thanks in advance

j
Was This Post Helpful? 0
  • +
  • -

#7 Hyper   User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: breakout in vb.net

Posted 16 March 2009 - 02:07 PM

1) Work on the spelling, we speak English. If it's your second language, try harder.
2) To make a brick "disappear" you would have to make it become the color of the background, no?
Was This Post Helpful? 0
  • +
  • -

#8 stayscrisp   User is offline

  • フカユ
  • member icon

Reputation: 1040
  • View blog
  • Posts: 4,325
  • Joined: 14-February 08

Re: breakout in vb.net

Posted 16 March 2009 - 06:02 PM

No i wouldn't make them the colour of the background, you should remove them from the game, the same way you loop to check for collisions you could also loop through to check for blocks that have been hit and then remove them. Hitting them would flag them as hit and then looping through would remove them from the list.

Or when you draw them only draw blocks that haven't been hit and also only update blocks that haven't been hit :^:

I would consider the first option to be the most effective though.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1