Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
What am I doing wrong?
Post Body

I'm trying to develop a game based on a raycaster engine. I used an engine for free from GitHub, but I think its from an older iteration of Python. I've already had to correct some syntax with my very limited knowledge of the language, but it's thrown up an error that I have no idea how to fix. Thanks for any help. Ive been learning like 3 days, though I have some understanding of coding through Scratch.

keys=[False]*324

# A map over the world

worldMap = [

[1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2],

[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2],

[2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],

[1, 0, 2, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 2, 3, 2, 3, 0, 0, 2],

[2, 0, 3, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],

[1, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2],

[2, 3, 1, 0, 0, 2, 0, 0, 0, 2, 3, 2, 0, 0, 0, 0, 0, 0, 0, 1],

[1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 2, 0, 0, 0, 2],

[2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 2, 1, 0, 0, 0, 1],

[1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 1, 0, 0, 0, 0, 0, 0, 0, 2],

[2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],

[1, 0, 2, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2],

[2, 0, 3, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 3, 2, 1, 2, 0, 1],

[1, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 2],

[2, 3, 1, 0, 0, 2, 0, 0, 2, 1, 3, 2, 0, 2, 0, 0, 3, 0, 3, 1],

[1, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 2, 0, 0, 2],

[2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 3, 0, 1, 2, 0, 1],

[1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 3, 0, 2],

[2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1],

[2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]]

# Closes the program

def close():

pygame.display.quit()

pygame.quit()

def main():

pygame.init()

# Head Up Display information (HUD)

font = pygame.font.SysFont('Verdana',20)

HUD = font.render("F1 / F2 - Screenshot JPEG/BMP F5/F6 - Shadows on/off F7/F8 - HUD Show/Hide", True, (0,0,0))

# Creates window

WIDTH = 1000

HEIGHT = 800

screen = pygame.display.set_mode((WIDTH, HEIGHT))

pygame.display.set_caption('PyRay - Python Raycasting Engine (v0.03)')

showShadow = True

showHUD = True

# Defines starting position and direction

positionX = 3.0

positionY = 7.0

directionX = 1.0

directionY = 0.0

planeX = 0.0

planeY = 0.5

# Movement constants

ROTATIONSPEED = 0.02

MOVESPEED = 0.03

# Trigeometric tuples variables for index

TGM = (math.cos(ROTATIONSPEED), math.sin(ROTATIONSPEED))

ITGM = (math.cos(-ROTATIONSPEED), math.sin(-ROTATIONSPEED))

COS, SIN = (0,1)

while True:

# Catches user input

# Sets keys[key] to True or False

for event in pygame.event.get():

if event.type == KEYDOWN:

if event.key == K_ESCAPE:

close()

return

keys[event.key] = True

elif event.type == KEYUP:

keys[event.key] = False

# Checks with keys are pressed by the user

# Uses if so that more than one button at a time can be pressed.

if keys[K_ESCAPE]:

close()

if keys[K_LEFT]:

oldDirectionX = directionX

directionX = directionX * ITGM[COS] - directionY * ITGM[SIN]

directionY = oldDirectionX * ITGM[SIN] directionY * ITGM[COS]

oldPlaneX = planeX

planeX = planeX * ITGM[COS] - planeY * ITGM[SIN]

planeY = oldPlaneX * ITGM[SIN] planeY * ITGM[COS]

if keys[K_RIGHT]:

oldDirectionX = directionX

directionX = directionX * TGM[COS] - directionY * TGM[SIN]

directionY = oldDirectionX * TGM[SIN] directionY * TGM[COS]

oldPlaneX = planeX

planeX = planeX * TGM[COS] - planeY * TGM[SIN]

planeY = oldPlaneX * TGM[SIN] planeY * TGM[COS]

if keys[K_UP]:

if not worldMap[int(positionX directionX * MOVESPEED)][int(positionY)]:

positionX = directionX * MOVESPEED

if not worldMap[int(positionX)][int(positionY directionY * MOVESPEED)]:

positionY = directionY * MOVESPEED

if keys[K_DOWN]:

if not worldMap[int(positionX - directionX * MOVESPEED)][int(positionY)]:

positionX -= directionX * MOVESPEED

if not worldMap[int(positionX)][int(positionY - directionY * MOVESPEED)]:

positionY -= directionY * MOVESPEED

This is the code in question...

pygame 2.6.0 (SDL 2.28.4, Python 3.10.12)

Hello from the pygame community. https://www.pygame.org/contribute.html

Traceback (most recent call last):

File "/home/alister/Downloads/pyray.py", line 228, in <module>

main()

File "/home/alister/Downloads/pyray.py", line 96, in main

if keys[K_LEFT]:

IndexError: list index out of range

And this was the error...

Duplicate Posts
202 posts with the exact same title by 186 other authors
View Details
Author
Account Strength
80%
Account Age
3 years
Verified Email
Yes
Verified Flair
No
Total Karma
1,111
Link Karma
51
Comment Karma
1,044
Profile updated: 1 week ago
Posts updated: 4 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
6 months ago