Help me build a little simulator thingy? Personal VB6 project.

Benjagan91
10-06-2009, 11:16 PM
Hi,

I'm new to VB6 but i can do things here and there with it. Now i'd like to build a simulator kinda thing.

Concept drawing: Click here (http://www.xtremevbtalk.com/attachment.php?attachmentid=30130&stc=1&d=1254891990)

When you run the program, within the square in the form, 15 squares will appear at random locations inside this square. There are 3 different colored squares: red, blue, green. Each square is 8x8 pixels. The timer down the bottom of the form begins counting upon runtime also.

Now i'm like each square to generate a random number out of 5... corresponding to the following:

1: left
2: right
3: up
4: down
5: idle

Whichever number is generated, the square will move in that direction 1 pixel. So the squares can only move in one direction at once. Each time the square moves, it 'levels' up 1. So if the square has moved 4 times, it is level 4. If the square generates number 5, it stays in the same spot and doesn't level. So if the square has moved 4 times and idled once, it's only level 4. These random numbers are generated once per second.

Now if these squares collide, it should check the color of the opposing square. If it is the same color, it ignores it and keeps on moving (or idle depending on the number generated) but it moves in a direction that is valid (it obviously can't stand on top of another square).

If the opposing square is another color, the one with the highest level remains and the lesser level square dissapears. The remaining square gets one point for it's team as recorded at the bottom of the form.

The computer should always check that 15 squares are in play at all times, 5 per side. So when 1 dies, another is spawned at a random location (not on top of an existing square).

On mouseover for each square should be displayed the current level of the square, and how long it has been in play.

To make things fair for all the squares, a level cap of eg. 50 should be introduced. I guess the level cap should depend on the size of the form/area they have to move around.

Can anybody help me design/code this please? If you're interested... :)

Thanks.

Regards, Benjagan91

EDIT: Actually i guess this should of went in the games programming area, even though it won't use DirectX... sorry!

jerome_gail26
10-07-2009, 06:49 AM
1. Create a timer
2. Inside the timer event, call a function which gives random number.

Here is the method that gives random number:

Public Function GiveRandomNumber() As Integer
Randomize
GiveRandomNumber = GiveRandomNumberRnd() * 4
End Sub

:D
on Timer:

Public Sub Timer1_Timer()
Select Case Round(GiveRandomNumber)
Case 0
'Move Left
Case 1
'Move right
Case 2
'Move up
Case 3
'Move down
Case Else
'Move idle
End Select
End Sub


If you notice i put Case Else instead of Case 4, so what ever result is you will not encounter logical error. :)


BTW, Im am not in front of a computer with vb6 app. So i havent try the code above but it should work.:D


Goodluck,
Jerome and Gail

Cerian Knight
10-07-2009, 03:39 PM
Just a few comments on J&G's code before you try to implement it:

Randomize should be moved to Form_Load so that it is only called once when the application starts to maximize random distribution.

'GiveRandomNumber = GiveRandomNumberRnd() * 4' should read 'GiveRandomNumber = Int(Rnd() *5)' to produce results from 0-4 with equal (instead of biased) distribution...

Then the 'Round' function can therefore be stripped from the 'GiveRandomNumber' function call in the 'Select Case' statement.

I suggest implementing that code and drawing up your own code logic to fill in the moves. Show us what you have if you get stuck.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum