Okay – 8 and half hours of work done… (I forgot to post a devlog between when I stopped and restarted working, whoops)
I had fun with this one haha
What i added:
Slider to change the gravity (total, changes for all current objects)
Slider to change the ball weight/size/mass (local and exclusive)
Back on track.
This was fun because I’ve never done anything of the sort, so here’s a bit of what I wrote:
PX_PER_M = 100 # scale factor from real-world m/s^2 to our pixel-space gravityEARTH_GRAVITY = 9.8 * PX_PER_MPLANET_GRAVITY_MS2 = { “mercury”: 3.7, “venus”: 8.87, “earth”: 9.8, “moon”: 1.62, “mars”: 3.71, “jupiter”: 24.79, “saturn”: 10.44, “uranus”: 8.69, “neptune”: 11.15, “pluto”: 0.62,}RESTITUTION = 0.8 # energy kept on bounceMAX_BALLS = 8BASE_RADIUS = 15RADIUS_PER_MASS = 5
(i’ll add screenshots so the text is clearer)
class Ball:
def init(self, x, y, vx=0.0, vy=0.0, mass=1.0):
self.x = x
self.y = y
self.vx = vx
self.vy = vy
self.mass = mass
self.radius = BASE_RADIUS + RADIUS_PER_MASS * mass
def state(self):
return {"x": self.x, "y": self.y, "radius": self.radius, "mass": self.mass}
class World:
def init(self, width, height, gravity=EARTH_GRAVITY):
self.width = width
self.height = height
self.gravity = gravity
self.balls = [Ball(x=width / 2, y=height / 4)]
def set_gravity(self, gravity):
self.gravity = gravity
def launch(self, x, y, vx, vy, mass=1.0):
if len(self.balls) >= MAX_BALLS:
self.balls.pop(0)
self.balls.append(Ball(x=x, y=y, vx=vx, vy=vy, mass=mass))
def step(self, dt):
for ball in self.balls:
ball.vy += self.gravity * dt
ball.x += ball.vx * dt
ball.y += ball.vy * dt
floor = self.height - ball.radius
ceiling = ball.radius
if ball.y > floor:
ball.y = floor
ball.vy = -ball.vy * RESTITUTION
elif ball.y < ceiling:
ball.y = ceiling
ball.vy = -ball.vy * RESTITUTION
left = ball.radius
right = self.width - ball.radius
if ball.x < left:
ball.x = left
ball.vx = -ball.vx * RESTITUTION
elif ball.x > right:
ball.x = right
ball.vx = -ball.vx * RESTITUTION
self.resolve_collisions()
What I plan to do:
Add different shapes (not really important tho)
add backgrounds
add labels for the details of each ball whcih will bleed into making the gravitas exclusive as well.
Let me know if you have any ideas!
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.