Apr-14-2019, 09:06 PM
So I am kind of new to pygame and python in general, and I am trying to make this basic game. But when I try to launch the game it just says there is an error and that it can't launch.
Here is the code:
I'd really appreciate some help. Thanks
Here is the code:
import pygame
import sys
import math
import random
import time
pygame.init
scrn_W = 1200
scrn_H = 500
screen = pygame.display.set_mode((scrn_W,scrn_H))
pygame.display.set_caption("TheGame")
pl_WIDTH = 50
pl_HEIGHT = 50
pl_x = 100
pl_y = 500 - pl_HEIGHT
vel = 10
color = (random.randint(1,255), random.randint(1,255), random.randint(1,255))
isJump = False
jumpCount = 10
obsVel = 5
obsX = scrn_W - obsW
obsY = scrn_H - obsH
run = True
while run:
pygame.time.delay(15)
obsXY = (obsX, obsY)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
if keys[pygame.K_RIGHT] and pl_x < scrn_W - pl_WIDTH:
pl_x += vel
if keys[pygame.K_LEFT] and pl_x > 0:
pl_x -= vel
if not(isJump):
#if keys[pygame.K_UP] and pl_y > 0:
# pl_y -= vel
#if keys[pygame.K_DOWN] and pl_y < scrn_H - pl_HEIGHT:
# pl_y += vel
if keys[pygame.K_SPACE]:
isJump = True
else:
if jumpCount >= -10:
pl_y -= (jumpCount * abs(jumpCount)) * 0.5
jumpCount -= 1
else:
isJump = False
jumpCount = 10
obsX = 0
if obsX <= 0:
obsVel *= 1.04
obsW = random.randint(1,100)
obsH = random.randint(1,100)
obsWH = (obsW, obsH)
obsX = scrn_W - obsW
obsY = scrn_H - obsH
colorOb = (random.randint(1,255), random.randint(1,255), random.randint(1,255))
pygame.draw.rect(screen, colorOb, (obsXY, obsWH), 0)
obsX -= obsVel
screen.fill((0,0,0))
pygame.draw.rect(screen, (255,0,0), (pl_x, pl_y, pl_WIDTH, pl_HEIGHT), 0)
pygame.display.update()
pygame.quit()The problem is supposedly in the "if obsX <= o:" if statement. I'd really appreciate some help. Thanks
