Difference between revisions of "IB Computer Science 1"

From WLCS
Line 1: Line 1:
 +
== Monday (10/21/13) ==
 +
'''Agenda:'''
 +
<syntaxhighlight lang="Python">
 +
import sys, pygame
 +
pygame.init()
 +
 +
width = 600
 +
height = 400
 +
dx = 1
 +
dy = 1
 +
black = 0, 0, 0
 +
 +
screen = pygame.display.set_mode((width, height))
 +
 +
ball = pygame.image.load("ball.gif")
 +
ballrect = ball.get_rect()
 +
 +
while True:
 +
    for event in pygame.event.get():
 +
        if event.type == pygame.QUIT:
 +
            sys.exit()
 +
 +
    ballrect = ballrect.move((dx,dy))
 +
   
 +
    if ballrect.left < 0 or ballrect.right > width:
 +
        dx *= -1
 +
    if ballrect.top < 0 or ballrect.bottom > height:
 +
        dy *= -1
 +
 +
    screen.fill(black)
 +
    screen.blit(ball, ballrect)
 +
    pygame.display.flip()
 +
</syntaxhighlight>
 +
 +
* Pygame walk-through and notes
 +
* Comment each line of code from the [http://www.pygame.org/docs/tut/intro/intro.html Pygame Tutorial]
 +
** You comment should be a note of what that line is doing
 +
* [http://www.pygame.org/docs/ Pygame Documentation]
 +
* Keyboard events in Pygame
 +
* Basic Game Play ("dodge the ball" w/ 2 players)
 +
*# Create 3 images and rectangles for 2 players and a ball
 +
*# Have one player controlled by arrow keys
 +
*# Have the other player controlled by W-A-S-D
 +
*# Add a third ball that bounces around the screen
 +
*# Check if either player rectangle collides with the ball rectangle...then...
 +
 
== Thursday - Friday (10/17/13 - 10/18/13) ==
 
== Thursday - Friday (10/17/13 - 10/18/13) ==
 
'''Agenda:'''
 
'''Agenda:'''

Revision as of 13:37, 21 October 2013

Monday (10/21/13)

Agenda:

import sys, pygame
pygame.init()

width = 600
height = 400
dx = 1
dy = 1
black = 0, 0, 0

screen = pygame.display.set_mode((width, height))
 
ball = pygame.image.load("ball.gif")
ballrect = ball.get_rect()

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()

    ballrect = ballrect.move((dx,dy))
    
    if ballrect.left < 0 or ballrect.right > width:
        dx *= -1
    if ballrect.top < 0 or ballrect.bottom > height:
        dy *= -1

    screen.fill(black)
    screen.blit(ball, ballrect)
    pygame.display.flip()
  • Pygame walk-through and notes
  • Comment each line of code from the Pygame Tutorial
    • You comment should be a note of what that line is doing
  • Pygame Documentation
  • Keyboard events in Pygame
  • Basic Game Play ("dodge the ball" w/ 2 players)
    1. Create 3 images and rectangles for 2 players and a ball
    2. Have one player controlled by arrow keys
    3. Have the other player controlled by W-A-S-D
    4. Add a third ball that bounces around the screen
    5. Check if either player rectangle collides with the ball rectangle...then...

Thursday - Friday (10/17/13 - 10/18/13)

Agenda:

Tuesday - Wednesday (10/15/13 - 10/16/13)

Agenda:

Thursday - Friday (10/10/13 - 10/11/13)

Friday - Wednesday (10/4/13 - 10/9/13)

Warmup:

  • Execute the code below
  • When prompted, use 100 for x and 200 for y
  • What does each line do? Analyze!
from turtle import *

setup(200, 400)
screensize(200, 400)
x = numinput("X prompt", "Please enter an x")
y = numinput("Y prompt", "Please enter a y")
goto(x,y)
exitonclick()

Agenda:

Wednesday - Thursday (10/2/13 - 10/3/13)

Agenda:

Tuesday (10/1/13)

Archives