I need help with some VB code. Ultimately I would like it in VBA because that's all I have. I am making a fun game to hide in all of my docs. It is a pong like game but you need to have your pad deflect a ball that a alien drops. I also need help making the aliens move by themselves and drop the balls at a specific spot. Any help or ideas would be nice.This is my first post so go easy on me.
Thanks
26 3650
I need help with some VB code. Ultimately I would like it in VBA because that's all I have. I am making a fun game to hide in all of my docs. It is a pong like game but you need to have your pad deflect a ball that a alien drops. I also need help making the aliens move by themselves and drop the balls at a specific spot. Any help or ideas would be nice.This is my first post so go easy on me.
Thanks
see we r not getting u
so if possible explain it in detail
I need help with some VB code. Ultimately I would like it in VBA because that's all I have. I am making a fun game to hide in all of my docs. It is a pong like game but you need to have your pad deflect a ball that a alien drops. I also need help making the aliens move by themselves and drop the balls at a specific spot. Any help or ideas would be nice.This is my first post so go easy on me.
Sounds an interesting idea. I hope it works out.
However, we generally expect people to work out what they want to do, and make some attempt at it. Then, when you have specific questions about points where you get stuck we can help with the how.
What have you achieved so far on this project?
Don't hate ur Computer
:)
see we r not getting u
so if possible explain it in detail
I am using VBA to make a game. The first thing that I want is to make a picture of a spaceship that I have move around the window randomly. I know that I need a randomize script of some kind but I tried and it didn't work. Help is always great.
Thanks
I am using VBA to make a game. The first thing that I want is to make a picture of a spaceship that I have move around the window randomly. I know that I need a randomize script of some kind but I tried and it didn't work. Help is always great.
Thanks
for that u may use timmer ctrl with less interval or u may use system second part or u may use rnd function to do so
try it
Good Luck
Sounds an interesting idea. I hope it works out.
However, we generally expect people to work out what they want to do, and make some attempt at it. Then, when you have specific questions about points where you get stuck we can help with the how.
What have you achieved so far on this project?
I have tried to make a randomize script but I need to make that do something to the ship. I need it random so people can't find all to possible combinations and beat it. I am trying to do this with at least 4 ships.
Thanks
for that u may use timmer ctrl with less interval or u may use system second part or u may use rnd function to do so
try it
Good Luck
My random number code looks like this:
Private Function RandomNumber() As Integer
Randomize Timer
RandomNumber = Int(Rnd * 100)
Label1 = RandomNumber
End Function
Private Sub CommandButton1_Click()
Call RandomNumber
End Sub
I push the button to make random numbers in the label1. But I need to make that move the picture.
Thanks
Don't hate ur Computer
:)
I don't know about that. Computers, cars, and lawn mowers are not here to stay. I agree with Thomas Watson, past president of IBM, who allegedly said, "I think there is a world market for maybe five computers." :D
I don't know about that. Computers, cars, and lawn mowers are not here to stay. I agree with Thomas Watson, past president of IBM, who allegedly said, "I think there is a world market for maybe five computers." :D
Fine that is enough I don't hate my 2 new vista computers just my 5 old ones. Now that I got that over with lets stay on topic with the game that I want to program.
Thanks
...I push the button to make random numbers in the label1. But I need to make that move the picture.
Not to sure about VBA, but in VB to move a picture you just use the .Move method of the PictureBox or ImageBox control, or set the .Top and/or .Left properties.
Not to sure about VBA, but in VB to move a picture you just use the .Move method of the PictureBox or ImageBox control, or set the .Top and/or .Left properties.
In VBA it is .Top and/or .Left but how can I make that random?
Thanks
In VBA it is .Top and/or .Left but how can I make that random?
Well, one way to move it at random would be to generate 2 random numbers, one for X coordinate and one for Y. Then you just add your random numbers to the .Top and .Left values.
There are better ways, of course. This tends to make them jiggle around like a mad thing.
What I like to do in such a case is initially establish a random value for the "speed" in each direction (horizontal/vertical). Then each move, you add that "speed" value to the current value. That way, the object moves in a random direction, but keep on moving that way until you change it.
Well, one way to move it at random would be to generate 2 random numbers, one for X coordinate and one for Y. Then you just add your random numbers to the .Top and .Left values.
There are better ways, of course. This tends to make them jiggle around like a mad thing.
What I like to do in such a case is initially establish a random value for the "speed" in each direction (horizontal/vertical). Then each move, you add that "speed" value to the current value. That way, the object moves in a random direction, but keep on moving that way until you change it.
That would be great. Could I do a thing where it it would bounce off the sides?
Thanks
That would be great. Could I do a thing where it it would bounce off the sides?
Sure, that's easy. You just check when you move it. If the horizontal position is < 0 or > form width, reverse the movement in that direction. Same for Y.
I'm just leaving work, but when I get home I'll see whether I have time to put together a simple demo that bounces around a window. It'll be in VB6, but should give you some ideas to play with.
Well, I've developed a working sample. It's a form which contains a picturebox. A number of coloured dots bounce around inside the picturebox.
There are buttons to add and remove dots, a scollbar to adjust the animation speed, a button to pause/continue the animation, and a checkbox to turn erasing of the dots on and off. If you turn the "tails" on, the dots aren't erased each time things are drawn, so they leave a trail behind. It help to show off the colour-cycling.
Sorry, I got a bit carried away.
Unfortunately, I'm not sure whether you will be able to make any use of it, but perhaps you can get some ideas from it.
First, I'll see whether I can attach a copy of the zipped project. Stay tuned...
How about that, it worked!
The zip contains a compiled EXE you should be able to run, so you can see what I'm talking about, anyway. I hope the code may give you some ideas, though it's probably not very good.
Well, I've developed a working sample. It's a form which contains a picturebox. A number of coloured dots bounce around inside the picturebox.
There are buttons to add and remove dots, a scollbar to adjust the animation speed, a button to pause/continue the animation, and a checkbox to turn erasing of the dots on and off. If you turn the "tails" on, the dots aren't erased each time things are drawn, so they leave a trail behind. It help to show off the colour-cycling.
Sorry, I got a bit carried away.
Unfortunately, I'm not sure whether you will be able to make any use of it, but perhaps you can get some ideas from it.
First, I'll see whether I can attach a copy of the zipped project. Stay tuned...
How about that, it worked!
The zip contains a compiled EXE you should be able to run, so you can see what I'm talking about, anyway. I hope the code may give you some ideas, though it's probably not very good.
I didn't understand how you did the animation. Help is great.
Thanks
I didn't understand how you did the animation. Help is great.
Although the code may look a bit daunting, the way the animation is done is actually quite simple.
For each of the X (horizontal) and Y (vertical) axes (let's ignore the colour for now) you have a value, and a speed (which I referred to as "delta", often used to indicate a rate of change). At each tick of the timer, you simply add the delta to the current value, and like magic, you have movement.
Then there is some extra code to bounce when it hits a boundary, by reversing the delta and adding it again (twice). And a bit more to randomly change the speed now and then.
Although the code may look a bit daunting, the way the animation is done is actually quite simple.
For each of the X (horizontal) and Y (vertical) axes (let's ignore the colour for now) you have a value, and a speed (which I referred to as "delta", often used to indicate a rate of change). At each tick of the timer, you simply add the delta to the current value, and like magic, you have movement.
Then there is some extra code to bounce when it hits a boundary, by reversing the delta and adding it again (twice). And a bit more to randomly change the speed now and then.
So you have the value and the speed. The value is the X and Y. The speed is also the timer. The timer is based off of the scroll bar value. The higher the value the faster it is the lower the value the slower it is. When the timer changes you add the delta to the current value. I think I am starting to get how to do my code but how do you do the timer and make it add the delta. (code example with discription if possible) Thanks for spending your time helping me.
So you have the value and the speed. The value is the X and Y. The speed is also the timer. The timer is based off of the scroll bar value. The higher the value the faster it is the lower the value the slower it is. When the timer changes you add the delta to the current value. I think I am starting to get how to do my code but how do you do the timer and make it add the delta. (code example with discription if possible) Thanks for spending your time helping me.
The timer code in my program was as follows... - Private Sub Timer1_Timer()
-
Timer1.Interval = SpeedDelay
-
Static Busy As Boolean
-
Static I As Long
-
' This is where all the animation happens...
-
If Not Busy Then
-
Busy = True
-
With Picture1
-
If Check1.Value = 0 Then
-
.Cls
-
End If
-
For I = 1 To NumberOfObjects
-
ApplyDeltaWithBounce X_pos(I), X_Delta(I), 0, .ScaleWidth, 2, -10, 10
-
ApplyDeltaWithBounce Y_pos(I), Y_Delta(I), 0, .ScaleHeight, 2, -10, 10
-
ApplyDeltaWithBounce R(I), R_Delta(I), 0, 255, 5, -15, 15
-
ApplyDeltaWithBounce G(I), G_Delta(I), 0, 255, 5, -15, 15
-
ApplyDeltaWithBounce B(I), B_Delta(I), 0, 255, 5, -15, 15
-
Picture1.PSet (X_pos(I), Y_pos(I)), RGB(R(I), G(I), B(I))
-
Next
-
.Refresh
-
DoEvents
-
End With
-
Busy = False
-
End If
-
End Sub
This code is basically the entire animation.
It loops through all the dots (I probably shouldn't called them "objects", as it may cause confusion). For each one, it passes each value/delta pair to a generic routine called ApplyDeltaWithBounce. This routine is designed to take the value and the delta, and apply the delta (amount of change, remember) to the value. It also accepts limits beyond which the value should "bounce". The last three parameters allow me to insert a bit of random change in the movement (if you watch you'll see that the dots sometimes change direction for no apparent reason) by saying " n% of the time, change the delta to something within these limtis".
With this sort of "black box" approach you don't necessarily need to understand (at first) exactly how each part of the program works - just what effect it has. This routine simply changes the value by the delta amount, bouncing when it hits the specified limits. The Timer1_Timer event procedure does the animation.
If you like, we can simplify the example by skipping the colour-cycling and the check for re-entry (the Busy flag). As I said, I got a bit carried away. Here's the simpler version - Private Sub Timer1_Timer()
-
Timer1.Interval = SpeedDelay
-
Static I As Long
-
' This is where all the animation happens...
-
With Picture1
-
If Check1.Value = 0 Then
-
.Cls
-
End If
-
For I = 1 To NumberOfObjects
-
ApplyDeltaWithBounce X_pos(I), X_Delta(I), 0, .ScaleWidth, 2, -10, 10
-
ApplyDeltaWithBounce Y_pos(I), Y_Delta(I), 0, .ScaleHeight, 2, -10, 10
-
Picture1.PSet (X_pos(I), Y_pos(I)), RGB(R(I), G(I), B(I))
-
Next
-
.Refresh
-
DoEvents
-
End With
-
End Sub
-
Private Sub Timer1_Timer()
Timer1.Interval = SpeedDelay
Static I As Long
' This is where all the animation happens...
With Picture1
If Check1.Value = 0 Then
.Cls
End If
For I = 1 To NumberOfObjects
ApplyDeltaWithBounce X_pos(I), X_Delta(I), 0, .ScaleWidth, 2, -10, 10
ApplyDeltaWithBounce Y_pos(I), Y_Delta(I), 0, .ScaleHeight, 2, -10, 10
Picture1.PSet (X_pos(I), Y_pos(I)), RGB(R(I), G(I), B(I))
Next
.Refresh
DoEvents
End With
End Sub
Can I change the Timer1.Interval = SpeedDelay to have a set interval so you wouldn't need a variable speed and scroll bar?
Can I change the Timer1.Interval = SpeedDelay to have a set interval so you wouldn't need a variable speed and scroll bar?
Of course.
I specifically put in the scrollbar and the SpeedDelay variable to allow me to adjust the speed on the fly. There's no reason you can't just set the timer interval at design time and leave it.
Of course.
I specifically put in the scroll bar and the Speed Delay variable to allow me to adjust the speed on the fly. There's no reason you can't just set the timer interval at design time and leave it.
If your scroll bar is at the fastest side what is you speed variable and how can I put that in the timer interval thing?
If your scroll bar is at the fastest side what is you speed variable and how can I put that in the timer interval thing?
To be honest, I don't think it matters what values I used. You should work out what you want to do, and play with values until you get the performance you want.
Just keep in mind that the timer's .Interval property specifies the number of milliseconds to pause between "ticks".
I just thought of something! Of you're working in VBA, there isn't any timer control, is there? There was a thread here not long ago in which we tracked down some alternatives. You may need to run some searches for things like "VBA timer control" and so on. (Actually, if I manage to find it, I might add it to the Tips & Tricks at the top of the forum.)
To be honest, I don't think it matters what values I used. You should work out what you want to do, and play with values until you get the performance you want.
Just keep in mind that the timer's .Interval property specifies the number of milliseconds to pause between "ticks".
I just thought of something! Of you're working in VBA, there isn't any timer control, is there? There was a thread here not long ago in which we tracked down some alternatives. You may need to run some searches for things like "VBA timer control" and so on. (Actually, if I manage to find it, I might add it to the Tips & Tricks at the top of the forum.)
Your right I don't need your value I just was lazy but I might find a better one if I try myself. I do know this timer code that spins a picture around the document maybe it could help us make a timer like yours for VBA if we change it. - Option Explicit
-
-
Sub Document_Open()
-
Application.OnTime When:=Now + TimeValue("00:00:02"), Name:="ShapeMover"
-
End Sub
-
-
Sub ShapeMover()
-
Dim oSH As Shape
-
Set oSH = ActiveDocument.Shapes(1)
-
oSH.IncrementRotation 10
-
-
Application.OnTime When:=Now + TimeValue("00:00:02"), Name:="ShapeMover"
-
End Sub
The TimeValue("00:00:02") should be useful.
The OnTime technique sounds quite useful.
I plan to gather together these sort of Timer substitutes and add them into the Tips & Tricks. Will include this one also, if it's not already there.
I found that the help in VBA said the you use an OnTime thing. As shown below.
Example
This example runs the macro named "Macro1" in the current module at 3:55 P.M. - Application.OnTime When:="15:55:00", Name:="Macro1"
This example runs the macro named "Macro1" 15 seconds from the time the example is run. The macro name includes the project and module name. - Application.OnTime When:=Now + TimeValue("00:00:15"), _
-
Name:="Project1.Module1.Macro1"
This example runs the macro named "Start" at 1:30 P.M. The macro name includes the project and module name. - Application.OnTime When:=TimeValue("1:30 pm"), _
-
Name:="VBAProj.Module1.Start"
So we would go: - Application.OnTime When:=Now + TimeValue("00:00:15"), _ Name:="J"
Where J is what we want to happen and we can change TimeValue("00:00:15") to the time that I want.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Xad |
last post by:
Hi, i'm looking for java code for a really simple, basic Pong game. As
simple as possible - even just two paddles and a ball bouncing will do.
Can anyone help?
Thanks
|
by: junglist |
last post by:
Hi,
i have created a Pong game Application where two players control their
pads using the keyboard. the problem is that one player is using the
action keys
VK_UP and VK_DOWN in keyPressed() and...
|
by: Sam |
last post by:
Hey all,
I want to create a computerised version of this game, though I'm not
really sure how to go about it. For those who don't know how the game
works, here's my attempt at a brief...
|
by: theodp |
last post by:
--> From http://www.techdirt.com/articles/20040406/1349225.shtml
Microsoft Patents Saving The Name Of A Game
Contributed by Mike on Tuesday, April 6th, 2004 @ 01:49PM
from the...
|
by: Will |
last post by:
I am looking to include a pong game or similar in an application I have
developed. I know it's possible to write a pong style game in VB is it
possible to write a pong style game in VBA? & can...
|
by: news.iq.ca |
last post by:
Hello.
Under
C:\Documents and Settings\Administrator\My Documents\My Projects\
I have created a folder, "ASPNET" where I plan to keep my projects.
I have started Administrative Tools ->...
|
by: Dr_Locke_Z2A |
last post by:
I was talking to my uncle the other day about getting into programming
games and he recommended to start teaching myself with really simple
games, like Pong simple. So I looked on google and...
|
by: DaVinci |
last post by:
I am writing a pong game.but met some problem.
the ball function to control the scrolling ball,
void ball(int starty,int startx)
{
int di ,i;
int dj,j;
di = 1;
dj = 1;
i = starty;
|
by: drsmooth |
last post by:
im just starting to work on AI things and i started with a pong game...
i came up with a system that every time the ball hits a wall or a paddle it calls the alert() method of the AIController...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |