Skip to content

Commit

Permalink
Add Save-Photo Button,
Browse files Browse the repository at this point in the history
Extend README.md with pictures,
reformat code, optimize imports
  • Loading branch information
johannesbuchholz committed Jan 22, 2023
1 parent ab2dba3 commit ac8cd10
Show file tree
Hide file tree
Showing 34 changed files with 159 additions and 134 deletions.
6 changes: 3 additions & 3 deletions FieldObjects/Items/ItemBase.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

from Utils.Const import *


class ItemBase:
"""
This class represents the base class of all items that may appear on the screen. It does not have any effect.
"""

def __init__(self, controller, gamescreen):
"""
Creates an base Item.
Creates a base Item.
:param controller: Controller instance of the game screen.
:param gamescreen: The gamescreen instance where this item is placed in.
Expand All @@ -19,7 +19,7 @@ def __init__(self, controller, gamescreen):

# This value should be manually adjusted depending on the respective Item that inherits this class.
self.duration = DURATION_NORMAL
self.image_path = "Data/DefaultIcon.png" # Relative path to item icon. (from __main__, 20 x 20 pixels, .png)
self.image_path = "Data/DefaultIcon.png"

self.player = None # Will be defined during method call activate.

Expand Down
4 changes: 1 addition & 3 deletions FieldObjects/Items/ItemBigAll.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from FieldObjects.Items.ItemBase import ItemBase
from Utils.Const import *

Expand All @@ -7,11 +6,11 @@ class ItemBigAll(ItemBase):
"""
Increases the size of every player but the collecting player by one step.
"""

# __init__ from base class.
def __init__(self, controller, gamescreen):
ItemBase.__init__(self, controller, gamescreen)
self.duration = DURATION_NORMAL
# Relative path to item icon. (from __main__, 20 x 20 pixels, .png)
self.image_path = "Data/IconBigAll.png"
self.players_to_ignore = [] # Stores all players to ignore by this item

Expand Down Expand Up @@ -43,4 +42,3 @@ def deactivate(self):
else:
# Choose next bigger value from the SPEEDS list
p.size = SIZES[max(SIZES.index(p.size) - 1, 0)]

6 changes: 3 additions & 3 deletions FieldObjects/Items/ItemBlock.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

from numpy.random import default_rng

from FieldObjects.Items.ItemBase import ItemBase
from Utils.Const import *

Expand All @@ -8,11 +8,11 @@ class ItemBlock(ItemBase):
"""
Places a Block randomly on the field.
"""

# __init__ from base class.
def __init__(self, controller, gamescreen):
ItemBase.__init__(self, controller, gamescreen)
self.duration = DURATION_INFINITE # No effective usage
# Relative path to item icon. (from __main__, 20 x 20 pixels, .png)
self.image_path = "Data/IconBlock.png"
self.rng = default_rng()
self.blocksize = 100
Expand All @@ -32,7 +32,7 @@ def activate(self, player):
to=(x_rand, y_rand, x_rand + self.blocksize, y_rand + self.blocksize)
)
# Effectively
self.gamescreen.walls[x_rand:x_rand+self.blocksize, y_rand:y_rand+self.blocksize] = -1
self.gamescreen.walls[x_rand:x_rand + self.blocksize, y_rand:y_rand + self.blocksize] = -1

def deactivate(self):
"""
Expand Down
3 changes: 1 addition & 2 deletions FieldObjects/Items/ItemClear.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from FieldObjects.Items.ItemBase import ItemBase
from Utils.Const import *

Expand All @@ -7,11 +6,11 @@ class ItemClear(ItemBase):
"""
Clears all walls within the game field.
"""

# __init__ from base class.
def __init__(self, controller, gamescreen):
ItemBase.__init__(self, controller, gamescreen)
self.duration = DURATION_INSTANT
# Relative path to item icon. (from __main__, 20 x 20 pixels, .png)
self.image_path = "Data/IconClear.png"

def activate(self, player):
Expand Down
3 changes: 1 addition & 2 deletions FieldObjects/Items/ItemFastAll.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from FieldObjects.Items.ItemBase import ItemBase
from Utils.Const import *

Expand All @@ -7,11 +6,11 @@ class ItemFastAll(ItemBase):
"""
Increases the speed of every player but the collecting player by one step if possible.
"""

# __init__ from base class.
def __init__(self, controller, gamescreen):
ItemBase.__init__(self, controller, gamescreen)
self.duration = DURATION_NORMAL
# Relative path to item icon. (from __main__, 20 x 20 pixels, .png)
self.image_path = "Data/IconFastAll.png"
self.players_to_ignore = [] # Stores all players having max speed at the time of collecting this item.

Expand Down
3 changes: 1 addition & 2 deletions FieldObjects/Items/ItemFastSelf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from FieldObjects.Items.ItemBase import ItemBase
from Utils.Const import *

Expand All @@ -7,11 +6,11 @@ class ItemFastSelf(ItemBase):
"""
Increases the speed of the collecting player by one step if possible.
"""

# __init__ from base class.
def __init__(self, controller, gamescreen):
ItemBase.__init__(self, controller, gamescreen)
self.duration = DURATION_SHORT
# Relative path to item icon. (from __main__, 20 x 20 pixels, .png)
self.image_path = "Data/IconFastSelf.png"
self.was_at_max_speed = False

Expand Down
3 changes: 1 addition & 2 deletions FieldObjects/Items/ItemFly.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from FieldObjects.Items.ItemBase import ItemBase
from Utils.Const import *

Expand All @@ -8,11 +7,11 @@ class ItemFly(ItemBase):
Makes the player flying and being able to cross any walls while not making a wall by himself during the time
of this item being active.
"""

# __init__ from base class.
def __init__(self, controller, gamescreen):
ItemBase.__init__(self, controller, gamescreen)
self.duration = DURATION_SHORT
# Relative path to item icon. (from __main__, 20 x 20 pixels, .png)
self.image_path = "Data/IconFly.png"

def activate(self, player):
Expand Down
5 changes: 1 addition & 4 deletions FieldObjects/Items/ItemGlueAll.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from FieldObjects.Items.ItemBase import ItemBase
from Utils.Const import *

Expand All @@ -7,15 +6,13 @@ class ItemGlueAll(ItemBase):
"""
Makes all players sbut the collecting player turn slower.
"""

# __init__ from base class.
def __init__(self, controller, gamescreen):
ItemBase.__init__(self, controller, gamescreen)
self.duration = DURATION_SHORT
# Relative path to item icon. (from __main__, 20 x 20 pixels, .png)
self.image_path = "Data/IconGlueAll.png"

self.player = None # Will be defined during method call activate.

self.players_to_ignore = []

def activate(self, player):
Expand Down
5 changes: 1 addition & 4 deletions FieldObjects/Items/ItemJump.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from FieldObjects.Items.ItemBase import ItemBase
from Utils.Const import *

Expand All @@ -7,15 +6,13 @@ class ItemJump(ItemBase):
"""
Moves the players 30 times the players speed pixels in forward direction.
"""

# __init__ from base class.
def __init__(self, controller, gamescreen):
ItemBase.__init__(self, controller, gamescreen)
self.duration = DURATION_ONETIME
# Relative path to item icon. (from __main__, 20 x 20 pixels, .png)
self.image_path = "Data/IconJump.png"

self.player = None # Will be defined during method call activate.

self.previous_speed = None

def activate(self, player):
Expand Down
4 changes: 2 additions & 2 deletions FieldObjects/Items/ItemPackage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

from numpy.random import default_rng

from FieldObjects.Items.ItemBase import ItemBase
from Utils.Const import *

Expand All @@ -8,11 +8,11 @@ class ItemPackage(ItemBase):
"""
Places three random items on the game field.
"""

# __init__ from base class.
def __init__(self, controller, gamescreen):
ItemBase.__init__(self, controller, gamescreen)
self.duration = DURATION_INSTANT
# Relative path to item icon. (from __main__, 20 x 20 pixels, .png)
self.image_path = "Data/IconPackage.png"
self.rng = default_rng()

Expand Down
9 changes: 5 additions & 4 deletions FieldObjects/Items/ItemRandom.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
from importlib import import_module

from numpy.random import default_rng

from FieldObjects.Items.ItemBase import ItemBase
from Utils.Const import *
from importlib import import_module


class ItemRandom(ItemBase):
"""
Activates a random item effect.
"""

# __init__ from base class.
def __init__(self, controller, gamescreen):
ItemBase.__init__(self, controller, gamescreen)
self.duration = DURATION_INSTANT
# Relative path to item icon. (from __main__, 20 x 20 pixels, .png)
self.image_path = "Data/IconRandom.png"
self.rng = default_rng()

self.available_item_names = self.controller.all_items

if self.available_item_names.__contains__("ItemRandom"):
self.available_item_names.remove("ItemRandom")

Expand All @@ -31,7 +32,7 @@ def activate(self, player):
self.player = player
# emulate a random item
item_to_create = self.rng.choice(self.available_item_names)
item_module = import_module("FieldObjects.Items."+item_to_create)
item_module = import_module("FieldObjects.Items." + item_to_create)
item_class = getattr(item_module, item_to_create)
emulated_item = item_class(self.controller, self.gamescreen)

Expand Down
4 changes: 2 additions & 2 deletions FieldObjects/Items/ItemRemoveBorder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from FieldObjects.Items.ItemBase import ItemBase
from Utils.Const import *

Expand All @@ -7,11 +6,12 @@ class ItemRemoveBorder(ItemBase):
"""
Toggles the game screen borders off.
"""

# __init__ from base class.
def __init__(self, controller, gamescreen):
ItemBase.__init__(self, controller, gamescreen)
self.duration = DURATION_NORMAL
self.image_path = "Data/IconRemoveBorder.png" # Relative path to item icon. (from __main__, 20 x 20 pixels, .png)
self.image_path = "Data/IconRemoveBorder.png"

def activate(self, player):
"""
Expand Down
6 changes: 1 addition & 5 deletions FieldObjects/Items/ItemSlickSelf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from FieldObjects.Items.ItemBase import ItemBase
from Utils.Const import *

