Jump to content

  • Log In with Google      Sign In   
  • Create Account


crohnsandme

Member Since 17 Feb 2013
Offline Last Active Feb 24 2013 04:00 PM

Posts I've Made

In Topic: is the size of my tile messing up the collision?

24 February 2013 - 04:20 AM

ok forget all above here is my new problem....

 

i am only dealing with single tiles on floor level so i know i maybe need stricter if statments once i jump up more levels but i can jump on top of a tile and both the left and right collision work for the sides of tile

 

coding:

 

//topoff
 
                    if (character.playerPosition.Y <= tile.Rectangle.Top &&
                         character.playerPosition.X + (character.rectangle.Width / 2) >= tile.Rectangle.X + (tile.Rectangle.Width/5) &&
                        character.playerPosition.X + (character.rectangle.Width / 2) <= tile.Rectangle.Right+70)
                    {
                        
                            character.playerPosition.Y = tile.Rectangle.Y - 64;
                            character.velocity.Y = 0f;
                            character.hasJumped = false;
                            
                            
                        
                    }
 
                    //leave top of tile
                    else
                        if (character.playerPosition.Y <= tile.Rectangle.Top &&
                         character.playerPosition.X + (character.rectangle.Width / 2) <= tile.Rectangle.X)
                        character.hasJumped = true;
                    else
                            if (character.playerPosition.Y <= tile.Rectangle.Top &&
                             character.playerPosition.X + (character.rectangle.Width / 2) >= tile.Rectangle.Right)
                                character.hasJumped = true;
                    
                    
 
                   
                    
                    
 
                    //touch left
 
                    if (character.playerPosition.X + 64 >= tile.Rectangle.X &&
                        character.rectangle.Y  >= tile.Rectangle.Y &&
                        character.rectangle.Left <= tile.Rectangle.Left)
                    {
                        character.playerPosition.X = tile.Rectangle.Left - 64;
                    }
 
                    //touch right
 
                    if (character.playerPosition.X  >= tile.Rectangle.Left  &&
                        character.playerPosition.X <= tile.Rectangle.Right+80&&
                        character.rectangle.Y >= tile.Rectangle.Y 
                        )
                    {
                        character.playerPosition.X = tile.Rectangle.Right+80;
                    }
 
 
but now when my character is on top of the tile it wont jump, i think i does attempt to jump but because of the on top if statement it always throws it back to the same position?
 
i tried saying if character.rectangle.bottom == tile.rectangle.top but i noticed when debugging that they never are the same? which i think maybe my problem?

In Topic: is the size of my tile messing up the collision?

23 February 2013 - 01:49 PM

does anyone have any tutorials on collision with tiles?  my player touching left of a tile works fine here is that code

 

 

if (character.playerPosition.X + 64 >= tile.Rectangle.X &&
                        character.rectangle.Y  >= tile.Rectangle.Y &&
                        character.rectangle.Left <= tile.Rectangle.Left)
                    {
                        character.playerPosition.X = tile.Rectangle.Left - 64;
                    }
 
and when i switch a few things round to do the right of the tiles it shoots me to the very right of all my tiles
 
if (character.playerPosition.X  <= tile.Rectangle.X + tile.Rectangle.Width  &&
                        character.rectangle.Y >= tile.Rectangle.Y &&
                        character.rectangle.Left <= tile.Rectangle.Left)
                    {
                        character.playerPosition.X = tile.Rectangle.X + tile.Rectangle.Width;
                    }
 
any chance anyone can help me work this out?im happy with the on top and underneath but the right is causing me problems

In Topic: is the size of my tile messing up the collision?

23 February 2013 - 12:33 PM

ok i admit that sounds confusing but could be because i been staring at the computer for last few hours , i think i can see where my problem is.... i am using an 2d array to create my map not a file(maybe my first mistake?)

 

here is an example of the map i using atm to test collision

 

                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0},
                {0,0,0,0,0,0,0,0,0,0,0,2,2,1,2,2,2,2,2,2}, 
                {0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,2,2,2},
                {0,0,0,0,1,0,0,0,1,0,0,2,2,2,2,2,2,2,2,2},
               
            }, 90);
 
now in the tutorial i used they used 64 as that final value for the size of width and height but then my camera has the map zoomed out far but when i changed it to 90 it made the tiles closer to the screen, but thew now when it comes to the collision the values are all weird, so my tiles width and height is 90x90 but my character is 128x128... i  need to try work out the if statements for the collision.... so frustrating , guess this is the problem following an tutorial and then changing things it forces you to learn and understand each line of code to find the problems guess thats supposed to be part of the fun lol

In Topic: is the size of my tile messing up the collision?

23 February 2013 - 10:29 AM

yes, basically when i have the collision for top,bottom,left and right i jump onto a tile and i end up half way up screen lol i tried using fixed numbers to work out whats happening but i must be missing something , also when it shoots half way up screen it will slowly fall down very slowly, i will relook over the coding and if im struggling by tonight i will post what i have got up and see whats wrong :)

 

thanks


In Topic: best beginner book Dirextx game programming?

23 February 2013 - 07:56 AM

ok well seeing as we will be using this at university im guessing ill go get lunas book and then i can read the other also for the things that are missed out of lunas book?

 

thanks guys/girls


PARTNERS