enp0s25 2 months ago
parent
commit
f6faa7377c
  1. BIN
      assets/other/Diogenes.png
  2. BIN
      assets/other/Pytagoras.png
  3. BIN
      assets/other/alex.png
  4. BIN
      assets/other/kospi.png
  5. BIN
      assets/psd/stairs.xcf
  6. BIN
      assets/resized/33.png
  7. BIN
      assets/resized/34.png
  8. BIN
      assets/resized/35.png
  9. BIN
      assets/resized/36.png
  10. BIN
      assets/resized/sokrates.png
  11. 38
      game.py
  12. BIN
      maps/large.bin
  13. 6
      maps/large.json
  14. BIN
      maps/main.bin
  15. BIN
      maps/main.bin~
  16. 6
      modules/GameObject.py
  17. 20
      modules/map_utils.py
  18. 205
      modules/tasks.py
  19. 2
      settings.json
  20. BIN
      tools/large.bin
  21. BIN
      tools/map-smaller2.png
  22. BIN
      tools/map.png
  23. 59
      tools/map_convert.py

BIN
assets/other/Diogenes.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

BIN
assets/other/Pytagoras.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

BIN
assets/other/alex.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 KiB

BIN
assets/other/kospi.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 KiB

BIN
assets/psd/stairs.xcf

Binary file not shown.

BIN
assets/resized/33.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
assets/resized/34.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

BIN
assets/resized/35.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
assets/resized/36.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
assets/resized/sokrates.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

38
game.py

