forked from InfoProjekt/game
first movement (wasd) with character integrated
started a new class for scenes Signed-off-by: SpagettiFisch <63868515+SpagettiFisch@users.noreply.github.com>
This commit is contained in:
parent
ea6d64b087
commit
2e66145dcc
5 changed files with 106 additions and 17 deletions
BIN
art/images/reddy.png
Normal file
BIN
art/images/reddy.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 654 B |
|
Before Width: | Height: | Size: 644 B After Width: | Height: | Size: 644 B |
22
classes.py
22
classes.py
|
|
@ -44,7 +44,7 @@ class Button():
|
|||
self.onePress = onePress
|
||||
self.alreadyPressed = False
|
||||
|
||||
with open('art/textbox.png', 'r') as tb:
|
||||
with open('art/images/textbox.png', 'r') as tb:
|
||||
self.box = pygame.image.load(tb)
|
||||
self.box = pygame.transform.scale(self.box, (width, height))
|
||||
|
||||
|
|
@ -53,15 +53,19 @@ class Button():
|
|||
|
||||
self.buttonSurf = self.font.render(buttonText, True, '#baab80')
|
||||
|
||||
def process(self, screen):
|
||||
def process(self, screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
||||
mousePos = pygame.mouse.get_pos()
|
||||
if self.buttonRect.collidepoint(mousePos):
|
||||
if pygame.mouse.get_pressed(num_buttons=3)[0]:
|
||||
if self.onePress:
|
||||
self.onclickFunction()
|
||||
elif not self.alreadyPressed:
|
||||
self.onclickFunction()
|
||||
self.alreadyPressed = True
|
||||
if 'play' in str(self.onclickFunction):
|
||||
self.onclickFunction(screen, clock, running, background, isblack, WIDTH, HEIGHT)
|
||||
self.alreadyPressed = True
|
||||
else:
|
||||
self.onclickFunction()
|
||||
self.alreadyPressed = True
|
||||
else:
|
||||
self.alreadyPressed = False
|
||||
self.box.blit(self.buttonSurf, [
|
||||
|
|
@ -81,7 +85,7 @@ class DropDown():
|
|||
self.menu_active = False
|
||||
self.active_option = -1
|
||||
|
||||
with open('art/textbox.png', 'r') as tb:
|
||||
with open('art/images/textbox.png', 'r') as tb:
|
||||
self.box = pygame.image.load(tb)
|
||||
self.box = pygame.transform.scale(self.box, (width, height))
|
||||
|
||||
|
|
@ -133,4 +137,10 @@ class DropDown():
|
|||
return -1
|
||||
|
||||
|
||||
|
||||
class Scene():
|
||||
def __init__(self, _type, bg, objects) -> None:
|
||||
self.name
|
||||
self.type = _type
|
||||
if self.type != 'cutscene':
|
||||
self.background = bg
|
||||
self.objects = objects
|
||||
|
|
|
|||
45
main.py
45
main.py
|
|
@ -3,6 +3,8 @@ import sys
|
|||
import json
|
||||
import time
|
||||
from classes import *
|
||||
from viecher import *
|
||||
fps = 60
|
||||
|
||||
def setUp(config):
|
||||
pygame.init()
|
||||
|
|
@ -27,6 +29,30 @@ def quitGame():
|
|||
def uwu():
|
||||
print('uwu')
|
||||
|
||||
def play(screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
||||
objects = []
|
||||
objects.append(MainCharacter('Herbert', 100, 'reddy.png', 125, 5, 1, 1, 50))
|
||||
while running:
|
||||
screen.fill('#000000')
|
||||
events = pygame.event.get()
|
||||
for event in events:
|
||||
if event.type == pygame.QUIT:
|
||||
quitGame()
|
||||
# RENDER YOUR GAME HERE
|
||||
"""with open(background, 'r') as i:
|
||||
bg = pygame.image.load(i)
|
||||
bg = pygame.transform.scale(bg, (WIDTH, HEIGHT))
|
||||
# fill the screen with an image to clear the screen
|
||||
screen.blit(bg, (0, 0))
|
||||
"""
|
||||
for obj in objects:
|
||||
obj.update(pygame.key.get_pressed())
|
||||
obj.draw(screen)
|
||||
# flip() the display to put your work on screen
|
||||
pygame.display.flip()
|
||||
|
||||
clock.tick(fps) # limits FPS to 60
|
||||
|
||||
def options(screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
||||
objects = []
|
||||
# List that is displayed while selecting the window resolution level
|
||||
|
|
@ -67,8 +93,8 @@ def options(screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
|||
def menu(screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
||||
objects = []
|
||||
objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'medieval', 48, "Exit game", quitGame))
|
||||
objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'medieval', 48, "Options", uwu))
|
||||
objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'medieval', 48, "Play", uwu))
|
||||
objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'medieval', 48, "Play", play))
|
||||
objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'medieval', 48, "Options", uwu))
|
||||
while running:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
|
|
@ -80,7 +106,7 @@ def menu(screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
|||
# fill the screen with an image to clear the screen
|
||||
screen.blit(bg, (0, 0))
|
||||
for obj in objects:
|
||||
obj.process(screen)
|
||||
obj.process(screen, clock, running, background, isblack, WIDTH, HEIGHT)
|
||||
|
||||
# flip() the display to put your work on screen
|
||||
pygame.display.flip()
|
||||
|
|
@ -91,8 +117,10 @@ def main():
|
|||
config = readConfig()
|
||||
screen, clock, running, isblack, background, objects = setUp(config["screen"])
|
||||
WIDTH, HEIGHT = screen.get_size()
|
||||
list1 = DropDown(50, 50, 128, 48, 'simple', 32, ['#881188', '#220044'], ['#991122', '#33ff11'], 'Test', ['Test 2', 'Test 17', '982'])
|
||||
|
||||
objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'medieval', 48, "Exit game", quitGame))
|
||||
objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'medieval', 48, "Options", uwu))
|
||||
objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'medieval', 48, "Play", play))
|
||||
|
||||
while running:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
|
|
@ -108,13 +136,8 @@ def main():
|
|||
# RENDER YOUR GAME HERE
|
||||
|
||||
else:
|
||||
selected_option = list1.update(pygame.event.get())
|
||||
if selected_option >= 0:
|
||||
list1.main = list1.options[selected_option]
|
||||
screen.fill('#000000')
|
||||
list1.draw(screen)
|
||||
for obj in objects:
|
||||
obj.process(screen)
|
||||
obj.process(screen, clock, running, background, isblack, WIDTH, HEIGHT)
|
||||
# flip() the display to put your work on screen
|
||||
pygame.display.flip()
|
||||
|
||||
|
|
|
|||
56
viecher.py
Normal file
56
viecher.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import pygame
|
||||
fps = 60
|
||||
|
||||
class Character():
|
||||
def __init__(self, name, ms, sprite) -> None:
|
||||
self.name = name
|
||||
self.speed = ms
|
||||
with open(f'art/images/{sprite}') as i:
|
||||
self.sprite = pygame.image.load(i)
|
||||
self.x = 524
|
||||
self.y = 524
|
||||
self.hidden = False
|
||||
|
||||
self.rect = pygame.Rect(self.x, self.y, self.sprite.get_width(), self.sprite.get_height())
|
||||
|
||||
def draw(self, screen):
|
||||
if self.hidden:
|
||||
return
|
||||
self.rect.x, self.rect.y = self.x, self.y
|
||||
screen.blit(self.sprite, self.rect)
|
||||
|
||||
|
||||
class NPC(Character):
|
||||
pass
|
||||
|
||||
|
||||
class Fighter(Character):
|
||||
def __init__(self, name, ms, sprite, health, damage, level, asp, atr) -> None:
|
||||
super().__init__(name, ms, sprite)
|
||||
self.health = health
|
||||
self.damage = damage
|
||||
self.level = level
|
||||
self.attack_speed = asp
|
||||
self.attack_range = atr
|
||||
|
||||
class MainCharacter(Fighter):
|
||||
def __init__(self, name, ms, sprite, health, damage, level, asp, atr, weapon=None, shield=None) -> None:
|
||||
super().__init__(name, ms, sprite, health, damage, level, asp, atr)
|
||||
self.attack_spell = weapon
|
||||
self.shield_spell = shield
|
||||
self.talking = False
|
||||
|
||||
def update(self, keys):
|
||||
if keys[pygame.K_w]:
|
||||
self.y -= self.speed / fps
|
||||
if keys[pygame.K_a]:
|
||||
self.x -= self.speed / fps
|
||||
if keys[pygame.K_s]:
|
||||
self.y += self.speed / fps
|
||||
if keys[pygame.K_d]:
|
||||
self.x += self.speed / fps
|
||||
|
||||
class Mobs(Fighter):
|
||||
def __init__(self, name, ms, sprite, health, damage, level, asp, atr, drops) -> None:
|
||||
super().__init__(name, ms, sprite, health, damage, level, asp, atr)
|
||||
self.drops = drops * (self.level / 2)
|
||||
Loading…
Add table
Reference in a new issue