NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import pygame
import math
import keyboard as kb

# FINESTRA----------------------------------------------------
pygame.init()
wn = pygame.display.set_mode((800, 600)) # RIPORTARE A 500
pygame.display.set_caption("RayCaster")
clock = pygame.time.Clock()

# VARIABILI E LISTE--------------------------------------------
tiles = []


class tile:
def __init__(self, x, y, sizex=40, sizey=40):
self.x = x
self.y = y
self.sizex = sizex
self.sizey = sizey

class lastpoint: #da rimuovere
x = 0
y = 0


class level:
mapp = [1, 1, 1, 1, 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, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0,
0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

def draw_map():
global tiles

tiles = []

for i in range(len(level.mapp)):
if level.mapp[i] == 1:
tiles.append(tile(i % 20 * 40, math.floor(i / 20) * 40))

# draw
pygame.draw.rect(wn, (255, 255, 255), (tiles[-1].x+1, tiles[-1].y+1, 38, 38))
else:
pygame.draw.rect(wn, (10, 10, 10), ( (i % 20 * 40) + 1 ,(math.floor(i / 20) * 40) + 1, 38, 38 ))






class player:
x = 50
y = 50
dire = 0
realdire = 0

def move(pressed, speed=2):
if pressed == 'w':
player.x += math.cos(player.realdire) * speed
player.y += math.sin(player.realdire) * speed

if pressed == 's':
player.x -= math.cos(player.realdire) * speed
player.y -= math.sin(player.realdire) * speed

if pressed == 'q':
player.dire -= 0.1
player.realdire = player.dire % (2 * math.pi) #conversione in radianti

if pressed == 'e':
player.dire += 0.1
player.realdire = player.dire % (2 * math.pi) #conversione in radianti

if pressed == "a":
#Setup
player.dire -= math.pi/2
player.realdire = player.dire % (2 * math.pi)
player.move("w")
#Reset
player.dire += math.pi/2
player.realdire = player.dire % (2 * math.pi)

if pressed == "d":
#Setup
player.dire += math.pi/2
player.realdire = player.dire % (2 * math.pi)
player.move("w")
#Reset
player.dire -= math.pi/2
player.realdire = player.dire % (2 * math.pi)

def collision(target):
if (player.x >= target.x and player.x <= target.x + 40) and (player.y >= target.y and player.y <= target.y + 40):
return True


# MainLoop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
quit()

#Collisioni
collision = False
for block in tiles:
if player.collision(block):
collision = True

break

# Comandi
if kb.is_pressed("w"): ######################
player.move("w")

for block in tiles:
if player.collision(block):
player.move("s")
break


if kb.is_pressed("s"): #-----------------------------------------
player.move("s")

for block in tiles:
if player.collision(block):
player.move("w")
break


if kb.is_pressed("q"): #-----------------------------------------
player.move("q")

if kb.is_pressed("e"): #-----------------------------------------
player.move("e")


if kb.is_pressed("a"): #-----------------------------------------
player.move("a")

for block in tiles:
if player.collision(block):
player.move("d")
break



if kb.is_pressed("d"): #-----------------------------------------
player.move("d")

for block in tiles:
if player.collision(block):
player.move("a")
break

#Draw line
lastpoint.x = player.x +( math.cos(player.realdire) * 10)
lastpoint.y = player.y +( math.sin(player.realdire) * 10)






# Z Order
pygame.draw.rect(wn, (0, 0, 0), (0, 0, 800, 600)) # cancella tutto
level.draw_map() # mappa
pygame.draw.rect(wn, (0, 255,0), (player.x - 5, player.y - 5, 10, 10)) # player
pygame.draw.line(wn, (230, 30, 30), (player.x, player.y), (lastpoint.x, lastpoint.y), 4) #direz
pygame.display.update()
clock.tick(60)
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.