Temporary level change
|
@ -5,7 +5,6 @@ from map import *
|
|||
from player import *
|
||||
from raycasting import *
|
||||
from object_renderer import *
|
||||
#from sprite_object import *
|
||||
from object_handler import *
|
||||
from pathfinding import *
|
||||
|
||||
|
@ -16,6 +15,7 @@ class Game:
|
|||
self.screen = pg.display.set_mode((WIDTH, HEIGHT))
|
||||
self.clock = pg.time.Clock()
|
||||
self.delta_time = 1
|
||||
self.level = spawn
|
||||
self.new_game()
|
||||
|
||||
def new_game(self):
|
||||
|
@ -23,16 +23,13 @@ class Game:
|
|||
self.player = Player(self)
|
||||
self.object_renderer = ObjectRenderer(self)
|
||||
self.raycasting = RayCasting(self)
|
||||
#self.static_sprites = SpriteObject(self)
|
||||
#self.animated_sprites = AnimatedSprite(self)
|
||||
self.object_handler = ObjectHandler(self)
|
||||
self.pathfinding = PathFinding(self)
|
||||
|
||||
def update(self):
|
||||
self.map.update(self.level)
|
||||
self.player.update()
|
||||
self.raycasting.update()
|
||||
#self.static_sprites.update()
|
||||
#self.animated_sprites.update()
|
||||
self.object_handler.update()
|
||||
pg.display.flip()
|
||||
self.delta_time = self.clock.tick(FPS)
|
||||
|
@ -47,6 +44,8 @@ class Game:
|
|||
self.map.draw()
|
||||
self.player.draw()
|
||||
else:
|
||||
pg.draw.rect(self.screen, FLOOR_COLOR, (0, HALF_HEIGHT, WIDTH, HALF_HEIGHT))
|
||||
pg.draw.rect(self.screen, ROOF_COLOR, (0, 0, WIDTH, HALF_HEIGHT))
|
||||
self.object_renderer.draw()
|
||||
|
||||
def check_events(self):
|
||||
|
@ -54,6 +53,12 @@ class Game:
|
|||
if event.type == pg.QUIT or (event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE):
|
||||
pg.quit()
|
||||
sys.exit()
|
||||
|
||||
if event.type == pg.KEYDOWN and event.key == pg.K_r:
|
||||
if self.level == spawn:
|
||||
self.level = spawn_unlocked
|
||||
else:
|
||||
self.level = spawn
|
||||
|
||||
def run(self):
|
||||
while True:
|
44
map.py
|
@ -1,7 +1,42 @@
|
|||
import pygame as pg
|
||||
from random import choice, random
|
||||
|
||||
_ = False
|
||||
mini_map = [
|
||||
spawn = [
|
||||
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
|
||||
[1, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 1],
|
||||
[1, _, _, 3, 3, 3, 3, _, _, _, 2, 2, 2, _, _, 1],
|
||||
[1, _, _, _, _, _, 4, _, _, _, _, _, 2, _, _, 1],
|
||||
[1, _, _, _, _, _, 4, _, _, _, _, _, 2, _, _, 1],
|
||||
[1, _, _, 3, 3, 3, 3, _, _, _, _, _, _, _, _, 1],
|
||||
[1, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 1],
|
||||
[1, _, _, _, 4, _, _, _, 4, _, _, _, _, _, _, 1],
|
||||
[1, 1, 1, 3, 1, 3, _, 1, 1, 3, _, _, 3, 1, 1, 1],
|
||||
[1, 1, 1, 1, _, _, _, 1, 1, 3, _, _, 3, 1, 1, 1],
|
||||
[1, 1, 1, _, _, 1, 1, 1, 1, 3, _, _, 3, 1, 1, 1],
|
||||
[1, 1, 3, _, 1, 1, 1, 1, 1, 3, _, _, 3, 1, 1, 1],
|
||||
[1, 4, _, _, _, _, _, _, _, _, _, _, _, _, _, 1],
|
||||
[3, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 1],
|
||||
[1, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 1],
|
||||
[1, _, _, 2, _, _, _, _, _, 3, 4, _, 4, 3, _, 1],
|
||||
[1, _, _, 5, _, _, _, _, _, _, 3, _, 3, _, _, 1],
|
||||
[1, _, _, 2, _, _, _, _, _, _, _, _, _, _, _, 1],
|
||||
[1, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 1],
|
||||
[3, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 1],
|
||||
[1, 4, _, _, _, _, _, _, 4, _, _, 4, _, _, _, 1],
|
||||
[1, 1, 3, 3, _, _, 3, 3, 1, 3, 3, 1, 3, 1, 1, 1],
|
||||
[1, 1, 1, 3, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1],
|
||||
[1, 3, 3, 4, _, _, 4, 3, 3, 3, 3, 3, 3, 3, 3, 1],
|
||||
[3, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 3],
|
||||
[3, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 3],
|
||||
[3, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 3],
|
||||
[3, _, _, 5, _, _, _, 5, _, _, _, 5, _, _, _, 3],
|
||||
[3, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 3],
|
||||
[3, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 3],
|
||||
[3, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 3],
|
||||
[3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
|
||||
]
|
||||
spawn_unlocked = [
|
||||
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
|
||||
[1, _, _, _, _, _, _, _, _, _, _, _, _, _, _, 1],
|
||||
[1, _, _, 3, 3, 3, 3, _, _, _, 2, 2, 2, _, _, 1],
|
||||
|
@ -39,7 +74,7 @@ mini_map = [
|
|||
class Map:
|
||||
def __init__(self, game):
|
||||
self.game = game
|
||||
self.mini_map = mini_map
|
||||
self.mini_map = spawn
|
||||
self.world_map = {}
|
||||
self.get_map()
|
||||
|
||||
|
@ -52,4 +87,9 @@ class Map:
|
|||
def draw(self):
|
||||
[pg.draw.rect(self.game.screen, 'darkgray', (pos[0] * 100, pos[1] * 100, 100, 100), 1)
|
||||
for pos in self.world_map]
|
||||
|
||||
def update(self, level):
|
||||
self.mini_map = level
|
||||
self.world_map = {}
|
||||
self.get_map()
|
||||
|
7
npc.py
|
@ -138,7 +138,10 @@ class NPC(AnimatedSprite):
|
|||
return False
|
||||
|
||||
def draw_ray_cast(self):
|
||||
pg.draw.circle(self.game.screen, 'red', (100 * self.x, 100 * self.y), 15)
|
||||
if self.dist < self.attack_dist:
|
||||
pg.draw.circle(self.game.screen, 'green', (100 * self.x, 100 * self.y), 15)
|
||||
else:
|
||||
pg.draw.circle(self.game.screen, 'red', (100 * self.x, 100 * self.y), 15)
|
||||
if self.ray_cast_player_npc():
|
||||
pg.draw.line(self.game.screen, 'orange', (100 * self.game.player.x, 100 * self.game.player.y),
|
||||
(100 * self.x, 100 * self.y), 2)
|
||||
(100 * self.x, 100 * self.y), 2)
|
||||
|
|
|
@ -14,8 +14,8 @@ class ObjectHandler:
|
|||
self.npc_positions = {}
|
||||
|
||||
# Sprite Map
|
||||
add_sprite(SpriteObject(game))
|
||||
add_sprite(AnimatedSprite(game))
|
||||
#add_sprite(SpriteObject(game))
|
||||
#add_sprite(AnimatedSprite(game))
|
||||
add_sprite(AnimatedSprite(game, path=self.animated_sprite_path + 'red_light/0.png', pos=(14.5, 5.5)))
|
||||
add_sprite(AnimatedSprite(game, path=self.animated_sprite_path + 'red_light/0.png', pos=(14.5, 7.5)))
|
||||
add_sprite(AnimatedSprite(game, path=self.animated_sprite_path + 'red_light/0.png', pos=(12.5, 7.5)))
|
||||
|
@ -27,7 +27,8 @@ class ObjectHandler:
|
|||
add_sprite(AnimatedSprite(game, path=self.animated_sprite_path + 'red_light/0.png', pos=(3.5, 18.5)))
|
||||
|
||||
# NPC Map
|
||||
add_npc(NPC(game))
|
||||
#add_npc(NPC(game))
|
||||
add_npc(NPC(game, path=self.npc_sprite_path + 'baller/0.png', pos=(14.5, 5.5), scale=0.6, shift=0.38))
|
||||
|
||||
|
||||
def update(self):
|
||||
|
|
|
@ -10,16 +10,12 @@ class ObjectRenderer:
|
|||
self.sky_offset = 0
|
||||
|
||||
def draw(self):
|
||||
self.draw_background()
|
||||
#self.draw_background()
|
||||
self.render_game_objects()
|
||||
|
||||
def draw_background(self):
|
||||
# Sky
|
||||
self.sky_offset = (self.sky_offset + 4.5 * self.game.player.rel) % WIDTH
|
||||
self.screen.blit(self.sky_texture, (-self.sky_offset, 0))
|
||||
self.screen.blit(self.sky_texture, (-self.sky_offset + WIDTH, 0))
|
||||
# Ground
|
||||
pg.draw.rect(self.screen, FLOOR_COLOR, (0, HALF_HEIGHT, WIDTH, HALF_HEIGHT))
|
||||
pg.draw.rect(self.screen, ROOF_COLOR, (0, 0, WIDTH, HALF_HEIGHT))
|
||||
|
||||
def render_game_objects(self):
|
||||
list_objects = sorted(self.game.raycasting.objects_to_render, key=lambda t: t[0], reverse=True)
|
||||
|
@ -40,5 +36,5 @@ class ObjectRenderer:
|
|||
2: self.get_texture('resources/textures/2.png'),
|
||||
3: self.get_texture('resources/textures/3.png'),
|
||||
4: self.get_texture('resources/textures/4.png'),
|
||||
5: self.get_texture('resources/textures/1.png'),
|
||||
5: self.get_texture('resources/textures/5.png'),
|
||||
}
|
10
player.py
|
@ -36,10 +36,10 @@ class Player:
|
|||
self.check_collision(dx, dy)
|
||||
|
||||
# player rotation with arrow keys
|
||||
#if keys[pg.K_LEFT]:
|
||||
# self.angle -= PLAYER_ROT_SPEED * self.game.delta_time
|
||||
#if keys[pg.K_RIGHT]:
|
||||
# self.angle += PLAYER_ROT_SPEED * self.game.delta_time
|
||||
if keys[pg.K_LEFT]:
|
||||
self.angle -= PLAYER_ROT_SPEED * self.game.delta_time
|
||||
if keys[pg.K_RIGHT]:
|
||||
self.angle += PLAYER_ROT_SPEED * self.game.delta_time
|
||||
self.angle %= math.tau # tau = 2 * pi
|
||||
|
||||
def check_wall(self, x, y):
|
||||
|
@ -68,7 +68,7 @@ class Player:
|
|||
|
||||
def update(self):
|
||||
self.movement()
|
||||
self.mouse_control()
|
||||
#self.mouse_control()
|
||||
|
||||
@property
|
||||
def pos(self):
|
||||
|
|
|
@ -91,7 +91,7 @@ class RayCasting():
|
|||
|
||||
# Draw the ray for debugging
|
||||
if DEBUG_MODE:
|
||||
pg.draw.line(self.game.screen, 'blue', (ox * 100, oy * 100),
|
||||
pg.draw.line(self.game.screen, 'yellow', (ox * 100, oy * 100),
|
||||
(100 * ox + 100 * depth * cos_a, 100 * oy + 100 * depth * sin_a), 1)
|
||||
|
||||
# Remove fish-eye effect
|
||||
|
|
BIN
resources/sprites/npc/baller/0.png
Normal file
After Width: | Height: | Size: 125 KiB |
BIN
resources/sprites/npc/baller/attack/0.png
Normal file
After Width: | Height: | Size: 125 KiB |
BIN
resources/sprites/npc/baller/death/0.png
Normal file
After Width: | Height: | Size: 125 KiB |
BIN
resources/sprites/npc/baller/idle/0.png
Normal file
After Width: | Height: | Size: 125 KiB |
BIN
resources/sprites/npc/baller/pain/0.png
Normal file
After Width: | Height: | Size: 125 KiB |
BIN
resources/sprites/npc/baller/walk/0.png
Normal file
After Width: | Height: | Size: 125 KiB |
BIN
resources/sprites/npc/fox/0.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
resources/sprites/npc/fox/attack/0.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
resources/sprites/npc/fox/death/0.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
resources/sprites/npc/fox/idle/0.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
resources/sprites/npc/fox/pain/0.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
resources/sprites/npc/fox/walk/0.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
resources/sprites/npc/tmp/0.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
resources/sprites/npc/tmp/attack/0.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
resources/sprites/npc/tmp/death/0.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
resources/sprites/npc/tmp/idle/0.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
resources/sprites/npc/tmp/pain/0.png
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
resources/sprites/npc/tmp/walk/0.png
Normal file
After Width: | Height: | Size: 17 KiB |
14
settings.py
|
@ -1,4 +1,5 @@
|
|||
import math
|
||||
import sys
|
||||
|
||||
# GAME SETTINGS
|
||||
RES = WIDTH, HEIGHT = 1600, 900
|
||||
|
@ -9,15 +10,18 @@ FPS = 0 # 0 = unlimited
|
|||
PLAYER_POS = 1.5, 5 # player position on the map
|
||||
PLAYER_ROT = 0
|
||||
PLAYER_SPEED = 0.002 # player speed
|
||||
PLAYER_ROT_SPEED = 0.004 # player rotation speed
|
||||
PLAYER_ROT_SPEED = 0.003 # player rotation speed
|
||||
PLAYER_SIZE_SCALE = 60
|
||||
|
||||
MOUSE_SENSITIVITY = 0.0003
|
||||
MOUSE_MAX_SPEED = 40
|
||||
MOUSE_BORDER_LEFT = 100
|
||||
MOUSE_BORDER_LEFT = 200
|
||||
MOUSE_BORDER_RIGHT = WIDTH - MOUSE_BORDER_LEFT
|
||||
MOUSE_BORDER_TOP = 100
|
||||
MOUSE_BORDER_BOTTOM = HEIGHT - MOUSE_BORDER_TOP
|
||||
|
||||
FLOOR_COLOR = (69, 69, 69)
|
||||
ROOF_COLOR = (50, 50, 50)
|
||||
|
||||
FOV = math.pi / 3
|
||||
HALF_FOV = FOV / 2
|
||||
|
@ -35,4 +39,8 @@ HALF_TEXTURE_SIZE = TEXTURE_SIZE // 2
|
|||
|
||||
# DEBUG SETTINGS
|
||||
DEBUG_MODE = False # show debug info
|
||||
FISH_EYE_FIX = True # fix fish eye effect
|
||||
FISH_EYE_FIX = True # fix fish eye effect
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
if sys.argv[1] == '-D':
|
||||
DEBUG_MODE = True
|