Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Arrays and my program - need some help


Reply
 
Thread Tools Display Modes
  #1  
Old 01-05-2005, 07:39 AM
FlyingCube FlyingCube is offline
Newcomer
 
Join Date: Jan 2005
Posts: 1
Default Arrays and my program - need some help


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

Quote:
'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
Reply With Quote
  #2  
Old 01-05-2005, 07:55 AM
fixitchris's Avatar
fixitchris fixitchris is offline
Contributor
 
Join Date: Dec 2004
Posts: 418
Default

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?
Reply With Quote
  #3  
Old 01-05-2005, 09:21 AM
noi_max's Avatar
noi_max noi_max is offline
Still asleep...

Retired Leader
* Expert *
 
Join Date: Nov 2003
Location: IronForge
Posts: 2,694
Default

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 Standards & Practices Tutorial

Good luck!

Max.
Attached Files
File Type: zip TestLoop.zip (1.9 KB, 2 views)
__________________
~ Jason

Use [vb][/vb] tags when posting code :) || Search the forum and MSDN|| Check out the Posting Guidelines
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->