Monday, 15 May 2017

problem solving with python #year 9 tech blog

over the last 2 weeks we have been working with python as a language and i'm learning to use  the computer language to design a game by writing code. we have been using three diffrent platforms to design our games

setting up the game in python idle window has been a step by step process we put in the code in order if we get it wrong then it doesn't work so it has to be right



# start game
import pygame
import random

#create a window

WIDTH = 360
HIGHT = 480
FPS = 30

# define a few useful colours

WHITE = (255,255,255)
BLACK =(0,0,0)
GREEN =(0,255,0)
RED =(255,0,0)
BLUE =(0,0,255)
CYAN =(0,255,255)

class player(pygame.sprite.Sprite):
    # sprite for player
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image= pygame.surface(50,50)
        self.image.fill(GREEN)
        self.rect= self.image.get_rect()
        self.rect.center = (WIDTH / 2,HIGHT / 2)

        def update(self):
            self.rect.x += 5
            if self.rect.left > WIDTH:
               self.rect.right = 0
            
        
# initialise pygame and create window
pygame.init()
pygame.mixer()
screen=pygame.display.set_mode(width,hieght)
pygame.display.set_caption("my game")
CLOCK = pygame.time.clock()

# creating sprites
all_sprites = pygame.sprite.group()

#game loop
running = true
while runnig:
# keep loop running a the right speed
 clock.ticks(FPS)
# process input (events)
 for event in pygame.event.get():
     # check for closing window
      if event.type == pygame.QUIT:
            running = false

# update

# draw /render
screen.fill(BLACK)
# after drawing every thing flip the display
pygame.display.flip()

pygame.quit()

i managed to write this code following a video and ms chowfin
explanied the reason of the code along the way i found a error and i couldnt fix it

No comments:

Post a Comment