A little stuck and could do with any sudjestions.

Aim:-
When the character goes past the middle of the screen, the background & level 
move downwards so the character can get to higher places, think sonic the 
hedgehog.

This is the bit I'm having problems with, I can get the character to get to the 
center, the background moves up & down but the character won't go back down 
when the level returns to normal height.

    if bkGroundRect['rect'].top < 0 and charRect['rect'].top < 
winCenterRect.top:
        
        bkGroundRect['rect'].top += spY
        platRect['rect'].top += spY
        jumpRect.top += spY
        charRect['dir'] = STOP

            
    if levelRect['rect'].bottom > winHeight and charRect['rect'].centery == 
winCenterx:
            bkGroundRect['rect'].bottom -= spY
            platRect['rect'].bottom -= spY
#            jumpRect.bottom -= spY
            charRect['dir'] = STOP

  #--this won't execute ? --#       
    if levelRect['rect'].bottom <= winHeight:
        if charRect['rect'].centery >= winCenterx and charRect['rect'].centerx 
< jumpRect.centerx:
            charRect['dir'] = DOWN

I've included the whole code as a note pad so the above makes more sense, don't 
worry about all the comments, that's just for my convenience.

Thanks guys

Mark

'knight meets wall, wall won't let knight pass, knight says 'neh'

import pygame, sys, time
from pygame.locals import *

pygame.init()
#--Display--#
winWidth = 400
winHeight = 400
winCenterx = int(winWidth / 2)
winCentery = int(winHeight / 2)
window = pygame.display.set_mode((winWidth, winHeight), 0, 32)
#--Display--#

#--Images--#
BackgroundImage = pygame.image.load('Background.jpg')
FloorImage = pygame.image.load('Floor.jpg')
BallImage = pygame.image.load('Ball.jpg')
#--Images--#

#--Movement Variables--#
forward = False
backward = False
jump = False
UP = 8
DOWN = 2
STOP = 5

spX = 3
spY = 5
#--Movement Variables--#

#--Level Rects--#
bkGroundScImage = pygame.transform.scale(BackgroundImage, (1000, 1000))
bkGroundRect = {'rect':pygame.Rect(0, -650, 1000, 1000), 'dir':UP}

levelScImage = pygame.transform.scale(FloorImage, (1000, 50))
levelRect = {'rect':pygame.Rect(0, winHeight - 50, 1000, 50), 'dir':DOWN}

platScImage = pygame.transform.scale(FloorImage, (100, 25))
platRect = {'rect':pygame.Rect(75, 270, 100, 25), 'dir':DOWN}

platScImage1 = pygame.transform.scale(FloorImage, (100, 25))
platRect1 = {'rect':pygame.Rect(225, 250, 100, 25), 'dir':UP}

platScImage2 = pygame.transform.scale(FloorImage, (100, 25))
platRect2 = {'rect':pygame.Rect(375, 200, 100, 25), 'dir':UP}

platScImage3 = pygame.transform.scale(FloorImage, (100, 25))
platRect3 = {'rect':pygame.Rect(575, 150, 100, 25), 'dir':UP}

platScImage4 = pygame.transform.scale(FloorImage, (100, 25))
platRect4 = {'rect':pygame.Rect(675, 150, 100, 25), 'dir':UP}

platScImage5 = pygame.transform.scale(FloorImage, (100, 25))
platRect5 = {'rect':pygame.Rect(575, 0, 100, 25), 'dir':UP}

platScImage6 = pygame.transform.scale(FloorImage, (100, 25))
platRect6 = {'rect':pygame.Rect(375, 0, 100, 25), 'dir':UP}
#--Level Rects--#
#--Caracter Rects--#
charScImage = pygame.transform.scale(BallImage, (50, 50))
charRect = {'rect':pygame.Rect(20, 300, 50, 50), 'dir':DOWN}

jumpScImage = pygame.transform.scale(FloorImage, (50, 140))
jumpRect = pygame.Rect(20, 210, 50, 140)

winCenterRectScImage = pygame.transform.scale(FloorImage, (60, 60))
winCenterRect = pygame.Rect(winCenterx  - 30, winCentery - 30, 60, 60)
#--Caracter Rects--#
#--Collision Variables--#

solidX = int(charRect['rect'].width - spX - spX - 2)
solidY = int(charRect['rect'].height - spY - spY- 1)
#--Collision Variables--#
while True:
#--Level & scenery--#
    window.blit(bkGroundScImage, bkGroundRect['rect'])
    window.blit(levelScImage, levelRect['rect'])
    window.blit(platScImage, platRect['rect'])
    window.blit(platScImage1, platRect1['rect'])
    window.blit(platScImage2, platRect2['rect'])
    window.blit(platScImage3, platRect3['rect'])
    window.blit(platScImage4, platRect4['rect'])
    window.blit(platScImage5, platRect5['rect'])
    window.blit(platScImage6, platRect6['rect'])
    levelRect['rect'].top = bkGroundRect['rect'].bottom
    
#--Level & scenery--#

#--Character--#
    window.blit(winCenterRectScImage, winCenterRect)
    winCenterRect.center = (winCenterx, winCentery)

    window.blit(jumpScImage, jumpRect)
    jumpRect.centerx = charRect['rect'].centerx
    
    window.blit(charScImage, charRect['rect'])
#--Character--#

#--Input controls--#
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()

        if event.type == KEYDOWN:
            if event.key == K_RIGHT:
                forward = True
                backward = False
            if event.key == K_LEFT:
                backward = True
                forward = False
            if event.key == K_UP:
                jump = True

        if event.type == KEYUP:
            if event.key == K_RIGHT:
                forward = False
            if event.key == K_LEFT:
                backward = False
            if event.key == K_UP:
                jump = False
#--Input controls--#

#--Movement--#
    if charRect['dir'] == UP:
        charRect['rect'].top -= spY
    if charRect['dir'] == DOWN:
        charRect['rect'].bottom += spY
        
#--Movement--#

#--Level movement--#
    if charRect['rect'].centerx >= winCenterx:
        if forward and levelRect['rect'].right > winWidth:
            
            levelRect['rect'].right -= spX
            platRect['rect'].right -= spX
            platRect1['rect'].right -= spX
            platRect2['rect'].right -= spX
            platRect3['rect'].right -= spX
            platRect4['rect'].right -= spX
            platRect5['rect'].right -= spX
            platRect6['rect'].right -= spX
            
    if charRect['rect'].centerx <= winCenterx:
        if backward and levelRect['rect'].left < 0:
            
            levelRect['rect'].left += spX
            platRect['rect'].left += spX
            platRect1['rect'].left += spX
            platRect2['rect'].right += spX
            platRect3['rect'].right += spX
            platRect4['rect'].right += spX
            platRect5['rect'].right += spX
            platRect6['rect'].right += spX
          
#--Level movement--#
    if bkGroundRect['rect'].top < 0 and charRect['rect'].top < 
winCenterRect.top:
        
        bkGroundRect['rect'].top += spY
        platRect['rect'].top += spY
        jumpRect.top += spY
        charRect['dir'] = STOP

            
    if levelRect['rect'].bottom > winHeight and charRect['rect'].centery == 
winCenterx:
            bkGroundRect['rect'].bottom -= spY
            platRect['rect'].bottom -= spY
#            jumpRect.bottom -= spY
            charRect['dir'] = STOP

            
    if levelRect['rect'].bottom <= winHeight:
        if charRect['rect'].centery >= winCenterx and charRect['rect'].centerx 
< jumpRect.centerx:
            charRect['dir'] = DOWN

#--Character movement--#
    if levelRect['rect'].left == 0:  
        if forward and charRect['rect'].centerx < winCenterx:
            charRect['rect'].centerx += spX
        if backward and charRect['rect'].left > 0:
            charRect['rect'].left -= spX

    if levelRect['rect'].right == winWidth:
        if forward and charRect['rect'].right < winWidth:
            charRect['rect'].right += spX
        if backward and charRect['rect'].centerx > winCenterx:
            charRect['rect'].centerx -= spX

    if levelRect['rect'].left < 0:
        if forward and charRect['rect'].right < winCenterRect.right:
            charRect['rect'].centerx += spX
    if levelRect['rect'].right > winWidth:
        if backward and charRect['rect'].left > winCenterRect.left:
            charRect['rect'].left -= spX
      
        
    if charRect['rect'].top <= jumpRect.top:
            charRect['dir'] = DOWN

#--Character movement--#

#--Collision detection--#
#--Level--#
    if charRect['rect'].colliderect(levelRect['rect']):
        if charRect['rect'].bottom > levelRect['rect'].top and 
charRect['rect'].top < levelRect['rect'].top - solidY:
            charRect['rect'].bottom = levelRect['rect'].top
            jumpRect.bottom = levelRect['rect'].top

        if charRect['rect'].left < levelRect['rect'].right and 
charRect['rect'].right > levelRect['rect'].right + solidX:
            charRect['rect'].left = levelRect['rect'].right
            
        if charRect['rect'].right > levelRect['rect'].left and 
