2D Lidar enabled Rover Tutorial Project
2023.07.17 18:59
# packages
import pygame
import sys
import math
# global constants
SCREEN_HEIGHT = 500
SCREEN_WIDTH = SCREEN_HEIGHT * 2
MAP_SIZE = 50
TILE_SIZE = int((SCREEN_WIDTH / 2) / MAP_SIZE)
# global variables
player_x = (SCREEN_WIDTH / 2) / 2
player_y = (SCREEN_WIDTH / 2) / 2
# map
MAP = (
'##################################################'
'# # #'
'# # #'
'# # #'
'# ################# # #'
'# # # #'
'# # # #'
'# # # #'
'# ################# # #'
'# # # # #'
'# # # ##### ######'
'# # # #'
'# # #'
'# # #'
'# # # #'
'# # # #'
'# ################# #'
'# #'
'# #'
'# #'
'# #'
'# #'
'# #'
'###################################### #'
'# #'
'# #'
'# #'
'# #'
'# #'
'# #'
'###################### #'
'# # #'
'# # #'
'# # #'
'# # #'
'# # #'
'# # #'
'# ############ ###### ########'
'# # #'
'# # #'
'# # #'
'# # #'
'# #############################'
'# # #'
'# # #'
'# #'
'# #'
'# # #'
'# # #'
'##################################################'
)
# init pygame
pygame.init()
# create game window
win = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
# set window title
pygame.display.set_caption('Raycasting')
# init timer
clock = pygame.time.Clock()
# draw map
def draw_map():
# loop over map rows
for row in range(MAP_SIZE):
# loop over map columns
for col in range(MAP_SIZE):
# calculate square index
square = row * MAP_SIZE + col
# draw map in the game window # window, color,
pygame.draw.rect(
win,
(50, 50, 100) if MAP[square] == '#' else (250, 250, 250),
(col * TILE_SIZE, row * TILE_SIZE, TILE_SIZE - 1, TILE_SIZE - 1)
)
# draw player on 2D board
pygame.draw.circle(win, (50, 100, 255), (int(player_x), int(player_y)), 6)
# game loop
while True:
# escape condition
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit(0)
# draw 2D map
draw_map()
# update display
pygame.display.flip()
# set FPS
clock.tick(30)
No. | Subject | Author | Date | Views |
---|---|---|---|---|
11 | Circuit Python 실험. [1] | me | 2023.09.25 | 186 |
10 | Speedybee F405 WING | me | 2023.09.05 | 228 |
9 | Orange Pi Zero 3 with Debian | me | 2023.09.02 | 222 |
8 | Logitech G Extreme 3D Pro USB Joystick | me | 2023.08.26 | 230 |
7 | Beagle Bone Blue as flight controller | me | 2023.08.26 | 294 |
6 | Ardupilot (Ardu-Rover) with Lidar | me | 2023.08.10 | 218 |
» | 2D Lidar enabled Rover Tutorial Project [1] | me | 2023.07.17 | 212 |
4 | Beagle Bone Blue for ArduPilot (Rover, Plane, Drone, Submersible, etc) | me | 2023.07.11 | 220 |
3 | Souther California R/C Flying Clubs | me | 2023.07.05 | 183 |
2 | Project : Rover One | me | 2023.01.18 | 246 |
1 | My SBCs that I have installed Lazarus IDE on them. | me | 2022.10.17 | 231 |
Original Source : https://github.com/maksimKorzh/raycasting-tutorials