Does anybody know how I can upload a .py file onto newgrounds? This is the code I'm trying to convert into an HTML5 file for it to be playable on here.
# Simple Pong
# Code by @TokyoEdTech
#Note: This project is designed for beginners. There will be NO
#Object Oriented Programming or Classes
#TEST YOUR CODE OFTEN!!! DON'T SAVE TESING AT THE VERY END!!!!
# turtle module lets you do graphics in your projects
import turtle
# os module lets you interact through text commands
import os
#for windows, it's import winsound
#Creating the window
wn = turtle.Screen() #The capitalizition of "S" is important
wn.title("Pong by @TokyoEdTech")
wn.bgcolor("black")
wn.setup(width=800, height=600)
wn.tracer(0) #This stops the window from updating
#Score
score_a = 0
score_b = 0
#Paddle A
paddle_a = turtle.Turtle() #[module].[Object](), it's CaSe SeNsItIvE
paddle_a.speed(0) #speed of animation, 0 sets it to maximum speed
paddle_a.shape("square")
paddle_a.color("white")
paddle_a.shapesize(stretch_wid=5, stretch_len=1)
paddle_a.penup()
paddle_a.goto(-350, 0) #(0,0) refers to the center of the window
#Paddle B, same as paddle A, just in a different spot
paddle_b = turtle.Turtle() #[module].[Object](), it's CaSe SeNsItIvE
paddle_b.speed(0) #speed of animation, 0 sets it to maximum speed
paddle_b.shape("square")
paddle_b.color("white")
paddle_b.shapesize(stretch_wid=5, stretch_len=1)
paddle_b.penup()
paddle_b.goto(350, 0) #(0,0) refers to the center of the window
#Ball
ball = turtle.Turtle() #[module].[Object](), it's CaSe SeNsItIvE
ball.speed(0) #speed of animation, 0 sets it to maximum speed
ball.shape("square")
ball.color("white")
#paddle_b.shapesize(stretch_wid=5, stretch_len=1)
ball.penup()
ball.goto(0, 0) #(0,0) refers to the center of the window
#moving the ball
ball.dx = 2 #every time the ball moves, it moves by 2 pixels
ball.dy = -2
# Pen
pen = turtle.Turtle() #[module].[Object](), it's CaSe SeNsItIvE
pen.speed(0) #animation speed
pen.color("white")
pen.penup()
pen.hideturtle() #so we don't see it, we only want the text
pen.goto(0, 260)
pen.write("Alayer A: 0 Player B: 0", align="center", font=("Courier", 24, "normal"))
#Function
def paddle_a_up():
y = paddle_a.ycor() #ycor comes from the turtle module
y += 20
paddle_a.sety(y)
def paddle_a_down():
y = paddle_a.ycor() #ycor comes from the turtle module
y -= 20
paddle_a.sety(y)
def paddle_b_up():
y = paddle_b.ycor() #ycor comes from the turtle module
y += 20
paddle_b.sety(y)
def paddle_b_down():
y = paddle_b.ycor() #ycor comes from the turtle module
y -= 20
paddle_b.sety(y)
#Keyboard binding
wn.listen() #listen to keyboard inputs
#moving paddle a
wn.onkeypress(paddle_a_up, "w") #Only respsonds to w, not W
wn.onkeypress(paddle_a_down, "s") #Only respsonds to s, not S
#moving paddle b
wn.onkeypress(paddle_b_up, "Up") #Only respsonds to up arrow
wn.onkeypress(paddle_b_down, "Down") #Only respsonds to down arrow
#Main game loop
while True:
wn.update()
# Move the ball
ball.setx(ball.xcor() + ball.dx)
ball.sety(ball.ycor() + ball.dy)
#Border checking
#y coordinates
if ball.ycor() > 290:
ball.sety(290)
ball.dy *= -1
#For Mac, it is afplay. For Linux, it is aplay
os.system("afplay bounce.wav&") #"&" cuts out the delay
#for windows, it's winsound.PlaySound("bounce.wav", winsound.SND_ASYNC)
if ball.ycor() < -290:
ball.sety(-290)
ball.dy *= -1
#For Mac, it is afplay. For Linux, it is aplay
os.system("afplay bounce.wav&") #"&" cuts out the delay
#for windows, it's winsound.PlaySound("bounce.wav", winsound.SND_ASYNC)
#x coordinates
if ball.xcor() > 390: #Right side of screen
ball.goto(0,0) #All coordinates with the .goto function should be in (x,y) format
ball.dx *= -1
score_a += 1
#updates score
pen.clear()
pen.write("Alayer A: {} Player B: {}".format(score_a, score_b), align="center", font=("Courier", 24, "normal"))
if ball.xcor() < -390: #Left side of screen
ball.goto(0,0) #All coordinates with the .goto function should be in (x,y) format
ball.dx *= -1
score_b += 1
#updates score
pen.clear()
pen.write("Alayer A: {} Player B: {}".format(score_a, score_b), align="center", font=("Courier", 24, "normal"))
# Paddle and ball collisions
if (ball.xcor() > 340 and ball.xcor() < 350) and (ball.ycor() < paddle_b.ycor() + 40 and ball.ycor() > paddle_b.ycor() - 40):
ball.setx(340)
ball.dx *= -1
#For Mac, it is afplay. For Linux, it is aplay
os.system("afplay bounce.wav&") #"&" cuts out the delay
#for windows, it's winsound.PlaySound("bounce.wav", winsound.SND_ASYNC)
if (ball.xcor() < -340 and ball.xcor() > -350) and (ball.ycor() < paddle_a.ycor() + 40 and ball.ycor() > paddle_a.ycor() - 40):
ball.setx(-340)
ball.dx *= -1
#For Mac, it is afplay. For Linux, it is aplay
os.system("afplay bounce.wav&") #"&" cuts out the delay
#for windows, it's winsound.PlaySound("bounce.wav", winsound.SND_ASYNC)