-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added multiple property decorators and added new methods to the butto…
…n class, and removed redundant variables, more info is provided in the release of 2.2.0
- Loading branch information
1 parent
f0b0294
commit 5d159c6
Showing
10 changed files
with
119 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,39 @@ | ||
import pygame as p | ||
|
||
from space_dodge.file_handling.constants_and_file_loading import WINDOW | ||
|
||
|
||
class Button: | ||
def __init__(self, image, x, y): | ||
self.image = image | ||
self._image = image | ||
self.x = x | ||
self.y = y | ||
self.pos = (x, y) | ||
self.width = image.get_width() | ||
self.height = image.get_height() | ||
self.image_hover = p.transform.scale(self._image, (self.width + 3, self.height + 3)) | ||
self.rect = p.Rect(x, y, self.width, self.height) | ||
|
||
@property | ||
def image(self): | ||
mouse_pos = p.mouse.get_pos() | ||
if self.rect.collidepoint(mouse_pos): | ||
return self.image_hover | ||
else: | ||
return self._image | ||
|
||
|
||
def update_rect(self, x): | ||
self.rect = p.Rect(x, self.y, self.width, self.height) | ||
self.x = x | ||
return self.rect | ||
|
||
def clicked(self): | ||
mouse_pos = p.mouse.get_pos() | ||
if self.rect.collidepoint(mouse_pos) and p.mouse.get_pressed()[0]: | ||
return True | ||
else: | ||
return False | ||
|
||
def draw(self): | ||
WINDOW.blit(self.image, self.pos) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,36 @@ | ||
from space_dodge.file_handling.constants_and_file_loading import HEIGHT, PLAYER_HEIGHT, PLAYER_WIDTH, PLAYER_VELOCITY, \ | ||
playerL, playerR | ||
playerL, playerR, WIDTH | ||
|
||
|
||
class Player: | ||
def __init__(self): | ||
self.x = 0 | ||
self._x = 0 | ||
self.y = HEIGHT - PLAYER_HEIGHT | ||
self.width = PLAYER_WIDTH | ||
self.height = PLAYER_HEIGHT | ||
self.velocity = PLAYER_VELOCITY | ||
self.left_image = playerL | ||
self.right_image = playerR | ||
self.image = playerL | ||
self._image = playerL | ||
self.direction = 0 # The direction the player is facing( written in binary ) 0 = left, 1 = right | ||
|
||
def direction(self, direction): | ||
if direction == 0: | ||
self.image = self.left_image | ||
@property | ||
def image(self): | ||
if self.direction == 0: | ||
self._image = self.left_image | ||
else: | ||
self.image = self.right_image | ||
return self.image | ||
self._image = self.right_image | ||
return self._image | ||
|
||
@property | ||
def x(self): | ||
return self._x | ||
|
||
@x.setter | ||
def x(self, value): | ||
if value - self.velocity >= 0 and value + self.velocity + self.width <= WIDTH: | ||
self._x = value | ||
|
||
@property | ||
def pos(self): | ||
return self._x, self.y |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.