<commit_before>'''
Created on Mar 2, 2016

@author: yoav
'''
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.image import Image
from kivy.properties import *
from kivy.clock import Clock
from kivy.core.window import Window
from collections import defaultdict
from kivy.uix.widget import Widget
from kivy.uix.button import Button
import itertools
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.uix.scatter import Scatter
import cmath
import math
from math import radians
import random
from kivy.config import Config, ConfigParser
import kivyoav.autosized_label
import os
from kivy.uix.settings import SettingItem
from kivyoav.autosized_label import AutoSizedLabel
from kivy.uix.popup import Popup
from kivy.core.audio import SoundLoader
import json

sm = ScreenManager()

KEYS = defaultdict(lambda: None)

Config.full_screen = 1

class Sprite(Scatter):
   
   
   
    source = StringProperty('')
    radius = NumericProperty(0.0)
    thrust =  NumericProperty(0.0)
    
    
        
    def __init__(self, game, velocity_x=0.0, velocity_y=0.0,
                 **kwargs):
        self.game = game
        attrs = {}
        for attr in 'rgba':
            if attr in kwargs:
                attrs[attr] = kwargs.pop(attr)
        super(Sprite, self).__init__( **kwargs )
        for attr, value in attrs.items():
            setattr(self, attr, value) 
        
        self.velocity_x = velocity_x
        self.velocity_y = velocity_y
       
        
        
    def update(self, plats=[],):
        thrust = self.thrust
        y_t = math.sin(radians(self.rotation)) * thrust
        x_t = math.cos(radians(self.rotation)) * thrust
        
        self.velocity_x += x_t
        self.velocity_y += y_t
        
        self.y += self.velocity_y
        self.x += self.velocity_x
        
        

    def distance(self, other):
        a = (self.center_x - other.center_x) ** 2
        b = (self.center_y - other.center_y)  ** 2
        return math.sqrt(a+b)
    
    
    def collide(self, other, area=0):
        d = self.distance(other)
        if d < (self.radius+other.radius+area):
            return 1
        
            

class GlobalStuff(object):
    
    
    @classmethod
    def init(cls):
        cls.right = Window.width
        cls.left = 0
        cls.top = Window.height
        cls.buttom = 0
        cls.center_x = Window.width / 2
        cls.center_y = Window.height / 2
        cls.size = cls.width, cls.height = Window.width, Window.height

    
class Bullet(Sprite):
    
    blow = NumericProperty(1.0)
    damage = NumericProperty(1)
    
    bullet_sounds = [SoundLoader.load('Music/shots/gunshot-00.mp3')
                     for _ in range(50)
                ]
    random.shuffle(bullet_sounds)
    
    for sound in bullet_sounds:
        sound.volume = 0.5
        
    next_bullet_sound = itertools.cycle(bullet_sounds)
        
    def __init__(self, game, owner, direction, **kw):
        super(Bullet, self).__init__(game, **kw)     
        self.rotation = direction#owner.rotation   
        self.velocity_x = owner.velocity_x + math.cos(radians(self.rotation)) * 8
        self.velocity_y = owner.velocity_y +  math.sin(radians(self.rotation)) * 8
        
        self.active = True
        self.first = 1
        self.owner = owner
        
        self.center = -200, -200
        self.blow_rate = 2.0
        
        self.counter = 0
        
    def hit_by(self, other):
        self.active = False
        self.counter = 40
        
        
    def update(self):
        if self.first:
            self.center = self.owner.center
            self.first=0
            next(self.next_bullet_sound).play()
        self.counter +=1
        bingo = self.game.check_player_collision(self, [self.owner])
        
        if bingo and self.active:
            self.active = False
            bingo.hit_by(self)
            self.counter = 25
        if self.counter > 50:
            self.game.remove_bullet(self)
            self.active = False
        if not self.active:
            self.velocity_x *= 0.75
            self.velocity_y *= 0.75
            self.blow *= self.blow_rate
            self.blow_rate *= 0.90
            
        super(Bullet, self).update()

class Player(Sprite):    
    lives = NumericProperty(5)
    
    def __init__(self, game, name, keys, **kw):
        super(Player, self).__init__(game, **kw)
        self.velocity_x = 0.0 * math.cos(radians(self.rotation))
        self.velocity_y = 0.0 * math.sin(radians(self.rotation))
        self.reload = 0
        self.reload_time = 20
        self.keys = keys
        self.name = name
        self.speed = 0.2
        self.bullets = 1
        

    def check_wall_collision(self):
        r = self.radius
        print(r, self.size, self.center)
        x, y = self.center
        if x - r < 0:
            return True
        if x + r > GlobalStuff.right:
            return True
        if y + r > GlobalStuff.top:
            return True
        if y-r < 0:
            return True
            

    def update(self,  user_pressed=KEYS):<commit_msg>small improvements to the gameplay to offer better sling-shots<commit_after>'''
Created on Mar 2, 2016

@author: yoav
'''
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.image import Image
from kivy.properties import *
from kivy.clock import Clock
from kivy.core.window import Window
from collections import defaultdict
from kivy.uix.widget import Widget
from kivy.uix.button import Button
import itertools
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
from kivy.uix.scatter import Scatter
import cmath
import math
from math import radians
import random
from kivy.config import Config, ConfigParser
import kivyoav.autosized_label
import os
from kivy.uix.settings import SettingItem
from kivyoav.autosized_label import AutoSizedLabel
from kivy.uix.popup import Popup
from kivy.core.audio import SoundLoader
import json

