kmklnkjlkjkl.py
Created by
wperez274
Created on
September 24, 2023
3.64 KB
from ion import *
from kandinsky import *
from random import randint
from time import sleep
WIDTH = 320
HEIGHT = 240
PLATFORM_COLOR = color ( 0 , 255 , 0 )
CRITT_COLOR = color ( 0 , 0 , 0 )
EYE_COLOR = color ( 255 , 0 , 0 )
BULLET_COLOR = color ( 0 , 0 , 255 )
PLATFORM_WIDTH = 40
PLATFORM_HEIGHT = 10
PLATFORM1_X = 100
PLATFORM1_Y = 100
PLATFORM2_X = 150
PLATFORM2_Y = 40
CRITT_WIDTH = 12
CRITT_HEIGHT = 16
critt1_x = randint ( PLATFORM1_X , PLATFORM1_X + PLATFORM_WIDTH - CRITT_WIDTH )
critt1_y = PLATFORM1_Y - CRITT_HEIGHT
critt1_direction = 1
critt2_x = randint ( PLATFORM2_X , PLATFORM2_X + PLATFORM_WIDTH - CRITT_WIDTH )
critt2_y = PLATFORM2_Y - CRITT_HEIGHT
critt2_direction = 1
player_x = 20
player_y = 200
player_width = 14
player_height = 22
player_velocity_y = 0
player_jumps = 3
bullets = []
while True :
FILL ( 0 , 0 , WIDTH , HEIGHT , color ( 255 , 255 , 255 ))
FILL ( PLATFORM1_X , PLATFORM1_Y , PLATFORM_WIDTH , PLATFORM_HEIGHT , PLATFORM_COLOR )
FILL ( PLATFORM2_X , PLATFORM2_Y , PLATFORM_WIDTH , PLATFORM_HEIGHT , PLATFORM_COLOR )
FILL ( critt1_x , critt1_y , CRITT_WIDTH , CRITT_HEIGHT , CRITT_COLOR )
FILL ( critt1_x + 2 , critt1_y + 2 , 4 , 4 , EYE_COLOR )
FILL ( critt1_x + 6 , critt1_y + 2 , 4 , 4 , EYE_COLOR )
FILL ( critt2_x , critt2_y , CRITT_WIDTH , CRITT_HEIGHT , CRITT_COLOR )
FILL ( critt2_x + 2 , critt2_y + 2 , 4 , 4 , EYE_COLOR )
FILL ( critt2_x + 6 , critt2_y + 2 , 4 , 4 , EYE_COLOR )
FILL ( player_x , player_y , player_width , player_height , color ( 0 , 0 , 255 ))
for bullet in bullets :
bullet_x , bullet_y , bullet_direction = bullet
FILL ( bullet_x , bullet_y , 4 , 4 , BULLET_COLOR )
critt1_x += critt1_direction * randint ( 1 , 5 )
critt2_x += critt2_direction * randint ( 1 , 5 )
if critt1_x < PLATFORM1_X or critt1_x + CRITT_WIDTH > PLATFORM1_X + PLATFORM_WIDTH :
critt1_direction *= - 1
if critt2_x < PLATFORM2_X or critt2_x + CRITT_WIDTH > PLATFORM2_X + PLATFORM_WIDTH :
critt2_direction *= - 1
if player_x < 0 :
player_x = 0
if player_x + player_width > WIDTH :
player_x = WIDTH - player_width
if player_y >= HEIGHT - player_height :
player_y = HEIGHT - player_height
player_velocity_y = 0
player_jumps = 3
player_velocity_y += 1
player_y += player_velocity_y
if keydown ( KEY_UP ) and player_jumps > 0 :
player_velocity_y = - 12
player_jumps -= 1
new_bullets = []
for bullet in bullets :
bullet_x , bullet_y , bullet_direction = bullet
bullet_x += bullet_direction * 5
if 0 <= bullet_x <= WIDTH :
new_bullets . append (( bullet_x , bullet_y , bullet_direction ))
bullets = new_bullets
if keydown ( KEY_OK ):
bullet_direction = 1
bullet_x = player_x + player_width
bullet_y = player_y + player_height // 2
bullets . append (( bullet_x , bullet_y , bullet_direction ))
if ( player_x < critt1_x + CRITT_WIDTH and player_x + player_width > critt1_x and
player_y < critt1_y + CRITT_HEIGHT and player_y + player_height > critt1_y ):
FILL ( 0 , 0 , WIDTH , HEIGHT , color ( 0 , 0 , 0 ))
sleep ( 1 )
FILL ( 0 , 0 , WIDTH , HEIGHT , color ( 255 , 255 , 255 ))
critt1_x = randint ( PLATFORM1_X , PLATFORM1_X + PLATFORM_WIDTH - CRITT_WIDTH )
critt1_y = PLATFORM1_Y - CRITT_HEIGHT
if ( player_x < critt2_x + CRITT_WIDTH and player_x + player_width > critt2_x and
player_y < critt2_y + CRITT_HEIGHT and player_y + player_height > critt2_y ):
FILL ( 0 , 0 , WIDTH , HEIGHT , color ( 0 , 0 , 0 ))
sleep ( 1 )
FILL ( 0 , 0 , WIDTH , HEIGHT , color ( 255 , 255 , 255 ))
critt2_x = randint ( PLATFORM2_X , PLATFORM2_X + PLATFORM_WIDTH - CRITT_WIDTH )
critt2_y = PLATFORM2_Y - CRITT_HEIGHT
sleep ( 0.05 )