from math import * from random import choice from kandinsky import fill_rect as F from ion import keydown as KP from ion import KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_OK from time import sleep SW, SH = 320, 220 GAME_OVER = False red = (255, 0, 0) black = (0, 0, 0) white = (255, 255, 255) blue = (0, 0, 255) bg = (110, 18, 23) x, y, w, h, c = 220, 200, 12, 20, (0, 0, 100) bullets = [] critter_x, critter_y, critter_w, critter_h = 200, 200, 10, 10 area = 0 move_direction = choice([-1, 1]) level_1 = [ [[0, 208, 78, 14, (176, 157, 217)], [0, 199, 14, 8, (144, 46, 229)], [126, 200, 32, 22, (51, 18, 23)], [177, 209, 10, 12, (39, 41, 41)]], [[0, 64, 148, 170, black], [105, 127, 114, 136, black], [162, 181, 28, 40, black], [30, 43, 28, 28, black], [51, 25, 54, 64, black], [37, 184, 42, 40, (189, 25, 51)], [13, 100, 24, 28, (45, 138, 186)]], [[75, 178, 154, 44, 'black'], [99, 145, 110, 44, 'black'], [114, 145, 86, 64, 'red'], [236, 85, 86, 64, 'red'], [50, 16, 22, 32, (153, 126, 88)]], [[40, 176, 50, 46, black], [168, 134, 154, 88, black], [202, 86, 120, 88, black], [246, 44, 76, 88, black], [90, 206, 76, 16, red]] ] def refresh_level(): F(0, 0, SW, SH, bg) for i in level_1[area]: F(*i) refresh_level() while not GAME_OVER: F(x, y, w, h, c) F(x + 3, y + 3, 4, 3, white) F(x + 9, y + 3, 4, 3, white) F(critter_x, critter_y, critter_w, critter_h, black) F(critter_x + 2, critter_y + 2, 2, 2, red) F(critter_x + 6, critter_y + 2, 2, 2, red) if move_direction == -1: F(critter_x + critter_w + 1, critter_y, 1, critter_h, bg) else: F(critter_x - 1, critter_y, 1, critter_h, bg) critter_x += move_direction if critter_x <= 0 or critter_x >= 310: move_direction *= -1 for bx, by, dx, dy in bullets: draw_rect(bx, by, 3, 3, blue) F(bx + 1, by + 1, 1, 1, white) if KP(KEY_LEFT): x -= 1 F(x + w + 1, y, 1, h, bg) if KP(KEY_RIGHT): x += 1 F(x - 1, y, 1, h, bg) if KP(KEY_OK): dx = 0 if critter_x < x: dx = -1 elif critter_x > x: dx = 1 bullets.append([x, y, dx, 0]) if KP(KEY_OK) and KP(KEY_UP): bullets.append([x, y, 0, -1]) bullets = [[bx + dx, by + dy, dx, dy] for bx, by, dx, dy in bullets if 0 <= bx < SW and 0 <= by < SH] sleep(0.05) refresh_level()