Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import simplegui
- import math
- Width = 500
- Height = 500
- player_sprite = simplegui.load_image("https://i.imglnx.com/fhN53R.png")
- sun_sprite_image = simplegui.load_image("https://i.imglnx.com/Vsd87P.png")
- class player_1:
- def __init__(self, circle1_center, circle1_radius, velocity_circle1, acceleration1, bounce_distance1, sun_hitbox_center, sun_hitbox_radius):
- self.circle1_center = circle1_center
- self.circle1_radius = circle1_radius
- self.velocity_circle1 = velocity_circle1
- self.acceleration1 = acceleration1
- self.bounce_distance1 = bounce_distance1
- #Sun integers
- self.sun_hitbox_center = sun_hitbox_center
- self.sun_hitbox_radius = sun_hitbox_radius
- def keydown1(self, key):
- 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
- def keyup1(self, key):
- 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
- def draw_sprites(self, canvas):
- global Width, Height
- canvas.draw_image(player_sprite, [1060/2, 1060/2], [1060, 1060], self.circle1_center, [40, 40])
- canvas.draw_image(sun_sprite_image, [3002/2, 3005/2], [3002, 3005], [Width/2,Height/2], [70, 70])
- 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
- def sun_orbit_collisions(self):
- x = math.pow((self.sun_hitbox_center[0]-self.circle1_center[0]), 2)
- y = math.pow((self.sun_hitbox_center[1]-self.circle1_center[1]), 2)
- distance = math.sqrt(x + y)
- #Collisions:
- if self.circle1_radius+self.sun_hitbox_radius >= distance:
- self.velocity_circle1[0] = -self.velocity_circle1[0]
- self.velocity_circle1[1] = -self.velocity_circle1[1]
- Call_player_1 = player_1([50, 450], 17, [0,0], 2, 10, [Width/2,Height/2], 70)
- def draw_sprites(canvas):
- global Call_Sprite_1
- Call_player_1.draw_sprites(canvas)
- Call_player_1.Movement()
- Call_player_1.Border_collisions()
- Call_player_1.sun_orbit_collisions
- 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.start()
Advertisement
Add Comment
Please, Sign In to add comment