Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 22nd, 2003, 05:01 PM
spunkygirl14 spunkygirl14 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Chicago, Illinois
Posts: 4 spunkygirl14 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Images Move Freely

I dont know if any of you have heard of these games:
Pong
Rebound
Smashing
But they all have one thing in common, they have a ball that moves freely without clicking the mouse or pressing a key. Thats what i am trying to do. Can you help me with a code or something?

Reply With Quote
  #2  
Old August 25th, 2003, 02:56 AM
Silian's Avatar
Silian Silian is offline
Gogga
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 198 Silian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Definitely heard of pong. I once wrote it in Javascript (although it's not complete. Have a few bugs to sort out, which is where I usually quit).

What you must do is insert a timer into your form. Set the timer's interval to 1 (in milliseconds). Then, in the timer code, you insert the code to move the ball. I usually have a variable: intTop, and intLeft to specify if it should move left or right.

Here's the untested code:

Code:
Dim intLeft
Dim intTop
Dim iPosTop
Dim iPosLeft

Private Sub Form_Load()
    iPosTop = btntest.Top
    iPosLeft = btntest.Left
    intLeft = 7
    intTop = 7
End Sub

Private Sub Timer1_Timer()
    iPosTop = iPosTop + intTop
    iPosLeft = iPosLeft + intLeft
    If (iPosTop >= (Form1.Height - 2 * btntest.Height)) Or (iPosTop <= 0) Then
        intTop = intTop * -1
        iPosTop = iPosTop + intTop
    End If
    If (iPosLeft >= (Form1.Width - btntest.Width)) Or (iPosLeft <= 0) Then
        intLeft = intLeft * -1
        iPosLeft = iPosLeft + intLeft
    End If
    btntest.Top = iPosTop
    btntest.Left = iPosLeft
End Sub

I used a button called btnTest instead of a picture.
By changing the values of intleft and inttop, you can make it move slower or faster, and at angles (e.g. setting inttop to 10 and intleft to 20, it will move more horizontically than vertically)

Last edited by Silian : August 25th, 2003 at 03:04 AM.

Reply With Quote
  #3  
Old August 29th, 2003, 04:12 AM
Nicnacs Nicnacs is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: UK Suffolk
Posts: 4 Nicnacs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to Nicnacs
Moving a ball

Hi, I'm interested in this as well, I've done darkBasic for a year and I got most of the math stuff sorted out (I even know most of the code for a car sim , but now I'm kind of back to square one just learning how vb itself works.
If you still need any code for it I can go and dig it out.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Images Move Freely


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT