|
notajf
Guest
|
 |
« Reply #105 on: September 01, 2011, 02:06:39 am » |
|
gitref.org
|
|
|
|
|
Logged
|
|
|
|
|
Orpheon
|
 |
« Reply #106 on: September 01, 2011, 06:33:08 am » |
|
Oh, we're literally porting the whole game graphics and all. Interesting.
Also, anyone want to teach me how to GIT? lol
http://book.git-scm.com/Also, who suggested changing graphics? Because I hadn't planned doing that. And I still need help for the collision problem.
|
|
|
|
|
Logged
|
Your mind is software. Program it. Your body is a shell. Change it. Death is a disease. Cure it. Extinction is approaching. Fight it.
|
|
|
Liam
Newbie
Offline
Posts: 16
|
 |
« Reply #107 on: September 01, 2011, 07:17:19 am » |
|
I've been looking at collision.py and I'm wondering what the logic behind lengthdir() def lengthdir(x, y):
x = x**2 y = y**2
return math.sqrt(x+y)
acting on the hspeed and vspeed at line 40. And in the next few lines at 49-51 # hs and vs is the normalized vector of hspeed and vspeed. hs = character.hspeed/length vs = character.vspeed/length
What is a normalized vector? I see...Then shouldn't you take the absolute value of the length there? Like # hs and vs is the normalized vector of hspeed and vspeed. hs = character.hspeed/abs(length) vs = character.vspeed/abs(length)
That seems to make the sprite less sticky and I get a bounceback effect off of walls. But when landing on a surface you'll fall through slowly after a bit
|
|
|
|
|
Logged
|
|
|
|
|
Orpheon
|
 |
« Reply #108 on: September 01, 2011, 07:25:59 am » |
|
I've been looking at collision.py and I'm wondering what the logic behind lengthdir() def lengthdir(x, y):
x = x**2 y = y**2
return math.sqrt(x+y)
acting on the hspeed and vspeed at line 40. And in the next few lines at 49-51 # hs and vs is the normalized vector of hspeed and vspeed. hs = character.hspeed/length vs = character.vspeed/length
What is a normalized vector? I see...Then shouldn't you take the absolute value of the length there? Like # hs and vs is the normalized vector of hspeed and vspeed. hs = character.hspeed/abs(length) vs = character.vspeed/abs(length)
That seems to make the sprite less sticky and I get a bounceback effect off of walls. But when landing on a surface you'll fall through slowly after a bit Well... After staring at the code for a while, I found out that objectCheckCollision is based off rects, which aren't updated during the testing.  def characterHitObstacle(character, wallmask):
newX = character.x newY = character.y
oldX = character.x-character.hspeed oldY = character.y-character.vspeed
hspeed = character.hspeed vspeed = character.vspeed
length = lengthdir(hspeed, vspeed)
if length == 0:# You haven't moved; if this happens something went wrong
return False
# hs and vs is the normalized vector of hspeed and vspeed. hs = character.hspeed/length vs = character.vspeed/length
i = 0 while objectCheckCollision(character, wallmask) and i < length:
character.rect.centerx -= hs character.rect.centery -= vs i += 1
# The character got pushed out, but now we need to let him move in the directions he's allowed to move.
character.rect.centerx += sign(character.hspeed)
if not objectCheckCollision(character, wallmask):
# There's empty space on the left/right
# Kill all vertical movement character.vspeed = 0
while True:
character.rect.centerx += sign(character.hspeed)
# If the new position has met a wall too: if objectCheckCollision(character, wallmask): character.rect.centerx -= sign(character.hspeed) break
else: character.rect.centerx -= sign(character.hspeed) character.rect.centery += sign(character.vspeed)
if not objectCheckCollision(character, wallmask):
# There's empty space on the left/right
# Kill all vertical movement character.hspeed = 0
i = 0 while i <= vspeed:
character.rect.centery += sign(character.vspeed)
# If the new position has met a wall too: if objectCheckCollision(character, wallmask): character.rect.centery -= sign(character.vspeed) break
character.rect.centery -= sign(character.vspeed)
character.x = character.rect.left-character.xImageOffset character.y = character.rect.top-character.yImageOffset # character.hspeed = 0 # character.vspeed = 0
# character.hspeed = oldX-character.x # character.vspeed = oldY-character.y
return True This is still buggy. EDIT: Actually, damn that code, I'll just make objectCheckCollision update the rects itself.As for those vectors, it's basically just moving the character exactly one step in a certain direction. Length 1. I'm using the term unit vectors since they work on the same principle. The point of that loop is to move the character at the last place during movement before any collision.
|
|
|
|
« Last Edit: September 01, 2011, 07:35:55 am by Orpheon »
|
Logged
|
Your mind is software. Program it. Your body is a shell. Change it. Death is a disease. Cure it. Extinction is approaching. Fight it.
|
|
|
|
MedO
|
 |
« Reply #109 on: September 01, 2011, 10:35:02 am » |
|
Short question, why are you turning collision masks into many many rectangles instead of using pygame.sprite.collide_mask?
|
|
|
|
|
Logged
|
It is the business of the future to be dangerous; and it is among the merits of science that it equips the future for its duties. [...] if you have a large enough codebase, any class of error that is syntactically legal probably exists there.
|
|
|
|
Psychopath
|
 |
« Reply #110 on: September 01, 2011, 10:40:07 am » |
|
Short question, why are you turning collision masks into many many rectangles instead of using pygame.sprite.collide_mask?
This is the part where they realize that there was an easy way already in existence and a few people hit themselves on the forehead for not noticing it sooner
|
|
|
|
|
Logged
|
(8:01:46 PM) Psychopath: I'm just wondering what the next hot thing to fall on my lap will be (8:01:57 PM) Lynn1: a girl maybe? (8:02:01 PM) Psychopath: 
|
|
|
|
notajf
Guest
|
 |
« Reply #111 on: September 01, 2011, 10:53:58 am » |
|
Short question, why are you turning collision masks into many many rectangles instead of using pygame.sprite.collide_mask?
This is the part where they realize that there was an easy way already in existence and a few people hit themselves on the forehead for not noticing it sooner Yep, like when I discovered Python actually had a TCP Server wrapper and there was no reason to use sockets directly.
|
|
|
|
|
Logged
|
|
|
|
|
Orpheon
|
 |
« Reply #112 on: September 01, 2011, 12:50:00 pm » |
|
Short question, why are you turning collision masks into many many rectangles instead of using pygame.sprite.collide_mask?
Originally, I planned to do that. I went to inform myself and asked around how to collide masks with other stuff. People were telling me using rects for this would be a ton more efficient (if you only check those rects near to you), because if the wallmask was a mask, then everything who should collide with it should be one too. I kinda trusted them, and also I know my way around rects much better than with masks. Also, that part is done, as in finished in a very small time. I'm having troubles with the collision response, not with the detection (which is easy and actually quite efficient).
|
|
|
|
|
Logged
|
Your mind is software. Program it. Your body is a shell. Change it. Death is a disease. Cure it. Extinction is approaching. Fight it.
|
|
|
|
Psychopath
|
 |
« Reply #113 on: September 01, 2011, 12:51:43 pm » |
|
Short question, why are you turning collision masks into many many rectangles instead of using pygame.sprite.collide_mask?
Originally, I planned to do that. I went to inform myself and asked around how to collide masks with other stuff. People were telling me using rects for this would be a ton more efficient (if you only check those rects near to you), because if the wallmask was a mask, then everything who should collide with it should be one too. I kinda trusted them, and also I know my way around rects much better than with masks. Also, that part is done, as in finished in a very small time. I'm having troubles with the collision response, not with the detection (which is easy and actually quite efficient). But a rect is just a mask with a rectangular shape 
|
|
|
|
|
Logged
|
(8:01:46 PM) Psychopath: I'm just wondering what the next hot thing to fall on my lap will be (8:01:57 PM) Lynn1: a girl maybe? (8:02:01 PM) Psychopath: 
|
|
|
|
notajf
Guest
|
 |
« Reply #114 on: September 01, 2011, 12:56:39 pm » |
|
Short question, why are you turning collision masks into many many rectangles instead of using pygame.sprite.collide_mask?
Originally, I planned to do that. I went to inform myself and asked around how to collide masks with other stuff. People were telling me using rects for this would be a ton more efficient (if you only check those rects near to you), because if the wallmask was a mask, then everything who should collide with it should be one too. I kinda trusted them, and also I know my way around rects much better than with masks. Also, that part is done, as in finished in a very small time. I'm having troubles with the collision response, not with the detection (which is easy and actually quite efficient). But a rect is just a mask with a rectangular shape  Collision checking is quicker with rects
|
|
|
|
|
Logged
|
|
|
|
|
Orpheon
|
 |
« Reply #115 on: September 01, 2011, 12:59:14 pm » |
|
Rect collision checking: if range(left1, right1) in range(left2, right2): { if range(top1, bottom1) in range(top2, bottom2): { return True } } return False Mask collision checking involves checking each pixel individually.
|
|
|
|
|
Logged
|
Your mind is software. Program it. Your body is a shell. Change it. Death is a disease. Cure it. Extinction is approaching. Fight it.
|
|
|
|
Psychopath
|
 |
« Reply #116 on: September 01, 2011, 01:00:57 pm » |
|
Short question, why are you turning collision masks into many many rectangles instead of using pygame.sprite.collide_mask?
Originally, I planned to do that. I went to inform myself and asked around how to collide masks with other stuff. People were telling me using rects for this would be a ton more efficient (if you only check those rects near to you), because if the wallmask was a mask, then everything who should collide with it should be one too. I kinda trusted them, and also I know my way around rects much better than with masks. Also, that part is done, as in finished in a very small time. I'm having troubles with the collision response, not with the detection (which is easy and actually quite efficient). But a rect is just a mask with a rectangular shape  Collision checking is quicker with rects I'm just wondering aloud, wouldn't it be more efficient to do raster-rect collisions instead of rect-rect collisions where there are a shitton of rects to parse through.
|
|
|
|
|
Logged
|
(8:01:46 PM) Psychopath: I'm just wondering what the next hot thing to fall on my lap will be (8:01:57 PM) Lynn1: a girl maybe? (8:02:01 PM) Psychopath: 
|
|
|
|
Orpheon
|
 |
« Reply #117 on: September 01, 2011, 01:04:33 pm » |
|
Short question, why are you turning collision masks into many many rectangles instead of using pygame.sprite.collide_mask?
Originally, I planned to do that. I went to inform myself and asked around how to collide masks with other stuff. People were telling me using rects for this would be a ton more efficient (if you only check those rects near to you), because if the wallmask was a mask, then everything who should collide with it should be one too. I kinda trusted them, and also I know my way around rects much better than with masks. Also, that part is done, as in finished in a very small time. I'm having troubles with the collision response, not with the detection (which is easy and actually quite efficient). But a rect is just a mask with a rectangular shape  Collision checking is quicker with rects I'm just wondering aloud, wouldn't it be more efficient to do raster-rect collisions instead of rect-rect collisions where there are a shitton of rects to parse through. The point is we'd have to do the raster-rect collision-ing ourselves. Which I have very little idea how. Also, most rects don't even get considered, they have to be close enough.
|
|
|
|
|
Logged
|
Your mind is software. Program it. Your body is a shell. Change it. Death is a disease. Cure it. Extinction is approaching. Fight it.
|
|
|
|
Psychopath
|
 |
« Reply #118 on: September 01, 2011, 01:07:29 pm » |
|
Short question, why are you turning collision masks into many many rectangles instead of using pygame.sprite.collide_mask?
Originally, I planned to do that. I went to inform myself and asked around how to collide masks with other stuff. People were telling me using rects for this would be a ton more efficient (if you only check those rects near to you), because if the wallmask was a mask, then everything who should collide with it should be one too. I kinda trusted them, and also I know my way around rects much better than with masks. Also, that part is done, as in finished in a very small time. I'm having troubles with the collision response, not with the detection (which is easy and actually quite efficient). But a rect is just a mask with a rectangular shape  Collision checking is quicker with rects I'm just wondering aloud, wouldn't it be more efficient to do raster-rect collisions instead of rect-rect collisions where there are a shitton of rects to parse through. The point is we'd have to do the raster-rect collision-ing ourselves. Which I have very little idea how. Also, most rects don't even get considered, they have to be close enough. You still have to technically parse through all existing rects just to identify which ones are near enough :v
|
|
|
|
|
Logged
|
(8:01:46 PM) Psychopath: I'm just wondering what the next hot thing to fall on my lap will be (8:01:57 PM) Lynn1: a girl maybe? (8:02:01 PM) Psychopath: 
|
|
|
|
Orpheon
|
 |
« Reply #119 on: September 01, 2011, 01:10:09 pm » |
|
Short question, why are you turning collision masks into many many rectangles instead of using pygame.sprite.collide_mask?
Originally, I planned to do that. I went to inform myself and asked around how to collide masks with other stuff. People were telling me using rects for this would be a ton more efficient (if you only check those rects near to you), because if the wallmask was a mask, then everything who should collide with it should be one too. I kinda trusted them, and also I know my way around rects much better than with masks. Also, that part is done, as in finished in a very small time. I'm having troubles with the collision response, not with the detection (which is easy and actually quite efficient). But a rect is just a mask with a rectangular shape  Collision checking is quicker with rects I'm just wondering aloud, wouldn't it be more efficient to do raster-rect collisions instead of rect-rect collisions where there are a shitton of rects to parse through. The point is we'd have to do the raster-rect collision-ing ourselves. Which I have very little idea how. Also, most rects don't even get considered, they have to be close enough. You still have to technically parse through all existing rects just to identify which ones are near enough :v Of course. But you have to that too with masks, you know. Only you have 6 times more pixels than I have rects, and actually even more because I made the wallmask hollow shells. And it's one if loop to test the x, and if that's correct it's another if loop to test the y.
|
|
|
|
« Last Edit: September 01, 2011, 01:10:55 pm by Orpheon »
|
Logged
|
Your mind is software. Program it. Your body is a shell. Change it. Death is a disease. Cure it. Extinction is approaching. Fight it.
|
|
|
|