forked from InfoProjekt/game
Merge pull request 'manual merge of lyzzys updates into Development' (#60) from Spafi/game:main into Development
Reviewed-on: InfoProjekt/game#60
This commit is contained in:
commit
96b15fd425
3 changed files with 27 additions and 16 deletions
|
|
@ -34,7 +34,7 @@ fonts = {
|
|||
}
|
||||
|
||||
class Button():
|
||||
def __init__(self, x, y, width, height, font, font_size, buttonText='Button', onclickFunction=None, onePress=False):
|
||||
def __init__(self, x, y, width, height, image, font, font_size, buttonText='', onclickFunction=None, onePress=False):
|
||||
self.font = pygame.font.Font(f'fonts/{fonts[font]}', font_size)
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
|
@ -44,7 +44,7 @@ class Button():
|
|||
self.onePress = onePress
|
||||
self.alreadyPressed = False
|
||||
|
||||
with open('art/images/textbox.png', 'r') as tb:
|
||||
with open(f'art/images/{image}', 'r') as tb:
|
||||
self.box = pygame.image.load(tb)
|
||||
self.box = pygame.transform.scale(self.box, (width, height))
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ class Button():
|
|||
|
||||
self.buttonSurf = self.font.render(buttonText, True, '#baab80')
|
||||
|
||||
def process(self, screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
||||
def update(self, screen, clock=None, running=None, background=None, isblack=None, WIDTH=None, HEIGHT=None):
|
||||
mousePos = pygame.mouse.get_pos()
|
||||
if self.buttonRect.collidepoint(mousePos):
|
||||
if pygame.mouse.get_pressed(num_buttons=3)[0]:
|
||||
|
|
|
|||
16
main.py
16
main.py
|
|
@ -75,7 +75,7 @@ def play(screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
|||
|
||||
for thing in objects[0]:
|
||||
thing.book.hidden = not freeze
|
||||
if not thing.update(pygame.key.get_pressed(), objects):
|
||||
if not thing.update(pygame.key.get_pressed(), pygame.mouse.get_pos(), objects):
|
||||
menu(screen, clock, running, background, isblack, WIDTH, HEIGHT)
|
||||
thing.draw(screen)
|
||||
|
||||
|
|
@ -135,9 +135,9 @@ 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, 160, 64, 'medieval', 48, "Play", play))
|
||||
#objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'medieval', 48, "Options", uwu))
|
||||
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, 'textbox.png', 'medieval', 48, "Play", play))
|
||||
#objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'textbox.png', 'medieval', 48, "Options", uwu))
|
||||
objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'textbox.png', 'medieval', 48, "Exit game", quitGame))
|
||||
while running:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
|
|
@ -150,7 +150,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, clock, running, background, isblack, WIDTH, HEIGHT)
|
||||
obj.update(screen, clock, running, background, isblack, WIDTH, HEIGHT)
|
||||
|
||||
# flip() the display to put your work on screen
|
||||
pygame.display.flip()
|
||||
|
|
@ -221,9 +221,9 @@ def main():
|
|||
config = readConfig()
|
||||
screen, clock, running, isblack, background, objects = setUp(config["screen"])
|
||||
WIDTH, HEIGHT = screen.get_size()
|
||||
#objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'medieval', 48, "Play", play))
|
||||
#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, "Exit game", quitGame))
|
||||
#objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 - 72, 160, 64, 'textbox.png', 'medieval', 48, "Play", play))
|
||||
#objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'textbox.png', 'medieval', 48, "Options", uwu))
|
||||
#objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'textbox.png', 'medieval', 48, "Exit game", quitGame))
|
||||
menu(screen, clock, running, background, isblack, WIDTH, HEIGHT)
|
||||
test(screen, clock, running, background, isblack, WIDTH, HEIGHT)
|
||||
|
||||
|
|
|
|||
21
viecher.py
21
viecher.py
|
|
@ -1,5 +1,6 @@
|
|||
import pygame as pg
|
||||
from classes import *
|
||||
|
||||
vec = pg.math.Vector2
|
||||
fps = 60
|
||||
|
||||
|
|
@ -195,8 +196,9 @@ class MainCharacter(Fighter):
|
|||
self.y = objects[3][0].height - 32 - self.rect.height + 1
|
||||
"""
|
||||
|
||||
def attack(self, obj, moveto = vec(0,1)):
|
||||
def attack(self, obj, mouse):
|
||||
if self.lastAttack + self.attack_speed * 1000 < pg.time.get_ticks():
|
||||
moveto = mouse- vec(self.x, self.y)
|
||||
if self.book.current_sp == 'fireball':
|
||||
weapon = Fireball('fb1', 100, self.x, self.y, moveto, 5)
|
||||
else:
|
||||
|
|
@ -204,11 +206,11 @@ class MainCharacter(Fighter):
|
|||
obj[3].append(weapon)
|
||||
self.lastAttack = pg.time.get_ticks()
|
||||
|
||||
def update(self, keys, objects):
|
||||
def update(self, keys, mouse, objects):
|
||||
if not self.talking:
|
||||
self.walk(keys, objects)
|
||||
if keys[pg.K_f]:
|
||||
self.attack(objects)
|
||||
if keys[pg.K_f]:
|
||||
self.attack(objects, vec(mouse))
|
||||
if self.health.health <= 0:
|
||||
return False
|
||||
else:
|
||||
|
|
@ -295,21 +297,30 @@ class Book():
|
|||
self.rect = pg.Rect(self.x, self.y, self.sprite.get_width(), self.sprite.get_height())
|
||||
self.sp_list = spells
|
||||
self.current_sp = current_spell
|
||||
self.buttons=[]
|
||||
self.buttons_height = 150
|
||||
|
||||
def draw(self, screen):
|
||||
if self.hidden:
|
||||
return
|
||||
self.rect.x, self.rect.y = self.x, self.y
|
||||
screen.blit(self.sprite, self.rect)
|
||||
for button in self.buttons:
|
||||
button.update(screen)
|
||||
|
||||
def addspell(self, spell):
|
||||
if spell not in self.sp_list:
|
||||
self.sp_list.append(spell)
|
||||
self.current_sp = spell
|
||||
self.buttons.append(Button(200, self.buttons_height, 58, 50, f'{spell}.png', 'medieval', 23))
|
||||
self.buttons_height += 100
|
||||
|
||||
def update_spell(self):
|
||||
self.current_sp = None
|
||||
|
||||
def update(self):
|
||||
pass
|
||||
|
||||
|
||||
class Mobs(Fighter):
|
||||
def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr, drops) -> None:
|
||||
super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue