<commit_before># program template for Spaceship
import simplegui
import math
import random

# globals for user interface
WIDTH = 800
HEIGHT = 600
dim = [ WIDTH, HEIGHT ]

MAX_MISSILES = 10
MAX_ROCKS = 12

angular_acceleration = 0.06
linear_acceleration = 0.1
missile_velocity = 3
friction = 0.06

class Game:
    def __init__(self):
        self.score = 0
        self.lives = 3
        self.time = 0.5

class Image:
    def __init__(self, url, center, size, radius = 0, lifespan = None, animated = False):
        self.center = center
        self.size = size
        self.radius = radius
        if lifespan:
            self.lifespan = lifespan
        else:
            self.lifespan = float('inf')
        self.animated = animated
        self.image = simplegui.load_image(url)

    def get_center(self):
        return self.center

    def get_size(self):
        return self.size

    def get_radius(self):
        return self.radius

    def get_lifespan(self):
        return self.lifespan

    def get_animated(self):
        return self.animated

    
# art assets created by <NAME>, may be freely re-used in non-commercial projects, please credit Kim
    
# debris images - debris1_brown.png, debris2_brown.png, debris3_brown.png, debris4_brown.png
#                 debris1_blue.png, debris2_blue.png, debris3_blue.png, debris4_blue.png, debris_blend.png
debris = Image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/debris2_blue.png",[320, 240], [640, 480])

# nebula images - nebula_brown.png, nebula_blue.png
nebula = Image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/nebula_blue.f2014.png",[400, 300], [800, 600])

# splash image
splash = Image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/splash.png",[200, 150], [400, 300])

# ship image
ship = Image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/double_ship.png",[45, 45], [90, 90], 35)

# missile image - shot1.png, shot2.png, shot3.png
missile = Image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/shot2.png",[5,5], [10, 10], 3, 50)

# asteroid images - asteroid_blue.png, asteroid_brown.png, asteroid_blend.png
asteroid = Image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/asteroid_blend.png",[45, 45], [90, 90], 40)

# animated explosion - explosion_orange.png, explosion_blue.png, explosion_blue2.png, explosion_alpha.png
explosion = Image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/explosion_alpha.png",[64, 64], [128, 128], 17, 24, True)

# sound assets purchased from sounddogs.com, please do not redistribute
soundtrack = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/soundtrack.mp3")
soundtrack.set_volume(.5)
missile_sound = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/missile.mp3")
missile_sound.set_volume(.5)
ship_thrust_sound = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/thrust.mp3")
ship_thrust_sound.set_volume(.5)
explosion_sound = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/explosion.mp3")
explosion_sound.set_volume(.5)

# helper functions to handle transformations
def angle_to_vector(ang):
    return [math.cos(ang), math.sin(ang)]

def dist(p,q):
    return math.sqrt((p[0] - q[0]) ** 2+(p[1] - q[1]) ** 2)


# Ship class
class Ship:
    def __init__(self, pos, vel, angle, image):
        self.pos = [pos[0],pos[1]]
        self.vel = [vel[0],vel[1]]
        self.thrust = False
        self.angle = angle
        self.angle_vel = 0
        self.image = image
        self.image_center = image.get_center()
        self.image_size = image.get_size()
        self.radius = image.get_radius()
        
    def draw(self,canvas):
        canvas.draw_image(self.image.image,
                          self.image.get_center(),
                          self.image.get_size(),
                          self.pos, self.image.get_size(), self.angle)
        #canvas.draw_circle(self.pos, self.radius, 1, "White", "White")

    def update(self):
        print self.pos, self.vel, self.thrust, self.angle, angle_to_vector(self.angle)
        self.angle += self.angle_vel
        if self.thrust:
            direction = angle_to_vector(self.angle)
            for x in range(2):
                direction[x] *= angular_acceleration 
                self.vel[x] += direction[x]
        else:
            for x in range(2):
                self.vel[x] = self.vel[x] * (  1 - friction )
                if self.vel[x] < 0.0000001: self.vel[x] = 0
                    
        for x in range(2):
            self.pos[x] += self.vel[x]
            if self.pos[x] > dim[x]:
                self.pos[x] = 0
            elif self.pos[x] < 0:
                self.pos[x] = dim[x]
    
    
# Sprite class
class Sprite:
    def __init__(self, pos, vel, ang, ang_vel, image, sound = None):
        self.pos = [pos[0],pos[1]]
        self.vel = [vel[0],vel[1]]
        self.angle = ang
        self.angle_vel = ang_vel
        self.image = image
        self.age = 0
        if sound:
            sound.rewind()
            sound.play()
   
    def draw(self, canvas):
        canvas.draw_image(self.image.image,
                          self.image.get_center(),
                          self.image.get_size(),
                          self.pos, self.image.get_size())
    
    def update(self):
        for x in range(2):
            self.pos[x] += self.vel[x]
            if self.pos[x] > dim[x]:
                self.pos[x] = 0
            elif self.pos[x] < 0:
                self.pos[x] = dim[x]
            
           
def draw(canvas):
    global game
    
    # animate background
    game.time += 1
    wtime = (game.time / 4) % WIDTH
    center = debris.get_center()
    size = debris.get_size()
    canvas.draw_image(nebula.image, nebula.get_center(), nebula.get_size(), [WIDTH / 2, HEIGHT / 2], [WIDTH, HEIGHT])
    canvas.draw_image(debris.image, center, size, (wtime - WIDTH / 2, HEIGHT / 2), (WIDTH, HEIGHT))
    canvas.draw_image(debris.image, center, size, (wtime + WIDTH / 2, HEIGHT / 2), (WIDTH, HEIGHT))
    
    # dras & update ship and sprites
    my_ship.draw(canvas)
    my_ship.update()
    for rock in rocks:
        rock.draw(canvas)
        rock.update()
    for missile in missiles:
        missile.draw(canvas)
        missile.update()
            
# timer handler that spawns a rock    
def rock_spawner():
    global rocks
    if len(rocks) > MAX_ROCKS: rocks = rocks[-(MAX_ROCKS-1):]
    a_rock = Sprite([WIDTH / 3, HEIGHT / 3], [1, 1], 0, 0, asteroid)
    rocks.append(a_rock)
    
def missile_spawner():
    global missiles
    if len(missiles) > MAX_MISSILES: missiles = missiles[-(MAX_MISSILES-1):]
    a_missile = Sprite([2 * WIDTH / 3, 2 * HEIGHT / 3], [-1,1], 0, 0, missile, missile_sound)
    missiles.append(a_missile)
    
def key_down(key):
    global my_ship, angular_acceleration
    if key==simplegui.KEY_MAP["left"]:
        my_ship.angle_vel = -angular_acceleration
    if key==simplegui.KEY_MAP["right"]:
        my_ship.angle_vel = angular_acceleration
    if key==simplegui.KEY_MAP["up"]:
        my_ship.thrust = True
    if key==simplegui.KEY_MAP["space"]:
        missile_spawner()
        
def key_up(key):
    global my_ship, angular_acceleration
    if key==simplegui.KEY_MAP["left"]:
        if my_ship.angle_vel == -angular_acceleration:
            my_ship.angle_vel = 0
    if key==simplegui.KEY_MAP["right"]:
        if my_ship.angle_vel == angular_acceleration:<commit_msg>added missiles velocity<commit_after># program template for Spaceship
import simplegui
import math
import random

# globals for user interface
WIDTH = 800
HEIGHT = 600
dim = [ WIDTH, HEIGHT ]

MAX_MISSILES = 10
MAX_ROCKS = 12

angular_acceleration = 0.06
linear_acceleration = 0.1
missile_velocity = 3
friction = 0.06

class Game:
    def __init__(self):
        self.score = 0
        self.lives = 3
        self.time = 0.5
        
    def draw(self,canvas):
        canvas.draw_text("Lives: %d"%(self.lives), (20,30), 20, "Red")
        canvas.draw_text("Score: %d"%(self.score), (WIDTH-100,30), 20, "Yellow")

class Image:
    def __init__(self, url, center, size, radius = 0, lifespan = None, animated = False):
        self.center = center
        self.size = size
        self.radius = radius
        if lifespan:
            self.lifespan = lifespan
        else:
            self.lifespan = float('inf')
        self.animated = animated
        self.image = simplegui.load_image(url)

    def get_center(self):
        return self.center

    def get_size(self):
        return self.size

    def get_radius(self):
        return self.radius

    def get_lifespan(self):
        return self.lifespan

    def get_animated(self):
        return self.animated

    
# art assets created by <NAME>, may be freely re-used in non-commercial projects, please credit Kim
    
# debris images - debris1_brown.png, debris2_brown.png, debris3_brown.png, debris4_brown.png
#                 debris1_blue.png, debris2_blue.png, debris3_blue.png, debris4_blue.png, debris_blend.png
debris = Image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/debris2_blue.png",[320, 240], [640, 480])

# nebula images - nebula_brown.png, nebula_blue.png
nebula = Image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/nebula_blue.f2014.png",[400, 300], [800, 600])

# splash image
splash = Image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/splash.png",[200, 150], [400, 300])

# ship image
ship = Image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/double_ship.png",[45, 45], [90, 90], 35)

# missile image - shot1.png, shot2.png, shot3.png
missile = Image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/shot2.png",[5,5], [10, 10], 3, 50)

# asteroid images - asteroid_blue.png, asteroid_brown.png, asteroid_blend.png
asteroid = Image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/asteroid_blend.png",[45, 45], [90, 90], 40)

# animated explosion - explosion_orange.png, explosion_blue.png, explosion_blue2.png, explosion_alpha.png
explosion = Image("http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/explosion_alpha.png",[64, 64], [128, 128], 17, 24, True)

# sound assets purchased from sounddogs.com, please do not redistribute
soundtrack = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/soundtrack.mp3")
soundtrack.set_volume(.5)
missile_sound = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/missile.mp3")
missile_sound.set_volume(.5)
ship_thrust_sound = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/thrust.mp3")
ship_thrust_sound.set_volume(.5)
explosion_sound = simplegui.load_sound("http://commondatastorage.googleapis.com/codeskulptor-assets/sounddogs/explosion.mp3")
explosion_sound.set_volume(.5)

# helper functions to handle transformations
def angle_to_vector(ang):
    return [math.cos(ang), math.sin(ang)]

def dist(p,q):
    return math.sqrt((p[0] - q[0]) ** 2+(p[1] - q[1]) ** 2)


# Ship class
class Ship:
    def __init__(self, pos, vel, angle, image):
        self.pos = [pos[0],pos[1]]
        self.vel = [vel[0],vel[1]]
        self.thrust = False
        self.angle = angle
        self.angle_vel = 0
        self.image = image
        self.image_center = image.get_center()
        self.image_size = image.get_size()
        self.radius = image.get_radius()
                
    def draw(self,canvas):
        canvas.draw_image(self.image.image,
                          self.image.get_center(),
                          self.image.get_size(),
                          self.pos, self.image.get_size(), self.angle)
        #canvas.draw_circle(self.pos, self.radius, 1, "White", "White")

    def update(self):
        print self.pos, self.vel, self.thrust, self.angle, angle_to_vector(self.angle)
        self.angle += self.angle_vel
        if self.thrust:
            direction = angle_to_vector(self.angle)
            for x in range(2):
                direction[x] *= angular_acceleration 
                self.vel[x] += direction[x]
            ship_thrust_sound.play()
            self.image.center[0] = 135
        else:
            ship_thrust_sound.pause()
            self.image.center[0] = 45
                    
        for x in range(2):
            self.pos[x] += self.vel[x]
            if self.pos[x] > dim[x]:
                self.pos[x] = 0
            elif self.pos[x] < 0:
                self.pos[x] = dim[x]
    
    
# Sprite class
class Sprite:
    def __init__(self, pos, vel, ang, ang_vel, image, sound = None):
        self.pos = [pos[0],pos[1]]
        self.vel = [vel[0],vel[1]]
        self.angle = ang
        self.angle_vel = ang_vel
        self.image = image
        self.age = 0
        if sound:
            sound.rewind()
            sound.play()
   
    def draw(self, canvas):
        canvas.draw_image(self.image.image,
                          self.image.get_center(),
                          self.image.get_size(),
                          self.pos, self.image.get_size())
    
    def update(self):
        for x in range(2):
            self.pos[x] += self.vel[x]
            if self.pos[x] > dim[x]:
                self.pos[x] = 0
            elif self.pos[x] < 0:
                self.pos[x] = dim[x]
                
                
def draw(canvas):
    global game
    
    game.draw(canvas)
    
    # animate background
    game.time += 1
    wtime = (game.time / 4) % WIDTH
    center = debris.get_center()
    size = debris.get_size()
    canvas.draw_image(nebula.image, nebula.get_center(), nebula.get_size(), [WIDTH / 2, HEIGHT / 2], [WIDTH, HEIGHT])
    canvas.draw_image(debris.image, center, size, (wtime - WIDTH / 2, HEIGHT / 2), (WIDTH, HEIGHT))
    canvas.draw_image(debris.image, center, size, (wtime + WIDTH / 2, HEIGHT / 2), (WIDTH, HEIGHT))
    
    # dras & update ship and sprites
    my_ship.draw(canvas)
    my_ship.update()
    for rock in rocks:
        rock.draw(canvas)
        rock.update()
    for missile in missiles:
        missile.draw(canvas)
        missile.update()
            
# timer handler that spawns a rock    
def rock_spawner():
    global rocks
    if len(rocks) > MAX_ROCKS: rocks = rocks[-(MAX_ROCKS-1):]
    a_rock = Sprite([WIDTH / 3, HEIGHT / 3], [1, 1], 0, 0, asteroid)
    rocks.append(a_rock)
    
def missile_spawner():
    global missiles
    if len(missiles) > MAX_MISSILES: missiles = missiles[-(MAX_MISSILES-1):]
        
    velocity = my_ship.vel
    add_velocity = angle_to_vector(my_ship.angle)
    for x in range(2):
        add_velocity[x] *= missile_velocity
        add_velocity[x] += velocity[x]
        
    cannon_pos = list(my_ship.pos)
        
    a_missile = Sprite(cannon_pos, add_velocity, 0, 0, missile, missile_sound)
    missiles.append(a_missile)
    
def key_down(key):
    global my_ship, angular_acceleration
    if key==simplegui.KEY_MAP["left"]:
        my_ship.angle_vel = -angular_acceleration
    if key==simplegui.KEY_MAP["right"]:
        my_ship.angle_vel = angular_acceleration
    if key==simplegui.KEY_MAP["up"]:
        my_ship.thrust = True
    if key==simplegui.KEY_MAP["space"]:
        missile_spawner()
        
def key_up(key):
    global my_ship, angular_acceleration
    if key==simplegui.KEY_MAP["left"]:
        if my_ship.angle_vel == -angular_acceleration:
            my_ship.angle_vel = 0
    if key==simplegui.KEY_MAP["right"]:
        if my_ship.angle_vel == angular_acceleration:
{'fraction_non_alphanumeric': 0.12646221941195068, 'fraction_numerical': 0.02415428390768258, 'mean_word_length': 2.575853493104228, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7532317', 'n_tokens_mistral': 5708, 'n_tokens_neox': 5248, 'n_words': 1058}