1
1
import pygame
2
2
import sys
3
3
from pygame .locals import *
4
- import math
4
+ # import math
5
5
6
6
clock = pygame .time .Clock ()
7
7
14
14
[[300 , 100 ], [300 , 300 ]]
15
15
]
16
16
17
- ray_position = pygame .Vector2 (100 , 200 )
17
+ # ray_position = pygame.Vector2(100, 200)
18
+
19
+ player = pygame .Vector2 (0 , 0 )
18
20
ray_direction = pygame .Vector2 (1 , 0 )
19
21
20
22
@@ -28,10 +30,10 @@ def cast_ray(walls):
28
30
x2 = wall [1 ][0 ]
29
31
y2 = wall [1 ][1 ]
30
32
31
- x3 = ray_position .x
32
- y3 = ray_position .y
33
- x4 = (ray_position + ray_direction ).x
34
- y4 = (ray_position + ray_direction ).y
33
+ x3 = player .x
34
+ y3 = player .y
35
+ x4 = (player + ray_direction ).x
36
+ y4 = (player + ray_direction ).y
35
37
36
38
den = (x1 - x2 ) * (y3 - y4 ) - (y1 - y2 ) * (x3 - x4 )
37
39
@@ -52,19 +54,19 @@ def cast_ray(walls):
52
54
while True :
53
55
54
56
screen .fill ((0 , 0 , 0 ))
55
-
56
57
mouse = pygame .mouse .get_pos ()
57
58
# pygame.draw.line(screen, (255, 255, 255),
58
59
# (WINDOW[0]/2, WINDOW[1]/2), mouse, 1)
59
60
60
- ray_direction .update ((mouse [0 ] - ray_position .x ) - ray_direction .x ,
61
- (mouse [1 ] - ray_position .y ) - ray_direction .y )
61
+ ray_direction .update ((mouse [0 ] - player .x ) - ray_direction .x ,
62
+ (mouse [1 ] - player .y ) - ray_direction .y )
62
63
ray_direction = ray_direction .normalize ()
63
64
64
65
ray_distance = pygame .Vector2 (
65
- ray_position .x + ray_direction .x * 20 , ray_position .y + ray_direction .y * 20 )
66
+ player .x + ray_direction .x * 20 , player .y + ray_direction .y * 20
67
+ )
66
68
67
- pygame .draw .line (screen , (255 , 255 , 0 ), ray_position , ray_distance )
69
+ pygame .draw .line (screen , (255 , 255 , 0 ), player , ray_distance )
68
70
69
71
for wall in walls :
70
72
pygame .draw .line (screen , (255 , 255 , 0 ), (300 , 100 ), (300 , 300 ))
@@ -77,7 +79,16 @@ def cast_ray(walls):
77
79
(int (point .x ), int (point .y )), 3 , 3 )
78
80
79
81
for event in pygame .event .get ():
80
- if event .type == QUIT :
82
+ if event .type == pygame .KEYDOWN :
83
+ if event .key == pygame .K_w :
84
+ player .y -= 5
85
+ if event .key == pygame .K_s :
86
+ player .y += 5
87
+ if event .key == pygame .K_d :
88
+ player .x += 5
89
+ if event .key == pygame .K_a :
90
+ player .x -= 5
91
+ if event .type == pygame .QUIT :
81
92
pygame .quit ()
82
93
sys .exit ()
83
94
0 commit comments