So far in computing we have learnt how to use scratch and I have been learning how to use python for two weeks.
I have used three programs when I was making my code: Tinker, Python IDLE and code combat.
I understand the Python is a language and I know if something goes wrong I can try my hardest to find out what is not working and solve the problem. I understand that Python is very precis about it's instructions so I have to work very carefully when setting up the script so there is no mistakes.
I have learnt how to make a python IDLE template,set up game loops,sprites and how to set up the window.
Here is my example of how to set up the window the line with hashtags are telling you what s happening they have no effect with the script:
#start pygame
import pygame
import random
#2. setting up window (FPS=Frames per second)
WIDTH = 360
HEIGHT = 480
FPS = 30
#intalize pygame and create window
pygame.init()
#To make sounds
pygame.mixer.init()
#Screen display
screen = pygame.display.set_mode((WIDTH, HEIGHT))
#Name and the clock (the clock is to keep the game running at the right speed)
pygame.display.set_caption("Joel's Game")
clock = pygame.time.Clock()
Here is my example on how set up the colors
#3 define a few useful colors (used to color in the background and sprites)
WHITE=(255, 255, 255)
BLACK=(0, 0, 0)
RED=(255, 0, 0)
GREEN=(0, 255, 0)
BLUE=(0, 0, 255)
Here is my example on how set up sprites for the player
#Creating the sprite for the player (setting up the player)
class Player(pygame.sprite.Sprite):
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, HEIGHT / 2)
def update(self):
self.rect.x += 5
if self.rect.left > WIDTH:
self.rect.right = 0
# Creating Sprites
all_sprites = pygame.sprite.Group()
player = Player()
all_sprites.add(player)
And last of all my example on how to set up a game loop
#game loop
running = True
while running:
#keeps game loop running at right speed
clock.tick(FPS)
# processes input (events)
for event in pygame.event.get():
#check for closing window
if event.type == pygame.QUIT:
running = False
# Update
all_sprites.update()
#draw and render the screen
screen.fill(BLACK)
all_sprites.draw(screen)
#always do after the Draw and render screen
pygame.display.flip()
# So you can quit the game
pygame.quit()
All of that is what I made for the first time I used Python IDLE.
I managed to make this game with few mistakes that I fixed very quickly so when I finished the session the game was working.I managed to make this script with miss Chowfins help in class