This is the first time I am using Pygame. And I am just starting to learn programming. At the moment I learning for about 4 to 7 months.
I followed the tutorial for the game I am making. (How to Program a Game! (in Python) by Keith Galli)
Unfortenately the colors will not be displayed in the game. So at the moment I am just staring at a black 'box'.
The game is a kind of 'space invaders'-game. So there are blue bricks falling from the top of the 'box', but at the moment you don see them.
Because I am jusing Linux Mint as my OS, I thought: mayby I need other code for the colours.
I tried ANSI code:
# ANSI escae code for colours:
#RED = "\e[0;31m"
#BLUE = "\e[34mBlue"
#YELLOW= "\e[33mYellow"
#BACKGROUND_COLOUR = "\e[30m"
instead of RGB:
# RGB colours:
RED = (255, 0, 0))
BLUE = (0, 0, 255))
YELLOW= (204, 204, 0)
BACKGROUND_COLOUR = (0, 0, 0))
But I stil do not see anything when I run the game :(
Here is some code:
import pygame
import random
import sys
import colorama
pygame.init()
WIDTH = 800
HEIGHT = 600
# ANSI escae code for colours:
#RED = "\e[0;31m"
#BLUE = "\e[34mBlue"
#YELLOW= "\e[33mYellow"
#BACKGROUND_COLOUR = "\e[30m"
# RGB colours:
RED = (255, 0, 0))
BLUE = (0, 0, 255))
YELLOW= (204, 204, 0)
BACKGROUND_COLOUR = (0, 0, 0))
player_size = 50
player_pos = [WIDTH/2, HEIGHT - 2 * player_size]
enemy_size = 50
enemy_pos = [random.randint(0, WIDTH - enemy_size), 0]
enemy_list = [enemy_pos]
SPEED = 10
screen = pygame.display.set_mode((WIDTH,HEIGHT))
# gameloop
game_over = False
score = 0
clock = pygame.time.Clock()
myFont = pygame.font.sysFont("monospace", 35)
def set_level(score,SPEED):
if score < 20:
SPEED = 5
elif score < 40:
SPEED = 8
elif score < 60:
SPEED = 12
else:
SPEED = 18
return SPEED
# SPEED = score / 5 +1
# return SPEED
def drop_enemies(enemy_list):
delay = random.random()
if len(enemy_list) < 10 and delay < 0.1:
x_pos = random.randint(0, WIDTH - enemy_size)
y_pos = 0
enemy_list.append([x_pos, y_pos])
def draw_enemies(enemy_list):
for enemy_pos in enemy_list:
pygame.draw.rect(screen, BLUE, (enemy_pos[0], enemy_pos[1],
enemy_size, enemy_size))
I hope to see the bricks in the game. Whick colorcoding to use... and how to implement these?
Blue for the ones falling from the sky, red for the player itself.