Пример #1
0
 def unit_init(self):
     self.groups = groups.unitgroup, groups.allgroup, self.owner.unitgroup
     pygame.sprite.Sprite.__init__(self, self.groups)
     self.base_image = pygame.image.load(tools.filepath(self.image_files["base"]))
     self.image = self.base_image
     self.rect = self.image.get_rect()
     self.rect.centerx = round(self.trueX + game_data.camera[0])
     self.rect.centery = round(self.trueY + game_data.camera[1])
     self.hp = self.maxHP
Пример #2
0
 def train(self, unit_index = 0):
     self.training_unit = self.training_list[unit_index]
     if self.owner.mineral >= self.training_unit.mineral_cost and self.training_unit.supply_cost <= (self.owner.max_supply - self.owner.supply)  and self.action == ID_STOP:
         self.building_progress = self.training_unit.building_time
         self.action = ID_TRAIN
         self.owner.mineral -= self.training_unit.mineral_cost
         
     else:
         sound = pygame.mixer.Sound(tools.filepath("beep.wav"))
         sound.play()
Пример #3
0
    def __new__(cls, *args, **kwargs):
        if cls.__logger == None:
            # 创建一下 日志类, 'cnodeApi' 为 logging name属性值
            cls.__logger = logging.getLogger('cnodeApi')
            cls.__logger.setLevel(logging.DEBUG)  # 设置日志级别 DEBUG

            log_path = tools.filepath('logs')
            logfile_path = os.path.join(log_path, 'api.log')
            fh = logging.FileHandler(
                logfile_path)  # 创建日志存储文件对象 app.log 日志存储文件名
            ch = logging.StreamHandler()  # 命令行输出流

            # log格式
            formatter = logging.Formatter(
                '%(asctime)s %(levelname)s %(name)s %(message)s')

            fh.setFormatter(formatter)  # 文件存储赋给 __logger
            ch.setFormatter(formatter)  # 输出流 添加日志格式

            cls.__logger.addHandler(fh)  # 文件存储赋给 __logger
            cls.__logger.addHandler(ch)  # 输出流 赋给 __logger

        return cls.__logger
Пример #4
0
 def changeImage(self,image="base"):
     self.base_image = pygame.image.load(tools.filepath(self.image_files[image]))
     self.image = self.base_image
     self.rect = self.image.get_rect()
Пример #5
0
def main():
    replay_list = []
    activePlayer = 1 # The player that is controlling the units
    attack = False  # True is controlls are in "attack mode" (clicking "A")

    pygame.init()
    screen = pygame.display.set_mode(game_data.WINDOW_SIZE, pygame.FULLSCREEN)
    #pygame.display.set_caption(GAME_NAME + VERSION)
    background = pygame.image.load(tools.filepath('background.png'))
    MOUSE_CURSOR1 = pygame.mouse.get_cursor()

    # Players
    players = [Player("Neutral"),
               Player("Good Guys", True, 50, (0,0,255)),
               Player("The Evil", True, 50, (255,0,0)),]
    players[1].enemies = [players[2]]
    players[2].enemies = [players[1]]

    # Iniciate the Minimap
    infobar = Infobar()

    # Iniciate the text
    text1 = Text("Player"+str(activePlayer)+":  "+players[activePlayer].name+"  "+str(players[activePlayer].mineral)+" Mineral", players[activePlayer].color,(10,0))
    for i, text in enumerate(["RightMouse: Move/Attack","MiddleMouse: Switch Player","A: Attack",  "Space: Reset Camera" , "CONTROL: Multi-Selection"]):
        Text(text, (255,255,255),(game_data.width-250,0+i*20))

    # Initial Units
    MineralPatch(480,50,players[0])
    MineralPatch(520,50,players[0])
    MineralPatch(560,50,players[0])
    MineralPatch(600,50,players[0])
    Worker(520, 150,players[1])
    Worker(560, 150,players[1])
    Nexus(540,200,players[1])    


    MineralPatch(480,1350,players[0])
    MineralPatch(520,1350,players[0])
    MineralPatch(560,1350,players[0])
    MineralPatch(600,1350,players[0])
    Worker(520, 1250,players[2])
    Worker(560, 1250,players[2])
    Nexus(540,1200,players[2]) 
    Turret(590,1200,players[2])

    # Main Loop
    clock=pygame.time.Clock()
    finish_game = False
    while not finish_game:
        milliseconds = clock.tick(game_data.fps)  # milliseconds passed since last frame
        seconds = milliseconds / 1000.0 # seconds passed since last frame (float)

        # Scroll Stuff
        if pygame.key.get_pressed()[pygame.K_RIGHT] or pygame.mouse.get_pos()[0] > game_data.width - 2 :
            if game_data.camera[0] > -game_data.map_width + game_data.width: game_data.camera[0] -= 10
        if pygame.key.get_pressed()[pygame.K_LEFT] or pygame.mouse.get_pos()[0] < 2:
            if game_data.camera[0] < 0: game_data.camera[0] += 10
        if pygame.key.get_pressed()[pygame.K_UP] or pygame.mouse.get_pos()[1] < 2:
            if game_data.camera[1] < 0: game_data.camera[1] += 10
        if pygame.key.get_pressed()[pygame.K_DOWN] or pygame.mouse.get_pos()[1] > game_data.height - 2:
            if game_data.camera[1] > -game_data.map_height  + game_data.height - game_data.infobar_height: game_data.camera[1] -= 10

        # events
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                finish_game = True

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    game_data.camera = [0,0]
                if event.key == pygame.K_ESCAPE:
                    pygame.event.post(pygame.event.Event(pygame.QUIT))

            if attack == False:
                if event.type == pygame.MOUSEBUTTONDOWN:
                    if event.button == 1:
                        if pygame.mouse.get_pos()[1] < (game_data.height - game_data.infobar_height):
                            for unit in players[activePlayer].unitgroup:
                                if unit.isPressed(pygame.mouse.get_pos()):
                                    if pygame.key.get_pressed()[pygame.K_LCTRL] == True and unit.selected == True: unit.selected = False
                                    else: unit.selected = True
                                else:
                                    if pygame.key.get_pressed()[pygame.K_LCTRL] == False: unit.selected = False
                        if infobar.minimap.isPressed(pygame.mouse.get_pos()):
                            posx, posy = infobar.minimap.getCamera(pygame.mouse.get_pos())
                            game_data.camera = [-posx/2, -posy/2]
                            #Minion(posx, posy, players[activePlayer])
                    if event.button == 2:
                        for unit in players[activePlayer].unitgroup: unit.selected = False
                        activePlayer = changePlayer(activePlayer, players)
                    if event.button == 3:
                        if pygame.mouse.get_pos()[1] < (game_data.height - game_data.infobar_height):
                            for unit in players[activePlayer].unitgroup:
                                if unit.selected == True and ID_UNIT in unit.types:
                                    unit.move((event.pos[0] - game_data.camera[0],event.pos[1]  - game_data.camera[1]))
                                    replay_list.append("move")
                                    for target in groups.unitgroup:
                                        if target.isPressed(pygame.mouse.get_pos()) and target.owner in unit.owner.enemies and target != unit and target.targetable == True:
                                            unit.attack(target)
                                            replay_list.append("attack")

                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_a:
                        for unit in players[activePlayer].unitgroup:
                            if ID_UNIT in unit.types and unit.selected == True:
                                pygame.mouse.set_cursor(*MOUSE_CURSOR2)
                                attack = True
                    if event.key == pygame.K_q:
                        for unit in players[activePlayer].unitgroup:
                            if ID_BUILDING in unit.types and unit.action == ID_STOP and unit.selected == True:
                                if len(unit.training_list) > 0:
                                    unit.train(0)
                    if event.key == pygame.K_w:
                        for unit in players[activePlayer].unitgroup:
                            if ID_BUILDING in unit.types and unit.action == ID_STOP and unit.selected == True:
                                if len(unit.training_list) > 1:
                                    unit.train(1)
                    if event.key == pygame.K_e:
                        for unit in players[activePlayer].unitgroup:
                            if ID_BUILDING in unit.types and unit.action == ID_STOP and unit.selected == True:
                                if len(unit.training_list) > 2:
                                    unit.train(2)
            else:
                if event.type == pygame.MOUSEBUTTONDOWN:
                    if pygame.mouse.get_pos()[1] < (game_data.height - game_data.infobar_height):
                        if event.button == 1:
                            unit_in_cursor = False
                            for unit in players[activePlayer].unitgroup:
                                if unit.selected == True and ID_UNIT in unit.types:
                                    for target in groups.unitgroup:
                                        if target.isPressed(pygame.mouse.get_pos()) and target != unit and target.targetable == True:
                                            unit.attack(target)
                                            replay_list.append("attack")
                                            unit_in_cursor = True
                                    if unit_in_cursor == False:
                                        unit.attack_move((event.pos[0] - game_data.camera[0],event.pos[1]  - game_data.camera[1]))
                                        replay_list.append("attack move")

                    pygame.mouse.set_cursor(*MOUSE_CURSOR1)
                    attack = False
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        pygame.mouse.set_cursor(*MOUSE_CURSOR1)
                        attack = False

        # Updates and Draws
        background_redraw(background, screen)
        groups.allgroup.update(seconds)
        for unit in groups.unitgroup:
            if unit.targetable == True:
                pygame.draw.rect(screen,(0,0,0),(unit.rect.left,unit.rect.top-7,unit.rect.width,3))
                pygame.draw.rect(screen,unit.owner.color,(unit.rect.left,unit.rect.top-7,unit.rect.width*unit.getLifeBar(),3))
                if ID_BUILDING in unit.types and unit.action == ID_TRAIN:
                    pygame.draw.rect(screen,(0,255,0),(unit.rect.left,unit.rect.bottom,unit.rect.width*unit.getBuildingProgress(),5))
                if ID_HARVESTER in unit.types and unit.action == ID_HARVEST:
                    pygame.draw.rect(screen,(0,255,0),(unit.rect.left,unit.rect.bottom,unit.rect.width*unit.passives[0].getHarvestingProgress(),5))

            if unit.selected == True:
                pygame.draw.ellipse(screen,(0,255,0), unit.rect.inflate(SELECTION_EXTRAX,SELECTION_EXTRAY), 1)

        font = pygame.font.Font(None, 25)
        text1.newmsg("Player"+str(activePlayer)+":  "+players[activePlayer].name+"  "+str(players[activePlayer].mineral)+" Mineral " +  str(players[activePlayer].supply) + "/" + str(players[activePlayer].max_supply) +   " Supply", players[activePlayer].color)
        groups.allgroup.draw(screen)
        pygame.display.flip( ) #update the screen
        for player in players: player.update()

    replay_list.append("quit")
    pygame.quit()
Пример #6
0
import numpy as np
import pylab as pl
import skimage
import skimage.io
import skimage.transform
import os
import sys
import tools as t

#----------------------------------------------------------initialize
#inputname = t.filepath("siftdata/ironman.jpg")
inputname = t.filepath("siftdata/lena.png")
#inputname = t.filepath("siftdata/building.jpg")
#inputname = t.filepath("siftdata/sculpture.jpg")

#only take grayscale image
Snum = 4 # number of different scales:4
Gnum = 6 # number of Gaussian layers in each scale:6
DoGnum = Gnum - 1
   
GaussianPyramid = {(0,0):0} #initialize a dictionary

#----------------------------------------------------------Gaussian pyramid



I = skimage.img_as_float(skimage.io.imread(inputname))
#IG = skimage.img_as_float(skimage.io.imread(inputname)) # when I is a gray scale image, the reading file is a 2d array
#IG = t.GrayToArray(I)
IG = t.TurnGray(I)
Пример #7
0
import numpy as np
import skimage
import skimage.io
import tools as t
import os
import copy as c

#----------------------------------------------------------initialize
inputname = t.filepath("siftdata/building.jpg")



#only take grayscale image
Snum = 4 # number of different scales:4
Gnum = 6 # number of Gaussian layers in each scale:6
DoGnum = Gnum - 1
   
GaussianPyramid = {(0,0):0} #initialize a dictionary




a = [[5,2,3],[6,1,9],[3,5,1]]
b = [1,2,3]
c = np.linalg.solve(a,b)
print c 




Пример #8
0
from ConfigParser import SafeConfigParser
from pygame import font
import tools

config = SafeConfigParser()
config.read(tools.filepath('config.ini'))
fps = config.getfloat('configuration','fps')

WINDOW_SIZE = width, height = 1024,768
map_width = 1200
map_height = 1400

infobar_height = 150
infobar_color = (155,0,0)
infobar_fontcolor = (255,255,255)

minimap_width = 200
minimap_height = infobar_height
minimap_color = (0,155,0)
minimap_bordercolor = infobar_color

selectionbox_width = 200
selectionbox_height = infobar_height
selectionbox_color = (0,155,0)
selectionbox_bordercolor = infobar_color

camera = [- map_width/6 , 0]