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
3 replies to this topic
#1
Posted 22 January 2011 - 07:44 PM
|
|
|
#2
Posted 22 January 2011 - 07:48 PM
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
Posted 22 January 2011 - 07:54 PM
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()
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
Posted 05 February 2011 - 11:26 PM
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.
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


Sign In
Create Account


Back to top









