Quantcast

Jump to content

» «
Photo

Help

7 replies to this topic
Huitzilopochtli
  • Huitzilopochtli

    Guitar Hero FTW

  • Members
  • Joined: 08 Mar 2005

#1

Posted 19 April 2005 - 07:23 PM

i am trying to make a game in a programming class in which i use a bucket to move (left/right) to catch coins falling from the top. if anyone knows visual basic at all...i need help with some code writing.

I am stuck on moving the bucket but I think the code is right, but it wont work. Or any other help would be greatly appreciated.

segosa
  • segosa

    Ghetto Star

  • BUSTED!
  • Joined: 15 May 2002

#2

Posted 19 April 2005 - 09:10 PM

If you think your code is right but aren't sure don't you think it would be a good idea to paste/include it somewhere in your post?

Anyway, to move an item you just refer to its .Left or .Top properties. Like

Bucket1.Left = Bucket1.Left + 1

to move it to the right by 1 twip. (16 twips in one pixel I believe)

Tsuroki
  • Tsuroki

    Gone Fishin'

  • Inactive Staff
  • Joined: 20 Jul 2002
  • None

#3

Posted 20 April 2005 - 12:29 AM

Moved to Programming. cool.gif

Jack_Knife
  • Jack_Knife

    we usually take all niggas garments

  • Leone Family Mafia
  • Joined: 08 Dec 2001

#4

Posted 20 April 2005 - 06:48 AM

15 twips is a pixel, actually Seg. tounge.gif

At mr. topic starter, like was previously mentioned, paste your code. That's the only way we can help really.

To move the bucket to where the moues is on the form, throw this into the Form_MouseMove sub:
CODE
bucketObject.left = X - bucketObject.width / 2

Luke
  • Luke

    suckmyrocket

  • Inactive Staff
  • Joined: 01 Dec 2003
  • None

#5

Posted 20 April 2005 - 03:18 PM

In addition, the number of Twips per pixel is stored in:
CODE
Screen.TwipsPerPixelX
Screen.TwipsPerPixelY


I'm more than willing to help you, but some more information would be nice.

Huitzilopochtli
  • Huitzilopochtli

    Guitar Hero FTW

  • Members
  • Joined: 08 Mar 2005

#6

Posted 20 April 2005 - 07:35 PM Edited by Huitzilopochtli, 20 April 2005 - 07:48 PM.

I got the bucket moving and it stops on each side with this code:

(General Declarations) : Const Moveinc as integer = 5

Dim MoveMouse as boolean

(Form KeyDown) : Select Case KeyCode
Case vbKeyLeft
If imgBucket.Left < 0 Then

Else
imgBucket.Left = imgBucket.Left - MoveInc
End If
Case vbKeyRight
If imgBucket.Left + imgBucket.Width > picStatus.Left Then

Else
imgBucket.Left = imgBucket.Left + MoveInc
End If
End Select

(Form MouseMove) : If MoveMouse = True Then
imgBucket.Left = X - imgBucket.Width / 2
ElseIf MoveMouse = False Then

End If

(CmdStart) : txtFocus.SetFocus
MoveMouse = True :That is Start game button:

(txtFocus) : Select Case KeyCode
Case vbKeyLeft
If imgBucket.Left < 0 Then

Else
imgBucket.Left = imgBucket.Left - MoveInc
End If
Case vbKeyRight
If imgBucket.Left + imgBucket.Width > picStatus.Left Then

Else
imgBucket.Left = imgBucket.Left + MoveInc
End If
End Select

More information: I have 6 coins (in an array) that will fall from 6 locations (in the sky) and will randomly fall downwards, and when it is aligned with the bucket, and touches imgbucket.top at the same time, the coin will be caught. (I know how to keep score and crap once I have the coin caught)

Edit: New code in mousemove moves the bucket with the mouse as well as the keyboard
Any code ideas?

BenMillard
  • BenMillard

    aka Cerbera

  • Members
  • Joined: 22 Jun 2002
  • None

#7

Posted 21 April 2005 - 01:47 PM Edited by Cerbera, 21 April 2005 - 01:50 PM.

If you surround your code using the CODE tag, it will normally retain the indentation. That makes it a lot easier for people to read. Also, you should add lots of comments to the code to explain what effect it has and what things are affected by it. I normally put a comment at the end of each line to explain in English what the VB is doing, so that I get both a programmatic explanation of the code from the VB and a more human-readable version to the right.

(EDIT) It would also be easier to read if you copied and pasted your code directly, rather than giving them new procedure names and so on.

Huitzilopochtli
  • Huitzilopochtli

    Guitar Hero FTW

  • Members
  • Joined: 08 Mar 2005

#8

Posted 21 April 2005 - 06:55 PM

Direct Code:

Option Explicit


Const MoveInc As Integer = 6
Dim MoveMouse As Boolean
Private Sub cmdAbout_Click()

About.Show 0


End Sub

Private Sub cmdExit_Click()

Unload Me

End Sub

Private Sub cmdInstructions_Click()

Instructions.Show 0


End Sub

Private Sub cmdStart_Click()


txtFocus.SetFocus
MoveMouse = True


End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Dim NewLeft As Integer

NewLeft = imgBucket.Left

Select Case KeyCode
Case vbKeyLeft
imgBucket.Left = imgBucket.Left - MoveInc
Case vbKeyRight
imgBucket.Left = imgBucket.Left + MoveInc
End Select

imgBucket.Left = NewLeft




End Sub

Private Sub Text1_Change()



End Sub


Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)


If MoveMouse = True Then
imgBucket.Left = X - imgBucket.Width / 2
ElseIf MoveMouse = False Then

End If





End Sub

Private Sub txtFocus_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode
Case vbKeyLeft
If imgBucket.Left < 0 Then

Else
imgBucket.Left = imgBucket.Left - MoveInc
End If
Case vbKeyRight
If imgBucket.Left + imgBucket.Width > picStatus.Left Then

Else
imgBucket.Left = imgBucket.Left + MoveInc
End If
End Select


End Sub




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users