Alterna · учебный материал

Python Games: Worlds on Canvas

Chapter 44 Alterna: Playing mechanics, worlds and creative studio Python Games with a browser Canvas shell of a common API.

Что в этом материале

Содержание и основные понятия

This chapter doesn't call itself pygame. Python sets the stage through a limited Canvas shell of the common API, and the browser honestly draws the result in
canvas
Mechanics and events are taken as a separate model, not assigned to another library.
design
Grade 8-11
Canvas shell
01
Headway
Three pages and a studio form a creative route without a workshop, an examination or a test site.
44.1 · traffic
Playing mechanics
Time frame, coordinates, speed, collision, and a clear order of renewal.
44.2 Space
Worlds and levels
Grid, points of interest, obstacles and seeds as a compact description of the reproducible world.
44.3 Creative environment
Python Game Studio
Run Python teams and get a run-by Canvas-world with real keys and game target.
02
Who's responsible for what
Python teams
They're describing the scene.
canvas.rect
,
canvas.circle
and
canvas.text
Python does not draw pixels himself.
Canvas shell
Draws Commands
The browser only receives verified coordinates, colours and dimensions, and then goes consecutively to the present Canvas.
Mechanical
Lives in a model
The time frame, input, and impact are dealt with separately on this chapter. The studio scene does not pretend to be an outside game engine.
Honest APl
This is not an implementation or a copy of the pygame. It is a small Canvas shell of the Common API that is available in the studio:
size
,
clear
,
rect
,
circle
,
line
and
text
.
03
Alt patrol: obstacles and feasibility
The patrol is moving through the cells. Try to run into an obstacle, and then ask the algorithm to show you the shortest feasible route.
ALT · PATROL
Is the signal reaching the lighthouse?
patrol
Lighthouse
obstacle
route
Control the arrows on the panel or the keys while he sees the focus.
04
Open-code game cycle
Start the setup, collect the stars, then change the speed, coordinates, or condition of the collection. The result is not separated from the cause: Python stays close to the Canvas game and is completely edited.
The game studio is downloading...
Three functions of one cycle
init()
Creates a fortune,
update(state, event, dt)
processes input and changes data,
draw(canvas, state)
If you remove the change in coordinates from
update
the drawing stays, but the game will stop responding to the control.

Structural map of textbooks