Example #1
0
 def setupGame(self):
     #This method sets up the game for the first time
     #Creating the ship and main character
     self.score = 0
     self.pikminList = []
     self.enemyList = []
     self.fruitList = []
     self.barbol = Character((640, 360), self)
     self.sunny = Spaceship((640, 300), self)
     #Spawning some pikmin initially for the player to control
     for i in range(8):
         self.sunny.spawnPikmin()
     quadlist = [1, 2, 3, 4]
     for j in range(4):
         #Spawning the fruit
         #Choosing a quadrant and removing it once it
         #has been used for a fruit
         quadrant = random.choice(quadlist)
         quadlist.remove(quadrant)
         #The x and y coordinates are chosen randomly based on the quadrant
         if quadrant == 1 or quadrant == 3:
             spawnX = random.randint(20, 510)
             if quadrant == 1:
                 spawnY = random.randint(20, 230)
             else:
                 spawnY = random.randint(490, 700)
         elif quadrant == 2 or quadrant == 4:
             spawnX = random.randint(770, 1260)
             if quadrant == 2:
                 spawnY = random.randint(20, 230)
             else:
                 spawnY = random.randint(490, 700)
         Fruit((spawnX, spawnY), self.sunny, self)
     quadlist = [1, 2, 3, 4]
     for k in range(4):
         quadrant = random.choice(quadlist)
         quadlist.remove(quadrant)
         if quadrant == 1 or quadrant == 3:
             spawnX = random.randint(20, 510)
             if quadrant == 1:
                 spawnY = random.randint(20, 230)
             else:
                 spawnY = random.randint(490, 700)
         elif quadrant == 2 or quadrant == 4:
             spawnX = random.randint(770, 1260)
             if quadrant == 2:
                 spawnY = random.randint(20, 230)
             else:
                 spawnY = random.randint(490, 700)
         Enemy("Enemy.png", (spawnX, spawnY), self.sunny, self)
Example #2
0
 def __init__(self, canvas, spaceship):
     from math import sin, cos, radians
     self.canvas = canvas
     self.spaceship = M.spaceship(canvas)
     self.vectors = list(range(-2, 2))
     self.angle = 0
     colors = [
         'gray40', 'gray50', 'gray60', 'gray70', 'gray75', 'gray80',
         'gray90'
     ]
     # pointsbad = [r.randint(20, 50), r.randint(20, 40),  # 1
     #           r.randint(-50, 10), r.randint(40, 50),  # 2
     #           r.randint(-40, -10), r.randint(-10, 30),  # 3
     #           r.randint(-50, -30), r.randint(-50, -30),  # 4
     #           r.randint(-10, 20), r.randint(-50, -30),  # 5
     #           r.randint(30, 40), r.randint(-50, -40),  # 6
     #           r.randint(0, 50), r.randint(-10, 10)]  # 7
     # self.points = list(map(lambda x: x // 2, points))
     self.points = [
         r.randint(10, 50) * cos(radians(self.angle + r.randint(-15, 15))),
         r.randint(10, 50) *
         sin(radians(self.angle + 0 + r.randint(-15, 15))),
         r.randint(10, 50) *
         cos(radians(self.angle + 60 + r.randint(-15, 15))),
         r.randint(10, 50) *
         sin(radians(self.angle + 60 + r.randint(-15, 15))),
         r.randint(10, 50) *
         cos(radians(self.angle + 120 + r.randint(-15, 15))),
         r.randint(10, 50) *
         sin(radians(self.angle + 120 + r.randint(-15, 15))),
         r.randint(10, 50) *
         cos(radians(self.angle + 180 + r.randint(-15, 15))),
         r.randint(10, 50) *
         sin(radians(self.angle + 180 + r.randint(-15, 15))),
         r.randint(10, 50) *
         cos(radians(self.angle + 240 + r.randint(-15, 15))),
         r.randint(10, 50) *
         sin(radians(self.angle + 240 + r.randint(-15, 15))),
         r.randint(10, 50) *
         cos(radians(self.angle + 300 + r.randint(-15, 15))),
         r.randint(10, 50) *
         sin(radians(self.angle + 300 + r.randint(-15, 15)))
     ]
     self.points = list(map(lambda x: int(round(x)), self.points))
     self.id = self.canvas.create_polygon(self.points,
                                          fill=r.choices(colors),
                                          width=2)
     self.x = r.choice(self.vectors)
     self.y = r.choice(self.vectors)
     self.canvas_height = self.canvas.winfo_height()
     self.speed = 1
     self.speedlimit = 4
     self.canvas.move(self.id, r.randint(100, 900), r.randint(100, 900))
Example #3
0
def runPyGame():
    # Initialise PyGame.
    pygame.init()

    # Set up the clock
    fps = 60
    dt = 1 / fps
    clock = pygame.time.Clock()

    # Set up the window.
    screen_size = (settings.SCREEN_WIDTH, settings.SCREEN_HEIGHT)
    screen = pygame.display.set_mode(screen_size)

    # Intialize input controller
    controller = UpdateController()

    # Initialize Spaceship
    ship = Spaceship()
    moon = Moon()

    # Setup Sprites:
    sprite_list = pygame.sprite.Group()
    sprite_list.add(ship)
    sprite_list.add(
        moon
    )  # TODO: The moon surface points are gonn have to be individual sprites

    # Main game loop
    while True:
        # Update sprites
        update(controller, dt, ship, moon)

        # Get time stuff
        dt = clock.tick(fps)
        fps_real = clock.get_fps()

        # Update screen
        draw(screen, ship, moon, fps_real)
def bullet_spray():
    for x in range(0,36):
        laser = Laser(spaceship.spaceship_direction + x * 10,spaceship.spaceship_x,spaceship.spaceship_y)
        lasers.append(laser)
    

pygame.mixer.music.load('DST-AngryRobotIII.mp3')
pygame.mixer.music.play(-1)
running = True
while running: #game loop
    for event in pygame.event.get(): #event loop
        if event.type == pygame.QUIT:
            running = False
        if event.type == pygame.MOUSEBUTTONUP and mode == 'menu':
            mode = 'play'
            spaceship = Spaceship()
            asteroid_list = []
            shot_counter = 0
            level = 1
            score = 0
            special = 5
            lasers = []
            new_level()

    pygame.time.delay(20)
    screen.fill(black)

    if mode == 'menu':
        message = myfont.render("Click to Start the Game" , 1, pygame.color.THECOLORS['white'])
        screen.blit(message, (220, 240))
        title = titlefont.render("ASTEROIDS" , 1, pygame.color.THECOLORS['white'])
Example #5
0
File: Main.py Project: Aym83/TIPE
##Appel des fonctions pour le système solaire et le vaisseau
soleil = Planet(None, "Soleil", 1.99e30, 1.39e6, 0, 0)
soleil.x = frame.frame.winfo_screenwidth() / 2
soleil.y = frame.frame.winfo_screenheight() / 2

mercure = Planet(soleil, "Mercure", 3.29e23, 4.88e3, 5.79e7, 61.76)
venus = Planet(soleil, "Venus", 4.87e24, 1.21e4, 1.08e8, -1.2)
terre = Planet(soleil, "Terre", 5.97e24, 1.27e4, 1.49e8, 0)
lune = Planet(terre, "Lune", 7.35e22, 3.47e3, 3.84e5, 0)
mars = Planet(soleil, "Mars", 6.42e23, 6.78e3, 2.27e8, 7.37)
jupiter = Planet(soleil, "Jupiter", 1.90e27, 1.40e5, 7.79e8, 82.87)
saturne = Planet(soleil, "Saturne", 5.68e26, 1.16e5, 1.42e9, 5.32)
uranus = Planet(soleil, "Uranus", 8.68e25, 5.07e4, 2.88e9, -54.7)
neptune = Planet(soleil, "Neptune", 1.02e26, 4.92e4, 4.50e9, -96.2)

vaisseau = Spaceship(soleil.x, soleil.y)

objects.append(soleil)
objects.append(mercure)
objects.append(venus)
objects.append(terre)
objects.append(lune)
objects.append(mars)
objects.append(jupiter)
objects.append(saturne)
objects.append(uranus)
objects.append(neptune)
objects.append(vaisseau)

##Boucle principale
Example #6
0
File: Main.py Project: Setzio/TIPE
soleil = Planet(None, "Soleil", 1.99e30, 1.39e6, 0, 0)
soleil.x = frame.frame.winfo_screenwidth()/2
soleil.y = frame.frame.winfo_screenheight()/2

mercure = Planet(soleil, "Mercure", 3.29e23, 4.88e3, 5.79e7, 308)
venus = Planet(soleil, "Venus", 4.87e24, 1.21e4, 1.08e8, 168)
terre = Planet(soleil, "Terre", 5.97e24, 1.27e4, 1.49e8, 175)
lune = Planet(terre, "Lune", 7.35e22, 3.47e3, 3.84e5, 113.8)
mars = Planet(soleil, "Mars", 6.42e23, 6.78e3, 2.27e8, 313)
jupiter = Planet(soleil, "Jupiter", 1.90e27, 1.40e5, 7.79e8, 309) 
saturne = Planet(soleil, "Saturne", 5.68e26, 1.16e5, 1.42e9, 168)
uranus = Planet(soleil, "Uranus", 8.68e25, 5.07e4, 2.88e9, 353)
neptune = Planet(soleil, "Neptune", 1.02e26, 4.92e4, 4.50e9, 324)

vaisseau = Spaceship(300, 300)

objects.append(soleil)
objects.append(mercure)
objects.append(venus)
objects.append(terre)
objects.append(lune)
objects.append(mars)
objects.append(jupiter)
objects.append(saturne)
objects.append(uranus)
objects.append(neptune)
objects.append(vaisseau)

##Boucle principale
FPS=60
Example #7
0
soleil = Planet(None, "Soleil", 1.99e30, 1.39e6, 0, 0)
soleil.x = frame.frame.winfo_screenwidth() / 2
soleil.y = frame.frame.winfo_screenheight() / 2

mercure = Planet(soleil, "Mercure", 3.29e23, 4.88e3, 5.79e7, 308)
venus = Planet(soleil, "Venus", 4.87e24, 1.21e4, 1.08e8, 168)
terre = Planet(soleil, "Terre", 5.97e24, 1.27e4, 1.49e8, 175)
lune = Planet(terre, "Lune", 7.35e22, 3.47e3, 3.84e5, 113.8)
mars = Planet(soleil, "Mars", 6.42e23, 6.78e3, 2.27e8, 313)
jupiter = Planet(soleil, "Jupiter", 1.90e27, 1.40e5, 7.79e8, 309)
saturne = Planet(soleil, "Saturne", 5.68e26, 1.16e5, 1.42e9, 168)
uranus = Planet(soleil, "Uranus", 8.68e25, 5.07e4, 2.88e9, 353)
neptune = Planet(soleil, "Neptune", 1.02e26, 4.92e4, 4.50e9, 324)

vaisseau = Spaceship(300, 300)

objects.append(soleil)
objects.append(mercure)
objects.append(venus)
objects.append(terre)
objects.append(lune)
objects.append(mars)
objects.append(jupiter)
objects.append(saturne)
objects.append(uranus)
objects.append(neptune)
objects.append(vaisseau)

##Boucle principale
FPS = 60
Example #8
0
from bullet import *
from star import *
from Boss import *
from Highscore import *
##largestNumber = 0
##file = open('test.txt', 'r')
##
##for line in file:
##    if line > largestNumber:
##        largestNumber = line
#print largestNumber
boss_spawner = 0
pygame.init()
screen = pygame.display.set_mode(
    [constants.SCREEN_WIDTH, constants.SCREEN_HEIGHT])
ss = Spaceship()
a = Alien(800, 100)
direction_counter = 50
bullet_counter = 0
bullets = []
aliens = [a]
stars = []
bosses = []
mode = "playing"
lose = pygame.image.load('you-lose-i-win.jpg')
lose = pygame.transform.scale(
    lose, (constants.SCREEN_WIDTH, constants.SCREEN_HEIGHT))
score = 0
score_font = pygame.font.SysFont("Times New Roman", 100)
alien_spawner = 0
def main():
	"""main function"""
	if not pygame.font:
		print("Cannot initialize fonts.")
		return
	global clock
	clock = pygame.time.Clock()
	pygame.init()
	if Settings.fullscreen:
		screenFlags = pygame.FULLSCREEN
		#screen_size is the resolution of the screen
	else:
		screenFlags = pygame.RESIZABLE
	screen = pygame.display.set_mode(Settings.screen_size, screenFlags)
	pygame.display.set_caption('Multiplayer Asteroids')
	pygame.mouse.set_visible(0)

	
	background = Background()
	fpsMeter = FpsMeter()
	

	#set up sprites
	allsprites = pygame.sprite.RenderUpdates()
	spaceships = pygame.sprite.RenderUpdates()
	missisles = pygame.sprite.RenderUpdates()
	asteroids = pygame.sprite.RenderUpdates()

	spaceship = Spaceship([Settings.map_size[0]//3, Settings.map_size[1]//2])
	spaceship2 = Spaceship([(Settings.map_size[0]*2) //3, Settings.map_size[1]//2])
	asteroid = Asteroid()
	allsprites.add(spaceship, spaceship2,  asteroid)
	asteroids.add(asteroid)
	spaceships.add(spaceship, spaceship2)

	pygame.display.flip()
	while True:
		#main game loop
		clock.tick(50) #fps
		

		for event in pygame.event.get():

			if event.type == USEREVENT and event.code == 0: #someone fired a missisle
				event.missisle.add(allsprites, missisles)
			elif event.type == KEYDOWN:
				if event.key == 273:	#up
					spaceship.startAccel()
				elif event.key == 119: 	#w
					spaceship2.startAccel()
				elif event.key == 274:	#down
					pass
				elif event.key == 115:	#s
					pass
				elif event.key == 275:	#right
					spaceship.startTurnRight()
				elif event.key == 97:	#a
					spaceship2.startTurnRight()
				elif event.key == 276:	#left
					spaceship.startTurnLeft()
				elif event.key == 100:	#d
					spaceship2.startTurnLeft()
				elif event.key == 109:	#m
					spaceship.shoot()
				elif event.key == 114:	#r
					spaceship2.shoot()
				elif event.key == 27:	#esc
					return
			elif event.type == KEYUP:
				if event.key == 273:	#up
					spaceship.stopAccel()
				elif event.key == 119: 	#w
					spaceship2.stopAccel()
				elif event.key == 274:	#down
					pass	
				elif event.key == 115:	#s
					pass
				elif event.key == 275:	#right
					spaceship.stopTurning()
				elif event.key == 97:	#a
					spaceship2.stopTurning()
				elif event.key == 276:	#left
					spaceship.stopTurning()
				elif event.key == 100:	#d
					spaceship2.stopTurning()
	
			elif event.type == QUIT:
				return


		fpsMeter.update()
		allsprites.update()


		#pygame.sprite.spritecollide(spaceship, asteroids, True)
		pygame.sprite.groupcollide(asteroids, missisles, True, True)
		pygame.sprite.groupcollide(asteroids, spaceships, True, True)
		pygame.sprite.groupcollide(spaceships, missisles, True, True)

		if pygame.sprite.collide_rect(spaceship, spaceship2):
			spaceship.kill()
			spaceship2.kill()

		if not len(asteroids.sprites())>0:#no asteroids
			asteroid = Asteroid()
			asteroids.add(asteroid)
			allsprites.add(asteroid)


		pygame.display.update([background.draw(screen), fpsMeter.draw(screen)] + allsprites.draw(screen))
Example #10
0
import random
import sys
import os
import time
import Spaceship
import Alien
import math
import Missile
import pygame
from pygame.locals import *
from random import randint
from pygame.time import *
from pygame.font import *

spaceship = Spaceship.ship()
alien = Alien.alien()
missile1 = Missile.Missile1()
missile2 = Missile.Missile2()


class Board:
    def __init__(self):
        pygame.init()
        pygame.display.set_caption("Space Invaders")
        self.score = 0
        alien.spawn()
        self.printboard()

    def printboard(self):

        screen = pygame.display.set_mode((600, 400))
Example #11
0
from Spaceship import *
from Globals import *
from Bullet import *
from Alien import *

pygame.init()

#score = 0

spaceship = Spaceship()
bullets = []
aliens = []
for n in xrange(5):
    aliens.append(Alien())


def reset():
    global score
    global spaceship
    global bullets
    global aliens
    global GameOver
    global leftKeyPressed
    global rightKeyPressed
    global bulletKey

    GameOver = False
    leftKeyPressed = False
    rightKeyPressed = False
    bulletKey = False
    if score:
Example #12
0
bullet1 = []
number1 = 0

bullet2 = []
number2 = 0

score = 0

for i in range(numa):
    i = Aliens.Aliens(random.choice(xnos), random.choice(
        ynos), pygame.time.get_ticks(), screen, arpita, alien)
    aliens.append(i)

start = pygame.time.get_ticks()

obj_ship = Spaceship.Spaceship(x, y, spaceship, screen)
obj_ship.ship()
screen.blit(marks, (220, 320))

while not over:  # game loop

    finish = pygame.time.get_ticks()
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            over = True

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_q:
                pygame.quit()
                sys.exit()
            if event.key == pygame.K_d:
Example #13
0
class Game():
    #This class controls the entire game
    def __init__(self):
        #This method initializes the game
        self.clock = pg.time.Clock()
        self.clockTick = 120
        self.background = 0, 0, 0
        self.display = pg.display.set_mode((1280, 720))
        self.currentScreen = "Menu"
        self.pikminList = []
        self.enemyList = []
        self.fruitList = []
        self.buttonDict = {}
        self.font = pg.font.Font("OpenSans-Regular.ttf", 22)
        self.pikImage = pg.image.load("pikmin.png")
        self.playerImage = pg.image.load("barbolD.png")
        self.enemyImage = pg.image.load("Enemy.png")
        self.appleImage = pg.image.load("apple.png")
        self.shipImage = pg.image.load("spaceship.png")
        self.gameMode = "Normal"
        self.score = 0
        pg.display.set_caption("Pikmin Mini")
        self.mainLoop()

    def drawText(self, text, x, y):
        #This method draws a textbox
        textBox = self.font.render(text, True, (255, 255, 255))
        textBoxRect = textBox.get_rect()
        textBoxRect.center = (x, y)
        if text not in self.buttonDict:
            self.buttonDict[text] = textBoxRect
        self.display.blit(textBox, textBoxRect)

    def getPikList(self):  #Returns the pikmin list
        return self.pikminList

    def getEnemyList(self):  #Returns the enemy list
        return self.enemyList

    def getFruitList(self):  #Returns the fruit list
        return self.fruitList

    def getScreen(self):  #Returns the games screen
        return self.display

    def addToList(self, obj):
        #Adds an object to their respective list
        if type(obj) == Fruit:
            self.fruitList.append(obj)
        elif type(obj) == Enemy:
            self.enemyList.append(obj)
        elif type(obj) == Pikmin:
            self.pikminList.append(obj)

    def removeFromList(self, obj):
        #Removes an object from their respective list
        if type(obj) == Fruit:
            self.fruitList.remove(obj)
        elif type(obj) == Enemy:
            self.enemyList.remove(obj)
        elif type(obj) == Pikmin:
            self.pikminList.remove(obj)

    def menuEventHandler(self):
        #This handles events on the main menu
        for event in pg.event.get():
            if event.type == pg.QUIT:
                sys.exit()
            if event.type == pg.MOUSEBUTTONDOWN:
                #Getting the mouse coordinates
                mousePos = pg.mouse.get_pos()
                for i in self.buttonDict:
                    #If the mouse clicked on a button then take action accordingly
                    if self.buttonDict[i].collidepoint(mousePos):
                        if i == "Start Game":
                            self.setupGame()
                            self.gameMode = "Normal"
                            self.currentScreen = "Game"
                            break
                        elif i == "Help":
                            self.currentScreen = "Help"
                            break
                        elif i == "Quit":
                            sys.exit()
                            break
                        elif i == "Start Endless Game":
                            self.setupGame()
                            self.gameMode = "Endless"
                            self.currentScreen = "Game"
                            break
                        self.buttonDict = {}

    def mainMenuDraw(self):
        #This method draws the main menu
        self.drawText("Start Game", 640, 140)
        self.drawText("Start Endless Game", 640, 240)
        self.drawText("Help", 640, 410)
        self.drawText("Quit", 640, 540)

    def helpEventHandler(self):
        #This method handles events on the help menu
        for event in pg.event.get():
            if event.type == pg.QUIT:
                sys.exit()
            if event.type == pg.MOUSEBUTTONDOWN:
                mousePos = pg.mouse.get_pos()
                for i in self.buttonDict:
                    if self.buttonDict[i].collidepoint(mousePos):
                        if i == "Back":
                            self.currentScreen = "Menu"
                        self.buttonDict = {}

    def helpDraw(self):
        #This method draws the help screen
        self.drawText(
            "You are the main character. You can move using the WASD Keys.",
            640, 20)
        playerRect = self.playerImage.get_rect()
        playerRect.midtop = (640, 40)
        self.display.blit(self.playerImage, playerRect)
        self.drawText(
            "These are pikmin and they will follow you. They can attack enemies, and they can pick up dead enemies and fruit",
            640, playerRect.bottom + 15)
        self.drawText("and bring them back to your ship.", 640,
                      playerRect.bottom + 40)
        pikRect = self.pikImage.get_rect()
        pikRect.midtop = (640, playerRect.bottom + 60)
        self.display.blit(self.pikImage, pikRect)
        self.drawText(
            "This is your ship, it takes fruit and converts it to juice, and takes enemies and spawns pikmin in return.",
            640, pikRect.bottom + 20)
        shipRect = self.shipImage.get_rect()
        shipRect.midtop = (640, pikRect.bottom + 40)
        self.display.blit(self.shipImage, shipRect)
        self.drawText(
            "The main point of the game is to command pikmin to pick up as much fruit and carry it back to the ship.",
            640, shipRect.bottom + 15)
        self.drawText(
            "If you run out of pikmin or cannot carry anymore fruit or enemies with your current number the game ends.",
            640, shipRect.bottom + 40)
        self.drawText(
            "This is an apple and it takes 2 pikmin to carry it back to the ship.",
            640, shipRect.bottom + 65)
        appleRect = self.appleImage.get_rect()
        appleRect.midtop = (640, shipRect.bottom + 80)
        self.display.blit(self.appleImage, appleRect)
        self.drawText(
            "This is an enemy. Enemies can follow pikmin, and attack them. When enemies die, pikmin can collect them. ",
            640, appleRect.bottom + 20)
        enemyRect = self.enemyImage.get_rect()
        enemyRect.midtop = (640, appleRect.bottom + 40)
        self.display.blit(self.enemyImage, enemyRect)
        self.drawText(
            "To command pikmin you need to be close enough to either fruit or enemy, and click on them.",
            640, enemyRect.bottom + 20)
        self.drawText(
            "Pikmin will do commands in a sequence then come back to following you.",
            640, enemyRect.bottom + 50)
        self.drawText(
            "The score depends on the amount of fruit carried back to the ship.",
            640, enemyRect.bottom + 80)
        self.drawText(
            "If a fruit needs two pikmin to carry, it will give you two points.",
            640, enemyRect.bottom + 110)
        self.drawText(
            "A normal game is won by reaching a score of 20 or more.", 640,
            enemyRect.bottom + 140)
        self.drawText(
            "An endless game continues till you either run out of pikmin, or cannot carry anymore fruit.",
            640, enemyRect.bottom + 170)
        self.drawText(
            "Any type of game can be quit by pressing the escape key. You cannot pause a game.",
            640, enemyRect.bottom + 200)
        self.drawText("Back", 640, 680)

    def setupGame(self):
        #This method sets up the game for the first time
        #Creating the ship and main character
        self.score = 0
        self.pikminList = []
        self.enemyList = []
        self.fruitList = []
        self.barbol = Character((640, 360), self)
        self.sunny = Spaceship((640, 300), self)
        #Spawning some pikmin initially for the player to control
        for i in range(8):
            self.sunny.spawnPikmin()
        quadlist = [1, 2, 3, 4]
        for j in range(4):
            #Spawning the fruit
            #Choosing a quadrant and removing it once it
            #has been used for a fruit
            quadrant = random.choice(quadlist)
            quadlist.remove(quadrant)
            #The x and y coordinates are chosen randomly based on the quadrant
            if quadrant == 1 or quadrant == 3:
                spawnX = random.randint(20, 510)
                if quadrant == 1:
                    spawnY = random.randint(20, 230)
                else:
                    spawnY = random.randint(490, 700)
            elif quadrant == 2 or quadrant == 4:
                spawnX = random.randint(770, 1260)
                if quadrant == 2:
                    spawnY = random.randint(20, 230)
                else:
                    spawnY = random.randint(490, 700)
            Fruit((spawnX, spawnY), self.sunny, self)
        quadlist = [1, 2, 3, 4]
        for k in range(4):
            quadrant = random.choice(quadlist)
            quadlist.remove(quadrant)
            if quadrant == 1 or quadrant == 3:
                spawnX = random.randint(20, 510)
                if quadrant == 1:
                    spawnY = random.randint(20, 230)
                else:
                    spawnY = random.randint(490, 700)
            elif quadrant == 2 or quadrant == 4:
                spawnX = random.randint(770, 1260)
                if quadrant == 2:
                    spawnY = random.randint(20, 230)
                else:
                    spawnY = random.randint(490, 700)
            Enemy("Enemy.png", (spawnX, spawnY), self.sunny, self)

    def gameDraw(self):
        #This method draws the game's screen
        #Updating the pikmin, fruit and enemies
        for i in self.pikminList:
            i.update()
        for k in self.fruitList:
            k.update()
        for j in self.enemyList:
            j.update()
        #Updating the ship and main character
        self.sunny.update()
        self.barbol.update()
        #Updating the score
        self.score = self.sunny.getScore()
        self.drawText("Score: " + str(self.score), 1200, 20)
        if self.gameMode == "Normal" and self.score >= 20:
            self.currentScreen = "Game Over"
        if len(self.pikminList) < 2:
            self.currentScreen = "Game Over"

    def userInput(self):
        #This method handles user input on the game screen
        for event in pg.event.get():
            #Quitting the entire game
            if event.type == pg.QUIT:
                sys.exit()
            if event.type == pg.MOUSEBUTTONDOWN:
                #Getting the mouse position
                mouseX, mouseY = pg.mouse.get_pos()[0], pg.mouse.get_pos()[1]
                #Checking for interactions with enemies
                for j in self.enemyList:
                    if j.getClicked(mouseX, mouseY):
                        for i in self.pikminList:
                            #If the pikmin is following and the command distance is ok
                            #then command the pikmin
                            if i.getTask() == "Follow" and i.getDistance(
                                    mouseX, mouseY):
                                i.attackEnemy(j)
                                i.changeTask("Attack")
                                break
                #Checking for interactions with fruit
                for k in self.fruitList:
                    if k.getClicked(mouseX, mouseY):
                        for i in self.pikminList:
                            #If the pikmin is following and the command distance is ok
                            #then command the pikmin
                            if i.getTask() == "Follow" and i.getDistance(
                                    mouseX, mouseY):
                                i.goToFruit(k)
                                i.changeTask("goTo")
                                break
        #Handling player movement
        self.movementHandler()

    def movementHandler(self):
        #This method handles user movement on the main screen
        movement = pg.key.get_pressed()
        if movement[pg.K_a]:
            self.barbol.move("left")
        elif movement[pg.K_d]:
            self.barbol.move("right")
        elif movement[pg.K_w]:
            self.barbol.move("up")
        elif movement[pg.K_s]:
            self.barbol.move("down")
        elif movement[pg.K_ESCAPE]:
            self.currentScreen = "Game Over"

    def pikminTaskHandler(self):
        #This method handles the pikmin's tasks
        for i in self.pikminList:
            if i.getTask() == "Follow":
                i.followCharacter(self.barbol)
            elif i.getTask() == "goTo":
                i.goToFruit()
            elif i.getTask() == "Attack":
                i.attackEnemy()

    def fruitTaskHandler(self):
        #This method handles the fruit's tasks
        for k in self.fruitList:
            if k.getTask() == "Move":
                k.moveToShip()
            elif k.getTask() == "None":
                self.fruitList.remove(k)

    def enemyTaskHandler(self):
        #This method handles the enemie's tasks
        for j in self.enemyList:
            if j.getTask() == "Walk":
                j.move()
            elif j.getTask() == "toShip":
                j.goToShip()
            elif j.getTask() == "Target":
                j.fightPikmin()

    def spawn(self, obj):
        #This method spawns new enemies or fruit
        #Getting the coordinates of the player
        x, y = self.barbol.getCoordinates()
        #Getting the player's quadrant
        if x < 720:
            if y > 360:
                playerQ = 3
            else:
                playerQ = 1
        else:
            if y > 360:
                playerQ = 4
            else:
                playerQ = 2
        #Removing the player's quadrant from possible quadrants
        quadlist = [1, 2, 3, 4]
        quadlist.remove(playerQ)
        quadrant = random.choice(quadlist)
        #Getting a random x and y to spawn the enemy or fruit with
        if quadrant == 1 or quadrant == 3:
            spawnX = random.randint(20, 510)
            if quadrant == 1:
                spawnY = random.randint(20, 230)
            else:
                spawnY = random.randint(490, 720)
        else:
            spawnX = random.randint(770, 1260)
            if quadrant == 2:
                spawnY = random.randint(20, 230)
            else:
                spawnY = random.randint(490, 700)
        #Spawning the enemy or fruit
        if obj == "Enemy":
            Enemy("Enemy.png", (spawnX, spawnY), self.sunny, self)
        elif obj == "Fruit":
            Fruit((spawnX, spawnY), self.sunny, self)

    def gameEventHandler(self):
        #This method handles the game's events
        #Handling user input
        self.userInput()
        #Handling tasks of other objects
        self.pikminTaskHandler()
        self.fruitTaskHandler()
        self.enemyTaskHandler()
        #Spawning enemy or fruit if an enemy or fruit is killed
        if len(self.fruitList) < 4:
            self.spawn("Fruit")
        if len(self.enemyList) < 4:
            self.spawn("Enemy")

    def gameOverDraw(self):
        #This method draws the game over screen
        if self.gameMode == "Normal":
            if self.score >= 20:
                text = "You Won!"
            else:
                text = "Try Again"
            self.drawText(text, 640, 360)
        if self.gameMode == "Endless":
            if self.score < 20:
                text = "Loser,"
            elif self.score > 30:
                text = "Amazing!"
            else:
                text = "Good Job!"
            self.drawText(text + " Here's your score: " + str(self.score), 640,
                          360)
        self.drawText("Click anywhere to continue", 640, 400)

    def gameOverEvent(self):
        #This method handles events on the game over screen
        for event in pg.event.get():
            if event.type == pg.QUIT:
                sys.exit()
            if event.type == pg.MOUSEBUTTONDOWN:
                self.currentScreen = "Menu"

    def mainLoop(self):
        #This function controls the main loop of the game
        while True:
            if self.currentScreen == "Menu":
                self.mainMenuDraw()
                self.menuEventHandler()
            elif self.currentScreen == "Game":
                self.gameDraw()
                self.gameEventHandler()
            elif self.currentScreen == "Help":
                self.helpDraw()
                self.helpEventHandler()
            elif self.currentScreen == "Game Over":
                self.gameOverDraw()
                self.gameOverEvent()
            #Refreshing the screen
            pg.display.flip()
            self.display.fill(self.background)
            self.clock.tick(self.clockTick)