Esempio n. 1
0
File: main.py Progetto: hellux/897
 def reset(self):
     """restore values and draw 3 player models"""
     self.lives = 3
     self.score = 0
     self.player_models = []
     for i in range(3):
         player = EnsPlayer()
         player.h = lu(20)
         player.w = player.h * 0.75
         player.cpos = lu(15) + lu(25) * i, HEIGHT - self.font_size - lu(15)
         player.set_points()
         self.player_models.append(player)
         self.add_widget(player)
Esempio n. 2
0
File: main.py Progetto: hellux/897
 def animate_explosion(self, pos):
     """spawns particles going in random directions and sets timer for removal"""
     size = lu(3)
     color = 1, 1, 1
     for _ in xrange(3):
         vel_m = lu(randint(0, 10) / 2.0 + 1)
         lifetime = randint(10, 20) / 60.0
         pivot = radians(randint(0, 360))
         vel = vel_m * cos(pivot), vel_m * sin(pivot)
         particle = EnsParticle(pos, size, color, vel)
         self.add_widget(particle, 1)
         self.particles.append(particle)
         Clock.schedule_once(
             partial(self.remove_entity, particle, self.particles),
             lifetime)
Esempio n. 3
0
File: main.py Progetto: hellux/897
class EnsScore(Widget):
    """displays and stores score and lives"""
    label = ObjectProperty(None)
    score = NumericProperty(0)
    lives = NumericProperty(0)
    h = NumericProperty(HEIGHT)
    font_size = NumericProperty(lu(50))
    scores = {"small": 100, "medium": 50, "large": 20}
    player_models = []

    def __init__(self, **kwargs):
        super(EnsScore, self).__init__(**kwargs)

    def reset(self):
        """restore values and draw 3 player models"""
        self.lives = 3
        self.score = 0
        self.player_models = []
        for i in range(3):
            player = EnsPlayer()
            player.h = lu(20)
            player.w = player.h * 0.75
            player.cpos = lu(15) + lu(25) * i, HEIGHT - self.font_size - lu(15)
            player.set_points()
            self.player_models.append(player)
            self.add_widget(player)

    def add(self, score_token):
        self.score += self.scores[score_token]

    def die(self):
        """subtract hp, remove player model"""
        self.lives -= 1
        self.remove_widget(self.player_models[self.lives])
Esempio n. 4
0
File: main.py Progetto: hellux/897
 def new_round(self):
     """spawns new asteroids"""
     for _ in xrange(4 + self.current_round * 2):
         #pos
         rand_x = randint(0, self.width)
         rand_y = randint(0, self.height)
         pos = choice([[rand_x, 0], [rand_x, self.height], [0, rand_y],
                       [self.width, rand_y]])
         if pos[0] != self.center_x:
             pivot = atan(
                 (self.center_y - pos[1]) / (self.center_x - pos[0]))
         else:
             pivot = 0
         if pos[0] > self.center_x:
             pivot += pi
         #vel
         pivot += radians(randint(-30, 30))
         vel_m = lu(randint(1, 5) / 2.0)
         vel = vel_m * cos(pivot), vel_m * sin(pivot)
         #col
         gray = randint(100, 150) / 255.0
         color = [gray + randint(-25, 25) / 255.0, gray, gray]
         #create ast
         asteroid = EnsAsteroid(pos, "large", vel, color)
         asteroid.move()
         self.create_entity(asteroid, self.asteroids)
     self.current_round += 1
Esempio n. 5
0
File: main.py Progetto: hellux/897
    def __init__(self, score, best):
        super(EnsEnd, self).__init__()
        for lbl in self.children:
            lbl.font_size = lu(50)

        self.lbl_game_over.font_size = lu(100)
        self.lbl_game_over.text = "GAME OVER"
        self.lbl_game_over.center = WIDTH / 2, HEIGHT * 0.8

        self.lbl_score.text = "Your score: " + str(score)
        self.lbl_score.center = WIDTH / 2, HEIGHT * 0.6

        self.lbl_best.text = "High score: " + str(best)
        self.lbl_best.center = WIDTH / 2, HEIGHT * 0.5

        self.lbl_retry.text = "Play again"
        self.lbl_exit.text = "Quit game"
Esempio n. 6
0
File: main.py Progetto: hellux/897
    def __init__(self, **kwargs):
        super(EnsStart, self).__init__(**kwargs)

        self.lbl_title.text = "EightNineSeven"
        self.lbl_title.font_size = lu(100)
        self.lbl_title.center = WIDTH / 2, HEIGHT * 0.6

        self.color = 0, 1, 1
        self.lbl_start.text = "Press anywhere to start"
        self.lbl_start.font_size = lu(40)
        self.lbl_start.center = WIDTH / 2, HEIGHT * 0.45

        self.lbl_info.text = "{}.{} {}\nKivy {}\nPython {}".format(
            __domain__, __package__, __version__, __kivy_version__, PY_VER)
        self.lbl_info.font_size = lu(15)
        self.lbl_info.halign = "center"
        self.lbl_info.center = WIDTH / 2, HEIGHT / 10
Esempio n. 7
0
 def reset(self):
     """remove all children widgets and set all values to start values"""
     self.clear_widgets()
     self.color[1] = 0.8
     self.h = lu(30)
     self.w = self.h * 0.75
     self.vel_boost_increase = self.w * 0.012
     self.pivot = pi / 2
     self.cosv = 0
     self.sinv = 1
     self.cpos = WIDTH / 2, HEIGHT / 2
     self.alive = True
Esempio n. 8
0
File: player.py Progetto: hellux/897
 def reset(self):
     """remove all children widgets and set all values to start values"""
     self.clear_widgets()
     self.color[1] = 0.8
     self.h = lu(30)
     self.w = self.h * 0.75
     self.vel_boost_increase = self.w * 0.012
     self.pivot = pi/2
     self.cosv = 0
     self.sinv = 1
     self.cpos = WIDTH/2, HEIGHT/2
     self.alive = True
Esempio n. 9
0
File: bullet.py Progetto: hellux/897
class EnsBullet(Widget):
    vel_x, vel_y = NumericProperty(0), NumericProperty(0)
    vel_m = lu(10)
    vel = ReferenceListProperty(vel_x, vel_y)

    def __init__(self, player):
        super(EnsBullet, self).__init__()
        self.width = lu(3)
        self.height = self.width
        self.center = player.points[0], player.points[1]
        self.vel = self.vel_m * player.cosv, self.vel_m * player.sinv

    def move(self):
        self.pos = Vector(*self.vel) + self.pos
        if not 0 < self.x < self.parent.width:
            self.x = self.parent.width - self.x
        if not 0 < self.y < self.parent.height:
            self.y = self.parent.height - self.y
        self.canvas.ask_update()
Esempio n. 10
0
File: main.py Progetto: hellux/897
 def destroy_asteroid(self, asteroid):
     """removes asteroid entity and if bigger than small creates a smaller one"""
     Clock.create_trigger(self.remove_entity(asteroid, self.asteroids))
     if asteroid.diameter == "large": diameter = "medium"
     elif asteroid.diameter == "medium": diameter = "small"
     else: return
     pivot = radians(randint(0, 360))
     vel_m = lu(2)
     vel_x = vel_m * cos(pivot)
     vel_y = vel_m * sin(pivot)
     for mul in [-1, 1]:
         asteroid = EnsAsteroid(
             [
                 asteroid.center_x + 5 * mul * vel_x,
                 asteroid.center_y + 5 * mul * vel_y
             ], diameter,
             [asteroid.vel_x + vel_x * mul, asteroid.vel_y + vel_y * mul],
             asteroid.color)
         self.asteroids.append(asteroid)
         self.add_widget(asteroid)
Esempio n. 11
0
File: main.py Progetto: hellux/897
class EnsDebugger(Widget):
    """if debug == True gathers variable values and displays them
       if fps == True displays fps"""
    label = ObjectProperty(None)
    debug = False
    fps = True
    label_text = StringProperty("")
    font_size = NumericProperty(lu(15))

    def update(self):
        self.label.top = HEIGHT
        self.label.right = WIDTH
        if self.debug:
            data = [
                ["fps", int(Clock.get_fps())],
                ["rfps", int(Clock.get_rfps())],
            ]
            self.label_text = "{}, {}.{} version {}".format(
                __title__, __domain__, __android_package__, __version__)
            for element, value in data:
                self.label_text += "\n[color=888888]{}:[/color] {}".format(
                    element, value)
        elif self.fps:
            self.label_text = "fps: {:.0f}".format(Clock.get_fps())
Esempio n. 12
0
File: bullet.py Progetto: hellux/897
 def __init__(self, player):
     super(EnsBullet, self).__init__()
     self.width = lu(3)
     self.height = self.width
     self.center = player.points[0], player.points[1]
     self.vel = self.vel_m*player.cosv, self.vel_m*player.sinv
Esempio n. 13
0
File: bullet.py Progetto: hellux/897
 def __init__(self, player):
     super(EnsBullet, self).__init__()
     self.width = lu(3)
     self.height = self.width
     self.center = player.points[0], player.points[1]
     self.vel = self.vel_m * player.cosv, self.vel_m * player.sinv