Forum Archive

[SOLVED] Why isn't my scene running?

Pythonistapro777

This is part of my agar.io clone. Where the cells all need to move as well as the player (a little). I wrote this code this morning and I don't know why it wouldn't work. Could someone please help with this?

Here's the code:

from scene import *
from random import *

class Particle(object):
    def __init__(self, wh):
        self.w = wh.w
        self.h = wh.h
        self.x = randint(0, self.w)
        self.y = randint(0, self.h)
        self.vx = randint(-10, 20)
        self.vy = randint(-10, 20)
        self.colour = Color(random(), random(), random())

    def update(self):
        self.x += self.vx
        self.y += self.vy
        self.vx *= 0.4
        self.vy *= 0.4
        if self.x > self.w:
            self.x = self.w
            self.vx *= -1
        if self.x < 0:
            self.x = 0
            self.vx *= -1
        if self.y > self.h:
            self.y = self.h
            self.vy *= -1
        if self.y < 0:
            self.y = 0
            self.vy *= -1

    def draw(self):
        fill(*self.colour)
        rect(self.x, self.y, 8, 8)

class Intro(Scene):
    def setup(self):
        self.particles = []
        for p in xrange(100):
            self.particles.append(Particle(self.size))

    def draw(self):
        background(0.00, 0.05, 0.20)
        for p in self.particles:
            p.update()
            p.draw()

    def touch_began(self, touch):
        global x1
        global y1
        x1=touch.location.x
        y1=touch.location.y


    def touch_moved(self, touch):
        x=touch.location.x
        y=touch.location.y

        while x1 > x:
            for p in self.particles:
                p.vx = p.vx + 1

        while x1 < x:
            for p in self.particles:
                p.vx = p.vx - 1

        while y1 > y:
            for p in self.particles:
                p.vy = p.vy + 1

        while y1 < y:
            for p in self.particles:
                p.vy = p.vy - 1

run(Intro())

Thanks in advance!

ccc

Comment out these two lines at the beginning of update():

        #self.vx *= 0.4
        #self.vy *= 0.4

Or slow down the speed decay...

        self.vx *= 0.998
        self.vy *= 0.998

Also, if any of your while loops in touch_moved() start then they will never end (infinite loop with no ui updates) because neither of the terms are modified in the body of those loops.