First off, sorry for posting those other threads -- a quick search on the forum, and a little research, and I solved all my own problems. :D
That said, i don't know what to look for to solve this next problem. Basically, i got my space invaders game almost complete; just need the bullet to work usin pic box. I got it to work on key down and stuff....like, the bullet moves fine. When it reaches top of form, I made it disappear and reset itself. Problem is it doesn't always shoot from the tank (i.e sumtimes it shoots from other parts of the form). I tried using invalidate and makin the pic box move left and right with tank...but that doesn't work either (because the pic box moves even after initially shot). Basically i want it so that the pic box (containing bullet) will shoot from the tank when space bar is hit (no matter where the tank is on the form), but only continue straight up the form after space bar is hit. That way, next time space bar is hit, the bullet will again come out of the tank, and continue along an unaltering path until it is reset.
Help -- or direct me to some sort of tutorial plz :( If you need further clarification, pls just ask
elnerdo 01-06-2005, 04:56 PM have something like this in your timer
if laserisshooting
laser.top = laser.top - 3 'whatevver
else
laser.left = tank.left + tank.width /2 - laser.width /2 ' so it will fire from the middle
laser.top = tank.top 'make sure the laser is below the tank on your form design
end if
this way, when the laser is not being fired, it will be always centered on the tank, and when it is being fired, it will only move up.
EDIT: when you finish, please post a copy, i would like to see it.
theController 01-06-2005, 05:56 PM have something like this in your timer
if laserisshooting
laser.top = laser.top - 3 'whatevver
else
laser.left = tank.left + tank.width /2 - laser.width /2 ' so it will fire from the middle
laser.top = tank.top 'make sure the laser is below the tank on your form design
end if
this way, when the laser is not being fired, it will be always centered on the tank, and when it is being fired, it will only move up.
yea this is the best way, just make your point location = the location of your tank
If your laser is not a picturebox (maybe decide this later). You can create a point and it would do the same basic thing as above,
laser.X = tank.Left + (tank.width / 2)
elnerdo 01-06-2005, 06:13 PM Mind if I ask, how are you making the aliens die when your laser hits them?
ThePentiumGuy 01-06-2005, 06:40 PM He probably stops rendering that alien? :P.
-The Pentium Guy
theController 01-06-2005, 06:42 PM He probably stops rendering that alien? :P.
-The Pentium Guy
Make sure you add a point to the score! :)
ThePentiumGuy 01-06-2005, 06:48 PM Just one? :P
Wow, thanks guys.
I'll have to try this out tomorrow (when I can get access to vb.net again).
And, to answer that questions bout makin the aliens die when hit:
I'm going to try to incorperate collision detection, so that when they get hit, sumthin will happen (i.e. add to score, show a blown up pic or sumthin, u know?). A little more research and some fiddlin around always helps!
Ill also take all of this into consideration.
Anyway, thanks again!
elnerdo 01-06-2005, 07:44 PM But how will he stop rendering that alien, the alien is a picturebox.
(Seriously, I want to know)
Elnerdo, your question is the same as mine heh.
As it turns out, I got the bullet workin fine...now to hit the aliens! As you know, they are contained in pic boxes. All well and good, until i found out they cant get hit (or at least not by what I have done).
I tried fiddling around with the .left and .top properties (u know, if picbox1.left = picbox2.left type thing -- i realized that the only way this would happen would be if they were on the exact same axis of symmetry...). So, nothin seems to work. As I understand it, collision detection (intersectswith) doesnt work with pic boxes...
Is there a way I can make pic boxes detect collision (i tried search on forum..). Or is there another property that can be used? OR do I have to create a rectange and use intersectwith (if so, please elaborate because from what i've read, i'm still a little confused).
Thanks again :D
ThePentiumGuy 01-07-2005, 02:21 PM http://www.vbprogramming.8k.com/tutorials/CollisionDetection.htm
Elnerdo: I think you could a) Delete the image (Pbox1.image = nothing) or b) Delete the picturebox (pbox1.dispose)
-The Pentium Guy
elnerdo 01-07-2005, 02:37 PM but for his collision detection, he probably has something like
MY EXAMPLE:
if picturebox1.bounds.intersectswith(laser.bounds)
wouldn't this get an error if he simply deleted the picturebox?
and for making the image go away, wouldn't the picturebox still be there, and thus wouldn't the laser hit it over and over again?
and if you noticed my example, using .bounds will allow .intersectswith to work
ThePentiumGuy 01-07-2005, 03:34 PM He *COULD* use an IF statement to check it. But there ARE better ways of going about this(Instead of:
OMG CREATE 85 PICTUREBOXES ON THIS FORM! THEN CREATE 85 BOOLEANS FOR EACH ONE
IF PBOX1EXISTS THEN
IF PBOX1.INTERSECT(WHATEVER) THEN OMG DO SOMETHING
END IF
IF PBOX2EXISTS THEN
IF PBOX2.INTERSECT(WHATEVER) THEN OMGDO SOMTEHING"
END IF
(Don't ask, going a little crazy today)). I know a few people who actually ... erm... did that.
Ok, my recommendation (heh sorry for the above randomness)
Look into collections. That way you can simply remove add pictureboxes to your collections when you want (per level, read from a file). And then check for collision (collections will resize themselves and 'bump' themselves... for example
pbox1 pbox2 pbox3 pbox4
if you delete pbox2 then it would automatically make the list:
pbox1 pbox3 pbox4). And then remove them as necessary (MyCollection.Add(myPbox, "GreenAlienWithBigHead") to add them, and MyCollcetion.Remove("GreenAlienWithBigHead") to remove them.
To check for collision you'd do something simply like:
for i = 1 to mycollection.length 'Collections start at 1 for some reason
If DirectCast(MyCollection.Item(i), PictureBox).IntersectWith(whatever) Then
MyCollection.Remove(i)
End If
Next
-The Pentium Guy
Elnerdo,
thanks for your ideas with the .bounds.intersectswith('blah). So far, its worked the best. (I also tried some of the collision tutorials, but they seemed to screw up the game...i.e. using the bounding boxes method, all the aliens would die if one got hit :P).
Just one minor problem, which i am currently working on. Basically, when the aliens get hit, i want them to go away completely. I think this might be what you guys were debating about. You see, all that happens is the aliens images dissapear, but the pic boxes still seem to be there, because i can still hit them.
Thanks for your previous hlp though guys. If you want to hlp with this, be welcome! (Im workin on it myself though, finally got a version at home).
Oh and sorry for not postin in a while.
One more thing, I guess you were right elnerdo about the pic boxes not really goin away. i tried usin dispose(), but maybe that doesnt do what i want :p
Oops, think i might've just figured sumtin out. I'll post a bit later if it works!
elnerdo 01-08-2005, 08:33 AM For a terribly inefficient method: you can move the aliens like 9000 pixels to the right when they're hit.
don't just go with this because it's easy though, pentiumguy's way is a LOT better
ThePentiumGuy 01-08-2005, 08:59 AM Or you can use a Collection like I said ;). It wil automatically "Take out" the alien you want to take out, and it will automatically "Sense" the fact that <X> alien doesn't exist and this <X> alien shouldn't be checked for collision detection with the laser.
-TPG
Iceplug 01-08-2005, 09:14 AM I would recommend using an ArrayList instead of a Collection. Arraylists have more methods that you can use and I hear that they are faster.
Dim AL As ArrayList = New ArrayList(85)
Dim LV As Integer
For LV = 0 To 84 Then
AL.Add(a monster)
Next
By here you should have 85 monsters in the arraylist.
To loop through all of the monsters in the arraylist, you can do:
Dim M As Monster
For Each M In AL
'draw it if it is not dead.
Next
of course if you want to clear a monster, you can just do
AL.Remove(M)
and that removes the monster that matches the one that you assign.
:)
ThePentiumGuy 01-08-2005, 09:21 AM The only problem I see with arraylists are that you HAVE to have a bound:
Dim AL As ArrayList = New ArrayList(85)
I also wish you can remove the Monster based on the KEY instead of removing it based on the actual .... monster.
This is an interesting debate...
-The Pentium Guy
Iceplug 01-08-2005, 09:26 AM That's not a bound, that's the capacity.
If you go over the capacity, then the arraylist has to increase its capacity to hold more items (which probably causes a performance cut if you go over)... but going over capacity hasn't been a problem for me yet.
You can also remove a Monster based on its INDEX by using .RemoveAt
AL.RemoveAt(LV)
if you so happened to want to use a For Loop instead of a For Each Loop.
Dim M As Monster
For LV = 0 To AL.Count - 1
M = DirectCast(AL(LV), Monster)
Next
Note that if your monster is a structure instead of a class, then you have to reassign the monster if you update it, so it may be easier for you to use a class.
By all means, keep debating! Just readin what you guys have to say hlps a lot.
Elnerdo, the way that you were explaining (the one that is inefficient), thats the way that I figured out on my own :p Your right though, it doesn't always give consistent, desirable results.
Basically, i used bounds.intersectswith(.bounds) and made it so that, if picbox1 (say the laser) hits pic box2 (say the aliean) then hide() alien or dispose() alien. Then i made it so that the picbox2 moved off the form, basically pushin it out of the game window. This sort of works, but I can be certain. And also, the pic boxes wit aliens dont always get hidden on first intersection (or so it seems) -- that is, if pic box1 goes over pic box2, pic box2 doesnt always seem to be hit (and disappear). A well...
Question for Iceplug,(maybe this has been explained already), will your way work with pic boxes? I thought i read that it involved drawing each alien...If this is true, than maybe i have to redesign this. I started it based on pic boxes, intending to explore a few new controls. So, i dont really know how to draw an alien (if u catch my drift) ;)
PentiumGuy, I guess i haven't really explored much of what you had to say. This probably being because I wanted to make things as simple as possible (and I don't fully understand what you were saying). Again, I'll try and follow this stuff, try to figure somethin out!
Of course, if you care to explain this to me, it would be a great help (same to you iceplug) :D
Thanks guys.
Ok, after a day of hard work (not! :D ) I got my game to work (somewhat) to my liking.
One question, though. How can I make form2 become the default screen, meaning, it will come up before form 1. Moreover, I want to accomplish this WITHOUT changing the property names of form1 and form2 (because I know this way works, and want to explore another way).
I tried something called TopMost...
this isn't doin anything though...maybe I've done something wrong?
Form2_Load('blah, usual here)
Me.topmost = true
end sub
I'm probably wrong, so plz hlp me out.
thanks guys.
Last thing (I hope.). If i wanted to add a background image to the form, would i go under properties, and backgroundimage, then specify the file for the image? (Please tell me there's another way, because doing it like this creates a TON of lag...)
Iceplug 01-09-2005, 08:46 AM Question for Iceplug,(maybe this has been explained already), will your way work with pic boxes? I thought i read that it involved drawing each alien...If this is true, than maybe i have to redesign this. I started it based on pic boxes, intending to explore a few new controls. So, i dont really know how to draw an alien (if u catch my drift)
I'm not sure that it will work too well with pictureboxes, but setting their Visible properties should cause the aliens to disappear. I usually recommend GDI+ for use in making games, because controls aren't really made for being moved around frequently.
How can I make form2 become the default screen, meaning, it will come up before form 1. Moreover, I want to accomplish this WITHOUT changing the property names of form1 and form2 (because I know this way works, and want to explore another way).
If you go over to your project in the Solution Explorer, right click and go to properties, you can change which form starts up first by changing the Startup object under General.
Last thing (I hope.). If i wanted to add a background image to the form, would i go under properties, and backgroundimage, then specify the file for the image? (Please tell me there's another way, because doing it like this creates a TON of lag...)
Yes, you could use GDI+ and a TextureBrush to draw a background instead of setting the form's BackgroundImage.
ThePentiumGuy 01-09-2005, 08:55 AM Yeah man you should really use GDI+ instead of pboxes. But that's up to you.
Iceplug, about ArrayLists vs Collections:
I'll run a little performance app testing thing for ArrayLists vs Collections and let you know. ArrayLists have more methods? Now that's something I'll ahve to look into. For "More methods" (than Collections), I'd just use a Collection.HashTable. In terms of features, I dont know the difference between Hashtables and ArrayLists. I'll check it out.
-TPG
|