03 - Draw Player & Movment

03/03-js-canvas/03-js-drawMove.js

The code dislayed above is written in javascript, which performs the python code below by clicking on the cavas. Press "J" to go to js-canvas-lesson and get the script.

Draw & Move Player
import pygame
from pygame.locals import *
def drawBlock():
    surface.fill((255,255,255))
    surface.blit(block,(block_x,block_y))
    pygame.display.flip()
if __name__ == '__main__':
    pygame.init()
    surface = pygame.display.set_mode((500,400))
    surface.fill((255,255,255))
    block = pygame.image.load('images/block.jpg').convert()
    block_x = 100
    block_y = 100
    pygame.display.flip()

    running = True
    while running:
        for event in pygame.event.get():
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE or event.key == K_q:
                    running = False
                if event.key == K_DOWN or event.key == K_s:
                    block_y += 10
                if event.key == K_UP or event.key == K_w:
                    block_y -= 10
                if event.key == K_LEFT or event.key == K_a:
                    block_x -= 10
                if event.key == K_RIGHT or event.key == K_d:
                    block_x += 10
            if event.type == QUIT:
                running = False
        drawBlock()

02

This sections goes over