@ -20,7 +20,7 @@ def main(screen, settings): @@ -20,7 +20,7 @@ def main(screen, settings):
offset_y = 0
# load map
map_info, map_data = map_utils.load_map("main")
map_info, map_data = map_utils.load_map("large")
wall_obj, wall_obj_noint, special_obj = map_utils.wall_chunk_load(map_data)
# create player
@ -32,24 +32,21 @@ def main(screen, settings): @@ -32,24 +32,21 @@ def main(screen, settings):
clock = pygame.time.Clock()
GameObject.clock = clock
start_time = pygame.time.get_ticks()
time = 0
max_time = settings['gametime']
time_font = pygame.font.SysFont("Sans Serif", 50)
for obj in special_obj:
obj.activate()
task_chance = settings['task_chance']
#
results = {
"WinDosXD":0,
"AP replacement":0
"WinDosXD": 0,
"AP replacement": 0,
"Diogenes": 0,
"Pytagoras": 0
}
# game main loop
while True:
# wait ms to achieve X FPS
clock.tick(settings['FPS'])
time = pygame.time.get_ticks() - start_time
# time = pygame.time.get_ticks() - start_time
# parse events
for event in pygame.event.get():
# check if window is closed
@ -85,12 +82,7 @@ def main(screen, settings): @@ -85,12 +82,7 @@ def main(screen, settings):
player.walk_d = False
if event.key in controls['up']:
player.walk_u = False
# chance of attempting to activate a new task
if random.randint(0,1000) < task_chance:
active_obj = random.choice(special_obj)
if not active_obj.active:
active_obj.activate()
# move player and calc new offset for walls
offset_x, offset_y = player.movement(offset_x, offset_y)
@ -113,7 +105,7 @@ def main(screen, settings): @@ -113,7 +105,7 @@ def main(screen, settings):
player.calc_way_out(wall)
# dark red background
screen.fill((50,0,0))
screen.fill((50, 0, 0))
# draw walls and floors
for wall in wall_obj:
if wall.pos_x + offset_x > -GameObject.TEXTURE_SIZE and wall.pos_x + offset_x < settings['window_size'][0]:
@ -128,17 +120,9 @@ def main(screen, settings): @@ -128,17 +120,9 @@ def main(screen, settings):
for obj in special_obj:
if player.rect.colliderect(obj.aoe_rect) and obj.active:
obj.glow(screen)
# check if we are out of time
sec_time = max_time - (time // 1000)
if sec_time <= 0:
return results
# time remaining
time_text = time_font.render(f"{sec_time//60}:{sec_time%60}", 1, (75, 20, 226))
# draw player
screen.blit(player.image, (player.pos_x, player.pos_y))
screen.blit(time_text, (10, 10))
# update screen
pygame.display.update()

BIN
maps/large.bin

Binary file not shown.

6
maps/large.json

@ -0,0 +1,6 @@ @@ -0,0 +1,6 @@
{
"size": [24, 64],
"name": "main",
"dtype": "uint8",
"block_map": []
}

BIN
maps/main.bin

Binary file not shown.

BIN
maps/main.bin~

Binary file not shown.

6
modules/GameObject.py

@ -9,7 +9,7 @@ TEXTURE_SIZE = 64 @@ -9,7 +9,7 @@ TEXTURE_SIZE = 64
# PLAYER_IMG_DIR = "assets/player/MC/"
WALL_IMG_DIR = "assets/resized/"
wall_images_count = 33
wall_images_count = 37
wall_images = []
bind_special_img = ((12, 23), (22, 24), (26, 27), (29, 30), (31, 32))
@ -97,6 +97,10 @@ class SpecialObject(WallObject): @@ -97,6 +97,10 @@ class SpecialObject(WallObject):
t = tasks.WinDosXD(screen, settings, clock)
elif self.t_type == "AP replacement":
t = tasks.GrellNetAP(screen, settings, clock)
elif self.t_type == "Diogenes":
t = tasks.Diogenes(screen, settings, clock)
elif self.t_type == "Pytagoras":
t = tasks.Pytagoras(screen, settings, clock)
result = t.do_task()
# 0 is success
if result == 0:

20
modules/map_utils.py

@ -15,16 +15,24 @@ def wall_chunk_load(walls): @@ -15,16 +15,24 @@ def wall_chunk_load(walls):
for wall_row_i in range(len(walls)):
for wall_i in range(len(walls[wall_row_i])):
# create wall and add it into correct category
if walls[wall_row_i][wall_i] == 0:
if walls[wall_row_i][wall_i] == 0 or walls[wall_row_i][wall_i] == 34:
wall_obj_noint.append(GameObject.WallObject((wall_i*64,wall_row_i*64), walls[wall_row_i][wall_i]))
# computers
elif walls[wall_row_i][wall_i] in (12, 22, 26, 29):
obj = GameObject.SpecialObject((wall_i*64,wall_row_i*64), walls[wall_row_i][wall_i], "WinDosXD")
# elif walls[wall_row_i][wall_i] in (12, 22, 26, 29):
# obj = GameObject.SpecialObject((wall_i*64,wall_row_i*64), walls[wall_row_i][wall_i], "Diogenes")
# wall_obj.append(obj)
# special_obj.append(obj)
# Access Point on a wall
# elif walls[wall_row_i][wall_i] == 31:
# obj = GameObject.SpecialObject((wall_i*64,wall_row_i*64), walls[wall_row_i][wall_i], "AP replacement")
# wall_obj.append(obj)
# special_obj.append(obj)
elif walls[wall_row_i][wall_i] == 33:
obj = GameObject.SpecialObject((wall_i*64,wall_row_i*64), walls[wall_row_i][wall_i], "Diogenes")
wall_obj.append(obj)
special_obj.append(obj)
# Access Point on a wall
elif walls[wall_row_i][wall_i] == 31:
obj = GameObject.SpecialObject((wall_i*64,wall_row_i*64), walls[wall_row_i][wall_i], "AP replacement")
elif walls[wall_row_i][wall_i] == 36:
obj = GameObject.SpecialObject((wall_i*64,wall_row_i*64), walls[wall_row_i][wall_i], "Pytagoras")
wall_obj.append(obj)
special_obj.append(obj)
else:

205
modules/tasks.py

@ -1,7 +1,212 @@ @@ -1,7 +1,212 @@
#!/usr/bin/env python3
from tkinter.tix import Tree
import pygame, sys
def display_text(settings, screen, text):
WIDTH, HEIGHT = settings['window_size']
bg = pygame.Surface((WIDTH-20, 100))
bg.set_alpha(128)
pygame.draw.rect(bg, (255, 255, 255), (0, 0, WIDTH-20, 100), 0, 5)
pygame.draw.rect(bg, (0, 0, 0), (5, 5, WIDTH-30, 90), 0, 5)
screen.blit(bg, (10, HEIGHT-105))
font = pygame.font.SysFont("Sans Serif", 45)
text_label = font.render(text, 1, (255, 255, 255))
screen.blit(text_label, (30, HEIGHT-95))
class Diogenes:
'''Move Alexander away'''
def __init__(self, screen, settings, clock):
self.settings = settings
self.screen = screen
self.clock = clock
self.img = pygame.image.load("assets/other/Diogenes.png")
self.alex_img = pygame.image.load("assets/other/alex.png")
self.name = "Move Alex"
self.task_type = "Diogenes"
self.done = False
def do_task(self):
'''open screen with task'''
alex_x = 600
alex_rect = pygame.Rect((600, 50), (250, 670))
alex_hold = False
dialog_texts = [
"Alex: Hey, don't wou want to improve your life? I can give you anything you want.",
"Diogenes: Just move away, you are blocking the sun.",
"Alex: Ok, sure"
]
dialog_index = 0
dialog_active = True
# main loop of task
while not self.done:
self.clock.tick(self.settings['FPS'])
# parse events
for event in pygame.event.get():
# check if window is closed
if event.type == pygame.QUIT:
exit_sig = True
sys.exit()
# check if a key was pressed
elif event.type == pygame.KEYDOWN:
# exit task when ESC is pressed
if event.key == pygame.K_ESCAPE:
# status 1 indicates task isn't finished
return 1
# check if a key was released
elif event.type == pygame.KEYUP:
if event.key in self.settings['controls']['right']:
pass
elif event.type == pygame.MOUSEBUTTONDOWN:
if dialog_active:
if dialog_index < len(dialog_texts) - 1:
dialog_index += 1
else:
dialog_active = False
# check if mouse is holding alex
elif alex_rect.collidepoint(event.pos):
alex_hold = True
elif event.type == pygame.MOUSEBUTTONUP:
# release alex, create new hitbox in its position
alex_rect = pygame.Rect((alex_x, 50), (250, 630))
alex_hold = False
# move alex with mouse
cur_pos = pygame.mouse.get_pos()
if alex_hold:
# don't go too far left
if cur_pos[0] > 700:
alex_x = 600
else:
# reset if alex reached destination
if cur_pos[0] < 300:
alex_hold = False
return 0
else:
alex_x = cur_pos[0]-100
# draw stuff into task window
task_window = pygame.Surface((self.settings['window_size'][0], self.settings['window_size'][1]))
task_window.fill((255,0,0))
task_window.blit(self.img, (0,0))
task_window.blit(self.alex_img, (alex_x, 0))
# blit task window on screen
if dialog_active:
display_text(self.settings, task_window, dialog_texts[dialog_index])
self.screen.blit(task_window, (0,0))
pygame.display.update()
class Pytagoras:
'''Move Alexander away'''
def __init__(self, screen, settings, clock):
self.settings = settings
self.screen = screen
self.clock = clock
self.img = pygame.image.load("assets/other/Pytagoras.png")
self.kospi_img = pygame.image.load("assets/other/kospi.png")
self.name = "Pytagoras"
self.task_type = "Pytagoras"
self.done = False
def do_task(self):
'''open screen with task'''
dialog2_correct_texts = [
"Kosper: Priatel, tesim sa!",
"Pythagoras: Oh right, how could I forget.",
]
dialog2_incorrect_texts = [
"Kosper: Uu! Priatel, toto je chyba!",
"Pytagoras: Hmm, I'll have to think about it a bit more."
]
dialog2_index = 0
dialog2_active = False
option1 = pygame.rect.Rect((425, 81), (215, 217))
option2 = pygame.rect.Rect((713, 81), (217, 217))
dialog1_text = "Pythagoras: Yesterday I found a formula but I can't remember which one it was."
dialog1_done = False
kosper_on_scene = False
dialog2_active = False
# main loop of task
while not self.done:
self.clock.tick(self.settings['FPS'])
# parse events
for event in pygame.event.get():
# check if window is closed
if event.type == pygame.QUIT:
exit_sig = True
sys.exit()
# check if a key was pressed
elif event.type == pygame.KEYDOWN:
# exit task when ESC is pressed
if event.key == pygame.K_ESCAPE:
# status 1 indicates task isn't finished
return 1
# check if a key was released
elif event.type == pygame.KEYUP:
if event.key in self.settings['controls']['right']:
pass
elif event.type == pygame.MOUSEBUTTONDOWN:
if not dialog1_done:
dialog1_done = True
elif option1.collidepoint(event.pos) and not kosper_on_scene:
for i in range(380, 0, -20):
task_window.blit(self.img, (0, 0))
task_window.blit(self.kospi_img, (i, 0))
self.screen.blit(task_window, (0, 0))
pygame.display.update()
kosper_on_scene = True
dialog2_texts = dialog2_correct_texts
dialog2_active = True
elif option2.collidepoint(event.pos) and not kosper_on_scene:
for i in range(380, 0, -20):
task_window.blit(self.img, (0, 0))
task_window.blit(self.kospi_img, (i, 0))
self.screen.blit(task_window, (0, 0))
pygame.display.update()
kosper_on_scene = True
dialog2_texts = dialog2_incorrect_texts
dialog2_active = True
elif dialog2_active:
if dialog2_index < len(dialog2_texts) - 1:
dialog2_index += 1
else:
dialog2_active = False
return 0
elif event.type == pygame.MOUSEBUTTONUP:
pass
# draw stuff into task window
task_window = pygame.Surface((self.settings['window_size'][0], self.settings['window_size'][1]))
task_window.fill((255,0,0))
task_window.blit(self.img, (0,0))
if kosper_on_scene:
task_window.blit(self.kospi_img, (0,0))
# blit task window on screen
if not dialog1_done:
display_text(self.settings, task_window, dialog1_text)
if dialog2_active:
display_text(self.settings, task_window, dialog2_texts[dialog2_index])
self.screen.blit(task_window, (0,0))
pygame.display.update()
class WinDosXD:
'''Help load WinDos by moving blue bar to right'''
def __init__(self, screen, settings, clock):

2
settings.json

@ -2,8 +2,6 @@ @@ -2,8 +2,6 @@
"window_size":[1280, 720],
"FPS":60,
"player_speed":10,
"gametime":120,
"task_chance":5,
"player":"mc",
"controls":{
"left": ["arrow_l", "a"],

BIN
tools/large.bin

Binary file not shown.

BIN
tools/map-smaller2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

BIN
tools/map.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 12 KiB

59
tools/map_convert.py

@ -58,6 +58,31 @@ else: @@ -58,6 +58,31 @@ else:
# create array with img dimensions
arr = np.ndarray((img.height, img.width), dtype=np.uint8)
mappings = {
'(255, 255, 255)': 0, # floor
'(255, 255, 0)': 12, # PC
'(255, 254, 0)': 22, # PC
'(255, 253, 0)': 26, # PC
'(255, 252, 0)': 29, # PC
'(0, 0, 200)': 23, # bsod
'(0, 0, 201)': 24, # bsod
'(0, 0, 202)': 27, # bsod
'(0, 0, 203)': 30, # bsod
'(198, 103, 0)': 11, # table
'(199, 103, 0)': 21, # table
'(200, 103, 0)': 25, # table
'(201, 103, 0)': 28, # table
'(128, 128, 128)': 13, # server
'(150, 150, 150)': 20, # skrina
'(0, 255, 255)': 31, # ap
'(255, 0, 0)': 33, # barrel
'(221, 221, 221)': 34, # stairs
'(198, 103, 1)': 35, # table
'(254, 0, 0)': 36
}
for i in range(img.height):
for j in range(img.width):
# find out what the color is, and encode it accordingly
@ -66,38 +91,8 @@ for i in range(img.height): @@ -66,38 +91,8 @@ for i in range(img.height):
if color == (0, 0, 0): #wall
w = wallcheck(img, j, i)
arr[i][j] = w
elif color == (255, 255, 255): #floorgang
arr[i][j] = 0
elif color == (255, 255, 0): #pc top
arr[i][j] = 12
elif color == (255, 254, 0): #pc bottom
arr[i][j] = 22
elif color == (255, 253, 0): #pc right
arr[i][j] = 26
elif color == (255, 252, 0): #pc left
arr[i][j] = 29
elif color == (0, 0, 200): #bsod top
arr[i][j] = 23
elif color == (0, 0, 201): #bsod bottom
arr[i][j] = 24
elif color == (0, 0, 202): #bsod right
arr[i][j] = 27
elif color == (0, 0, 203): #bsod left
arr[i][j] = 30
elif color == (198, 103, 0): #table top
arr[i][j] = 11
elif color == (199, 103, 0): #table bottom
arr[i][j] = 21
elif color == (200, 103, 0): #table right
arr[i][j] = 25
elif color == (201, 103, 0): #table left
arr[i][j] = 28
elif color == (128, 128, 128): #server
arr[i][j] = 13
elif color == (150, 150, 150): #skrina
arr[i][j] = 20
elif color == (0, 255, 255): #ap
arr[i][j] = 31
else:
arr[i][j] = mappings[str(color)]
# convert array to bytes and write to file
out_bytes = arr.tobytes()

Loading…
Cancel
Save