locked
Bugs and Suggestions to Pixelgame RRS feed

  • General discussion

  • hi there! im working pretty much on my new game with my "collision engine"! you can add as many rectangles as you want, and the player will collide with them!(with the cost of lag..)
    heres the code:
    DVR397

    please tell me when you find any bugs or if you have tips or ideas! its still not done btw. i also want to add an AI.. (there already is one, but its not done. and you have to change the code to "unlock" it.. just set the variable "Enemy" from "Human" to "CPU".)

    controls are:
    player1:
    Movement = Arrow Keys
    Shoot: = Right Ctrl
    Jump: = RightShift

    Player2:
    Movement = W,A,S,D
    Jump: = LeftShift
    Shoot = Currently not coded

    TODO:
    -Add different types of weapons(e.g. shotgun and pistol)
    -Fix Collision (players sometimes falling through floor)
    -Fix not detecting the floor
    -add items
    -code AI
    -Maybe make players collide with each other
    Live for nothing, OR CODE FOR SOMETHING!
    • Edited by Dudeson Monday, September 7, 2009 5:32 PM
    Saturday, September 5, 2009 6:27 PM

All replies

  • here the updated version:
    RZQ745

    i added healthbars, "ragdolls" on player death, "360°" aiming and optimized the code really much.

    can anyone tell me why the players just detect they're on the floor on some blocks?? and not on all?? (textwindow, true and false things)
    i really need to fix that!
    Live for nothing, OR CODE FOR SOMETHING!
    Sunday, September 6, 2009 12:49 AM
  • General comments:

    1] Your code is getting long enough that you really should have some decent comments
      make them useful and descriptive, say what the intention is
      add enough detail to describe what any calculations are meant to do, not how it is done (we have the code)
      don't use comments to state the obvious
    2] Use the Right Click Format Program
    3] Use variables for quantities that you use a lot (e.g. Pwidth = 20 for character width)
    4] To get the keyboard input to work with the textwindow open (debugging only I know), requires the user to first set focus (click) the graphicswindow.

    Looking at the routine Collision:

    With good comments this would be easier!  First if comment could be "Player overlapping (just touching) box vertically".

    Then check:

    1] whether your logic is correct, particularly use of ElseIf - do you mean to check for horizontal overlap only if there is no vertical overlap?
    2] check the contact criteria, ie. Player overlaps the top of the box and overlaps the box horizontally, but not vertically.
    3] Is it possible for the vertical falling speed of the Player to be such that from one timestep to the next he falls right through the top of the box.

    Sunday, September 6, 2009 11:10 AM
  • about the collision, youre right about nr. 3.

    about the comments. i didnt add them because i actually didnt mean to post it on the forums..
    Live for nothing, OR CODE FOR SOMETHING!
    Sunday, September 6, 2009 2:11 PM
  • Dudeson said:
    "can anyone tell me why the players just detect they're on the floor on some blocks?? and not on all?? (textwindow, true and false things)"

    i found out whats wrong! the variable "PlayerTG" (playertouchingground) is being set to "True" or "False" in a "for" function, wich is checking if the player is on the block or not. if he is on the block, PlayerTG is "True", else its "False".
    BUT, the "Reaction"(sets player "Gravity" to 0 if true, and doesnt change it if its false), to playertg true or false, comes after the "for" function. so it can just react to the 5th block. it can just check if the player is touching the 5th block, because the same variable gets set to true or false 5 times in a row, till theres a "reaction" to it... i hope you know what i mean...

    does someone know a solution for this???
    Live for nothing, OR CODE FOR SOMETHING!
    Sunday, September 6, 2009 5:15 PM
  • Well spotted Dudeson.  Basically you need to think your Collision routine more carefully.

    First work out exactly you want to happen - write it out, then think how to code it.

    Perhaps you want to check each block first to find which block the player is on or landing on first, then do the rest only for this block.  You may want PlayerTG[i] to not be true or false, but set to the block number you are on (0 for none).

    Sunday, September 6, 2009 6:32 PM
  • "Well spotted Dudeson." that sounds so funny! XD

    i already tought about doing multiple TG variables...

    good idea! that would optimize it, and should work^^
    im gonna try it out now! thx!
    Live for nothing, OR CODE FOR SOMETHING!
    Monday, September 7, 2009 4:14 PM
  • man! i just cant get it to work! please help me! heres the latest code:
    WCZ577


    ....
    Live for nothing, OR CODE FOR SOMETHING!
    Monday, September 7, 2009 5:30 PM
  • well.. i fixed it half... here: QKT493

    i coded that the "for" function, or how you call it, ends, when the player touches the floor. (i did it with "n=5" in "for n = 1 to 5".  is there a better way to do this?)
    it works pretty well! BUT sometimes, when you stand on a block, and touch another one with the side of the player (X coordinate) the player just moves trough the block (happens just to some "combination" of blocks. i dont know wich one yet..), because it isnt checking for the collision with that block...
    Live for nothing, OR CODE FOR SOMETHING!
    Monday, September 7, 2009 5:48 PM
  • Yes, this is a reasonable way to end a loop that you know is unnecessary.

    A slight variant below that for me is easier to follow - if this show the issue you mentioned, then it is probably due to the tolerances you are using.  For example the fall velocity may be too large to find the player intersecting the top of a box.

    Using 2 loops shouldn't be a big overhead, since each only holds roughly half the code, and it keeps the horizontal and vertical velocities independent, which is good because they are influenced by different effects.  The comments and separating the code into separate ideas where possible are more than just style - it helps to understand and maintain the code.

    Sub Collision
     
      'HORIZONTAL VELOCITY
     
      'Player hits side of box while falling or on top of another box
      For n = 1 To 5
        IF PlayerY[i]+20 >= BlockY[n] And PlayerY[i] <= BlockY[n]+BlockHeight[n] Then
          If PlayerX[i]+20 > BlockX[n] And PlayerX[i]+20 < BlockX[n]+1 Then
            playerWX[i] = -0.01
          ElseIf PlayerX[i] < BlockX[n]+BlockWidth[n] And PlayerX[i] > BlockX[n]-1 Then
            playerWX[i] = 0.01
          EndIf
        EndIf
      EndFor
     
      'VERTICAL VELOCITY
     
      'Player falling assumed initially
      PlayerTG[i] = 0 'Not on any box unless we set it below
      For n = 1 To 5
        IF PlayerX[i]+20 >= BlockX[n] and PlayerX[i] <= BlockX[n]+BlockWidth[n] Then
          'Player on top of box
          If PlayerY[i]+21 > BlockY[n] and PlayerY[i] < BlockY[n]+1 Then
            If Shift[i] = 1 Then
              playerWY[i] = -1 'Jump
            Else
              playerWY[i] = 0
            EndIf
            PlayerTG[i] = n 'Box player is on
            n = 5 'No need to check further since we can only be on one box
          EndIf
        EndIf
      EndFor

    EndSub


    BTW, using the Shift key to fire causes Sticky Keys to be activated on Vista - perhaps use a different key to fire (perhaps Up to jump and Control to fire).

    • Edited by litdev Saturday, September 12, 2009 12:46 PM comment on Shift key added
    Saturday, September 12, 2009 10:55 AM
  • Yes, this is a reasonable way to end a loop that you know is unnecessary.

    A slight variant below that for me is easier to follow - if this show the issue you mentioned, then it is probably due to the tolerances you are using.  For example the fall velocity may be too large to find the player intersecting the top of a box.

    Using 2 loops shouldn't be a big overhead, since each only holds roughly half the code, and it keeps the horizontal and vertical velocities independent, which is good because they are influenced by different effects.  The comments and separating the code into separate ideas where possible are more than just style - it helps to understand and maintain the code.

    Sub Collision
     
      'HORIZONTAL VELOCITY
     
      'Player hits side of box while falling or on top of another box
      For n = 1 To 5
        IF PlayerY[i]+20 >= BlockY[n] And PlayerY[i] <= BlockY[n]+BlockHeight[n] Then
          If PlayerX[i]+20 > BlockX[n] And PlayerX[i]+20 < BlockX[n]+1 Then
            playerWX[i] = -0.01
          ElseIf PlayerX[i] < BlockX[n]+BlockWidth[n] And PlayerX[i] > BlockX[n]-1 Then
            playerWX[i] = 0.01
          EndIf
        EndIf
      EndFor
     
      'VERTICAL VELOCITY
     
      'Player falling assumed initially
      PlayerTG[i] = 0 'Not on any box unless we set it below
      For n = 1 To 5
        IF PlayerX[i]+20 >= BlockX[n] and PlayerX[i] <= BlockX[n]+BlockWidth[n] Then
          'Player on top of box
          If PlayerY[i]+21 > BlockY[n] and PlayerY[i] < BlockY[n]+1 Then
            If Shift[i] = 1 Then
              playerWY[i] = -1 'Jump
            Else
              playerWY[i] = 0
            EndIf
            PlayerTG[i] = n 'Box player is on
            n = 5 'No need to check further since we can only be on one box
          EndIf
        EndIf
      EndFor

    EndSub


    BTW, using the Shift key to fire causes Sticky Keys to be activated on Vista - perhaps use a different key to fire (perhaps Up to jump and Control to fire).

    That’s some interesting points you have raised. I wonder if its going to stick. Anyways I learn something new all the same. Thanks!

     

     

    steve barbarich , choosehottubsdirect.com


    Monday, February 14, 2011 6:15 AM