sm = ScreenManager()

KEYS = defaultdict(lambda: None)

Config.full_screen = 1

class Sprite(Scatter):
   
   
   
    source = StringProperty('')
    radius = NumericProperty(0.0)
    thrust =  NumericProperty(0.0)
    
    
        
    def __init__(self, game, velocity_x=0.0, velocity_y=0.0,
                 **kwargs):
        self.game = game
        attrs = {}
        for attr in 'rgba':
            if attr in kwargs:
                attrs[attr] = kwargs.pop(attr)
        super(Sprite, self).__init__( **kwargs )
        for attr, value in attrs.items():
            setattr(self, attr, value) 
        
        self.velocity_x = velocity_x
        self.velocity_y = velocity_y
       
        
        
    def update(self, plats=[],):
        thrust = self.thrust
        y_t = math.sin(radians(self.rotation)) * thrust
        x_t = math.cos(radians(self.rotation)) * thrust
        
        self.velocity_x += x_t
        self.velocity_y += y_t
        
        self.y += self.velocity_y
        self.x += self.velocity_x
        
        

    def distance(self, other):
        a = (self.center_x - other.center_x) ** 2
        b = (self.center_y - other.center_y)  ** 2
        return math.sqrt(a+b)
    
    
    def collide(self, other, area=0):
        d = self.distance(other)
        if d < (self.radius+other.radius+area):
            return 1
        
            

class GlobalStuff(object):
    
    
    @classmethod
    def init(cls):
        cls.right = Window.width
        cls.left = 0
        cls.top = Window.height
        cls.buttom = 0
        cls.center_x = Window.width / 2
        cls.center_y = Window.height / 2
        cls.size = cls.width, cls.height = Window.width, Window.height

    
class Bullet(Sprite):
    
    blow = NumericProperty(1.0)
    damage = NumericProperty(1)
    
    bullet_sounds = [SoundLoader.load('Music/shots/gunshot-00.mp3')
                     for _ in range(50)
                ]
    random.shuffle(bullet_sounds)
    
    for sound in bullet_sounds:
        sound.volume = 0.5
        
    next_bullet_sound = itertools.cycle(bullet_sounds)
        
    def __init__(self, game, owner, direction, **kw):
        super(Bullet, self).__init__(game, **kw)     
        self.rotation = direction#owner.rotation   
        self.velocity_x = owner.velocity_x + math.cos(radians(self.rotation)) * 4
        self.velocity_y = owner.velocity_y +  math.sin(radians(self.rotation)) * 4
        
        self.active = True
        self.first = 1
        self.owner = owner
        
        self.center = -200, -200
        self.blow_rate = 2.0
        self.max_counter = 100
        self.counter = 0
        
    def hit_by(self, other):
        self.active = False
        self.counter = 40
        
        
    def update(self):
        if self.first:
            self.center = self.owner.center
            self.first=0
            next(self.next_bullet_sound).play()
        self.counter +=1
        bingo = self.game.check_player_collision(self, [self.owner])
        
        if bingo and self.active:
            self.active = False
            bingo.hit_by(self)
            self.counter = 25
        if self.counter > self.max_counter:
            self.game.remove_bullet(self)
            self.active = False
        if not self.active:
            self.velocity_x *= 0.75
            self.velocity_y *= 0.75
            self.blow *= self.blow_rate
            self.blow_rate *= 0.90
            
        super(Bullet, self).update()

class Player(Sprite):    
    lives = NumericProperty(5)
    
    def __init__(self, game, name, keys, **kw):
        super(Player, self).__init__(game, **kw)
        self.velocity_x = 0.0 * math.cos(radians(self.rotation))
        self.velocity_y = 0.0 * math.sin(radians(self.rotation))
        self.reload = 0
        self.reload_time = 20
        self.keys = keys
        self.name = name
        self.speed = 0.2
        self.bullets = 1
        

    def check_wall_collision(self):
        r = self.radius - 5
        print(r, self.size, self.center)
        x, y = self.center
        if x  < 0:
            return True
        if x  > GlobalStuff.right:
            return True
        if y > GlobalStuff.top:
            return True
        if y < 0:
            return True
            

    def update(self,  user_pressed=KEYS):
{'fraction_non_alphanumeric': 0.09553528564570331, 'fraction_numerical': 0.014402304368698993, 'mean_word_length': 1.8404690482683392, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5642448', 'n_tokens_mistral': 3370, 'n_tokens_neox': 3248, 'n_words': 763}