Beispiel #1
0
    def _explosionparticles(self, particlescaling):
        dirt = pygame.Surface([4, 4])
        dirt.fill((0, 0, 0))
        dirt.set_colorkey((0, 0, 0))
        #pygame.gfxdraw.filled_circle(dirt, int(dirt.get_rect().w/2), int(dirt.get_rect().h/2), 2, self.terrain.groundcolor)
        pygame.draw.rect(dirt, self.terrain.groundcolor, ((0, 0), (4, 4)))

        normalvec = self.terrain.normalmap[int(self.pos[0])]
        surfacevec = self.terrain.normalmap[int(self.pos[0])].getnormalvec()
        for i in range(int(self.blastradius * particlescaling)):
            direction = (
                normalvec * (random.randint(-50, 400) / 10.0) +
                (random.randint(-80, 80) / 10.0) * surfacevec).getuvec()
            velocity = random.randint(0, 1100) / 100.0
            bouncyparticle(self.pos.copy(), self.terrain, dirt, 3.0, direction,
                           velocity, self.particlelist, True, 2.0, None, 1000,
                           0.3)

        #explosion particle surface
        surface = pygame.Surface(
            [self.blastradius * 2 + 10, self.blastradius * 2 + 10])
        surface.fill((0, 0, 0))
        surface.set_colorkey((0, 0, 0))
        pygame.gfxdraw.filled_circle(surface, int(surface.get_rect().w / 2),
                                     int(surface.get_rect().h / 2),
                                     int(self.blastradius + 2),
                                     pygame.color.THECOLORS["orange"])
        particle(self.pos, surface, 2.5, Vector2d(0.0, 0.0), 0.0, 0.0,
                 self.particlelist, True, 0.3)
    def update(self, dt):
        #this list holds all the forces acting on the missile
        forces = [self._forcedrag(), self._forcegravity(), self.wind.force]

        #update position and velocity depeneing on the timestep
        for i in range(2):
            self.velocity[i] += (sum([j[i] for j in forces]) / self.m) * dt
            self.pos[i] += 20.0 * self.velocity[i] * dt

        #if new pos is outside bounds delete
        if 0 < self.pos[0] < self.terrain.bounds[0] - 1.0:
            #if new pos is under ground explode
            if self.terrain.heightmap[int(self.pos[0])] < self.pos[1]:
                #set player x position to own x position
                self.player.pos[0] = self.pos[0]

                #set player on ground and update turret
                self.player.setonground()
                self.player.updateTurret()

                #white explosion particle at player position
                radius = 23
                surface = pygame.Surface([radius * 2 + 5, radius * 2 + 5])
                surface.fill((0, 0, 0))
                surface.set_colorkey((0, 0, 0))
                pygame.draw.circle(surface, pygame.color.THECOLORS["white"],
                                   (int(surface.get_rect().w / 2),
                                    int(surface.get_rect().h / 2)), radius)
                particle(self.player.pos, surface, 2.5, Vector2d(0.0, 0.0),
                         0.0, 0.0, self.entities[2], True, 0.3)

                #delete missile
                self.delete = True
        else:
            self.delete = True
Beispiel #3
0
    def update(self, dt):
        if not self.impacted:
            #this list holds all the forces acting on the missile
            forces = [self._forcedrag(), self._forcegravity(), self.wind.force]

            #update position and velocity depeneing on the timestep
            for i in range(2):
                self.velocity[i] += (sum([j[i] for j in forces]) / self.m) * dt
                self.pos[i] += 20.0 * self.velocity[i] * dt

            #if new pos is outside bounds delete
            if 0 < self.pos[0] < self.terrain.bounds[0] - 1.0:
                #if new pos is under ground explode
                if self.terrain.heightmap[int(self.pos[0])] < self.pos[1]:
                    #delete missile
                    self.impacted = True
                    self.pos[1] = self.terrain.heightmap[int(self.pos[0])]
            else:
                self.delete = True
        else:
            self.alivetimer += dt
            if self.alivetimer < self.maxtimealive:
                self.timesincesmoke += dt
                if self.timesincesmoke > self.smokeinterval:
                    self.timesincesmoke = 0.0
                    dir = Vector2d(random.randint(-5, 5), -38.0).getuvec()
                    radius = 5
                    smoke = pygame.Surface([radius * 2 + 2, radius * 2 + 2])
                    smoke.fill((0, 0, 0))
                    smoke.set_colorkey((0, 0, 0))
                    pygame.draw.circle(smoke, self.color, (int(
                        smoke.get_rect().w / 2), int(smoke.get_rect().h / 2)),
                                       radius)
                    particle(self.pos.copy(), smoke, random.randint(2, 5), dir,
                             1.25, 0.19, self.entities[2], True, 0.0,
                             self.wind, 8.0)

                if not self.bombsdeployed and self.alivetimer > self.bombdelay:
                    self.bombsdeployed = True
                    distance = 27
                    for i in range(-2, 3):
                        dropbomb([self.pos[0] + i * distance, -20],
                                 Vector2d(0.0, 1.0), random.randint(20, 27),
                                 self.terrain, self.wind, self.entities,
                                 self.player, 10.0, self.color)
            else:
                self.delete = True
Beispiel #4
0
    def _getTurretUnitVector(self):
        if self.controlActive:
            target = [float(i) for i in pygame.mouse.get_pos()]

            if self.turretOrigin != target:
                mousevec = Vector2d.getvectorfrompoints(self.turretOrigin, target).getuvec()

                return self._limitvecangle(mousevec, self.terrain.normalmap[int(self.pos[0])])
        else:
            return self._limitvecangle(self.turretVector, self.terrain.normalmap[int(self.pos[0])])
Beispiel #5
0
    def updateNormalmap(self, rangex):
        distance = 7

        for i in rangex:
            origin = [
                max(float(i - distance), 0.0),
                float(self.heightmap[max(i - distance, 0)])
            ]
            target = [
                float(min(i + distance, self.bounds[0] - 1)),
                float(self.heightmap[min(i + distance, self.bounds[0] - 1)])
            ]
            self.normalmap[i] = Vector2d.getvectorfrompoints(
                origin, target).getuvec().getnormalvec()
        return
Beispiel #6
0
    def update(self, dt):
        #smoke system
        if self.destroyed:
            self.timesincesmoke += dt
            if self.timesincesmoke > self.smokeinterval:
                self.timesincesmoke = 0.0 + 0.1 * self.smokeinterval * random.randint(0, 3)
                dir = Vector2d(random.randint(-5, 5), -38.0).getuvec()
                smoke = pygame.Surface([7 * 2 + 5, 7 * 2 + 5])
                smoke.set_colorkey((0, 0, 0))
                smoke.blit(self.smoke, (0, 0))
                particle(self.pos.copy(), smoke, random.randint(2, 5), dir, 1.75, 0.19, self.entities[2], True, 0.0, self.wind, 8.0)

        if self.controlActive:
            #move in the direction of movedir,if movedir is 0 dont move
            if self.left:
                self.move(dt, -1.0)
            elif self.right:
                self.move(dt, 1.0)

            self.updateTurret()
            return
Beispiel #7
0
    def respawn(self, xpos):
        self.pos = [float(xpos), 0.0]

        self.fuel = self.initialfuel

        self.kills = 0
        self.health = self.initialhealth
        self.controlActive = False
        self.left = False
        self.right = False
        self.shotcharging = False
        self.destroyed = False
        self.shotcounter = 0

        #inventory
        self.inventory = self.defaultinventory.copy()

        #set tank on ground and update turret vector
        self.setonground()
        self.turretVector = Vector2d(random.randint(-5.0, 5.0), -5.0).getuvec()
        self.updateTurret()
Beispiel #8
0
    def update(self, dt):
        #this list holds all the forces acting on the missile
        forces = [self._forcedrag(), self._forcegravity(), self.wind.force]

        #update position and velocity depeneing on the timestep
        for i in range(2):
            self.velocity[i] += (sum([j[i] for j in forces]) / self.m) * dt
            self.pos[i] += 20.0 * self.velocity[i] * dt

        #if new pos is outside bounds delete
        if 0 < self.pos[0] < self.terrain.bounds[0] - 1.0:
            #if new pos is under ground explode
            if self.terrain.heightmap[int(self.pos[0])] < self.pos[1]:
                explosion(self.pos, self.terrain, self.entities, self.player, 65, 1, 0.4)

                flash = pygame.Surface([self.terrain.bounds[0], self.terrain.bounds[1]])
                flash.fill(pygame.color.THECOLORS["white"])
                particle([flash.get_rect().w/2, flash.get_rect().h/2], flash, 2.5, Vector2d(0, 0), 0, 0.0, self.entities[2], True, 0.3)

                self.delete = True
        else:
            self.delete = True
 def _forcegravity(self):
     return Vector2d(0, (self.g * self.m))
Beispiel #10
0
 def __init__(self, max):
     self.max = int(max * 100)
     self.force = Vector2d(0.0, 0.0)
     self.newWind()
Beispiel #11
0
 def newWind(self):
     if self.max == 0:
         self.force = Vector2d(0.0, 0.0)
     else:
         self.force = Vector2d(
             float(random.randint(-self.max, self.max)) / 100.0, 0.0)
Beispiel #12
0
    def __init__(self, settings, name, terrain, wind, entities, aliveplayers, color=pygame.color.THECOLORS["red"]):
        #references
        self.entities = entities
        self.entities[0].append(self)
        self.terrain = terrain
        self.aliveplayers = aliveplayers
        self.wind = wind
        self.settings = settings

        #default inventory
        nrmissile = -1 if self.settings.inventory['Infinite missiles'] else self.settings.inventory['Amount missile']
        nrbouncybomb = -1 if self.settings.inventory['Infinite bouncybombs'] else self.settings.inventory['Amount bouncybomb']
        nrairstrike = -1 if self.settings.inventory['Infinite airstrikes'] else self.settings.inventory['Amount airstrike']
        nrteleporter = -1 if self.settings.inventory['Infinite teleporters'] else self.settings.inventory['Amount teleporter']
        nrnukes = -1 if self.settings.inventory['Infinite nukes'] else self.settings.inventory['Amount nuke']

        self.defaultinventory = playerinventory([missile, bouncybomb, airstrike, teleportermissile, nuke], [nrmissile, nrbouncybomb, nrairstrike, nrteleporter, nrnukes], 0, self)

        #maximum height difference the player can drive over
        self.maxheightdiff = self.settings.gamevalues['Max height diff']


        # maximum turrent angle in radians
        self.maxturretangle = self.settings.gamevalues["Max turret angle"] * (np.pi / 180.0)

        #fuel in seconds
        self.usefuel = self.settings.gamevalues["Enable fuel"]
        self.initialfuel = float(self.settings.gamevalues["Initial fuel"])
        self.fuel = self.initialfuel

        self.color = color
        self.name = name
        #helath from 0 to 1
        self.initialhealth = self.settings.gamevalues["Initial health"]
        self.health = self.initialhealth

        #counters
        self.shotcounter = 0
        self.kills = 0
        self.wins = 0

        # set to true if tank is at a new position, so that body gets redrawn
        self.newpos = True

        #shooting
        self.shootingstarttime = 0.0
        self.minshotpower = 0.1
        self.shotcharging = False
        self.fullpowershottime = self.settings.gamevalues["Fullpower shot time"] # time to charge full power shot in seconds
        self.shootingratio = self.settings.gamevalues["Shot power"]

        # player name font
        self.font = pygame.font.SysFont('Calibri', 11)

        #turret
        self.turretVector = Vector2d(0.0, -1.0)
        self.turretEndpoint = []
        self.turretOrigin = []

        # speed in pixels per second
        self.speed = self.settings.gamevalues["Player speed"]
        #if moving left or right
        self.left = False
        self.right = False

        #surfaces
        #smoke surface
        self.timesincesmoke = 0.0
        smoke = pygame.Surface([7 * 2 + 5, 7 * 2 + 5])
        smoke.fill((0, 0, 0))
        smoke.set_colorkey((0, 0, 0))
        pygame.draw.circle(smoke, pygame.color.THECOLORS["grey"], (int(smoke.get_rect().w / 2), int(smoke.get_rect().h / 2)), 7)
        self.smoke = smoke
        #fire
        fireorange = pygame.Surface([7 * 2 + 2, 7 * 2 + 2])
        fireorange.fill((0, 0, 0))
        fireorange.set_colorkey((0, 0, 0))
        pygame.draw.circle(fireorange, pygame.color.THECOLORS["orange"], (int(fireorange.get_rect().w / 2), int(fireorange.get_rect().h / 2)), 4)
        self.fireorange = fireorange
        #body
        self.sprite = pygame.Surface([self.width, self.height], pygame.SRCALPHA)
        #text
        self.textsurface = self.font.render(self.name, False, self.color)

        #toggles
        self.drawToggle = True
        self.delete = False
        self.controlActive = False
        self.destroyed = False
        return
Beispiel #13
0
    def draw(self, screen):
        if self.drawToggle:
            self.sprite.fill((0, 0, 0, 0))
            #turret
            pygame.draw.line(screen, self.color, self.turretOrigin, self.turretEndpoint, 3)

            #only draw rotated body when pos is updated
            if self.newpos:
                self.newpos = False
                #body
                pygame.draw.polygon(self.sprite, self.color, self.body)
                #rotate body
                self.rotatedbody = pygame.transform.rotate(self.sprite, np.rad2deg(self.terrain.normalmap[int(self.pos[0])].findCCWAngle(Vector2d(0.0, -1.0))))

            #draw
            screen.blit(self.rotatedbody, (self.pos[0] - self.rotatedbody.get_width() / 2.0, self.pos[1] - self.rotatedbody.get_height() / 2.0))

            #draw text and health bar
            if not self.destroyed:
                #fuelbar
                if self.usefuel:
                    pygame.draw.rect(screen, self.color, ((self.pos[0]-13, self.pos[1]-28), (26, 4)), 1)
                    pygame.draw.rect(screen, self.color, ((self.pos[0]-13, self.pos[1]-28), (26*max(self.fuel/self.initialfuel, 0.0), 4)))

                #health bar
                pygame.draw.rect(screen, self.color, ((self.pos[0]-13, self.pos[1]-33), (26, 4)), 1)
                pygame.draw.rect(screen, self.color, ((self.pos[0]-13, self.pos[1]-33), (26*max(self.health/self.initialhealth, 0.0), 4)))

                screen.blit(self.textsurface, (self.pos[0]-self.textsurface.get_rect().w/2, self.pos[1]-50))
        return
Beispiel #14
0
 def pickupparticle(self, item, amount):
     text = "+" + str(amount) + " " + item._name
     textsurface = self.owner.font.render(text, False, self.owner.color)
     particle([self.owner.pos[0], self.owner.pos[1] - 50], textsurface, 3,
              Vector2d(0.0, -1.0), 0.7, 0.19, self.owner.entities[2], True,
              0.0, None, 8.0)
Beispiel #15
0
 def _distance(self, pos1, pos2):
     return Vector2d.getvectorfrompoints(pos2, pos1).length()
Beispiel #16
0
 def draw(self, screen):
     #rotate the sprite in the direcction of the velocity vector
     rotated = pygame.transform.rotate(self.sprite, np.rad2deg(self.velocity.findCCWAngle(Vector2d(0.0, 1.0))))
     screen.blit(rotated, (self.pos[0] - rotated.get_rect().w / 2.0, self.pos[1] - rotated.get_rect().h / 2.0))