示例#1
0
def main():
    window = Window(WIDTH, HEIGHT, "Python Invaders")
    renderer = window.renderer

    # Load sprites
    player_sprite = renderer.LoadSprite("Sprites/player.png")
    parrot_sprite = renderer.LoadSprite("Sprites/parrot.png")

    # Load objects
    player = Player(player_sprite, WIDTH, HEIGHT)
    parrots = ParrotHandler(parrot_sprite, WIDTH, HEIGHT)
    window.AddObject(player)
    window.AddObject(parrots)

    bullets = []
    while window.IsRunning():
        if player.ShouldFire():
            bullets.append([player.pos[0], player.pos[1]])

        bullets_hit = []
        for bullet in bullets:
            bullet[1] -= 10
            if parrots.TestCollision(bullet[0], bullet[1]) or bullet[1] <= 0:
                bullets_hit.append(bullet)
            else:
                renderer.SetPixel(int(bullet[0]), int(bullet[1]), 0, 255, 0)

        for bullet in bullets_hit:
            bullets.remove(bullet)
        window.Update()
示例#2
0
def setupObjects():
    """Setup global objects for drawing"""
    #globs.StarBackground = StarBackground.StarBackground(0, 0, .1, .1)
    globs.MapBackground = tilemap.Map()
    globs.Player = Player.Player(globs.startPosX, globs.startPosY,
                                 globs.playerWidth, globs.playerHeight)
    globs.Background = Background.Background()
 def __init__(self):
     # Bind to the port
     try:
         self.server_i.bind((Server.m_host, Server.m_port))
         print("Server started. Listening for incoming connections...")
     except:
         pass
     # Main loop to add new clients
     while True:
         data, addr = self.server_i.recvfrom(self.buffer)
         # print(str(addr) + ": " + data.decode('utf-8'))
         data = data.decode('utf-8')
         if addr not in self.clients:
             self.clients.append(addr)
             self.client_lobby.append((data, addr))
             print(data + ' has joined the server.')
             if len(self.client_lobby) == 2:
                 p1 = Player(self.client_lobby[0][0],
                             self.client_lobby[0][1], 1)
                 p2 = Player(self.client_lobby[1][0],
                             self.client_lobby[1][1], 1)
                 self.client_lobby = []
                 self.in_game[0] = (p1, p2)
                 print(self.in_game[0][0].username + ' and ' +
                       self.in_game[0][1].username +
                       ' have started a game together.')
                 index = 0
                 d1 = 'player 1'
                 t = threading.Thread(target=Server.receiving_thread,
                                      args=(self, index, d1, True))
                 t.start()
                 d2 = 'player 2'
                 t1 = threading.Thread(target=Server.receiving_thread,
                                       args=(self, index, d2, True))
                 t1.start()
             connected = "Connected to the server. Waiting for another player..."
             Server.sendResult(self, addr, str.encode(connected))
         else:
             index = self.clients.index(addr)
             t = threading.Thread(target=Server.receiving_thread,
                                  args=(self, index, data, False))
             t.start()
示例#4
0
    def __init__(self, sc, s):
        self.listofPlayers = []
        self.thisStep = Step(sc)
        self.previousStep = copy.deepcopy(s)
        self.currentRound = 0
        self.currentStep = 0
        self.samplecounter = sc
        self.GS = GameSettings()
        for x in range(self.GS.NrOfP):
            name = 'Player ' + str(x)
            self.listofPlayers.append(Player(name))
            print(self.listofPlayers[x])
        self.winer = ''
        self.currentWormsSet = []
        self.gameID = 0
        self.gameSettingsID = 0

        return
示例#5
0
 def __init__(self, *args, **kwargs):
     self.winer = ''
     self.GS = GameSettings()
     self.reservedEC = kwargs.get('reservedEC', set())
     self.P = kwargs.get('p', Player('N'))
     pv = copy.deepcopy(self.P.playerVars)
     #        self.P.nofRoundPausing = kwargs.get('nofpr',0)
     #event card
     pd = kwargs.get('playingdeck', list())
     self.EC = EventCards(pv, self.reservedEC, pd)
     #worm card
     wcdeck = kwargs.get('wcdeck', list())
     self.WC = WormCards(pv, wcdeck)
     #---
     self.playerDesicion = False
     self.myDesicion = desicion()
     self.stepNr = kwargs.get('currentStep', 0)
     self.roundNr = kwargs.get('currentRound', 0)
     self.sampleNr = kwargs.get('samplecounter', 0)
     return
示例#6
0
def setupObjects():
    """Setup global objects for drawing"""
    globs.Player = Player.Player(globs.playerStartPos, globs.playerScale)
    globs.MeshObjects.append(Map.MapRoom(math3d.vec3(0,0,0), "dungeon"))
示例#7
0
from random import randrange
from GameObjects.Player import *
from GameObjects.Game import *
from GameObjects.Cards import *
#import GameObjects.Cards import *

from copy import deepcopy
import mssql

tempply = Player('')
GS = GameSettings()
sampleCounter = 0

previousStep = Step()

#initial

print("Hello From Game Simulation! Data Generation is begining")
gsID = mssql.insertGameSettings(GS)
while sampleCounter <= GS.sampleQuantity:
    mygame = Game(sampleCounter, previousStep)
    mygame.gameSettingsID = gsID
    mygame.gameID = mssql.insertGame(mygame)
    firstdeck = mygame.thisStep.EC.playingdeck
    #play
    print("---Game : " + str(sampleCounter) + "---")
    condition = True

    while condition:
        mygame.currentRound = mygame.currentRound + 1
        mygame = copy.deepcopy(mygame.playOneRound())
示例#8
0
    def add_player(self, posx, posy, imgindex):

        self.player = Player(posx, posy, imgindex)
        self.player_sprites.add(self.player)
示例#9
0
def setupObjects():
    """Setup global objects for drawing"""
    globs.StarBackground = StarBackground.StarBackground(0, 0)
    globs.MapBackground = tilemap.Map()
    globs.objectsToDraw.append(Player.Player(0, 0, .25))
示例#10
0
def setupObjects():
    """Setup global objects for drawing"""
    globs.Player = Player.Player(globs.startPosX, globs.startPosY, globs.startPosZ,
                                 globs.playerWidth, globs.playerHeight, globs.playerDepth)
    globs.MeshObjects.append(Map.MapRoom(math3d.vec3(0,0,0), "dungeon"))