Question

without using PYGAME design a basic game with python name Frogger or single player pong. maybe...

without using PYGAME design a basic game with python name Frogger or single player pong. maybe use turtle.

DO NOT USE PYGAME... no pygame.. please.. i really need your help

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Try the below code hope it solves your query.

import simplegui

import random


WIDTH = 600
HEIGHT = 400   
BALL_RADIUS = 20
PAD_WIDTH = 8
PAD_HEIGHT = 80
HALF_PAD_WIDTH = PAD_WIDTH / 2
HALF_PAD_HEIGHT = PAD_HEIGHT / 2

def ball_init(right):
global ball_pos, ball_vel
  
ball_pos,ball_vel= [0, 0], [0, 0]

if right == True:
ball_pos = [WIDTH / 2, HEIGHT / 2]
ball_vel = [random.randrange(2, 4), -random.randrange(1, 3)]
if right == False:
ball_pos = [WIDTH / 2, HEIGHT / 2]
ball_vel = [-random.randrange(2, 4), -random.randrange(1, 3)]

def new_game():
global paddle1_pos, paddle2_pos, paddle1_vel, paddle2_vel
global score1, score2
global score1_string, score2_string
score1_string = "0"
score2_string = "0"
  
paddle1_pos = [PAD_WIDTH / 2, HEIGHT / 2]
paddle2_pos = [WIDTH - PAD_WIDTH / 2, HEIGHT / 2]
paddle1_vel, paddle2_vel, score1, score2 = 0, 0, 0, 0
ball_init(True)


def limit():
global paddle1_pos, paddle2_pos, paddle1_vel, paddle2_vel

if paddle1_pos[1] < HALF_PAD_HEIGHT:
paddle1_pos[1] = HALF_PAD_HEIGHT
paddle1_vel = 0
elif paddle1_pos[1] > HEIGHT - HALF_PAD_HEIGHT:
paddle1_pos[1] = HEIGHT - HALF_PAD_HEIGHT
paddle1_vel = 0

if paddle2_pos[1] < HALF_PAD_HEIGHT:
paddle2_pos[1] = HALF_PAD_HEIGHT
paddle2_vel = 0
elif paddle2_pos[1] > HEIGHT - HALF_PAD_HEIGHT:
paddle2_pos[1] = HEIGHT - HALF_PAD_HEIGHT
paddle2_vel = 0

  
def draw(c):
global score1, score2, paddle1_pos, paddle2_pos, ball_pos, ball_vel
global score1_string, score2_string

limit()
paddle1_pos[1] += paddle1_vel
paddle2_pos[1] += paddle2_vel
  

c.draw_line([WIDTH / 2, 0],[WIDTH / 2, HEIGHT], 1, "White")
c.draw_line([PAD_WIDTH, 0],[PAD_WIDTH, HEIGHT], 1, "White")
c.draw_line([WIDTH - PAD_WIDTH, 0],[WIDTH - PAD_WIDTH, HEIGHT], 1, "White")
  
pad1top = [paddle1_pos[0], paddle1_pos[1] - HALF_PAD_HEIGHT]
pad1bot = [paddle1_pos[0], paddle1_pos[1] + HALF_PAD_HEIGHT]
c.draw_line(pad1top, pad1bot, PAD_WIDTH, "White")

pad2top = [paddle2_pos[0], paddle2_pos[1] - HALF_PAD_HEIGHT]
pad2bot = [paddle2_pos[0], paddle2_pos[1] + HALF_PAD_HEIGHT]
c.draw_line(pad2top, pad2bot, PAD_WIDTH, "White")

ball_pos[0] += ball_vel[0]
ball_pos[1] += ball_vel[1]
  
if ball_pos[1] <= BALL_RADIUS:
ball_vel[1] = - ball_vel[1]
if ball_pos[1] > (HEIGHT - 1 - BALL_RADIUS):
ball_vel[1] = - ball_vel[1]
if ball_pos[0] <= PAD_WIDTH + BALL_RADIUS:
if ( pad1top[1] <= ball_pos[1] <= pad1bot[1] ):
ball_vel[0] = - ball_vel[0] * 1.1
else:
ball_init(1)
score2 += 1
score2_string = str(score2)
  

if ball_pos[0] >= WIDTH - PAD_WIDTH - BALL_RADIUS:
if ( pad2top[1] <= ball_pos[1] <= pad2bot[1] ):
ball_vel[0] = - ball_vel[0] * 1.1
else:
ball_init(0)
score1 += 1
score1_string = str(score1)

c.draw_circle(ball_pos, BALL_RADIUS, 1, "White", "White")
c.draw_text(score2_string, (450, 50), 36, "White")
c.draw_text(score1_string, (150, 50), 36, "White")

  
def keydown(key):
acc = 1
global paddle1_vel, paddle2_vel
if key==simplegui.KEY_MAP["s"]:
paddle1_vel += acc
if key==simplegui.KEY_MAP["down"]:
paddle2_vel += acc

def keyup(key):
acc = 1
global paddle1_vel, paddle2_vel
if key==simplegui.KEY_MAP["w"]:
paddle1_vel -= acc
if key==simplegui.KEY_MAP["up"]:
paddle2_vel -= acc

def restart():
new_game()

def exit():
window.stop()


window = simplegui.create_frame("Single Pong", WIDTH, HEIGHT)
window.set_draw_handler(draw)
window.set_keydown_handler(keydown)
window.set_keyup_handler(keyup)
window.add_button("Want to Play Again?? CLick ME", restart, 100)
window.add_button("Click to EXIT",exit,100)


window.start()
new_game()

Add a comment
Know the answer?
Add Answer to:
without using PYGAME design a basic game with python name Frogger or single player pong. maybe...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT