#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    7
    Rep Power
    0

    physics sim trouble


    I'm having some trouble with my physics sim. The object thats falling falls at a certain speed and doesn't get faster, but it should. Is there a way i can e-mail u my program and u can tell me whats wrong.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Posts
    89
    Rep Power
    13
    why don't you just post your code here?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    7
    Rep Power
    0
    Code:
    ###############Physics Sim################
    
    import pygame
    from pygame.locals import *
    import sys, pygame
    
    pygame.init()
    
    ##Objects##
    clock = pygame.time.Clock()
    
    ####Sim#####
    
    ##Screen Setup##
    scr_size = [800, 600]
    bg_color = [255, 255, 255]
    screen = pygame.display.set_mode((scr_size))
    
    class Ball:
        """ Ball class """
    
        def __init__(self, pos = [400.0,300.0], vel = [0.0,0.0], mass = 1.0, radius = 20, color=[0, 0, 0]):
            self.pos = pos
            self.vel = vel
            self.mass = mass
            self.radius = radius
            self.radius = radius
            self.color = color
            #print 'init called'
    
        def __str__(self):
            s = 'Pos: '
            s += str(self.pos)
            s += '\n'
            s += 'Vel: '
            s += str(self.vel)
            s += '\n'
            s += 'Mass: '
            s += str(self.mass)
            s += '\n'
            s += 'Radius: '
            s += str(self.radius)
            return s
    
        def draw(self):
            newpos = self.pos
            newpos[1] = 600 - newpos[1]
            pygame.draw.circle(screen, self.color ,newpos ,self.radius)
    
                
            
    class World:
        """ World Class """
        def __init__(self, gravity = [0.0,0.0]):
            self.gravity = gravity
            self.objects = []
    
        def add(self, new_object):
            self.objects.append(new_object)
    
        def step(self,time = clock.get_time()):
            for x in self.objects:
                x.vel[0] += self.gravity[0] * time
                x.vel[1] += self.gravity[1] * time
    
                x.pos[0] += x.vel[0] * time
                x.pos[1] += x.vel[1] * time
    #########################################################
    
    ##########Key Setup###########
    
    keydown = []
    for key in range(512):
        keydown.append(False)
    
    def updatemove():
        if keydown[K_p]:
            print ball_ln
            print " "
            
    ##############################
    
    def update_scr():
        screen.fill(bg_color)
        ball.draw()
        pygame.display.flip()
    
    ball = Ball()
    w = World(gravity=[0.0,-9.8])
    
    w.add(ball)
    
    
    ####Main Loop####
    while 1:
        clock.tick(60)
        update_scr()
        updatemove()
        
        for event in pygame.event.get():
            if event.type == pygame.QUIT: sys.exit()
            if event.type == pygame.KEYDOWN:
                keydown[event.key] = 1
            if event.type == pygame.KEYUP:
                keydown[event.key] = 0
            ball_ln = ball
        w.step(1)
    Last edited by netytan; August 22nd, 2004 at 09:34 PM. Reason: Use code tags!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Canada
    Posts
    242
    Rep Power
    0
    Repost using [ code ] [/ code ] tags (without the spaces, obviously) and you'll probably get more answers.
  8. #5
  9. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    Here you go:
    Code:
        def step(self,time = clock.get_time()):
    The value of time is constant. It is set only when the interpreter runs through your code for the first time as it is loaded.

    grim

IMN logo majestic logo threadwatch logo seochat tools logo