Volume6 - Events, Callback Function

found at Gitbook editor, in other :

CodeCraft with Python Volume ii

buzz coder campus

====start

Volume 6: Events, Keyboard Control

In some popular 3D world crafting game, the player has some tools to use such as pickaxes, showels, so the players can dig through dirt, gravel, sand and chop wood blocks. Never mind the fancy names, to achieve different tasks, either putting up a block or chop away a block, basically the player just use a simple click of the mouse.

In CodeCraft, let's realize all the above functions and make that happen: by clicking the mouse or a key, we can put up a block or delete it, and we can do much more: such as putting up a column, a huge cube, a fancy flower or a growing seedling...

We will do all the programming work behind the scene, we define how things work responding to the mouse or keys' click, and touch some advance topic in Python, callback functions.

Contents:

28- Callback Function 29-Event, On_mouse_click 30 - Keyboard Control

====end intro

Game class defined some object methods we can use to program some similar tools, such as digging tools:

digger: delete a block by mouse click; shovel: digs faster, 2 blocks dissapear on each click

shovel: dig faster, delete two blocks at one mouse click

axe: chops wood faster (on each click, 2 wood blocks disppear)

Building tools: put_brick: put a brick block at mouse_click

put_wall: put up a 3*3 brick wall at mouse_click put_cube: put_many_things: flower, hollowCube, stairs..., about any structure that you defined as a function.

farming tool: hoe: hoe: turn grass block into to dirt (farmland) ((if mouse_position is solid/grass??, put_dirt; else, do nothing

put_flower: put_flower on mouse_click; plant_flower: put_seed(timer, later grow into a flower; plant_tree(timer, grow into bigger tree;

plant_grain: dirt land, timer, dirt bumps, shift away, brown columns grow and three green block on top

TNT(idea)

if click on TNT block: TNT turn red/black/red, bigger red(3*3)/yellow/red/black, a big hole

results matching ""

    No results matching ""