[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] circular movement in pygame
- To: pygame-users@xxxxxxxx
- Subject: [pygame] circular movement in pygame
- From: diliup gabadamudalige <diliupg@xxxxxxxxx>
- Date: Tue, 28 Apr 2015 18:22:28 +0530
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Tue, 28 Apr 2015 08:52:33 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=hVwhiq8hoii4xPEb8rHxqBqHbAxFdO0Xs2uwoatA0d4=; b=nX7SyvFwb+d95awWCFkSddbPNykmVP5ku+oQ0pcCV2o5RFORbq+KUlqWzQt8Tz05yO Bm+/A79UwwKKhyY2QsiVqzoI7TySIOUiSB6JQte5Hoikd6/N3reJopXKDhjowo7nMK1L J86XogaXI1NZ5tRX/LDDzy6ZljK3TFljLqqKHY/DTlA6F5Wmp9Cfy/3UXEgJTmdzMPAl L/gSK/kmhfLKHY1Xe7Vxw8hkoW0saPN8+XZPMTt405Pm0ieVoI+Mr4cnPFMILAiXDFLd rBnp/Pxsb6ufWjN36SWddRPjh1xK3d1Orgxihd+SGUcSxDEPlj4z6JxqbFViARiL5RvP KKuA==
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Looking at the code on this page lines 47 & 48
I tired it in the code attached and strangely it works ok but only OUTSIDE THE class. When I implement the exact code in a class it does something weird. I can't find where I have gone wrong.
Please help.
Many thanks in advance.
Diliup Gabadamudalige
**********************************************************************************************
This e-mail is confidential. It may also be legally privileged. If you are not the intended recipient or have received it in error, please delete it and all copies from your system and notify the sender immediately by return e-mail. Any unauthorized reading, reproducing, printing or further dissemination of this e-mail or its contents is strictly prohibited and may be unlawful. Internet communications cannot be guaranteed to be timely, secure, error or virus-free. The sender does not accept liability for any errors or omissions.
**********************************************************************************************
import sys, os, pygame, itertools
from math import sin,cos,pi, radians
from pygame.locals import *
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (50,50) #Set window position
pygame.init()
clock = pygame.time.Clock()
FPS = 1000
SCREENW = 800 #screen width
SCREENH = 740 #screen height
BLACK = (0, 0, 0)
BLUE = (0, 0, 255)
ORANGE = (128, 100, 30)
FONT1= "Cookie-Regular.ttf"
SCREEN = pygame.display.set_mode((SCREENW, SCREENH), 0, 32) #display screen
clock = pygame.time.Clock()
#-------------------------------------------------------------------------------
def maketext(msg,fontsize, colour = ORANGE, font = FONT1):
mafont = pygame.font.Font(font, fontsize)
matext = mafont.render(msg, True, colour)
matext = matext.convert_alpha()
return matext
#-------------------------------------------------------------------------------
def print_info():
""""""
textcos = maketext(str(round(obj.rect.x, 2)) + " " + str(round(obj.rect.y, 2)), 30)
SCREEN.blit(textcos, (obj.rect.x, obj.rect.y + 30))
#-------------------------------------------------------------------------------
class object_factory(pygame.sprite.Sprite):
def __init__(self, imagelist, xpos = 0, ypos = 0, speedx = 0, speedy = 0, value = 0):
"""Constructor"""
pygame.sprite.Sprite.__init__(self)
self.name = ""
self.frame = 0
self.imagelist = imagelist
self.image = imagelist[self.frame]
self.mask = pygame.mask.from_surface(self.image) # pixelmask
self.rect = self.image.get_rect()
self.rect.x = xpos
self.rect.y = ypos
self.speedx = speedx
self.speedy = speedy
self.timer = 0
self.timerlimit = 10
#----------------------------------------------------------------------
def move(self): # wallsprites, Herosprite, looptime
self.rect.x += self.speedx
self.rect.y += self.speedy
#----------------------------------------------------------------------
def update(self):
""""""
self.image = self.imagelist[self.frame]
if self.timer >= self.timerlimit:
self.frame += 1
if self.frame >= len(self.imagelist):
self.frame = 0
self.timer = 0
self.timer += 1
plat = pygame.image.load("plt0.png").convert_alpha()
star = pygame.image.load("gemp0.png").convert_alpha()
box = pygame.image.load("crateB.png").convert_alpha()
platforms = pygame.sprite.Group()
boxes = pygame.sprite.Group()