|
-
Sep 27th, 2000, 06:32 AM
#1
Thread Starter
Addicted Member
I'm making a tile-based turn-based game. I'm having severe problems in the code I'm writing for weapons fire. I've got this code in a timer, but it's just not working properly. I had this code working before (it's my original code), although that was for a completely different part of the game. I've tried to adapt it for the tactical engine, but it isn't working (the co-ordinates are wrong and there's negative values)... here it is anyway:
Code:
WeaponX2 = Soldiers(SelectedSoldier).SoldierXPos - 1
WeaponY2 = Soldiers(SelectedSoldier).SoldierYPos - 1
XDifference = (WeaponX1 - WeaponX2)
XDifferenceSqr = XDifference * XDifference
YDifference = (WeaponY1 - WeaponY2)
YDifferenceSqr = YDifference * YDifference
PointToPointDistance = Sqr(XDifferenceSqr + YDifferenceSqr)
WeaponDistance = PointToPointDistance - 0.05
If WeaponDistance <= 0 Then
'Weapon Hits Target
Timer(1).Enabled = False
Else
TravelVariable = WeaponDistance / PointToPointDistance
WeaponXPos = XDifference * TravelVariable
WeaponYPos = YDifference * TravelVariable
BitBlt GridImage.hDC, (WeaponX2 - 1 - WeaponXPos) * 24, (WeaponY2 - 1 - WeaponYPos), 24, 24, GraphicsSource(4).hDC, 24, 0, vbSrcAnd
BitBlt GridImage.hDC, (WeaponX2 - 1 - WeaponXPos) * 24, (WeaponY2 - 1 - WeaponYPos), 24, 24, GraphicsSource(4).hDC, 0, 0, vbSrcPaint
GridImage.Refresh
WeaponX1 = WeaponX2 - WeaponXPos
WeaponY1 = WeaponY2 - WeaponYPos
I really want to keep this distance-formula style of doing this. There just something wrong in there, just can't figure it out. Basically these values should be on an X/Y grid, from 0 to the size of the map (X and Y size).
WeaponX1/WeaponY1 is the weapon target, and WeaponX2/WeaponY2 is the current soldier position (which then transforms into the bullet position after the first loop of code).
Please, if someone can correct this code for me I'd be very grateful... =)
Thanks!
-Git
[Edited by git on 09-27-2000 at 07:49 AM]
-
Sep 27th, 2000, 07:13 AM
#2
Thread Starter
Addicted Member
Nevermind, think I fixed it. =)
-
Sep 27th, 2000, 11:38 AM
#3
PowerPoster
Stop using timers!
Immediately!
I've seen the word 'Timer' in your code! Can you explain that!?
*argh* Never use timers!!! And especially not MORE THAN ONE!!! There's your bug, delete the timer! No, delete the whole control from the VB dll!

In fact Timer's really suck!
-
Sep 27th, 2000, 04:40 PM
#4
Addicted Member
To understand recursion, one must first understand the concept of recursion.
-
Sep 27th, 2000, 07:30 PM
#5
Thread Starter
Addicted Member
Yeah, been using them so this code is activated (so it's a smooth dot moving across the screen).
I know you can use other timer-type things, but I've tried them and it crashed VB. =(
-Git
-
Sep 28th, 2000, 06:05 PM
#6
Frenzied Member
It really makes me feel sick if I have to read someone uses timers in his mainloop!!!!!!!!!!!
That's so sad!
What about using a do loop and checking for speed with gettickcount?
Timers slow down and are inaccurate (sometimes)
I only use timers on some commands one time. After waiting about 10ms to do something they are deactivated forever!
KILL THE TIMER AND THE GAME WILL BE BETTER 200 TIMES
Sanity is a full time job
Puh das war harter Stoff!
-
Sep 28th, 2000, 09:03 PM
#7
Hyperactive Member
Wait till muti threading hits you :)
I've had plenty of experience with this in the Java
environment so I always try to do things with a very OO mindset.
So when I set about recently to develop an AI for a multi-
player game, I started using Anonymous Pipes to help me.
To emulate multi-threading I have to have my AI module as a
standalone app which is spawned by my main game app.
The beauty of this is that the movement arbiter in the game doesn't have a timer, doesn't sleep or anything so primitive
Using the pipes and the API call WaitForMultipleObjects, my arbiter thread is literally idle. He doesn't wake up ever n milliseconds like he would if using the Sleep API. He isn't in a fast loop eating up my processor time doing nothing... he is simply and utterly suspended.
To wake him up, one of the AI agents fires an event (or shuts down) and bank, the arbiter is awake and running again...
So although I can't argue with any of the advice you are giving poor git, I suspect that once multi-threading becomes easy for the masses (ala VB7), alot of your existing games will be able to be improved significantly...
Off my soap box now 
Cheers
-
Sep 29th, 2000, 04:56 AM
#8
Member
that sounds like some nice coding Paul - I've had experience with POSIX threads under solaris but that's about it and I'd love to be able to get some mutlithreaded VB going - fancy posting some example code ?
K
----------------------------------
VB6 Ent SP4 Win2K Pro Platform SDK
-
Sep 29th, 2000, 06:45 AM
#9
Hyperactive Member
I'll do that soon
It's the weekend now so it might not be for a few days 
Cheers
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|