forked from InfoProjekt/game
Development #2
3 changed files with 29 additions and 17 deletions
|
|
@ -34,7 +34,7 @@ fonts = {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Button():
|
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.font = pygame.font.Font(f'fonts/{fonts[font]}', font_size)
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
|
|
@ -44,7 +44,7 @@ class Button():
|
||||||
self.onePress = onePress
|
self.onePress = onePress
|
||||||
self.alreadyPressed = False
|
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.image.load(tb)
|
||||||
self.box = pygame.transform.scale(self.box, (width, height))
|
self.box = pygame.transform.scale(self.box, (width, height))
|
||||||
|
|
||||||
|
|
@ -53,7 +53,7 @@ class Button():
|
||||||
|
|
||||||
self.buttonSurf = self.font.render(buttonText, True, '#baab80')
|
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()
|
mousePos = pygame.mouse.get_pos()
|
||||||
if self.buttonRect.collidepoint(mousePos):
|
if self.buttonRect.collidepoint(mousePos):
|
||||||
if pygame.mouse.get_pressed(num_buttons=3)[0]:
|
if pygame.mouse.get_pressed(num_buttons=3)[0]:
|
||||||
|
|
@ -227,4 +227,4 @@ class Obstacle(GameObjects):
|
||||||
self.rect = pygame.Rect((x, y), self.background.get_size())
|
self.rect = pygame.Rect((x, y), self.background.get_size())
|
||||||
|
|
||||||
def draw(self, screen):
|
def draw(self, screen):
|
||||||
screen.blit(self.background, self.rect)
|
screen.blit(self.background, self.rect)
|
||||||
|
|
|
||||||
16
main.py
16
main.py
|
|
@ -64,7 +64,7 @@ def play(screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
||||||
if not freeze:
|
if not freeze:
|
||||||
for thing in objects[0]:
|
for thing in objects[0]:
|
||||||
thing.book.hidden = not freeze
|
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)
|
menu(screen, clock, running, background, isblack, WIDTH, HEIGHT)
|
||||||
thing.draw(screen)
|
thing.draw(screen)
|
||||||
|
|
||||||
|
|
@ -127,9 +127,9 @@ def options(screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
||||||
|
|
||||||
def menu(screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
def menu(screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
||||||
objects = []
|
objects = []
|
||||||
objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2, 160, 64, 'medieval', 48, "Play", play))
|
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, 'medieval', 48, "Options", uwu))
|
#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, 'medieval', 48, "Exit game", quitGame))
|
objects.append(Button(WIDTH / 2 - 80, HEIGHT / 2 + 72, 160, 64, 'textbox.png', 'medieval', 48, "Exit game", quitGame))
|
||||||
while running:
|
while running:
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
|
|
@ -142,7 +142,7 @@ def menu(screen, clock, running, background, isblack, WIDTH, HEIGHT):
|
||||||
# fill the screen with an image to clear the screen
|
# fill the screen with an image to clear the screen
|
||||||
screen.blit(bg, (0, 0))
|
screen.blit(bg, (0, 0))
|
||||||
for obj in objects:
|
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
|
# flip() the display to put your work on screen
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
|
|
@ -180,9 +180,9 @@ def main():
|
||||||
config = readConfig()
|
config = readConfig()
|
||||||
screen, clock, running, isblack, background, objects = setUp(config["screen"])
|
screen, clock, running, isblack, background, objects = setUp(config["screen"])
|
||||||
WIDTH, HEIGHT = screen.get_size()
|
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 - 72, 160, 64, 'textbox.png', '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, 160, 64, 'textbox.png', '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, "Exit game", quitGame))
|
||||||
menu(screen, clock, running, background, isblack, WIDTH, HEIGHT)
|
menu(screen, clock, running, background, isblack, WIDTH, HEIGHT)
|
||||||
test(screen, clock, running, background, isblack, WIDTH, HEIGHT)
|
test(screen, clock, running, background, isblack, WIDTH, HEIGHT)
|
||||||
|
|
||||||
|
|
|
||||||
22
viecher.py
22
viecher.py
|
|
@ -1,4 +1,6 @@
|
||||||
import pygame as pg
|
import pygame as pg
|
||||||
|
from classes import *
|
||||||
|
|
||||||
vec = pg.math.Vector2
|
vec = pg.math.Vector2
|
||||||
fps = 60
|
fps = 60
|
||||||
|
|
||||||
|
|
@ -163,8 +165,9 @@ class MainCharacter(Fighter):
|
||||||
if isinstance(touches, NPC):
|
if isinstance(touches, NPC):
|
||||||
touches.talk(objects)
|
touches.talk(objects)
|
||||||
|
|
||||||
def attack(self, obj, moveto = vec(0,1)):
|
def attack(self, obj, mouse):
|
||||||
if self.lastAttack + self.attack_speed * 1000 < pg.time.get_ticks():
|
if self.lastAttack + self.attack_speed * 1000 < pg.time.get_ticks():
|
||||||
|
moveto = mouse- vec(self.x, self.y)
|
||||||
if self.book.current_sp == 'fireball':
|
if self.book.current_sp == 'fireball':
|
||||||
weapon = Fireball('fb1', 100, self.x, self.y, moveto, 5)
|
weapon = Fireball('fb1', 100, self.x, self.y, moveto, 5)
|
||||||
else:
|
else:
|
||||||
|
|
@ -172,11 +175,11 @@ class MainCharacter(Fighter):
|
||||||
obj[3].append(weapon)
|
obj[3].append(weapon)
|
||||||
self.lastAttack = pg.time.get_ticks()
|
self.lastAttack = pg.time.get_ticks()
|
||||||
|
|
||||||
def update(self, keys, objects):
|
def update(self, keys, mouse, objects):
|
||||||
if not self.talking:
|
if not self.talking:
|
||||||
self.walk(keys, objects)
|
self.walk(keys, objects)
|
||||||
if keys[pg.K_f]:
|
if keys[pg.K_f]:
|
||||||
self.attack(objects)
|
self.attack(objects, vec(mouse))
|
||||||
if self.health.health <= 0:
|
if self.health.health <= 0:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
|
@ -263,21 +266,30 @@ class Book():
|
||||||
self.rect = pg.Rect(self.x, self.y, self.sprite.get_width(), self.sprite.get_height())
|
self.rect = pg.Rect(self.x, self.y, self.sprite.get_width(), self.sprite.get_height())
|
||||||
self.sp_list = spells
|
self.sp_list = spells
|
||||||
self.current_sp = current_spell
|
self.current_sp = current_spell
|
||||||
|
self.buttons=[]
|
||||||
|
self.buttons_height = 150
|
||||||
|
|
||||||
def draw(self, screen):
|
def draw(self, screen):
|
||||||
if self.hidden:
|
if self.hidden:
|
||||||
return
|
return
|
||||||
self.rect.x, self.rect.y = self.x, self.y
|
self.rect.x, self.rect.y = self.x, self.y
|
||||||
screen.blit(self.sprite, self.rect)
|
screen.blit(self.sprite, self.rect)
|
||||||
|
for button in self.buttons:
|
||||||
|
button.update(screen)
|
||||||
|
|
||||||
def addspell(self, spell):
|
def addspell(self, spell):
|
||||||
if spell not in self.sp_list:
|
if spell not in self.sp_list:
|
||||||
self.sp_list.append(spell)
|
self.sp_list.append(spell)
|
||||||
self.current_sp = 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):
|
def update(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Mobs(Fighter):
|
class Mobs(Fighter):
|
||||||
def __init__(self, name, ms, sprite, x, y, health, damage, level, asp, atr, drops) -> None:
|
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)
|
super().__init__(name, ms, sprite, x, y, health, damage, level, asp, atr)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue