CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2012
    Posts
    3

    Post Rotated parallelogram collision detection "RPG"

    Hello I am in grade 12 programming("ICS4U") and I have decided to create a game in Java for my end term project/exam. I have collected an image off the Internet because I like its perspective. I will be making my own using it as a template. Although I am not very skilled with math and my efforts are outweighed.
    Anyways after days of trial and error, I cannot get my collision detection working just right.
    I have decided that id post my problem to a forum and hope for the best. :| attached is my entire project RamL.Java is the primary file. Thanks in advance!! I will do my best to return the favor to the forum.
    Attached Files Attached Files

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: Rotated parallelogram collision detection "RPG"

    You are unlikely to get an answer unless you post the relevant code in code tags and explain what the problem is. Just saying it isn't working is not good enough, you need to give an explanation of what is happening and what should happen.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Jan 2012
    Posts
    3

    Exclamation Re: Rotated parallelogram collision detection "RPG"

    Alright, my primary problem is my collision detection is slightly off and locks the sprite in the corner to the far right. My background is attached to this comment.
    <\code> public void updateHero() {

    temp = heroCharacter.getCenterX();
    tempY = heroCharacter.getCenterY();




    nonWalk = true;
    if(temp >= 0 & temp <= 580){
    upperY = 480 - (0.55 * temp);
    upperLeft = true;
    }

    if(temp >= 581 & temp <= 1020){
    upperY = 380 - (0.50 * (1020 - temp));
    upperRight = true;
    }

    if(temp >= 0 & temp <= 445){
    lowerY = 445 + (0.55 * temp); ///thisone
    lowerLeft = true;
    }

    if (temp >= 445 & temp <= 10120){
    lowerY = 370 + (0.55 * (1020 - temp));
    lowerRight = true;
    }
    if(tempY < upperY){
    nonWalk = false;
    if (upperLeft = true){
    heroCharacter.setX(heroCharacter.getX() + 1);
    }
    if (upperRight = true){
    heroCharacter.setX(heroCharacter.getX() - 1);
    }
    heroCharacter.setY(heroCharacter.getY() + 1);
    heroCharacter.setVelY(0);
    heroCharacter.setVelX(0);
    }
    if(tempY > lowerY){
    nonWalk = false;

    if (lowerLeft = true){
    heroCharacter.setX(heroCharacter.getX()+ 1);
    }
    if (lowerRight = true){
    heroCharacter.setX(heroCharacter.getX()- 1);
    }

    heroCharacter.setY(heroCharacter.getY() - 1);
    heroCharacter.setVelY(0);
    heroCharacter.setVelX(0);
    }

    }


    if(nonWalk == true){

    heroCharacter.incX(heroCharacter.getVelX());
    heroCharacter.incY(heroCharacter.getVelY());
    }
    }

    <\code>
    Attached Images Attached Images  

  4. #4
    Join Date
    Jan 2012
    Posts
    3

    Re: Rotated parallelogram collision detection "RPG"

    sorry never used forums much here is vb6 code i used to try to solve this problem
    Code:
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    'calculate the top y
    Dim topY As Single
    Dim lowerY As Single
    'case for the top y
    Select Case X
        Case 0 To 580
        topY = 480 - (335 / 580) * X
        Case 581 To 1020
        topY = 400 - (235 / 435) * (1020 - X)
        Case Else
            Exit Sub
    End Select
    'case for the lower Y
    Select Case X
        Case 0 To 435
        lowerY = 480 + 235 / 435 * X
        Case 436 To 1020
        lowerY = 400 + 235 / 585 * (1020 - X)
        Case Else
        Exit Sub
    End Select
    
    Label1.Caption = topY
    Label2.Caption = lowerY
    Label3.Caption = X
    Label4.Caption = Y
    
    Select Case Y
        Case Is < topY: Form1.BackColor = vbRed
        Case Is > lowerY: Form1.BackColor = vbBlue
        Case Else: Form1.BackColor = vbWhite
    End Select
    
    End Sub
    
    Private Sub Form_Resize()
    Line1(0).X1 = 0
    Line1(0).Y1 = 480
    
    Line1(0).X2 = 580
    Line1(0).Y2 = 160
    
    Line1(1).X1 = 580
    Line1(1).Y1 = 160
    
    Line1(1).X2 = 1020
    Line1(1).Y2 = 400
    
    Line1(2).X1 = 1020
    Line1(2).Y1 = 400
    
    Line1(2).X2 = 435
    Line1(2).Y2 = 715
    
    Line1(3).X1 = 435
    Line1(3).Y1 = 715
    
    Line1(3).X2 = 0
    Line1(3).Y2 = 480
    
    
    
    End Sub

  5. #5
    Join Date
    Jan 2012
    Posts
    3

    Re: Rotated parallelogram collision detection "RPG"

    I am not completely sure how to create a formula that will detect if your x,y cord is out of bounds on this background, is it distorted ? what shape is the walkable area? I have started looking at tiled base games but I do not understand how it works, or what dimensions would give me a similar look as this image.

Tags for this Thread

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

Featured