PDA

Click to See Complete Forum and Search --> : Argh, what is wrong with this !?


git
Sep 27th, 2000, 06:32 AM
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:


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]

git
Sep 27th, 2000, 07:13 AM
Nevermind, think I fixed it. =)

Fox
Sep 27th, 2000, 11:38 AM
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!

DarkMoose
Sep 27th, 2000, 04:40 PM
Timerz are evil :O

git
Sep 27th, 2000, 07:30 PM
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

/\/\isanThr0p
Sep 28th, 2000, 06:05 PM
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

PaulLewis
Sep 28th, 2000, 09:03 PM
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

kleve
Sep 29th, 2000, 04:56 AM
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 ? :)

PaulLewis
Sep 29th, 2000, 06:45 AM
It's the weekend now so it might not be for a few days :)

Cheers