Jump to content

collision detection in pygame

- - - - -

  • Please log in to reply
3 replies to this topic

#1
BRUTAL

BRUTAL

    Newbie

  • Members
  • PipPip
  • 22 posts
How can i put collision detection in my pygame i just want for my sprite to be able to jump on a piece of land and it stay there

#2
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
Yes, you can put collision detection in your game that employs PyGame as it's engine, you'll simply need to implement it. What have you got so far with your game?
Wow I changed my sig!

#3
BRUTAL

BRUTAL

    Newbie

  • Members
  • PipPip
  • 22 posts
bif="bg.jpg"
mc="ball.png"

import pygame, sys
from pygame.locals import *

pygame.init()
screen=pygame.display.set_mode((840,525),0,32)

background=pygame.image.load(bif).convert()
mouse_c=pygame.image.load(mc).convert_alpha()

x,y=0,0
movex, movey=0,0

while True:

#for event in pygame.event.get():
#if event.type == QUIT:
##pygame.quit()
##sys.exit()
#if event.type==KEYDOWN:
##if event.key==K_LEFT:
###movex=-1
##elif event.key==K_RIGHT:
###movex=+1
##elif event.key==K_UP:
###movey=-1
##elif event.key==K_DOWN:
###movey=+1
#if event.type==KEYUP:
##if event.key==K_LEFT:
###movex=0
##elif event.key==K_RIGHT:
###movex=0
##elif event.key==K_UP:
###movey=0
##elif event.key==K_DOWN:
###movey=0
#x+=movex
#y+=movey

#screen.blit(background,(0,0))
#screen.blit(mouse_c,(x,y))

#pygame.display.update()

#4
kctan

kctan

    Newbie

  • Members
  • Pip
  • 5 posts
Take a look at the documentation here:
sprite - Pygame Documentation
Look for those functions that deal with 'collide'. Basically, these functions help you to detect collision between sprites. You will still need to code the behavior after collision occurs. For a player jumping onto a platform, you will need to find out the y position of the platform that collides with your player, and 'lock' your player at that height. This will give the impression that the player has landed on the platform.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users