charRect['rect'].left < levelRect['rect'].left  - solidX:
            charRect['rect'].right = levelRect['rect'].left

        if charRect['rect'].top < levelRect['rect'].bottom and 
charRect['rect'].bottom > levelRect['rect'].bottom + solidY:
            charRect['rect'].top = levelRect['rect'].bottom

        if charRect['rect'].bottom >= levelRect['rect'].top:
            if jump == True:
                charRect['dir'] = UP
#--Level--#

#--Platform--#
    if charRect['rect'].colliderect(platRect['rect']):
        if charRect['rect'].bottom > platRect['rect'].top and 
charRect['rect'].top < platRect['rect'].top - solidY:
            charRect['rect'].bottom = platRect['rect'].top
            jumpRect.bottom = platRect['rect'].top

        if charRect['rect'].left < platRect['rect'].right and 
charRect['rect'].right > platRect['rect'].right + solidX:
            charRect['rect'].left = platRect['rect'].right
            
        if charRect['rect'].right > platRect['rect'].left and 
charRect['rect'].left < platRect['rect'].left  - solidX:
            charRect['rect'].right = platRect['rect'].left

        if charRect['rect'].top < platRect['rect'].bottom and 
charRect['rect'].bottom > platRect['rect'].bottom + solidY:
            charRect['rect'].top = platRect['rect'].bottom
        
        if charRect['rect'].bottom == platRect['rect'].top:    
            if jump == True:
                charRect['dir'] = UP

        if charRect['rect'].top == platRect['rect'].bottom:
            charRect['dir'] = DOWN
#--Platform--#
            
#--Platform1--#
    if charRect['rect'].colliderect(platRect1['rect']):
        if charRect['rect'].bottom > platRect1['rect'].top and 
charRect['rect'].top < platRect1['rect'].top - solidY:
            charRect['rect'].bottom = platRect1['rect'].top
            jumpRect.bottom = platRect1['rect'].top

        if charRect['rect'].left < platRect1['rect'].right and 
charRect['rect'].right > platRect1['rect'].right + solidX:
            charRect['rect'].left = platRect1['rect'].right
            
        if charRect['rect'].right > platRect1['rect'].left and 
charRect['rect'].left < platRect1['rect'].left  - solidX:
            charRect['rect'].right = platRect1['rect'].left

        if charRect['rect'].top < platRect1['rect'].bottom and 
charRect['rect'].bottom > platRect1['rect'].bottom + solidY:
            charRect['rect'].top = platRect1['rect'].bottom

        if charRect['rect'].bottom == platRect1['rect'].top:
            if jump == True:
                charRect['dir'] = UP

        if charRect['rect'].top == platRect1['rect'].bottom:
            charRect['dir'] = DOWN
#--Platform1--#

#--Platform2--#
    if charRect['rect'].colliderect(platRect2['rect']):
        if charRect['rect'].bottom > platRect2['rect'].top and 
charRect['rect'].top < platRect2['rect'].top - solidY:
            charRect['rect'].bottom = platRect2['rect'].top
            jumpRect.bottom = platRect2['rect'].top

        if charRect['rect'].left < platRect2['rect'].right and 
charRect['rect'].right > platRect2['rect'].right + solidX:
            charRect['rect'].left = platRect2['rect'].right
            
        if charRect['rect'].right > platRect2['rect'].left and 
charRect['rect'].left < platRect2['rect'].left  - solidX:
            charRect['rect'].right = platRect2['rect'].left

        if charRect['rect'].top < platRect2['rect'].bottom and 
charRect['rect'].bottom > platRect2['rect'].bottom + solidY:
            charRect['rect'].top = platRect2['rect'].bottom

        if charRect['rect'].bottom == platRect2['rect'].top:
            if jump == True:
                charRect['dir'] = UP

        if charRect['rect'].top == platRect2['rect'].bottom:
            charRect['dir'] = DOWN
#--Platform2--#

#--Platform3--#
    if charRect['rect'].colliderect(platRect3['rect']):
        if charRect['rect'].bottom > platRect3['rect'].top and 
charRect['rect'].top < platRect3['rect'].top - solidY:
            charRect['rect'].bottom = platRect3['rect'].top
            jumpRect.bottom = platRect3['rect'].top

        if charRect['rect'].left < platRect3['rect'].right and 
charRect['rect'].right > platRect3['rect'].right + solidX:
            charRect['rect'].left = platRect3['rect'].right
            
        if charRect['rect'].right > platRect3['rect'].left and 
