Re: [Tutor] Pong code

2018-02-14 Thread Alan Gauld via Tutor
On 14/02/18 23:22, terrapin-tur...@lycos.com wrote:
>
> Alan,
>
> I know NOTHING of this program.
>

So how did you find it?
What do you hope to do with it?

BTW You sent this to me only,. you need to use Reply-All
or Reply-List to include the tutor list. I've CCd the list in this response.

> Here is what I have:
>
> import pygame
> import sys
> import random
> pygame.init()
> gameSurface=pygame.display.set_mode((450,450))
> pygame.display.set_caption("Pong Player")
> pygame.mouse.set_visible(0)
>
> GREEN=(0,200,0)
> BLUE=(0,0,128)
> PURPLE=(102,0,102)
> WHITE=(255,255,255)
>
> rect1x=20
> rect1y=100
> rect2x=400
> rect2y=100
> gameSurface.fill(WHITE)
> pygame.draw.rect(gameSurface, GREEN,(rect1x, rect1y,30,150))
> pygame.draw.rect(gameSurface, GREEN,(rect2x, rect2y,30,150))
> ballx=random.randint(200,300)
> bally=random.randint(100,150)
> pygame.draw.circle(gameSurface, BLUE,(ballx, bally),20)
> pygame.display.update()
>

So this apparently draws two green rectangles and a ball at
a random location.

> FPS=20
> fpsClock=pygame.time.Clock()
>

This sets the frames per second timer to 20fps.
>
> pygame.key.set_repeat(1,1)
> if event.type==KEYDOWN:
> pygame.quit()
> sys.exit()
>

The previous two lines should be indented.
Indentation is critical in Python so you need to post
in plain text not HTML or RTF. Without the indentation
it gets difficult to tell what is going on.

But in this case it basically exits the program when
the KEYDOWN event is received. (Whatever KEYDOWN and
event meanĀ  in this context - I don't see them defined
anywhere.)

> if event.key==K_q:
> ballx=ballx+1
> pygame.draw.circle(gameSurface, WHITE,(ballx, bally),20)
> pygame.draw.circle(gameSurface, BLUE,(ballx, bally),20)
>

If q is pressed it draws another 2 balls. I have no idea why,
I never played pong...
>
> if event.key==K_LEFT:
> ballx=ballx-1
> pygame.draw.circle(gameSurface, WHITE,(oldballx, bally),20)
> pygame.draw.circle(gameSurface, BLUE,(ballx, bally),20)
> if ballx==70:
> pygame.draw.rect(gameSurface, PURPLE,(rect1x, rect1y,30,150))
> if ballx==380:
> pygame.draw.rect(gameSurface,PURPLE,(rect2x, rect2y,30,150))
>
More of the same kind of thing.

> pygame.display.update()
fpsClock.tic(FPS)
>
> pygame.display.update()
>

> What it means
>

Its a game using PyGame.
Have you read the PyGame tutorial?
If not I suggest you start there and then try asking questions
on the pyGame forum, because almost all the code is PyGame
specific rather than generic Python.

> Does this makes any sense to anyone? 

Sure, I'm sure a PyGame user would find it very straightforward.
You probably just need to do some research/reading.

But the big questions are:
- what is it supposed to do?
- What does it actually do?
- do you get any error messages? If so what?

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pong code

2018-02-14 Thread Alan Gauld via Tutor
On 13/02/18 13:41, terrapin-tur...@lycos.com wrote:
> Anyone know the pygame pong code and want to assist in a student learn
> where the mistakes in the code reside? 
> 
> Yes, reply to this mail.

That's not how it works.

You post a question and the code and any error messages
and we (collectively) try to help you.

It is a community tutor not one to one.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor