Compare commits
	
		
			No commits in common. "0564d778a12336843eaab71bb0975264281ba86a" and "96b15fd4250f056e159986c7ebaf7677a7279022" have entirely different histories.
		
	
	
		
			0564d778a1
			...
			96b15fd425
		
	
		
					 3 changed files with 23 additions and 27 deletions
				
			
		
							
								
								
									
										23
									
								
								classes.py
									
										
									
									
									
								
							
							
						
						
									
										23
									
								
								classes.py
									
										
									
									
									
								
							|  | @ -34,13 +34,12 @@ fonts = { | |||
| } | ||||
| 
 | ||||
| class Button(): | ||||
|     def __init__(self, x, y, width, height, image, font, font_size, buttonText='', onclickFunction=None, onePress=False, attributes=None): | ||||
|     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 | ||||
|         self.width = width | ||||
|         self.height = height | ||||
|         self.attributes = attributes | ||||
|         self.onclickFunction = onclickFunction | ||||
|         self.onePress = onePress | ||||
|         self.alreadyPressed = False | ||||
|  | @ -54,15 +53,15 @@ class Button(): | |||
| 
 | ||||
|         self.buttonSurf = self.font.render(buttonText, True, '#baab80') | ||||
| 
 | ||||
|     def update(self, screen): | ||||
|     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]: | ||||
|                 if self.onePress: | ||||
|                     self.onclickFunction() | ||||
|                 elif not self.alreadyPressed: | ||||
|                     if self.attributes: | ||||
|                         self.onclickFunction(*self.attributes) | ||||
|                     if 'play' in str(self.onclickFunction): | ||||
|                         self.onclickFunction(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||
|                         self.alreadyPressed = True | ||||
|                     else: | ||||
|                         self.onclickFunction() | ||||
|  | @ -159,10 +158,10 @@ class Scene(GameObjects): | |||
|         self.level = level | ||||
|         self.current_level = 0 | ||||
| 
 | ||||
|     def update(self, change:bool, objects): | ||||
|     def update(self, change:bool): | ||||
|         if change: | ||||
|             self.current_level += 1 | ||||
|         self.level[self.current_level].update(objects) | ||||
|         self.level[self.current_level].update() | ||||
|         self.background = self.level[self.current_level].background | ||||
|         if isinstance(self.objects, list): | ||||
|             for obj in self.objects[0] + self.objects[1] + self.objects[2]: | ||||
|  | @ -185,10 +184,10 @@ class Stage(GameObjects): | |||
|         self.rooms = rooms | ||||
|         self.current = 0 | ||||
|      | ||||
|     def update(self, objects): | ||||
|     def update(self): | ||||
|         for room in self.rooms: | ||||
|             if room.id == self.current: | ||||
|                 room.update(objects) | ||||
|                 room.update() | ||||
|                 self.background = room.background | ||||
|         keys = pygame.key.get_pressed() | ||||
|         if keys[pygame.K_RIGHT]: | ||||
|  | @ -217,6 +216,7 @@ class Room(GameObjects): | |||
|             self.locked = False | ||||
|         [self.objects[3].append(wall) for wall in self.genWalls(WIDTH, HEIGHT)] | ||||
|          | ||||
|          | ||||
|     def genWalls(self, WIDTH, HEIGHT): | ||||
|         walls = [] | ||||
|         walls.append(Obstacle('wall_l', 'wall', None, True, 32, 32, True, WIDTH=4, HEIGHT=HEIGHT)) | ||||
|  | @ -225,10 +225,7 @@ class Room(GameObjects): | |||
|         walls.append(Obstacle('wall_b', 'wall', None, True, 32, HEIGHT + 28, True, WIDTH=WIDTH, HEIGHT=4)) | ||||
|         return walls | ||||
| 
 | ||||
|     def update(self, objects): | ||||
|         self.objects = objects | ||||
|         if not self.objects[1]: | ||||
|             self.locked = False | ||||
|     def update(self): | ||||
|         return | ||||
|      | ||||
|     def draw(self, screen): | ||||
|  |  | |||
							
								
								
									
										13
									
								
								main.py
									
										
									
									
									
								
							
							
						
						
									
										13
									
								
								main.py
									
										
									
									
									
								
							|  | @ -31,13 +31,12 @@ def genRooms(WIDTH, HEIGHT, type:str, objects:list): | |||
|     room_objects = [Obstacle('dirt', 'boulder', 'art/images/dirt2.png', False, 32, 32, WIDTH=WIDTH - 64, HEIGHT=HEIGHT - 64)] | ||||
|     room_objects.append(Obstacle('river', 'water', 'art/images/river1.png', True, 32, 32, WIDTH=WIDTH - 64, HEIGHT=HEIGHT - 64)) | ||||
|     rooms = [ | ||||
|         Room(type, 'normal', f'art/images/{type}.png', [objects[0], objects[1], objects[2], [room_objects[random.randint(0, len(room_objects) - 1)] for i in range(0, 5)]], WIDTH - 64, HEIGHT - 64, [True, True, True, False], 0), | ||||
|         Room(type, 'normal', f'art/images/{type}.png', [objects[0], objects[1], objects[2], [room_objects[random.randint(0, len(room_objects) - 1)] for i in range(0, 5)]], WIDTH - 64, HEIGHT - 64, [True, True, True, False], 1), | ||||
|         Room(type, 'normal', f'art/images/{type}.png', [objects[0], objects[1], objects[2], [room_objects[random.randint(0, len(room_objects) - 1)] for i in range(0, 5)]], WIDTH - 64, HEIGHT - 64, [True, True, True, False], 2), | ||||
|         Room(type, 'normal', f'art/images/{type}.png', [objects[0], objects[1], objects[2], [room_objects[i] for i in range(0, random.randint(0, len(room_objects)))]], WIDTH - 64, HEIGHT - 64, [True, True, True, False], 0), | ||||
|         Room(type, 'normal', f'art/images/{type}.png', [objects[0], objects[1], objects[2], [room_objects[i] for i in range(0, random.randint(0, len(room_objects)))]], WIDTH - 64, HEIGHT - 64, [True, True, True, False], 1), | ||||
|         Room(type, 'normal', f'art/images/{type}.png', [objects[0], objects[1], objects[2], [room_objects[i] for i in range(0, random.randint(0, len(room_objects)))]], WIDTH - 64, HEIGHT - 64, [True, True, True, False], 2), | ||||
|             ] | ||||
|     return rooms | ||||
| 
 | ||||
|          | ||||
| def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): | ||||
|     main = [MainCharacter('Herbert', 100, 'oldman.png', 500, 500, 20, 5, 1, 1, 50)] | ||||
|     mobs = [Skeleton(i, random.randint(40, 60), 'reddy.png', random.randint(20,1000), random.randint(20,700), 5, 1, 1, 1, 200) for i in range(0,random.randint(2, 8))] | ||||
|  | @ -67,7 +66,7 @@ def play(screen, clock, running, background, isblack, WIDTH, HEIGHT): | |||
|         screen.blit(bg, (0, 0)) | ||||
| """  | ||||
|         if not freeze: | ||||
|             scene.update(False, objects) | ||||
|             scene.update(False) | ||||
|             objects = scene.getObjects() | ||||
|             screen.blit(scene.background, (32, 32)) | ||||
|             for thing in objects[3]: | ||||
|  | @ -136,7 +135,7 @@ 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, 'textbox.png', 'medieval', 48, "Play", play, attributes=[screen, clock, running, background, isblack, WIDTH, HEIGHT])) | ||||
|     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: | ||||
|  | @ -151,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.update(screen) | ||||
|             obj.update(screen, clock, running, background, isblack, WIDTH, HEIGHT) | ||||
| 
 | ||||
|         # flip() the display to put your work on screen | ||||
|         pygame.display.flip() | ||||
|  |  | |||
							
								
								
									
										12
									
								
								viecher.py
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								viecher.py
									
										
									
									
									
								
							|  | @ -1,6 +1,5 @@ | |||
| import pygame as pg | ||||
| from classes import * | ||||
| from main import * | ||||
| 
 | ||||
| vec = pg.math.Vector2 | ||||
| fps = 60 | ||||
|  | @ -171,11 +170,11 @@ class MainCharacter(Fighter): | |||
|                     if touches.name == 'wall_l': | ||||
|                         self.x += (2 + (self.x - touches.rect.x)) | ||||
|                     elif touches.name == 'wall_r': | ||||
|                         self.x -= (2 + self.rect.width - (touches.rect.x - self.x)) | ||||
|                         self.x -= (self.rect.width - (touches.rect.x - self.x)) | ||||
|                     if touches.name == 'wall_t': | ||||
|                         self.y += (2 + (self.y - touches.rect.y)) | ||||
|                     elif touches.name == 'wall_b': | ||||
|                         self.y -= (2 + self.rect.height - (touches.rect.y - self.y)) | ||||
|                         self.y -= (self.rect.height - (touches.rect.y - self.y)) | ||||
|                     return | ||||
|                  | ||||
|             if self.x <= touches.rect.x: self.x -= (self.rect.width - (touches.rect.x - self.x)) | ||||
|  | @ -313,14 +312,15 @@ class Book(): | |||
|         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, attributes=[spell], onclickFunction=self.update_spell)) | ||||
|             self.buttons.append(Button(200, self.buttons_height, 58, 50, f'{spell}.png', 'medieval', 23)) | ||||
|             self.buttons_height += 100 | ||||
| 
 | ||||
|     def update_spell(self, spell): | ||||
|         self.current_sp = spell | ||||
|     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