Answer the question
In order to leave comments, you need to log in
What is the difference between handwritten code and pasted code?
I welcome everyone! I immediately apologize for a possibly stupid question, but I do not understand what is going wrong.
And so, watching a couple of videos on YouTube, I write code by analogy as the author of the video does, in the intermediate result he launches the program and it works in his video, but mine throws an error.
Having opened a new Python script in the second window, I pasted part of his code, which he will post on github - as a result, it works. And mine is exactly the same, which I wrote with my hands, throws an error.
What's the real deal?
import pygame as pg
import pymunk.pygame_util
pymunk.pygame_util.positive_y_is_up = False
DISP = WIDTH, HEIGHT = 600, 600
FPS = 60
pg.init()
display = pg.display.set_mode(DISP)
clock = pg.time.Clock()
draw_options = pymunk.pygame_util.DrawOptions(display)
# Пространство
space = pymunk.Space
space.gravity = 0, 2000
# Динамический объект мяч
ball_mass = 1
ball_radius = 20
ball_moment = pymunk.moment_for_circle(ball_mass, 0, ball_radius)
ball_body = pymunk.Body(ball_mass, ball_moment)
ball_body.position = WIDTH // 2, 0
ball_snape = pymunk.Circle(ball_body, ball_radius)
space.add(ball_body, ball_snape)
while True:
display.fill(pg.Color('black'))
for i in pg.event.get():
if i.type == pg.QUIT:
exit()
space.step(1 / FPS)
space.debug_draw(draw_options)
pg.display.flip()
clock.tick(FPS)
import pygame as pg
import pymunk.pygame_util
pymunk.pygame_util.positive_y_is_up = False
RES = WIDTH, HEIGHT = 1200, 1000
FPS = 60
pg.init()
surface = pg.display.set_mode(RES)
clock = pg.time.Clock()
draw_options = pymunk.pygame_util.DrawOptions(surface)
space = pymunk.Space()
space.gravity = 0, 8000
ball_mass = 1
ball_radius = 20
ball_moment = pymunk.moment_for_circle(ball_mass, 0, ball_radius)
ball_body = pymunk.Body(ball_mass, ball_moment)
ball_body.position = WIDTH // 2, 0
ball_snape = pymunk.Circle(ball_body, ball_radius)
space.add(ball_body, ball_snape)
while True:
surface.fill(pg.Color('black'))
for i in pg.event.get():
if i.type == pg.QUIT:
exit()
space.step(1 / FPS)
space.debug_draw(draw_options)
pg.display.flip()
clock.tick(FPS)
Answer the question
In order to leave comments, you need to log in
Try creating a new project, and copy your code (that you wrote by hand) and paste it into the new project
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question