File size: 2,239 Bytes
21229be efa4041 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
import random
class FoodManager:
def __init__(self):
self.amount = 5
class BodyPart:
position = [-1, -1]
class Head:
_position = 0
_velocity = [1, 1]
class Tail:
_position = 3
_velocity = [0, 0]
def check_collision():
global head, tail, body, food_manager
collision = False
tail_x, body_items, food_size = len(tail._position)-1, len(body), body_item_width() + body_margin()
if abs(head._position) < food_size / 2:
body_items += 1
for _ in range(body_items+1):
if min(_ == head._position - 1, len(head._position) - 1) > max(body._position, food._position):
collision = True
break
if food_manager.amount > 0:
for _ in range(4):
if abs(_ == head._position % food_size or _ == tail._position % food_size) <= food_size / 4:
collision = True
break
else:
collision |= abs(head._position) >= food_size / 2
return collision
def set_score_label_text():
label_str = "Score: {}".format(game.points)
global score_label
score_label.setText(label_str)
def main():
game.setWindowSize((len(header)+min(game_field_width(), body_height())+178, len(footer)))
global header, footer
header.pushLabels(["Settings", "FPS"])
footer.pushButtonLabels(["New Game", "Quit Game"])
score_label.setText("Score: 0")
player.addKeyboardControlledActor(main_actor)
play_loop = game.repeat(game.timePerFrame/60, 1, update)
def update(deltaTime):
global game
# Setup Food Manager
food_manager = FoodManager()
while True:
# Initialize game components
initGameComponents()
# Start playing the game
playLoop()
def checkCollision():
# Check collisions here
pass
def setScoreText():
# Set scores
pass
def addBodyParts():
# Add body parts
pass
def removeTailSegments():
# Remove tail segments
pass
def addHeadAndTailSegmentToBoard():
# Add head and tail segment to board
pass
def growWithoutEating():
# Grow without eating
pass
def stopPlaying():
# Stop Playing
pass
def changeDirectionAfterCrash():
# Change Direction After Crash
pass
initGameComponents()
playLoop() |