charRect['rect'].left < platRect3['rect'].left  - solidX:
            charRect['rect'].right = platRect3['rect'].left

        if charRect['rect'].top < platRect3['rect'].bottom and 
charRect['rect'].bottom > platRect3['rect'].bottom + solidY:
            charRect['rect'].top = platRect3['rect'].bottom
        
        if charRect['rect'].bottom == platRect3['rect'].top:    
            if jump == True:
                charRect['dir'] = UP

        if charRect['rect'].top == platRect3['rect'].bottom:
            charRect['dir'] = DOWN
#--Platform3--#

#--Platform4--#
    if charRect['rect'].colliderect(platRect4['rect']):
        if charRect['rect'].bottom > platRect4['rect'].top and 
charRect['rect'].top < platRect4['rect'].top - solidY:
            
            charRect['rect'].bottom = platRect4['rect'].top
            jumpRect.bottom = platRect4['rect'].top

        if charRect['rect'].left < platRect4['rect'].right and 
charRect['rect'].right > platRect4['rect'].right + solidX:
            
            charRect['rect'].left = platRect4['rect'].right
            
        if charRect['rect'].right > platRect4['rect'].left and 
charRect['rect'].left < platRect4['rect'].left  - solidX:
            
            charRect['rect'].right = platRect4['rect'].left

        if charRect['rect'].bottom < platRect4['rect'].bottom :
            charRect['rect'].bottom = platRect4['rect'].top

        if charRect['rect'].bottom >= platRect4['rect'].top:
            if jump == True:
                charRect['dir'] = UP
#--Platform4--#

#--Platform5--#
    if charRect['rect'].colliderect(platRect5['rect']):
        if charRect['rect'].bottom > platRect5['rect'].top and 
charRect['rect'].top < platRect5['rect'].top - solidY:
            charRect['rect'].bottom = platRect5['rect'].top
            jumpRect.bottom = platRect5['rect'].top

        if charRect['rect'].left < platRect5['rect'].right and 
charRect['rect'].right > platRect5['rect'].right + solidX:
            charRect['rect'].left = platRect5['rect'].right
            
        if charRect['rect'].right > platRect5['rect'].left and 
charRect['rect'].left < platRect5['rect'].left  - solidX:
            charRect['rect'].right = platRect5['rect'].left

        if charRect['rect'].top < platRect5['rect'].bottom and 
charRect['rect'].bottom > platRect5['rect'].bottom + solidY:
            charRect['rect'].top = platRect5['rect'].bottom

        if charRect['rect'].bottom >= platRect5['rect'].top:
            if jump == True:
                charRect['dir'] = UP

        if charRect['rect'].top == platRect5['rect'].bottom:
            charRect['dir'] = DOWN
#--Platform5--#

#--Platform6--#
    if charRect['rect'].colliderect(platRect6['rect']):
        if charRect['rect'].bottom > platRect6['rect'].top and 
charRect['rect'].top < platRect6['rect'].top - solidY:
            charRect['rect'].bottom = platRect6['rect'].top
            jumpRect.bottom = platRect6['rect'].top

        if charRect['rect'].left < platRect6['rect'].right and 
charRect['rect'].right > platRect6['rect'].right + solidX:
            charRect['rect'].left = platRect6['rect'].right
            
        if charRect['rect'].right > platRect6['rect'].left and 
charRect['rect'].left < platRect6['rect'].left  - solidX:
            charRect['rect'].right = platRect6['rect'].left

        if charRect['rect'].top < platRect6['rect'].bottom and 
charRect['rect'].bottom > platRect6['rect'].bottom + solidY:
            charRect['rect'].top = platRect6['rect'].bottom

        if charRect['rect'].bottom >= platRect6['rect'].top:
            if jump == True:
                charRect['dir'] = UP

        if charRect['rect'].top == platRect6['rect'].bottom:
            charRect['dir'] = DOWN
#--Platform6--#
#--Collision detection--#

#--platRect4 movement--#
    if platRect4['dir'] == UP:
        platRect4['rect'].top -= 1
    if platRect4['dir'] == DOWN:
        platRect4['rect'].bottom += 1

    if platRect4['rect'].top >= levelRect['rect'].top:
        if platRect4['dir'] == DOWN:
            platRect4['dir'] = UP
    if platRect4['rect'].top <= bkGroundRect['rect'].top + 200:
        if platRect4['dir'] == UP:
            platRect4['dir'] = DOWN
#--PlatRect4 movement--#


    pygame.display.update()
    time.sleep(0.6)












_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to