Expand All @@ -7,16 +6,13 @@ class ItemSlickSelf:
"""
Makes the collecting player turn faster.
"""

# __init__ from base class.
def __init__(self, controller, gamescreen):
ItemBase.__init__(self, controller, gamescreen)

self.duration = DURATION_LONG
# Relative path to item icon. (from __main__, 20 x 20 pixels, .png)
self.image_path = "Data/IconSlickSelf.png"

self.player = None # Will be defined during method call activate.

self.ignore = None

def activate(self, player):
Expand Down
4 changes: 1 addition & 3 deletions FieldObjects/Items/ItemSlowAll.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from FieldObjects.Items.ItemBase import ItemBase
from Utils.Const import *

Expand All @@ -7,11 +6,11 @@ class ItemSlowAll(ItemBase):
"""
Decrease the speed of every player but the collecting player by one step.
"""

# __init__ from base class.
def __init__(self, controller, gamescreen):
ItemBase.__init__(self, controller, gamescreen)
self.duration = DURATION_NORMAL
# Relative path to item icon. (from __main__, 20 x 20 pixels, .png)
self.image_path = "Data/IconSlowAll.png"
self.players_to_ignore = [] # Stores all players to ignore by this item

Expand Down Expand Up @@ -43,4 +42,3 @@ def deactivate(self):
else:
# Choose next bigger value from the SPEEDS list
p.speed = SPEEDS[min(SPEEDS.index(p.speed) + 1, len(SPEEDS) - 1)]

4 changes: 1 addition & 3 deletions FieldObjects/Items/ItemSlowSelf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from FieldObjects.Items.ItemBase import ItemBase
from Utils.Const import *

Expand All @@ -7,11 +6,11 @@ class ItemSlowSelf(ItemBase):
"""
Decreases the speed of the collecting player by one step.
"""

# __init__ from base class.
def __init__(self, controller, gamescreen):
ItemBase.__init__(self, controller, gamescreen)
self.duration = DURATION_SHORT
# Relative path to item icon. (from __main__, 20 x 20 pixels, .png)
self.image_path = "Data/IconSlowSelf.png"
self.ignore = False # Indicates if this Items effect should be ignored

Expand Down Expand Up @@ -40,4 +39,3 @@ def deactivate(self):
pass
else:
self.player.speed = SPEEDS[min(SPEEDS.index(self.player.speed) + 1, len(SPEEDS) - 1)]

3 changes: 1 addition & 2 deletions FieldObjects/Items/ItemSmallSelf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from FieldObjects.Items.ItemBase import ItemBase
from Utils.Const import *

Expand All @@ -7,11 +6,11 @@ class ItemSmallSelf(ItemBase):
"""
Increases the size of every player but the collecting player by one step.
"""

# __init__ from base class.
def __init__(self, controller, gamescreen):
ItemBase.__init__(self, controller, gamescreen)
self.duration = DURATION_NORMAL
# Relative path to item icon. (from __main__, 20 x 20 pixels, .png)
self.image_path = "Data/IconSmallSelf.png"
self.was_at_min_size = False

Expand Down
2 changes: 1 addition & 1 deletion FieldObjects/Items/ItemZiggZaggAll.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from FieldObjects.Items.ItemBase import ItemBase
from Utils.Const import *

Expand All @@ -8,6 +7,7 @@ class ItemZiggZaggAll(ItemBase):
sets the collecting everybody's but the collecting players turn rate to RATE_RIGHT_ANGLE.
Every turn will then be a 90 degree turn.
"""

# __init__ from base class.
def __init__(self, controller, gamescreen):
ItemBase.__init__(self, controller, gamescreen)
Expand Down
2 changes: 1 addition & 1 deletion FieldObjects/Items/ItemZiggZaggSelf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from FieldObjects.Items.ItemBase import ItemBase
from Utils.Const import *

Expand All @@ -7,6 +6,7 @@ class ItemZiggZaggSelf(ItemBase):
"""
Sets the collecting players turn rate to RATE_RIGHT_ANGLE. every turn will then be a 90 degree turn.
"""

# __init__ from base class.
def __init__(self, controller, gamescreen):
ItemBase.__init__(self, controller, gamescreen)
Expand Down
Loading

0 comments on commit ac8cd10

Please sign in to comment.