Example #1
0
    def onMove(self, offset, link_count = 0):
        #Collision detection run on movement
        fr = 1
        m_rects = [x.rect for x in self.game.EntityHandler.monsters]
        if self.player_r.x > self.game.Grid.bounds[0] or self.player_r.x <= 0:
            self.player_r.x -= offset[0]
        if self.player_r.y > self.game.Grid.bounds[1] or self.player_r.y <= 0:
            self.player_r.y -= offset[1]
        for rect in self.game.solid_list + m_rects:
            link_active = 0
            if 'LINK' in rect:
                link = self.game.links[link_count]
                rect = literal_eval(link[1])
                link_count += 1
                link_active = 1
            if self.player_r.colliderect(rect):
                if link_active:
                    self.game.blit_list = mapLoader.load(link[2], self.game, new_pos = link[3], face = link[4])
                else:
                    #bring on mask collision
                    mask = pygame.mask.Mask((rect.width, rect.height))
                    mask.fill()
                    player_mask = self.player_masks[self.player_face + str(int(self.player_state)) + '.png']
                    ppos = self.getPos()
                    offset_x =  self.player_r.x - rect.x
                    offset_y =  self.player_r.y - rect.y

                    if mask.overlap(player_mask, (offset_x, offset_y)):
                        self.player_r.y -= offset[1]
                        self.player_r.x -= offset[0]
Example #2
0
    def updateMapTrans(self):
        self.sheet.set_alpha(self.sheet_alpha)
        self.game.screen.blit(self.sheet, (0,0))
        self.game.Player.can_move = 0

        if not self.fading:
            self.sheet_alpha += 8
            if self.sheet_alpha > 270:
                self.fading = True
                mv = self.game.Player.map_vars
                self.game.blit_list =  mapLoader.load(mv[2], self.game, new_pos = mv[3], face = mv[4])
        else:
            self.sheet_alpha -= 8
            if self.sheet_alpha <= 0:
                self.fading = self.game.Player.map_change = False
                self.sheet_alpha = self.game.Player.can_move = 1
Example #3
0
 def processCommand(self, message):
     """
     Processes a chat command and spawns an item or monster accordingly.
     """
     if message.startswith("/"):
         # meant to be a command
         message = message.replace('-', '_')
         command = message.split(" ")
         if 'spawn' in message:
             self.game.Monster(self.game, command[1], self.game.unoff(list(pygame.mouse.get_pos())), 1)
         elif 'place' in message:
             self.game.Item(self.game, command[1], self.game.unoff(list(pygame.mouse.get_pos())), world=1)
         elif 'get' in message:
             self.game.Invent.add(command[1], self.game.Invent.nextFreeSlot())
         elif 'map' in message:
             self.game.blit_list = mapLoader.load(command[1], self.game)
    def __init__(self):
        #window setup
        pygame.display.set_caption('Necromonster')
        pygame.display.set_icon(pygame.image.load(os.path.join('rec', 'misc', 'icon.png')))
        self.main_path = os.getcwd()

        # initiate the clock and screen
        self.clock = pygame.time.Clock()
        self.last_tick = pygame.time.get_ticks()
        self.screen_res = [900, 650]
        self.center_point = [470., 350.]
        self.screen = pygame.display.set_mode(self.screen_res, pygame.HWSURFACE, 32)

        #DEBUG values
        self.DEBUG = 1
        self.RECT_DEBUG = 0

        #Init custom game classe(s)
        self.EntityHandler = EntityHandler(self)
        self.Scheduler = Schedule(self)
        self.Projectile = Projectile
        self.Monster = Monster
        self.Item = Item
        self.Invent = Invent(self)
        self.Weapon = Weapon
        self.Garment = Garment
        self.Player = Player(self)
        self.HUD = HUD(self)

        # Init entity manager vars
        self.entities = []

        # load fonts, create font list
        self.text_list = []
        self.default_font = pygame.font.SysFont(None, 20)

        # get the map that you are on
        self.blit_list = mapLoader.load('home', self)

        self.Item(self, 'Mythril', [350, 400], world=1)

        while 1:
            self.Loop()
Example #5
0
    def updateMapTrans(self):
        self.sheet.set_alpha(self.sheet_alpha)
        self.game.screen.blit(self.sheet, (0, 0))
        self.game.Player.can_move = 0

        if not self.fading:
            self.sheet_alpha += 8
            if self.sheet_alpha > 270:
                self.fading = True
                mv = self.game.Player.map_vars
                self.game.blit_list = mapLoader.load(mv[2],
                                                     self.game,
                                                     new_pos=mv[3],
                                                     face=mv[4])
        else:
            self.sheet_alpha -= 8
            if self.sheet_alpha <= 0:
                self.fading = self.game.Player.map_change = False
                self.sheet_alpha = self.game.Player.can_move = 1
Example #6
0
 def onMove(self, offset, link_count = 0):
     #Collision detection run on movement
     m_rects = [x.rect for x in self.game.EntityHandler.monsters]
     if self.player_r.x > self.game.Grid.bounds[0] or self.player_r.x <= 0:
         self.player_r.x -= offset[0]
     if self.player_r.y > self.game.Grid.bounds[1] or self.player_r.y <= 0:
         self.player_r.y -= offset[1]
     for rect in self.game.solid_list + m_rects:
         link_active = 0
         if 'LINK' in rect:
             link = self.game.links[link_count]
             rect = literal_eval(link[1])
             link_count += 1
             link_active = 1
         if self.player_r.colliderect(rect):
             if link_active:
                 self.game.blit_list = mapLoader.load(link[2], self.game, new_pos = link[3], face = link[4])
             else:
                 self.player_r.y -= offset[1]
                 self.player_r.x -= offset[0]
Example #7
0
 def processCommand(self, message):
     """
     Processes a chat command and spawns an item or monster accordingly.
     """
     if message.startswith("/"):
         # meant to be a command
         message = message.replace('-', '_')
         command = message.split(" ")
         if 'spawn' in message:
             self.game.Monster(
                 self.game, command[1],
                 self.game.unoff(list(pygame.mouse.get_pos())), 1)
         elif 'place' in message:
             self.game.Item(self.game,
                            command[1],
                            self.game.unoff(list(pygame.mouse.get_pos())),
                            world=1)
         elif 'get' in message:
             self.game.Invent.add(command[1],
                                  self.game.Invent.nextFreeSlot())
         elif 'map' in message:
             self.game.blit_list = mapLoader.load(command[1], self.game)
Example #8
0
from player import Player
from mapElements import *
from numpy import asarray, array
import mapLoader
from random import randint

player1 = Player(x=500, y=500, acceleration=1)
entities = list()
entities.append(player1)

platforms = list()
platforms += mapLoader.load('Platformer/res/map.txt')
screenBox: array
screenDim: array


def set_screen_info(width, height):
    global screenBox, screenDim
    screenBox = asarray([0, 0, width, height])
    screenDim = asarray([width, height])


def game_loop():
    for e in entities:
        e.update(platforms)

    for p in platforms:
        p.update(player1)


def game_draw(screen):
Example #9
0
    def __init__(self):
        """
        Main game class initialization. All other class references point to this class as "game"
        """
        # window setup
        pygame.display.set_caption('Necromonster')
        pygame.display.set_icon(pygame.image.load(os.path.join('rec', 'misc', 'icon.png')))
        self.main_path = os.getcwd()

        # initiate the clock and screen object
        self.clock = pygame.time.Clock()
        self.FPS = 50
        self.last_tick = pygame.time.get_ticks()
        self.screen_res = [900, 650]
        self.center_point = [470, 350]
        self.screen = pygame.display.set_mode(self.screen_res, pygame.HWSURFACE, 32)

        #DEBUG values
        self.DEBUG = 1
        self.RECT_DEBUG = 0
        self.angle = 0

        #Init and assign custom game class(es)
        self.EntityHandler = EntityHandler(self)
        self.ParticleManager = ParticleManager(self)
        self.Scheduler = Schedule(self)
        self.Entity = Entity
        self.Projectile = Projectile
        self.Monster = Monster
        self.NPC = NPC
        self.NPCText = NPCText
        self.Item = Item
        self.Inventory = Invent
        self.Invent = self.Inventory(self)
        self.Weapon = Weapon
        self.Garment = Garment
        self.Player = Player(self)
        self.HUD = HUD(self)

        # Init entity manager vars
        self.entities = []
        self.shadows = []

        # load fonts, create font list
        # do not use pygame.font.SysFont!
        self.text_list = []
        self.default_font = pygame.font.Font(os.path.join('rec', 'font', 'freesansbold.ttf'), 15)
        self.speak_font = pygame.font.Font(os.path.join('rec', 'font', 'freesansbold.ttf'), 30)

        # load the map that player is on
        self.INSIDE = 0
        self.blit_list = mapLoader.load('home', self)

        # spawn initial map items/entities
        self.Item(self, 'Mythril', [350, 400], world=1)
        self.NPC(self, "blacksmith", [400, 400], 100, 'still')
        for i in xrange(4):
            self.Monster(self, 'chicken', [200+(i*50),650], 1, 'neutral')
        self.Monster(self, "goop", [100, 100], 1, 'aggressive')

        # begin main game loop
        while 1:
            self.Loop()
Example #10
0
    def __init__(self):
        """
        Main game class initialization. All other class references point to this class as "game"
        """
        # window setup
        pygame.display.set_caption('Necromonster')
        pygame.display.set_icon(
            pygame.image.load(os.path.join('rec', 'misc', 'icon.png')))
        self.main_path = os.getcwd()

        # initiate the clock and screen object
        self.clock = pygame.time.Clock()
        self.FPS = 50
        self.last_tick = pygame.time.get_ticks()
        self.screen_res = [900, 650]
        self.center_point = [470, 350]
        self.screen = pygame.display.set_mode(self.screen_res,
                                              pygame.HWSURFACE, 32)

        #DEBUG values
        self.DEBUG = 1
        self.RECT_DEBUG = 0
        self.angle = 0

        #Init and assign custom game class(es)
        self.EntityHandler = EntityHandler(self)
        self.ParticleManager = ParticleManager(self)
        self.Scheduler = Schedule(self)
        self.Entity = Entity
        self.Projectile = Projectile
        self.Monster = Monster
        self.NPC = NPC
        self.NPCText = NPCText
        self.Item = Item
        self.Inventory = Invent
        self.Invent = self.Inventory(self)
        self.Weapon = Weapon
        self.Garment = Garment
        self.Player = Player(self)
        self.HUD = HUD(self)

        # Init entity manager vars
        self.entities = []
        self.shadows = []

        # load fonts, create font list
        # do not use pygame.font.SysFont!
        self.text_list = []
        self.default_font = pygame.font.Font(
            os.path.join('rec', 'font', 'freesansbold.ttf'), 15)
        self.speak_font = pygame.font.Font(
            os.path.join('rec', 'font', 'freesansbold.ttf'), 30)

        # load the map that player is on
        self.INSIDE = 0
        self.blit_list = mapLoader.load('home', self)

        # spawn initial map items/entities
        self.Item(self, 'Mythril', [350, 400], world=1)
        self.NPC(self, "blacksmith", [400, 400], 100, 'still')
        for i in xrange(4):
            self.Monster(self, 'chicken', [200 + (i * 50), 650], 1, 'neutral')
        self.Monster(self, "goop", [100, 100], 1, 'aggressive')

        # begin main game loop
        while 1:
            self.Loop()