Arrays and my program - need some help

FlyingCube
01-05-2005, 07:39 AM
I am doing a little game program where there are some images which you must prevent from reaching the bottom of the screen. Eventually they will move diagonally and at different speeds as more are added later on. I used an array so i can add more later easily.

My problem is with the slowdown portion of my code. When you click the image it moves upwards and slows down incrementally. Everything about that works fine, except that if you click another picture while the one is moving up that picture stops and the new picture starts moving with the slowdown applied from the last picture. Like this diagram

highest height without interruption
|
|
|
|
| |height when interrupted
| |
| | |next height if you click before the counter is up still.
|_______|________|______

Could i maybe fix this by resetting the counter to 0 when clicked?

But the problem still remains that the picture will stop when another is clicked

What can i do to prevent this? Currently you cannot survive the first wave

'Array problem

Dim begin As Boolean
Dim intcounter As Integer
Dim imageclick As Boolean
Dim curslowdown As Currency
Dim intindexclick As Integer
Option Explicit

'This makes imageclick true and assigns intindexclick so that the object you clicked moves
Private Sub Picture1_Click(Index As Integer)
imageclick = True
intindexclick = Index
Call Timer1_Timer
End Sub

'This controls the movement of the objects towards the bottom
Private Sub Timer1_Timer()
begin = True
If begin = True Then
'the picture begins moving down
Picture1(intcounter).Top = Picture1(intcounter).Top + 150
'this is a counter to go through the array of pictures
intcounter = intcounter + 1
If intcounter = 6 Then
intcounter = 0
End If
End If
'controls the upwards movement of the picture that is clicked
If imageclick = True Then
Picture1(intindexclick).Top = Picture1(intindexclick).Top - 150 + curslowdown
'slowdown is incremented until it reaches 150, which is the value that it moves up, so it stops and it moves back down
If curslowdown = 150 Then
curslowdown = 0
imageclick = False
Else
curslowdown = curslowdown + 2
End If
End If
End Sub

Here is my code, any ideas on what i can do? Should i just scrap the array idea even though it would be easier to add more with an array later?

bleh, just ignore the diagram, it screwed up when i posted the message

fixitchris
01-05-2005, 07:55 AM
what i would do is create an 2d array : Picture1.index , position.
then each time you click on another picture, its index and postition would get added to this array.
this way the timer could iterate through the array and advance any Picture1(index) that exist in this array. as well as updating its new position.


or

your current idea is good, just that you would need to iterate through the picture1s with a loop, so that it can advance each picture at each _timer event.


your imageclick variable is causing problems.


eh?

noi_max
01-05-2005, 09:21 AM
Well, I don't think you can create a 2 dimensional control array....

Here's some suggestions of what to do:

Create an array of a User Defined Type to hold a boolean for "clicked" and a data type for the "slowdown" effect.

Re-dimension the array to match the Ubound of your picturebox array.

Use a For/Next loop structure to handle all of the data in your new array and your pictureboxes in one fell swoop.

I'm posting an example with comments to show some of this in action.

Most of what you need to know about arrays and loops can be found in the ..

Good luck!

Max.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum