summaryrefslogtreecommitdiff
path: root/GameEngine/GoalCollection.py
diff options
context:
space:
mode:
authorbd-912 <bdunahu@gmail.com>2023-11-12 20:10:57 -0700
committerbd-912 <bdunahu@gmail.com>2023-11-12 20:26:49 -0700
commita2b56742da7b30afa00f33c9a806fa6031be68a5 (patch)
tree94acd653183c0cc57e0434f39f5d3917eb99fdc0 /GameEngine/GoalCollection.py
parentfa75138690814ad7a06194883a12f25c3936a15e (diff)
Added initial files
Diffstat (limited to 'GameEngine/GoalCollection.py')
-rw-r--r--GameEngine/GoalCollection.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/GameEngine/GoalCollection.py b/GameEngine/GoalCollection.py
new file mode 100644
index 0000000..17e9721
--- /dev/null
+++ b/GameEngine/GoalCollection.py
@@ -0,0 +1,33 @@
+#+AUTHOR: bdunahu
+#+TITLE: multiplayer.py
+#+DESCRIPTION: goal object for multiagent snake
+
+import pygame as pg
+from random import randint
+from collections import namedtuple
+
+Point = namedtuple('Point', 'x, y')
+GREEN = (0,128,43)
+
+class Goal():
+ def __init__(self, display, window_width=640, window_height=480, game_units=40):
+ ''' create initial location '''
+ self.location = None
+
+ self.display = display
+ self.window_width = window_width
+ self.window_height = window_height
+ self.game_units = game_units
+
+ def reset(self, hazards=[]):
+ ''' generate new coordinates for goal '''
+ x = randint(0, (self.window_width-self.game_units )//self.game_units )*self.game_units
+ y = randint(0, (self.window_height-self.game_units )//self.game_units )*self.game_units
+ self.location = Point(x, y)
+ if self.location in hazards:
+ self.reset(hazards)
+
+ def draw(self):
+ ''' draw rectangle directly on field '''
+ pg.draw.rect(self.display, GREEN, pg.Rect(self.location.x, self.location.y,
+ self.game_units, self.game_units))