Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import simplegui
- import math
- Width = 900
- Height = 900
- boost_message = "Hold spacebar to boost"
- boost_message_color = "Yellow"
- player_sprite = simplegui.load_image("https://i.imgrpost.com/imgr/2018/03/01/fhN53R.png")
- sun_sprite_image = simplegui.load_image("https://i.imgrpost.com/imgr/2018/03/01/Vsd87P.png")
- sun_atmosphere_image = simplegui.load_image("https://i.imgrpost.com/imgr/2018/03/01/bf7wqA.png")
- explosion_image = simplegui.load_image("")
- game_over_message = ("")
- class player_1:
- def __init__(self, circle1_center, circle1_radius, velocity_circle1, acceleration1, bounce_distance1, circle1_mass):
- self.circle1_center = circle1_center
- self.circle1_radius = circle1_radius
- self.velocity_circle1 = velocity_circle1
- self.acceleration1 = acceleration1
- self.bounce_distance1 = bounce_distance1
- self.circle1_mass = circle1_mass
- def keydown1(self, key):
- global boost_message, boost_message_color
- if key == simplegui.KEY_MAP["left"]:
- self.velocity_circle1[0] -= self.acceleration1
- elif key == simplegui.KEY_MAP["up"]:
- self.velocity_circle1[1] -= self.acceleration1
- elif key == simplegui.KEY_MAP["right"]:
- self.velocity_circle1[0] += self.acceleration1
- elif key == simplegui.KEY_MAP["down"]:
- self.velocity_circle1[1] += self.acceleration1
- elif key == simplegui.KEY_MAP["space"]:
- self.acceleration1 *= 3
- boost_message = "BOOST ACTIVATED"
- boost_message_color = "Red"
- def keyup1(self, key):
- global boost_message, boost_message_color
- if key == simplegui.KEY_MAP["left"]:
- self.velocity_circle1[0] = 0
- elif key == simplegui.KEY_MAP["up"]:
- self.velocity_circle1[1] = 0
- elif key == simplegui.KEY_MAP["right"]:
- self.velocity_circle1[0] = 0
- elif key == simplegui.KEY_MAP["down"]:
- self.velocity_circle1[1] = 0
- elif key == simplegui.KEY_MAP["space"]:
- self.acceleration1 /= 3
- boost_message = "Hold spacebar to boost"
- boost_message_color = "Yellow"
- def draw_player_1_sprite(self, canvas):
- global Width, Height
- canvas.draw_image(player_sprite, [1060/2, 1060/2], [1060, 1060], self.circle1_center, [40, 40])
- def Movement(self):
- self.circle1_center[0] = self.circle1_center[0] + self.velocity_circle1[0]
- self.circle1_center[1] = self.circle1_center[1] + self.velocity_circle1[1]
- def Border_collisions(self):
- global Width, Height
- if self.circle1_center[0] <= self.circle1_radius:
- self.circle1_center[0] += self.bounce_distance1
- elif self.circle1_center[0] >= Width-self.circle1_radius:
- self.circle1_center[0] -= self.bounce_distance1
- elif self.circle1_center[1] <= self.circle1_radius:
- self.circle1_center[1] += self.bounce_distance1
- elif self.circle1_center[1] >= Height-self.circle1_radius:
- self.circle1_center[1] -= self.bounce_distance1
- class sun_sprite:
- def __init__(self, sun_hitbox_center, sun_hitbox_radius):
- self.sun_hitbox_center = sun_hitbox_center
- self.sun_hitbox_radius = sun_hitbox_radius
- def draw_sun(self, canvas):
- global Width, Height
- canvas.draw_image(sun_sprite_image, [3002/2, 3005/2], [3002, 3005], self.sun_hitbox_center, [100, 100])
- class sun_atmosphere:
- def __init__(self, sun_atmosp_center, sun_atmosp_radius, sun_atmosp_mass, sun_atmosp_time):
- self.sun_atmosp_center = sun_atmosp_center
- self.sun_atmosp_radius = sun_atmosp_radius
- self.sun_atmosp_mass = sun_atmosp_mass
- self.sun_atmosp_time = sun_atmosp_time
- def draw_atmosphere(self, canvas):
- global Width, Height
- canvas.draw_image(sun_atmosphere_image, [2136/2, 2136/2], [2136, 2136], self.sun_atmosp_center, [550, 550])
- def influence_speed(self):
- global Call_player_1
- #Distance
- dx = self.sun_atmosp_center[0]-Call_player_1.circle1_center[0]
- dy = self.sun_atmosp_center[1]-Call_player_1.circle1_center[1]
- distance = math.sqrt(dx**2 + dy**2)
- #Force and Mass
- Force_Scalar = Call_player_1.circle1_mass * self.sun_atmosp_mass/(distance**2)
- theta = math.atan2 (dy, dx)
- Fx = math.cos(theta) * Force_Scalar
- Fy = math.sin(theta) * Force_Scalar
- #If Statements
- #X-Axis Right Side
- if Call_player_1.circle1_center[0] > self.sun_atmosp_center[0]:
- theta = -theta
- #X-Axis Left Side
- elif Call_player_1.circle1_center[0] < self.sun_atmosp_center[0]:
- theta = math.fabs(theta)
- #Y-Axis Top
- elif Call_player_1.circle1_center[1] > self.sun_atmosp_center[1]:
- theta = math.fabs(theta)
- #Y-Axis Bottom
- elif Call_player_1.circle1_center[1] < self.sun_atmosp_center[1]:
- theta = -theta
- #Acceleration
- ax = Fx/Call_player_1.circle1_mass
- ay = Fy/Call_player_1.circle1_mass
- #Velocity
- Call_player_1.velocity_circle1[0] = Call_player_1.velocity_circle1[0] + ax*20
- Call_player_1.velocity_circle1[1] = Call_player_1.velocity_circle1[1] + ay*20
- #Final Speed Add
- Call_player_1.circle1_center[0] += Call_player_1.velocity_circle1[0]
- Call_player_1.circle1_center[1] += Call_player_1.velocity_circle1[1]
- def sun_atmosp_timer(self):
- global Call_player_1, timer, Call_sun_sprite
- dx = self.sun_atmosp_center[0]-Call_player_1.circle1_center[0]
- dy = self.sun_atmosp_center[1]-Call_player_1.circle1_center[1]
- distance = math.sqrt(dx**2 + dy**2)
- if Call_player_1.circle1_radius+self.sun_atmosp_radius >= distance:
- timer.start()
- self.sun_atmosp_time += 1
- if Call_player_1.circle1_radius+Call_sun_sprite.sun_hitbox_radius >= distance:
- self.sun_atmosp_time -= 1
- else:
- timer.stop()
- self.sun_atmosp_time = 0
- class sun_explosion:
- def __init__(self, sun_explosion_time, explosion_teller):
- self.sun_explosion_time = sun_explosion_time
- self.explosion_teller = explosion_teller
- def draw_explosion(self, canvas):
- global Call_sun_sprite
- canvas.draw_image(explosion_image, [765/2, 489/2], [765, 489], Call_sun_sprite.sun_hitbox_center, [600, 383])
- def sun_explosion_collision(self):
- global Call_player_1, explosion_image, Call_sun_sprite
- x = math.pow((Call_sun_sprite.sun_hitbox_center[0]-Call_player_1.circle1_center[0]), 2)
- y = math.pow((Call_sun_sprite.sun_hitbox_center[1]-Call_player_1.circle1_center[1]), 2)
- distance = math.sqrt(x + y)
- #Collisions:
- if Call_player_1.circle1_radius+Call_sun_sprite.sun_hitbox_radius >= distance:
- explosion_image = simplegui.load_image("https://i.imgrpost.com/imgr/2018/03/09/explosion.png")
- def sun_explosion_timer(self):
- global Call_player_1, timer_explosion, explosion_image, Call_sun_sprite
- dx = Call_sun_sprite.sun_hitbox_center[0]-Call_player_1.circle1_center[0]
- dy = Call_sun_sprite.sun_hitbox_center[1]-Call_player_1.circle1_center[1]
- distance = math.sqrt(dx**2 + dy**2)
- if Call_player_1.circle1_radius+Call_sun_sprite.sun_hitbox_radius >= distance:
- timer.start()
- self.sun_explosion_time += 1
- Call_player_1.velocity_circle1[0] = 0
- Call_player_1.velocity_circle1[1] = 0
- self.explosion_teller = 1
- else:
- timer.stop()
- self.sun_explosion_time = 0
- if self.sun_explosion_time > 100:
- Call_player_1.circle1_center = [100, 800]
- Call_player_1.velocity_circle1 = [0, 0]
- explosion_image = simplegui.load_image("")
- class player_lives:
- def __init__(self, lives):
- self.lives = lives
- def lives_deduction(self):
- global Call_sun_explosion
- if Call_sun_explosion.explosion_teller == 1:
- self.lives = 0
- Call_sun_explosion.explosion_teller = 0
- def game_over(self):
- global Call_sun_explosion, game_over_message
- if self.lives == 0:
- game_over_message = "GAME OVER"
- if Call_sun_explosion.sun_explosion_time > 100:
- frame.stop()
- class reset_position:
- def reset_button():
- global Call_player_1
- Call_player_1.circle1_center = [100, 800]
- Call_player_1.velocity_circle1 = [0, 0]
- Call_player_1 = player_1([100, 800], 17, [0,0], 4, 10, 6)
- Call_sun_sprite = sun_sprite([Width/2,Height/2], 57)
- Call_sun_atmosphere = sun_atmosphere([Width/2,Height/2], 240, 15, 0)
- Call_reset_position = reset_position
- Call_sun_explosion = sun_explosion(0, 0)
- Call_player_lives = player_lives(1)
- def draw_sprites(canvas):
- global Call_player_1, Call_sun_sprite, boost_message_color, boost_message, game_over_message
- Call_player_1.Movement()
- Call_player_1.Border_collisions()
- #Draw Layer 5 - Atmosphere
- Call_sun_atmosphere.draw_atmosphere(canvas)
- Call_sun_atmosphere.influence_speed()
- Call_sun_atmosphere.sun_atmosp_timer()
- #Draw Layer 4 - Sun
- Call_sun_sprite.draw_sun(canvas)
- #Draw Layer 3 - Player
- Call_player_1.draw_player_1_sprite(canvas)
- #Draw Layer 2 - Explosion
- Call_sun_explosion.draw_explosion(canvas)
- Call_sun_explosion.sun_explosion_collision()
- Call_sun_explosion.sun_explosion_timer()
- #Draw Layer 1 - Text
- canvas.draw_text("Time spent in atmosphere:" + " " + str(Call_sun_atmosphere.sun_atmosp_time), [10,25], 18, "White")
- canvas.draw_text(boost_message, [10,70], 14, boost_message_color)
- Call_player_lives.lives_deduction()
- canvas.draw_text("Lives left:" + " " + str(Call_player_lives.lives), [10,50], 18, "White")
- canvas.draw_text(game_over_message, [150 ,(Height/2 + 25)], 100, "Red")
- Call_player_lives.game_over()
- def keydown(key):
- global Call_player_1
- Call_player_1.keydown1(key)
- def keyup(key):
- global Call_player_1
- Call_player_1.keyup1(key)
- frame = simplegui.create_frame("Circle Orbital Simulation", Width, Height)
- frame.set_draw_handler(draw_sprites)
- frame.set_keydown_handler(keydown)
- frame.set_keyup_handler(keyup)
- frame.add_button("Reset Position of Player", Call_reset_position.reset_button, 200)
- timer = simplegui.create_timer(100, Call_sun_atmosphere.sun_atmosp_timer)
- timer_explosion = simplegui.create_timer(100, Call_sun_explosion.sun_explosion_timer)
- frame.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement