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]
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]