Results 1 to 9 of 9

Thread: Argh, what is wrong with this !?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Posts
    225
    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]

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Posts
    225
    Nevermind, think I fixed it. =)

  3. #3
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    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!

  4. #4
    Addicted Member DarkMoose's Avatar
    Join Date
    Jul 2000
    Location
    in a box
    Posts
    185
    Timerz are evil :O
    To understand recursion, one must first understand the concept of recursion.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Posts
    225
    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

  6. #6
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181

    Angry

    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!

  7. #7
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    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
    Paul Lewis

  8. #8
    Member
    Join Date
    May 2000
    Posts
    45

    Smile

    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

  9. #9
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    I'll do that soon

    It's the weekend now so it might not be for a few days

    Cheers
    Paul Lewis

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width