Click to See Complete Forum and Search --> : Moving an object in VB
Rebeckah
Dec 5th, 2000, 11:19 PM
This question is more complicated than it probably should be, but it wasn't my idea.
(This is for a final project in school, so I'm not asking anyone to actually write the code, if you can just give me a good handle on what I'm missing.)
Problem:
A pachinko game with 7 rows and 28 pins in it. (1 pin in row one, two in row two, and so forth.) Somehow I have to create a program that will drop a ball from the top of the screen down the hiarchy of pins.
Wait, it gets better. We have to have three variables: intRows, curPin, and nextPin--or something like that.
My problem? We've been learning how to code simple forms, like enter the sales amount and I'll give you the commission. I don't know how to define these stupid variables, much less how to tell the ball how to go down the rows. (Except that intNext = intPin + intRow + (0 or 1--which I think is simply RND)
Can anyone help? Soon?
Thanks,
Rebeckah
HarryW
Dec 6th, 2000, 12:06 AM
Well, a couple questions I guess...
Do you need graphics to show the ball moving?
What kind of output are you expecting? Just which column the ball ends up in?
I don't think defining the variables should be much of a problem. Just declare them like
Dim intRows As Integer
etc.
But that's pretty obvious. What's the problem with the variables?
How are you indexing your pins? I mean, I'm guessing you've given them all numbers from the looks of your equation there. Are they arranged like this?
. 1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
or like this?
. 1
11 12
21 22 23
31 32 33 34
41 42 43 44 45
51 52 53 54 55 56
61 62 63 64 65 66 67
Just so you can get some decent examples.
Rebeckah
Dec 6th, 2000, 10:00 AM
My problem with variables is simply that my understanding of them is still shaky--actually, after sleeping on it, I think I've got that part down a little better.
The pins are set up like your first example, 0 - 27 with 0 being the top, single pin in row one, 1 & 2 are in row two, etc.
Yes, it would be better to show the ball moving through the pins graphically. The outcome is for the ball to move through the 7th row and then the game reset--but it has to move in a statistically viable way. (Meaning that it will end up going past the middle pins in the 7th row far more often than it will go through the two corner pins in the 7th row.) I also need each pin that the ball collides with to change color, indicating a strike--I think I can handle that part, though.
Then, I'll set up a second form to collect the information on the hits in the bottom row and show them as a graph. That part I can puzzle out--it's the sort of thing I've been learning. Moving balls along the screen isn't something we've covered at all.
Thanks again for responding.
Rebeckah
HarryW
Dec 6th, 2000, 01:13 PM
Well okay. Have you done any graphics before? In case you haven't, they can be sort of tricky. It depends on whether you want the ball to move down the things slowly and smoothly, or if you just want it to disappear and reappear a row down each time, sort of jerkily.
The latter way is probably easier to understand, but won't look so good.
For your ball-falling algorithm, you just need to record which pin the ball is at currently, then choose randomly which sub-pin to fall to next. I suggest you have 8 invisible pins at the bottom, so that when they get hit you know that the ball has reached the bottom and you know which column it's in.
The two sub pins will be:
nextPin = currPin + rowNum + (1 or 0)
rowNum is the row number, which also happens to be the number of pins in the current row. You can either increment this every time the ball falls down one row, or you can work it out from the current pin number. The former is probably easier.
Rebeckah
Dec 7th, 2000, 12:27 PM
Thank you, it's finally moving down the pins. (Now all I have to do is figure out why my random numbers don't seem very random.) Any ideas?
My formula is:
intRnd = Int((1000 - 1 + 1) * Rnd + 1)
If intRnd >= 500 Then intCol = intCol + 1
If intRnd < 499 Then intCol = intCol - 1
But the ball seems to be falling to the right more than to the left.
intCol is the variable for the right or left movement of the ball. (intRow is simply + 720 twips the whole way down.)
Thanks again--now that the ball is actually moving down the screen I'm sure I can eventually figure out all the rest. It's just been too long since the last time I took math, and I didn't really like it when I did. I can see I'm going to have to start some serious reviewing if I'm going to be a programmer.
Rebeckah
HarryW
Dec 7th, 2000, 01:26 PM
Oh I see, You're just modelling the movement of the ball rather than modelling the pins and making the ball move from pin to pin. Not that there's anythig wrong with that, it's probably easier :)
Randomize Timer
intRnd = 1 - 2 * Int(Rnd * 2)
That will give you either +1 or -1. I'm not sure if that will fix your problem but it might do, try it.
HarryW
Dec 7th, 2000, 08:50 PM
Hehe, yes well we could model the entire physics of the thing I suppose :) Including coefficent of restitution for the ball; you could choose different kinds of ball and they would bounce around between the pins, and all kinds of stuff :) Or then again, maybe this way is easier ;)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.