Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Apr 2009
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Why doesnt this work. (Pygame)

    Pgame.py ::
    Code:
    #!/usr/bin/env python
    # Pygame Basics
    _image_game_backround = "background.jpg"
    _image_mouse_pointer = "pointer.png"
    _image_game_paddle = "paddle.jpg"
    _image_game_char = "char.gif"
    ##
    ### Imports
    ##
    import colors
    from player import *
    import pygame
    import sys
    import random
    from math import *
    from pygame.locals import *
    from datetime import datetime
    
    ##
    ### Pygame Essentials
    ##
    pygame.init()
    screen = pygame.display.set_mode((640,480),0,32)
    py_pointer = pygame.image.load(_image_mouse_pointer).convert_alpha()
    py_bg = pygame.image.load(_image_game_backround).convert()
    py_clock = pygame.time.Clock()
    #
    #Variables
    #
    
    #Futer Character
    _player = Player(100)
    #Paddle
    _paddle_pos_x,_paddle_pos_y = 0,0
    _paddle = pygame.image.load(_image_game_paddle).convert()
    _current_pos_x,_current_pos_y = 0,0
    
    #Ball(SQuare)
    _ball_pos_x,_ball_pos_y = 320,240
    _ball_current_x, _ball_current_y = 0,0
    _ball = pygame.image.load(_image_mouse_pointer).convert()
    _ball_decision_x = 0
    _ball_decision_y = 0
    #
    ## Starting Infinite Loop
    #
    
    while True:
        #Basic Setup
        screen.blit(py_bg,(0,0))
        py_clock.tick(100)
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            if event.type == KEYDOWN:
                if event.key == K_LEFT:
                    _current_pos_x -=1
                elif event.key == K_RIGHT:
                    _current_pos_x +=1
                elif event.key == K_UP:
                    _current_pos_y -=1
                elif event.key == K_DOWN:
                    _current_pos_y +=1
            if event.type == KEYUP:
                if event.key == K_LEFT:
                    _current_pos_x = 0    
                elif event.key == K_RIGHT:
                    _current_pos_x = 0
                elif event.key == K_UP:
                    _current_pos_y = 0
                elif event.key == K_DOWN:
                    _current_pos_y = 0
        _paddle_pos_x += _current_pos_x
        _paddle_pos_y += _current_pos_y
        screen.blit(_paddle,(0,_paddle_pos_y))
        
        #ball
        _ball_decision_x = random.randint(1, 12)
        _ball_decision_y = random.randint(1, 12)
        if _ball_decision_x <= 6:
            _ball_pos_x += 1
            if _ball_pos_x < 1:
                _ball_pos_x += 5
        elif _ball_decision_x >= 5:
            _ball_pos_x -= 1
            if _ball_pos_x < 1:
                _ball_pos_x += 5
        if _ball_decision_y <= 5:
            _ball_pos_y += 1
            if _ball_pos_y < 1:
                _ball_pos_y += 5
        elif _ball_decision_y >= 5:
            _ball_pos_y -= 1
            if _ball_pos_y < 1:
                _ball_pos_y += 5
        screen.blit(_ball,(_ball_pos_x,_ball_pos_y))
            #that was a nice loop wasnt it.
        _player.show
        pygame.display.update()
    player.py

    Code:
    #!/usr/bin/env python
    import pygame
    screen = pygame.display.set_mode((640,480),0,32)
    class Player(pygame.sprite.Sprite):
        def __init__(self, _xpos):
    
        #  pygame.sprite.Sprite.__init__(self)
          self.prevpos = (0, 0, 0, 0)
          self.image = pygame.image.load('char.gif').convert_alpha()
          self.rect = self.image.get_rect()
          self.rect.x = _xpos
          self.x,self.y = 0,0
          self.mx,self.my = 200,200
          screen.blit(self.image,(self.mx,self.my))
          pygame.display.update()
        def show():
          screen.blit(self.image,(self.mx,self.my))
    And for good measure colors.py
    Code:
    #!/usr/bin/env python
    grey = (84,84,84)
    skyblue = (185,211,238)
    black = (0,0,0)
    blue = (0,0,255)
    green = (34,139,34)
    yellow = (255,255,0)
    brown = (139,69,19)
    orange = (255,140,0)
    pink = (255,192,203)
    I figured it would show my images and have the char at 200,200 on the screen and he would stay and that would be consistent but he doenst show up and ive been stuck here forever.
    Attached Thumbnails Attached Thumbnails Why doesnt this work. (Pygame)-background.jpg  
    Attached Images Attached Images    


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •