
u/LooseStore8141

Give me a number between 1 and 4003
I keep seeing other people doing this and I wanna try it so give me a number between 1 and 4003 and I'll give you a song off my playlist
my raycaster has a weird fisheye effect even after fixing it with trig
Code:
import pygame
import time
import math
print("Loading...")
pygame.init()
clock = pygame.time.Clock()
debug = False
stage = 0 #variable declaration
squarx = 0
squary = 0
red = (255,0,0)
white = (255,255,255)
blue = (0, 0, 255)
rectcolour = red
fov = math.pi / 3
raynum = 400
max_depth = 800
mapsize = 16
tilesize = 50
dispa = []
res = 1900, 1000
resx, resy = res
screen = pygame.display.set_mode((res))
class Map:
def \_\_init\_\_(self):
self.rayenvironment = \[ #map data storage
\[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\],
\[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1\],
\[1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1\],
\[1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1\],
\[1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1\],
\[1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1\],
\[1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1\],
\[1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1\],
\[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1\],
\[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\]
\]
self.environment = \[ #so map generation doesn't break
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
\]
def draw(self, generation, stage, line):
for i in self.environment: #generates the map
generation += 1
if generation >= len(self.environment) + 1:
break
if stage >= mapsize:
line += 1
stage = 0
if i == 1:
rectcolour = red
else:
rectcolour = white
pygame.draw.rect(screen, rectcolour, (squarx + 50 \* stage, squary + 50 \* line, 50, 50))
if stage < mapsize:
stage += 1
map = Map()
class Player:
def \_\_init\_\_(self, playx, playy):
self.pos = pygame.math.Vector2(playx, playy)
self.angle = 180
self.speed = 1.5
self.turnspeed = 5
self.size = 10
def inputs(self):
self.x, self.y = self.pos
keys = pygame.key.get\_pressed()
if keys\[pygame.K\_LEFT\]:
self.angle -= self.turnspeed
if keys\[pygame.K\_RIGHT\]:
self.angle += self.turnspeed
forward\_vector = pygame.math.Vector2(0, -1)
forward\_vector.rotate\_ip(self.angle)
if keys\[pygame.K\_UP\]:
self.pos += forward\_vector \* self.speed
if keys\[pygame.K\_DOWN\]:
self.pos -= forward\_vector \* self.speed
player = Player(75, 125)
def disp():
tilwid = resx / raynum
generation = 0
for i in dispa:
if generation >= raynum:
break
hig = resy - i
briraw = round(i / 15)
if briraw != 0:
bri = 1 / briraw
else:
bri = 0
pygame.draw.rect(screen, (round(155 \* bri), round(135 \* bri), round(13 \* bri)), (tilwid \* generation, resy / 2 - hig / 2, tilwid + 1, hig))
generation += 1
dispa.clear()
def cast():
degtorad = math.pi / 180
player\_angle\_r = player.angle \* degtorad - 1.5708
start\_angle = player\_angle\_r - fov/2
step\_angle = fov/raynum
for i in range(raynum):
ray\_angle = start\_angle + i \* step\_angle
for depth in range(1, max\_depth, 2):
target\_x = player.x + math.cos(ray\_angle) \* depth
target\_y = player.y + math.sin(ray\_angle) \* depth
col = int(target\_x / tilesize)
row = int(target\_y / tilesize)
if 0 <= col < mapsize and 0 < row <= mapsize:
if map.rayenvironment[row][col] == 1:
if debug == True:
pygame.draw.line(screen, red, player.pos, (target_x, target_y), 1)
dispa.append(math.dist(player.pos, (target_x, target_y)) * math.cos(player_angle_r - ray_angle))
break
running = True
while running:
screen.fill((0, 0, 0))
clock.tick(60)
for event in pygame.event.get(): #handles program end
if event.type == pygame.QUIT:
running = False
if debug == True:
map.draw(0, 0, 0)
player.inputs()
if debug == True:
pygame.draw.circle(screen, blue, player.pos, 10)
cast()
if debug == False:
disp()
pygame.display.flip()
pygame.quit()
Why isn't this working?
import pygame
WID = int(input("Screen width?"))
print(WID)
HIG = int(input("Screen height?"))
print(HIG)
print("Loading...")
pygame.init()
environment = [
1, 1, 1, 1, 1, 1, 1, 1,
1, 0, 1, 0, 0, 0, 1, 1,
1, 0, 1, 0, 1, 0, 0, 1,
1, 0, 1, 1, 0, 1, 0, 1,
1, 0, 0, 1, 0, 1, 0, 1,
1, 1, 0, 0, 0, 0, 0, 1,
1, 1, 1, 0, 0, 0, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1
]
screen = pygame.display.set_mode((500, 500))
running = True
stage = 0
squarx = 0;
squary = 0;
red = hex(255, 0, 0)
white = hex(255, 255, 255)
rectcolour = red
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
for i in environment:
print(i)
stage += 1
if i == 1:
rectcolour = red
else:
rectcolour = white
print(rectcolour)
pygame.draw.rect(screen, rectcolour, (squarx + 100 \* stage, squary + 100 \* stage, 100, 100))
pygame.display.flip()
print("Loaded successfully")
input("end of program.")
This is my first time touching python in a while and i don't get why it keeps immediately closing when I get past the first two inputs
Edit: solved
Why do enemies keep spawning in inns?
I don't have any quests running, and yet every time I go to rest at an inn, I get to 1 hour and an enemy spawns and I have to kill it before I can heal again. I have no idea what to do.
Map for a novel I'm working on AMA (there is also a world map but you can only do one image at a time)
Songs should be on par or angrier than no pity for a coward
My vibrato sounds terrible and I can't hold a note without it drifting