Author |
Message |
blaster0
|
Posted: Fri May 26, 2006 12:01 am Post subject: fighting game help |
|
|
I have decided to make a fighting game in vb and everything is perfect except that I cannot get the player and the opponent to move simultaneously.
Some stuff you might want to know is :
1)because of vb's prioritizing ways I have my form key down and it says
if keycode=vbkeydown then
key=1
end if
then in a timer (I have 2 one for player, 1 for comp) I have the
commands.
2)I made a delay command for myself that looks like this
Private Sub delay(delayamount As Integer)
Dim time1 As Double
Dim time2 As Double
time1 = Timer
time2 = Timer
Do Until (time2 - time1) * 1000 >= delayamount
time2 = Timer
Loop
End Sub
Thanks for your help in advance
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Darkmantis
|
Posted: Fri May 26, 2006 10:37 am Post subject: (No subject) |
|
|
everyone on here says that there is no way to do that with vb, but I know you can in turing
|
|
|
|
|
|
blaster0
|
Posted: Fri May 26, 2006 12:12 pm Post subject: (No subject) |
|
|
This delay command is the same as the turing one with the same problems and very bad, but possible solutions. Although people have made games like pacman, etc. that respond to player movement as well as computer movement and perform both simultaneously (maybe multi-threading, but don't know how to use).
This works fine having the computer move 2 objects using 2 timers simultaneously, but the weird key inputting is the problem
Thanks
|
|
|
|
|
|
Darkmantis
|
|
|
|
|
McKenzie
|
Posted: Sat May 27, 2006 4:18 pm Post subject: (No subject) |
|
|
actually this is a fairly easy, and common problem. VB (like many languages) only tells you when Windows events happen. In this case it is the press or release of a key. In order to know what the status of all the keys is all you need to do is make an array and store the status yourself. Here is an example: (Oh, use WASD and arrow keys)
Description: |
|
Download |
Filename: |
fight.vbp |
Filesize: |
599 Bytes |
Downloaded: |
176 Time(s) |
Description: |
|
Download |
Filename: |
fight.frm |
Filesize: |
1.93 KB |
Downloaded: |
135 Time(s) |
|
|
|
|
|
|
cool dude
|
Posted: Sat May 27, 2006 5:20 pm Post subject: (No subject) |
|
|
very interesting McKenzie. maybe u should put this in the tutorial section as well because many ppl ask how to use more than one key and i just know here it will get lost and someone will reask. oh and i think u mixed your directions up on your side keys (A = right and D = left )
|
|
|
|
|
|
Brightguy
|
Posted: Sat May 27, 2006 10:19 pm Post subject: Re: fighting game help |
|
|
That's one way to do it, although there may be problems with it. For example, the form only recieves the KeyUp and KeyDown events when the form has the focus. So if you press a key, switch the focus to another window, and then release the key, you won't be able to tell it's been released.
One way to fix that is to use the approach shown in this thread.
|
|
|
|
|
|
blaster0
|
Posted: Sun May 28, 2006 1:36 pm Post subject: (No subject) |
|
|
ok thanks, but the main problem still exists.
The problem is that i am animating 1 user moving and 1 computer moving.
I am basically recreating a gif and therefore need to delay between each picture (for example load pic delay 100 ms move load pic...).
But I can't really use the timer for this (I need to delay within a timer).
Here is an example program. Tell me if you can fix it.
Description: |
just make sure the pics are right, but any pics will do |
|
Download |
Filename: |
example.zip |
Filesize: |
1.33 KB |
Downloaded: |
140 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
cool dude
|
Posted: Sun May 28, 2006 7:49 pm Post subject: (No subject) |
|
|
the easiest way to delay things is by making a module first and type this code
code: |
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) |
then in your actualy code everytime you want to make a delay all you do is type
code: |
refresh
sleep(1000)
|
note: "1000" is just how many milliseconds you delay it for so you can change that number.
hope this helps
|
|
|
|
|
|
McKenzie
|
Posted: Sun May 28, 2006 9:26 pm Post subject: (No subject) |
|
|
Umm...I don't think you understand how timers work. Here is a simple example of using a gif in VB.
Description: |
|
Download |
Filename: |
VB gif.zip |
Filesize: |
112.33 KB |
Downloaded: |
124 Time(s) |
|
|
|
|
|
|
blaster0
|
Posted: Sun May 28, 2006 9:33 pm Post subject: (No subject) |
|
|
Cool dude: I'm sorry, but this isn't working for me. Do you have an example prog or something I could use, or maybe I just have someother problem. I just used my prog above and substituted as neccessary.
McKenzie: True, but I need that to execute only every "x" seconds, which I can set by using a randomizing number with tmr1.interval
|
|
|
|
|
|
cool dude
|
Posted: Mon May 29, 2006 4:17 pm Post subject: (No subject) |
|
|
wat error message r u getting?
here are the steps to make a sample example program
1) make a module. to make a module on the toolbar at the top you will see file, edit, view, ...etc. click on project menu. then click add module. a popup will appear and just click open
2) in the module all you do is copy and paste this code
code: |
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) |
3) go to your form and make 2 shapes and set there fillstyle to solid so you can see their colour and make a command button
4) then double click on the command button and type this code:
code: | Private Sub Command1_Click()
Shape1.FillColor = vbRed
Refresh
Sleep (1000)
Shape2.FillColor = vbBlue
End Sub |
see wat happens? the first box is red and after a second the next box turns blue. i hope that worked for you if not please post the error message you get. Remember always do refresh before sleep
|
|
|
|
|
|
blaster0
|
Posted: Mon May 29, 2006 7:19 pm Post subject: (No subject) |
|
|
I think I fixed it anyway.
But I think your command has the same problem as mine had.
It's something like this:
Public Sub delay(delayvalue as integer)
dim time1 as integer
dim time2 as integer
time1=timer
time2=timer
do until (time2-time1)*1000>=delayvalue
time2=timer
loop
end sub
Thanks to eveyone for your help and this thread I can see will be linked to many times in the future.
|
|
|
|
|
|
cool dude
|
Posted: Mon May 29, 2006 8:00 pm Post subject: (No subject) |
|
|
my command has no problem with it. if you can't simply follow instructions that is not my fault. if u followed step by step for the example program i made you would see how much easier and smaller my code is than yours and in fact my code is more efficient than yours so i suggest trying it. wat exactly about my code that is not working because i'm running it as i'm typing and its perfect so i'm guessing you did something wrong
|
|
|
|
|
|
blaster0
|
Posted: Mon May 29, 2006 9:40 pm Post subject: (No subject) |
|
|
Thanks for your concern, but the problem is that you cannot run 2 sleep commands simulateously. ie: in separate timers. This is because sleep, like delay stops the entire program before continuing (this is what I meant by the prioritizing mentioned above).
|
|
|
|
|
|
|