Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_STORE
17 changes: 17 additions & 0 deletions data/scripts/classes/player.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,31 @@ def __init__(self, start_pos, width, height, vel, jump_height, reach_distance=4)
self.animation_counter = 0
self.animation_flip = False

self.death = False

self.firstFall = True

self.fallDistance = 0


def move(self, tile_rects):

self.rect, self.collision_types, self.hit_list = move(self.rect, tile_rects, self.movement)

print(self.fallDistance)

if self.collision_types['bottom'] and not self.jumping:
self.movement[1] = 1

if self.collision_types['bottom'] and self.fallDistance >= 5:
if not self.firstFall:
self.death = True
self.fallDistance = 0
self.firstFall = False

if not self.collision_types['bottom'] and not self.movement[1] <= 15:
self.fallDistance+= 1

if not self.collision_types['bottom']:
self.jumping = False
self.movement[1] += GRAVITY_STRENGTH
Expand Down
22 changes: 22 additions & 0 deletions data/scripts/core_functions.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from data.variables import *
import pygame
import math

Expand Down Expand Up @@ -57,3 +58,24 @@ def draw_rect_alpha(display, color, rect):
shape_surf = pygame.Surface(pygame.Rect(rect).size, pygame.SRCALPHA)
pygame.draw.rect(shape_surf, color, shape_surf.get_rect())
display.blit(shape_surf, rect)

def draw_text(surf, text, size, x, y):
font = pygame.font.Font(None, size)
text_surface = font.render(text, True, (0,0,0))
text_rect = text_surface.get_rect()
text_rect.midtop = (x, y)
surf.blit(text_surface, text_rect)

def show_death_screen(screen):
WIDTH = WINDOW_SIZE[0]
HEIGHT = WINDOW_SIZE[1]
draw_text(screen, "You Died!", 64, WIDTH / 2, HEIGHT / 4)
draw_text(screen, "You Fell From High Place", 40,
WIDTH / 2, HEIGHT / 2)
draw_text(screen, "Noob", 30, WIDTH / 2, HEIGHT * 3 / 4)
pygame.display.flip()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
2 changes: 1 addition & 1 deletion data/variables.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pygame

WINDOW_SIZE = (1920, 1080) # Measured in pixels
WINDOW_SIZE = (1280,720) # Measured in pixels
GRAVITY_STRENGTH = 1
CHUNK_SIZE = 8 # Measured in blocks. I do not recommend changing this
TILE_SIZE = 64 # Measured in pixels
Expand Down
129 changes: 70 additions & 59 deletions main.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from data.scripts.classes.terrain import Terrain
from data.scripts.classes.hotbar import Hotbar

from data.scripts.core_functions import draw, distance
from data.scripts.core_functions import draw, distance, show_death_screen, draw_text

from data.variables import *

Expand All @@ -16,12 +16,12 @@

screen = pygame.display.set_mode(WINDOW_SIZE)

player = Player((0, -200), TILE_SIZE-10, TILE_SIZE*2-10, 9, 13)
player = Player((0, -200), TILE_SIZE-10, TILE_SIZE+TILE_SIZE-10, 9, 13)
hotbar = Hotbar()
terrain = Terrain()
terrain.generate_chunk(0, 0)

while __name__ == '__main__':
while True:

clock.tick(60)
pygame.display.set_caption(str(int(clock.get_fps())))
Expand All @@ -35,59 +35,70 @@
(player.rect.y - scroll[1] - (WINDOW_SIZE[1]/2 + player.height/2 - 100)) / SCROLL_STIFF
)

for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()

if event.type == pygame.KEYDOWN:
if event.key == pygame.K_a:
player.moving_left = True
if event.key == pygame.K_d:
player.moving_right = True
if event.key == pygame.K_SPACE or event.key == pygame.K_w:
player.jumping = True

try:
if int(pygame.key.name(event.key)) != 0:
hotbar.selected_slot = int(pygame.key.name(event.key))
except ValueError:
pass

if event.type == pygame.KEYUP:
if event.key == pygame.K_d:
player.moving_right = False
if event.key == pygame.K_a:
player.moving_left = False

if event.type == pygame.MOUSEBUTTONUP:
if event.button == 1:
player.break_block(terrain, hotbar)
if event.button == 3:
player.place_block(terrain, hotbar)

if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 4:
if hotbar.selected_slot != 9:
hotbar.selected_slot += 1
else:
hotbar.selected_slot = 1

if event.button == 5:
if hotbar.selected_slot != 1:
hotbar.selected_slot -= 1
else:
hotbar.selected_slot = 9

for chunk in list(set([i.chunk for i in terrain.map])):
if distance(player.current_chunk, chunk) >= RENDER_DISTANCE:
terrain.unload_chunk(chunk)

player.get_selected_block(terrain, mx, my)

terrain.update(player)
player.update(terrain)
hotbar.update()

draw(screen, terrain, player, hotbar)

if not player.death:

for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()

if event.type == pygame.KEYDOWN:
if event.key == pygame.K_a:
player.moving_left = True
if event.key == pygame.K_d:
player.moving_right = True
if event.key == pygame.K_SPACE or event.key == pygame.K_w:
player.jumping = True

try:
if int(pygame.key.name(event.key)) != 0:
hotbar.selected_slot = int(pygame.key.name(event.key))
except ValueError:
pass

if event.type == pygame.KEYUP:
if event.key == pygame.K_d:
player.moving_right = False
if event.key == pygame.K_a:
player.moving_left = False

if event.type == pygame.MOUSEBUTTONUP:
if event.button == 1:
player.break_block(terrain, hotbar)
if event.button == 3:
player.place_block(terrain, hotbar)

if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 4:
if hotbar.selected_slot != 9:
hotbar.selected_slot += 1
else:
hotbar.selected_slot = 1

if event.button == 5:
if hotbar.selected_slot != 1:
hotbar.selected_slot -= 1
else:
hotbar.selected_slot = 9

for chunk in list(set([i.chunk for i in terrain.map])):
if distance(player.current_chunk, chunk) >= RENDER_DISTANCE:
terrain.unload_chunk(chunk)

player.get_selected_block(terrain, mx, my)

terrain.update(player)
player.update(terrain)
hotbar.update()

draw(screen, terrain, player, hotbar)
else:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
for chunk in list(set([i.chunk for i in terrain.map])):
if distance(player.current_chunk, chunk) >= RENDER_DISTANCE:
terrain.unload_chunk(chunk)
draw(screen,terrain)
show_death_screen(screen)