Source Code

C++ Got ya down? Half-Life 2 Coding Related.
Post Reply
Chandler
npc_hunter
npc_hunter
Posts: 559
Joined: Thu Jun 22, 2006 5:06 am

Source Code

Post by Chandler »

A game I wrote.
It's written in Python.
Rleased it because I can. BITCHES.
It's about 1 hour's worth of gameplay.

Code: Select all

from sahengine import games
from sahengine import color
import random
import math
games.init(screen_width=1000,screen_height=840, fps = 60)

class Star(games.Sprite):
    LAYER = 10
    images = [(games.load_image("Data/Images/Backgrounds/star_001.png"),2),
              (games.load_image("Data/Images/Backgrounds/star_002.png"),1)]
    
    def __init__(self):
        picture,dy = random.choice(Star.images)
        games.Sprite.__init__(self, image=picture,
                              x=random.randrange(games.screen.width),
                              y=random.randrange(810),
                              z=Star.LAYER, dy=dy)
    def update(self):
        if self.y > games.screen.height:
            self.y = 0
            self.x = random.randrange(games.screen.width)

class Wraith(games.Sprite):
    LAYER = 1
    image = games.load_image("Data/Images/Player/wraith.png")
    S_uhoh = games.load_sound("Data/Sound/Player/LastTransmission.wav")
    S_die = games.load_sound("Data/Sound/Player/Death.wav")
    laser_count = 0
    laser_level = 0
    missile_count = 0

    def __init__(self):
        games.Sprite.__init__(self, image=Wraith.image,
                              x=games.screen.width/2,
                              bottom=games.screen.height,
                              z=Wraith.LAYER)
        self.health1 = games.Text(value="Shield:", size=25, color=(255,255,255),
                                 left=20, top=20)
        games.screen.add(self.health1)
        self.health = games.Text(value=100, size=25, color=(255,255,255),
                                 left=self.health1.right+10, top=20)
        games.screen.add(self.health)

        self.ammo1 = games.Text(value="Missiles:", size=25, color=(255,255,255),
                                 left=20, top=50)
        games.screen.add(self.ammo1)
        self.ammo = games.Text(value=40, size=25, color=(255,255,255),
                                 left=self.ammo1.right+10, top=50)
        games.screen.add(self.ammo)
        
        self.score1 = games.Text(value="Score:", size=25, color=(255,255,255),
                                 right=games.screen.width-100, top=20)
        games.screen.add(self.score1)
        self.score = games.Text(value=0, size=25, color=(255,255,255),
                                 left=self.score1.right+60, top=20)
        games.screen.add(self.score)
        self.lowhealth = False

    def shoot(self):
        if self.laser_count == 0 and self.laser_level == 0:
            self.laser_count = 100
            games.screen.add(Laser(self.x,self.top,0))
        if self.laser_count == 0 and self.laser_level == 1:
            self.laser_count = 60
            games.screen.add(Laser(self.x-3, self.top,0))
            games.screen.add(Laser(self.x+3, self.top,0))
        if self.laser_count == 0 and self.laser_level == 2:
            self.laser_count = 50
            games.screen.add(Laser(self.x,self.top,0))
            games.screen.add(Laser(self.x-3,self.top,-1,-2.8))
            games.screen.add(Laser(self.x+3,self.top, 1,-2.8))
        if self.laser_count == 0 and self.laser_level == 3:
            self.laser_count = 40
            games.screen.add(Laser(self.x-3,self.top,0))
            games.screen.add(Laser(self.x+3,self.top,0))
            games.screen.add(Laser(self.x-5,self.top,-1,-2.8))
            games.screen.add(Laser(self.x+5,self.top, 1,-2.8))
        elif self.laser_count == 0 and self.laser_level >= 4:
            self.laser_count = 40
            games.screen.add(Laser(self.x-3,self.top,0))
            games.screen.add(Laser(self.x+3,self.top,0))
            games.screen.add(Laser(self.x-4,self.top,  -0.5,-2.95,-5))
            games.screen.add(Laser(self.x-9,self.top+1,-0.5,-2.95,-5))
            games.screen.add(Laser(self.x+4,self.top,   0.5,-2.95,5))
            games.screen.add(Laser(self.x+9,self.top+1, 0.5,-2.95,5))
            if self.laser_level >= 5:
                self.laser_count = 30
                games.screen.add(Laser(self.x-5,self.top,  -1,-2.8,-18))
                games.screen.add(Laser(self.x-10,self.top+2,-1,-2.8,-18))
                games.screen.add(Laser(self.x+5,self.top,   1,-2.8,18))
                games.screen.add(Laser(self.x+10,self.top+2, 1,-2.8,18))          
            if self.laser_level >= 6:
                games.screen.add(Laser(self.x-7, self.top,  -1.5,-2.5,-25))
                games.screen.add(Laser(self.x-13,self.top+3,-1.5,-2.5,-25))
                games.screen.add(Laser(self.x+7, self.top,   1.5,-2.5,25))
                games.screen.add(Laser(self.x+13,self.top+3, 1.5,-2.5,25))
            if self.laser_level >= 7:
                games.screen.add(Laser(self.x-9, self.top,  -1.85,-2.25,-34))
                games.screen.add(Laser(self.x-15,self.top+4,-1.85,-2.25,-34))
                games.screen.add(Laser(self.x+9, self.top,   1.85,-2.25,34))
                games.screen.add(Laser(self.x+15,self.top+4, 1.85,-2.25,34))
            if self.laser_level >= 8:
                games.screen.add(Laser(self.x-2,self.top,  -0.25,-3,-4))
                games.screen.add(Laser(self.x-7,self.top+0.5,-0.25,-3,-4))
                games.screen.add(Laser(self.x+2,self.top,   0.25,-3,4))
                games.screen.add(Laser(self.x+7,self.top+0.5, 0.25,-3,4))

                games.screen.add(Laser(self.x-5,self.top,   -0.75,-2.88,-12))
                games.screen.add(Laser(self.x-10,self.top+2,-0.75,-2.88,-12))
                games.screen.add(Laser(self.x+5,self.top,    0.75,-2.88,12))
                games.screen.add(Laser(self.x+10,self.top+2, 0.75,-2.88,12))

                games.screen.add(Laser(self.x-5,self.top,  -1.3,-2.63,-22))
                games.screen.add(Laser(self.x-10,self.top+2,-1.3,-2.63,-22))
                games.screen.add(Laser(self.x+5,self.top,   1.3,-2.63,22))
                games.screen.add(Laser(self.x+10,self.top+2, 1.3,-2.63,22))

                games.screen.add(Laser(self.x-9, self.top,  -1.7,-2.37,-29))
                games.screen.add(Laser(self.x-15,self.top+4,-1.7,-2.37,-29))
                games.screen.add(Laser(self.x+9, self.top,   1.7,-2.37,29))
                games.screen.add(Laser(self.x+15,self.top+4, 1.7,-2.37,29))
            if self.laser_level >= 9:
                self.laser_count = 15

    def missile(self):
        if self.missile_count == 0 and self.ammo.value > 0:
            games.screen.add(Missile(x=self.x+20, y=self.y))
            games.screen.add(Missile(x=self.x-20, y=self.y))
            self.missile_count = 100
            self.ammo.value -= 2

    def die(self):
        Wraith.S_die.play(0)
        games.screen.add(Explosion(Explosion.images_big, x=self.x, y=self.y))                                
        self.destroy()
        Game.end()
    
    def update(self):
        if self.health.value <= 30 and not self.lowhealth:
            Wraith.S_uhoh.play(0)
            self.lowhealth = True
            self.health1.color = (255,0,0)
            self.health.color = (255,0,0)
        if self.health.value <1>= 100:
            self.health.value = 100
        if games.mouse.is_pressed(0):
            Wraith.shoot(self)
        if self.laser_count > 0:
            self.laser_count -= 1
        if games.mouse.is_pressed(2):
            Wraith.missile(self)
        if self.missile_count > 0:
            self.missile_count -= 1
        if games.mouse.is_pressed(1):
            games.screen.add(Ring(x=self.x,y=self.y))
        if games.keyboard.is_pressed(games.K_d):
            self.die()
        self.x = games.mouse.x
        self.y = games.mouse.y

class Laser(games.Sprite):
    LAYER = 3
    image = games.load_image("Data/Images/Weapons/Player/laser.png")
    S_shoot = games.load_sound("Data/Sound/Weapons/Laser.wav")
    S_shield = games.load_sound("Data/Sound/Enemies/ScoutShield.wav")
    
    def __init__(self, x, y, dx, dy=-3, angle=0):
        games.Sprite.__init__(self, image=Laser.image, angle=angle,
                              x=x, y=y, dx=dx, dy=dy, z=Laser.LAYER)
        Laser.S_shoot.play(0)
    def check_hit(self):
        if self.overlapping_sprites(layer=Protoss.LAYER):
            Laser.S_shield.play(0)
            for enemy in self.overlapping_sprites(layer=Protoss.LAYER):
                enemy.health -= 1
                games.screen.add(Shield(x=enemy.x,y=enemy.y,angle=90))
            self.destroy()

    def update(self):
        self.check_hit()
        if self.bottom < 0:
            self.destroy()

class Missile(games.Animation):
    LAYER = 3

    sound = games.load_sound("Data/Sound/Weapons/Missile.wav")
    v = 2.5
    
    images = []
    images.append(games.load_image("Data/Images/Weapons/Player/Missile.png"))
    boss = []
    boss.append(games.load_image("Data/Images/Weapons/Enemy/boss_001.png"))
    boss.append(games.load_image("Data/Images/Weapons/Enemy/boss_002.png"))

    def __init__(self, x, y, dy=-1, targets=2, images=images):
        games.Animation.__init__(self, images = images,
                                x=x, y=y, z=Laser.LAYER, dx=0, dy=dy,
                                n_repeats=0, repeat_interval = 5)
        self.targets = targets
        Missile.sound.play(0)

    def distance(self,a,b):
        return math.sqrt(abs(a.x-b.x)**2+abs(a.y-b.y)**2)

    def seek(self):
        self.target = games.screen.get_sprites(self.targets)[0]
        for enemy in games.screen.get_sprites(self.targets):
            if self.distance(self,enemy) <self> 180 and self.dx == 0:
            self.angle = 359
            
        if self.angle <direction> direction:
            self.angle -= 1
        
        self.dx = Missile.v * math.sin(self.angle*math.pi/180)
        self.dy = Missile.v * -math.cos(self.angle*math.pi/180)

    def check_hit(self):
        if self.overlapping_sprites(layer=self.targets):
            Laser.S_shield.play(0)
            for enemy in self.overlapping_sprites(layer=self.targets):
                if self.targets == 2:
                    enemy.health -= 10
                    games.screen.add(Shield(x=enemy.x,y=enemy.y,angle=90))
                elif self.targets == 1:
                    enemy.health.value -= 20
                    games.screen.add(Shield(x=enemy.x,y=enemy.y,angle=-90))
            games.screen.add(Explosion(images=Explosion.images_small,x=self.x,y=self.y))
            self.destroy()

    def update(self):
        if games.screen.get_sprites(self.targets):
            self.seek()
        if self.x <0> games.screen.width:
            self.destroy()
        if self.y <0> games.screen.height:
            self.destroy()
        self.check_hit()
            

class Ring(games.Animation):
    LAYER = 3
    S_boom = games.load_sound("Data/Sound/Player/Boom.wav")
    images = []
    for i in range(9):
        images.append(games.load_image(("Data/Sprites/Ring/ring_"+str(i+1)+".gif")))
    for i in range(10):
        images.append(games.load_image(("Data/Sprites/Ring/ring_1"+str(i)+".gif")))
    for i in range(10):
        images.append(games.load_image(("Data/Sprites/Ring/ring_2"+str(i)+".gif")))
    images.append(games.load_image(("Data/Sprites/Ring/ring_30.gif")))
    
    def __init__(self, x, y):
        games.Animation.__init__(self, images=Ring.images, z=Ring.LAYER,
                                 x=x, y=y, n_repeats=1, repeat_interval=3)

    def update(self):
        if self.overlapping_sprites(layer=ProtossAttack.LAYER):
            for laser in self.overlapping_sprites(layer=ProtossAttack.LAYER):
               laser.destroy()
            Ring.S_boom.play(0)


class Protoss(games.Sprite):
    LAYER = 2
    total = 0
    
    shuttle = games.load_image("Data/Images/Enemies/shuttle.png")
    observer = games.load_image("Data/Images/Enemies/observer.png")
    scout = games.load_image("Data/Images/Enemies/scout.png")
    corsair = games.load_image("Data/Images/Enemies/corsair.png")
    arbiter = games.load_image("Data/Images/Enemies/arbiter.png")
    S_kill = [games.load_sound("Data/Sound/Taunt/SoGood.wav"),games.load_sound("Data/Sound/Taunt/GottaGetMe.wav"),
              games.load_sound("Data/Sound/Taunt/BestStarfighter.wav"), games.load_sound("Data/Sound/Taunt/YoursTruly.wav"),
              games.load_sound("Data/Sound/Taunt/GottaDie.wav"), games.load_sound("Data/Sound/Taunt/Invincible.wav")]
    S_die = games.load_sound("Data/Sound/Enemies/ScoutDeath.wav")
    S_gurgle = games.load_sound("Data/Sound/Enemies/ScoutGurgle.wav")
    S_go = games.load_sound("Data/Sound/Enemies/ScoutGo.wav")
    S_aiur = games.load_sound("Data/Sound/Enemies/LifeAiur.wav")
    S_serve = games.load_sound("Data/Sound/Taunt/ThusServe.wav")
    S_talk = games.load_sound("Data/Sound/Enemies/ScoutTalk.wav")
    S_target = games.load_sound("Data/Sound/Taunt/Target.wav")
    S_bringiton = games.load_sound("Data/Sound/Taunt/BringItOn.wav")

    def __init__(self, image, x, y, health=1, ai=0, dy=1, dx=0,
                 attack=0, bonus=0, angle=0, k=1, score=10):
        games.Sprite.__init__(self, image=image, angle=angle,
                              x=x, y=y, z = Protoss.LAYER, dx=dx, dy=dy)
        self.score = score
        self.health = health
        self.ai = ai
        self.attack = attack
        self.bonus = bonus
        self.k = k
        Protoss.total += 1

    def move(self):
        if self.ai == 1:
            if self.y == 350:
                self.dy = 0
                if self.angle > 195 or self.angle < 165:
                    self.k *= -1
                self.angle += self.k
        if self.ai == 2:
            if self.y == 450:
                if self.k < 75:
                    self.dy = 0
                    self.k += 1
                elif self.k == 75:
                    Protoss.S_target.play(0)
                    self.k += 1
                elif self.angle <180> 75:
                    self.angle += 1
                else :
                    self.angle = 180
                    self.dy = -2
        if self.ai == 3:
            if self.y == 250:
                if self.k == 1:
                    Protoss.S_talk.play(0)
                self.k += 1
                if self.k <150> 150:
                    self.attack = 1
                    self.dy = 1
        if self.ai == 4:
            if self.y == 250:
                if self.k == 1:
                    Protoss.S_go.play(0)
                self.k += 1
                if self.k < 150:
                    self.dy = 0
                elif self.k == 150:
                    self.health = 2
                elif 151 <= self.k <= 300:
                    self.attack = 1
                else :
                    self.dy = 0.3
        if self.ai == 5:
            if self.y == 150:
                self.k += 1
                if self.k < 350:
                    self.dy = 0
                elif self.k == 350 :
                    self.health = 2
                    self.attack = 1
                    self.dy = random.choice([0.3,0.4,0.5,0.6,0.7,0.8,0.9,1])
                    self.dx = random.choice([-1,-0.5,-0.25,0,0.25,0.5,1])
        if self.ai == 6:
            if self.y == 110:
                self.k += 1
                if self.k < 250:
                    self.dy = 0
                elif self.k == 250 :
                    self.health = 2
                    self.attack = 1
                    self.dy = random.choice([0.3,0.4,0.5,0.6,0.7,0.8,0.9,1])
                    self.dx = random.choice([-1,-0.5,-0.25,0,0.25,0.5,1])
        if self.ai == 7:
            if self.y == 70:
                if self.k == 1:
                    Protoss.S_bringiton.play(0)
                self.k += 1
                if self.k < 150:
                    self.dy = 0
                elif self.k == 150:
                    self.health = 2
                    self.attack = 1
                    self.dy = random.choice([0.3,0.4,0.5,0.6,0.7,0.8,0.9,1])
                    self.dx = random.choice([-1,-0.5,-0.25,0,0.25,0.5,1])
        if self.ai == 8:
            if self.y == 150 and self.k < 200:
                if self.k == 1:
                    Protoss.S_aiur.play(0)
                self.k += 1
                if self.k <150>= 200:
                if self.y > 200 or self.top < 100:
                    self.dy *= -1
                if self.x <250> games.screen.width-250:
                    self.dx *= -1
                    
                    

    def shoot(self):
        if self.attack == 1:
            fire = random.randrange(200)
            if fire == 0 and self.top > 0:
                games.screen.add(ProtossAttack(image=ProtossAttack.spark,
                                              x=self.x, y=self.bottom,
                                              dy=1.8, damage=10))
        if self.attack == 2:
            fire = random.randrange(30)
            if fire == 0 and self.top > 0:
                games.screen.add(ProtossAttack2(images=ProtossAttack2.zap,
                                                x=self.x, y=self.bottom-5,
                                                dy=2.2, damage=2))
        if self.attack == 8:
            
            if self.k == 200:
                self.fire = random.choice([0,1,2])
                self.timer = 0
                self.lasertimer = 0
                self.changer = 0
                self.k = 201

            if self.changer == 5:
                self.fire = random.choice([0,1,2])
                self.changer = 0

            if self.timer > 0:
                self.timer -= 1
            if self.lasertimer > 0:
                self.lasertimer -= 1
                
            if self.fire == 0:
                self.timer = 30
                self.changer += 1
            if self.lasertimer == 0:
                self.lasertimer = 50
                
                games.screen.add(ProtossAttack(self.x-3,self.bottom, 0, 3, 0))
                games.screen.add(ProtossAttack(self.x+3,self.bottom, 0, 3, 0))

                games.screen.add(ProtossAttack(self.x-4,self.bottom,  -0.5,2.95,5))
                games.screen.add(ProtossAttack(self.x+4,self.bottom,   0.5,2.95,-5))

                games.screen.add(ProtossAttack(self.x-5,self.bottom,   -1,2.8,18))
                games.screen.add(ProtossAttack(self.x+5,self.bottom,    1,2.8,-18))

                games.screen.add(ProtossAttack(self.x-7, self.bottom,  -1.5,2.5,25))
                games.screen.add(ProtossAttack(self.x+7, self.bottom,   1.5,2.5,-25))
 
                games.screen.add(ProtossAttack(self.x-9, self.bottom,  -1.85,2.25,34))
                games.screen.add(ProtossAttack(self.x+9, self.bottom,   1.85,2.25,-34))
            if self.fire == 1 and self.timer == 0:
                self.timer = 2
                self.changer += 0.01

                games.screen.add(ProtossAttack2(images=ProtossAttack2.zap,
                                                x=self.x, y=self.bottom, dy=7, damage=5))
                
            if self.fire == 2 and self.timer == 0:
                self.timer = 100
                self.changer += 1

                games.screen.add(Missile(x=self.x, y=self.bottom+10, targets=1,
                                         images= Missile.boss))

    
    def check_collision(self):
        if self.overlapping_sprites(layer=Wraith.LAYER):
            for enemy in self.overlapping_sprites(layer=Wraith.LAYER):
                enemy.health.value -= 50
                games.screen.add(Shield(x=enemy.x, y=enemy.y, angle=-90))
            self.health -= 100

    def explode(self):
        for wraith in games.screen.get_sprites(1):
            wraith.score.value += self.score
        games.screen.add(Explosion(Explosion.images,self.x,self.y))
        self.destroy()
        k = random.randrange(8)
        if k == 0:
            Protoss.S_gurgle.play(0)
        else:
            Protoss.S_die.play(0)
        k = random.randrange(5)
        if k == 0:
            sound = random.choice(Protoss.S_kill)
            sound.play(0)
        if self.bonus == 1:
            games.screen.add(Bonus(self.x, self.y, dx=0, images=Bonus.laser))
        if self.bonus == 2:
            games.screen.add(Bonus(self.x, self.y, dx=0, images=Bonus.laser))
            games.screen.add(Bonus(self.x, self.y, dx=random.choice([-1,1]),
                                   images=Bonus.shield))
        Protoss.total -= 1
                     
    def update(self):
        self.move()
        self.shoot()
        self.check_collision()
        if self.health <= 0:
            self.explode()
        if self.left <0> games.screen.width:
            self.dx *= -1
        if self.top > games.screen.height:
            self.destroy()
            Protoss.total -= 1
        if Protoss.total == 0:
            Game.advance()

class ProtossAttack(games.Sprite):
    LAYER = 3
    spark = games.load_image("Data/Images/Weapons/Enemy/spark.png")
    S_shield = games.load_sound("Data/Sound/Player/Shield.wav")

    def __init__(self, x, y, dx=0, dy=1, angle=0, damage=2, image=spark):
        games.Sprite.__init__(self, image=image,
                              x=x, y=y, dy=dy, dx=dx, z=ProtossAttack.LAYER)
        self.damage = damage
    def check_hit(self):
        if self.overlapping_sprites(layer=Wraith.LAYER):
            ProtossAttack.S_shield.play(0)
            for enemy in self.overlapping_sprites(layer=Wraith.LAYER):
                enemy.health.value -= self.damage
                games.screen.add(Shield(enemy.x, enemy.y, angle=-90))
            self.destroy()

    def update(self):
        self.check_hit()
        if self.top > games.screen.height:
            self.destroy()

class ProtossAttack2(games.Animation):
    LAYER = 3
    zap = []
    for i in range(6):
        zap.append(games.load_image("Data/Sprites/Zap/zap_"+str(i+1)+".png"))
    S_shield = games.load_sound("Data/Sound/Player/Shield.wav")

    def __init__(self, images, x, y, dy, damage):
        games.Animation.__init__(self, images=images,
                              x=x, y=y, dy=dy, z=ProtossAttack.LAYER)
        self.damage = damage
    def check_hit(self):
        if self.overlapping_sprites(layer=Wraith.LAYER):
            ProtossAttack.S_shield.play(0)
            for enemy in self.overlapping_sprites(layer=Wraith.LAYER):
                enemy.health.value -= self.damage
                games.screen.add(Shield(enemy.x, enemy.y, angle=-90))
            self.destroy()

    def update(self):
        self.check_hit()
        if self.top > games.screen.height:
            self.destroy()

class Bonus(games.Animation):
    laser = [games.load_image("Data/Images/Bonus/bonus_001.png"),games.load_image("Data/Images/Bonus/bonus_002.png")]
    shield = [games.load_image("Data/Images/Bonus/bonus_003.png"),games.load_image("Data/Images/Bonus/bonus_004.png")]

    def __init__(self, x, y, dx, images):
        games.Animation.__init__(self, images=images,
                              x=x, y=y, z=Laser.LAYER, dy=1, dx=dx,
                                 n_repeats=0, repeat_interval=5)

    def pickup(self):
        if self.overlapping_sprites(layer=Wraith.LAYER):
            if self.images == Bonus.laser:
                for wraith in self.overlapping_sprites(layer=Wraith.LAYER):
                    wraith.laser_level += 1
                    wraith.score.value += 20
                    games.screen.add(Pickup(x=wraith.x,y=wraith.y))
                    self.destroy()
            elif self.images == Bonus.shield:
                for wraith in self.overlapping_sprites(layer=Wraith.LAYER):
                    wraith.health.value += 50
                    wraith.score.value += 30
                    games.screen.add(Pickup(x=wraith.x,y=wraith.y))
                    self.destroy()
            

    def update(self):
        self.pickup()
        if self.left <0> games.screen.width:
            self.dx *= -1
        if self.y > games.screen.height:
            self.destroy()

class Explosion(games.Animation):
    images = []
    for i in range(9):
        images.append(games.load_image(("Data/Sprites/Explosion/explosion_"+str(i+1)+".gif")))
    for i in range(8):
        images.append(games.load_image(("Data/Sprites/Explosion/explosion_1"+str(i)+".gif")))

    images_big = []
    for i in range(9):
        images_big.append(games.load_image(("Data/Sprites/Explosion_Big/explosion_big_"+str(i+1)+".gif")))
    for i in range(10):
        images_big.append(games.load_image(("Data/Sprites/Explosion_Big/explosion_big_1"+str(i)+".gif")))
    for i in range(10):
        images_big.append(games.load_image(("Data/Sprites/Explosion_Big/explosion_big_2"+str(i)+".gif")))
    images_big.append(games.load_image(("Data/Sprites/Explosion_Big/explosion_big_30.gif")))

    images_small = []
    for i in range(9):
        images_small.append(games.load_image(("Data/Sprites/Explosion_Small/explosion_small_"+str(i+1)+".gif")))

    def splash(self):
        if self.images == Explosion.images_small:
            for enemy in self.overlapping_sprites(2):
                enemy.health -= 2
    
    def __init__(self, images, x, y):
        games.Animation.__init__(self, images=images,
                                 x=x, y=y, n_repeats=1, repeat_interval=5)

class Shield(games.Animation):
    images = []
    for i in range(4):
        images.append(games.load_image(("Data/Sprites/Shield/shield_"+str(i+1)+".png")))
    
    def __init__(self, x, y, angle):
        games.Animation.__init__(self, images=Shield.images, angle=angle,
                                 x=x, y=y, n_repeats=1, repeat_interval=5)

class Pickup(games.Animation):
    sound = games.load_sound("Data/Sound/Taunt/Dada.wav")
    images = []
    for i in range(4):
        images.append(games.load_image(("Data/Sprites/PickUp/pickup_"+str(i+1)+".png")))
    
    def __init__(self, x, y):
        games.Animation.__init__(self, images=Pickup.images,
                                 x=x, y=y, n_repeats=1, repeat_interval=5)
        Pickup.sound.play(0)

class LevelWarning(games.Animation):
    images = []
    for i in range(9):
        images.append(games.load_image(("Data/Sprites/Warning/warning_"+str(i+1)+".gif")))
    for i in range(6):
        images.append(games.load_image(("Data/Sprites/Warning/warning_1"+str(i)+".gif")))

    def __init__(self):
        games.Animation.__init__(self, images=LevelWarning.images,
                                 x=games.screen.width/2, y=50, n_repeats=2, repeat_interval=5)

class Game(object):

    level = 0
    
    inst1 = games.Text(value="You don't like Protoss.",
                       color = (255,255,255),
                       size = 30,
                       left = 50,
                       top = 50)
    inst2 = games.Text(value="The time has come to show them who's the real  pro-boss.",
                       color = (255,255,255),
                       size = 30,
                       left = 100,
                       top = 80)

    
    malfunction = games.load_sound("Data/Sound/Taunt/Malfunction.wav")
    S_launch = games.load_sound("Data/Sound/Taunt/LaunchOrders.wav")
    
    def initialize():
        games.screen.event_grab = True
        games.music.load("Data/Music/theme.ogg")
        
    initialize = staticmethod(initialize)

    def intro():
        games.screen.clear()
        
        games.screen.background = games.load_image("Data/Images/Backgrounds/title.png",transparent=False)

        begin = games.Question(value="Hit enter to begin...", color = (255,255,255),
                        size = 45, x = 380, y=games.screen.height-120,
                        responses = [(games.K_RETURN,Game.play)])
        
        games.screen.add(Game.inst1)
        games.screen.add(Game.inst2)
        games.screen.add(begin)

        Game.level = 0
        
        games.screen.mainloop()

    intro = staticmethod(intro)
    
    def play():
        Game.inst1.destroy()
        Game.inst2.destroy()
        for thing in games.screen.get_sprites(0):
            thing.destroy()
        
        Game.S_launch.play(0)
        
        games.mouse.is_visible = False
        games.screen.background = games.load_image("Data/Images/Backgrounds/stars.png",transparent=False)
        games.music.play(-1)
        
        #--Stars--#        
        for i in range(25):
            games.screen.add(Star())         

        #--Player--#
        games.screen.add(Wraith())

        Game.advance()

    play = staticmethod(play)


    def advance():

        Game.level += 1
        games.screen.add(LevelWarning())
        
        if Game.level == 1:
            #--1st Observer--#
            for i in range(1):
                arrival = 5
                dy=1
                observer = Protoss(image=Protoss.observer,
                                   x=games.screen.width/2,
                                   y=arrival*dy*-50,
                                   dy=dy, ai=1,
                                   angle = 180, score=5)
                games.screen.add(observer)

            #--1st Shuttle--#
            for i in range(1):
                arrival = 15
                dy=2
                shuttle = Protoss(image=Protoss.shuttle,
                                  x=games.screen.width/2,
                                  y=arrival*dy*-50, score=5,
                                  dy=dy, ai=2, bonus =1, health = 1)
                games.screen.add(shuttle)
                           
            #--2nd Shuttle--#
            for i in range(1):
                arrival = 35
                dy=1
                shuttle = Protoss(image=Protoss.shuttle,
                                   x=random.randrange(games.screen.width),
                                   y=arrival*dy*-50,
                                   dy=dy, bonus=1, score=5)
                games.screen.add(shuttle)
                
            #--Trio Scouts--#
            for i in range(-1,2):
                arrival = 30
                dy=1
                scout = Protoss(image=Protoss.scout,
                            x=games.screen.width/2+50*i, y=arrival*dy*-50-abs(i)*50,
                            dy=dy, attack=0, health=20, ai=3, score=10)
                games.screen.add(scout)
                
        elif Game.level == 2:
            #--Wave 1 Scouts--#
            for i in range(10):
                arrival = 6
                dy=1.5
                scout = Protoss(image=Protoss.scout,
                                x= 40*i + 30,
                                y=arrival*-50 - 20*i,
                                dx=0, dy=dy,
                                attack=1, health=2, score=10)
                games.screen.add(scout)

            #--Wave 2 Scouts--#
            for i in range(10):
                arrival = 18
                dy=1.5
                scout = Protoss(image=Protoss.scout,
                                x= games.screen.width - (40*i + 30),
                                y=arrival*-50 - 20*i,
                                dx=0, dy=dy,
                                attack=1, health=2, score=10)
                games.screen.add(scout)

            #--3rd Shuttle--#
            for i in range(1):
                arrival = 20
                dy=1
                shuttle = Protoss(image=Protoss.shuttle,
                                   x=random.randrange(games.screen.width),
                                   y=arrival*dy*-50,
                                   dy=dy, bonus=1, score=5)
                games.screen.add(shuttle)

            #--Wave 3 Scouts--#
            for i in range(25):
                arrival = 35
                dy=1
                scout = Protoss(image=Protoss.scout,
                                x= 40*i + 20,
                                y=arrival*dy*-50,
                                dx=0, dy=dy, ai=4,
                                attack=0, health=20, score=10)
                games.screen.add(scout) 

        elif Game.level == 3:
            #--4th Shuttle--#
            for i in range(1):
                arrival = 0
                dy=1.5
                shuttle = Protoss(image=Protoss.shuttle,
                                   x=random.randrange(games.screen.width),
                                   y=arrival*dy*-50,
                                   dy=dy, bonus=1, score=5)
                games.screen.add(shuttle)

            #--Wave 4 Scouts--#
            for i in range(25):
                arrival = 5
                dy=1
                scout = Protoss(image=Protoss.scout,
                                x= 40*i + 20,
                                y=arrival*dy*-50,
                                dx=0, dy=dy, ai=5,
                                attack=0, health=20, score=10)
                games.screen.add(scout)
            for i in range(25):
                arrival = 7
                dy=1
                scout = Protoss(image=Protoss.scout,
                                x= 40*i + 20,
                                y=arrival*dy*-50,
                                dx=0, dy=dy, ai=6,
                                attack=0, health=20, score=10)
                games.screen.add(scout)
            for i in range(25):
                arrival = 9
                dy=1
                scout = Protoss(image=Protoss.scout,
                                x= 40*i + 20,
                                y=arrival*dy*-50,
                                dx=0, dy=dy, ai=7,
                                attack=0, health=20, score=10)
                games.screen.add(scout)

        elif Game.level == 4:
            #--4th Shuttle--#
            for i in range(1):
                arrival = 2
                dy=1
                shuttle = Protoss(image=Protoss.shuttle,
                                   x=random.randrange(games.screen.width),
                                   y=arrival*dy*-50,
                                   dy=dy, bonus=2, score=5)
                games.screen.add(shuttle)

            #--Wave 5 Corsairs--#
            for i in range(-1,2):
                arrival = 8
                dy=0.5
                corsair = Protoss(image=Protoss.corsair,
                                x= games.screen.width/2+200*i,
                                y=arrival*-50,
                                dx=0, dy=dy, ai=0,
                                attack=2, health=4, score=20)
                games.screen.add(corsair)

            #--Wave 5 Scouts--#
            for i in range(5):
                arrival = 6
                dy=1.5
                scout = Protoss(image=Protoss.scout,
                                x= 15*i + 30,
                                y=arrival*dy*-50 - 40*i,
                                dx=0, dy=dy,
                                attack=1, health=2, score=10)
                games.screen.add(scout)
            for i in range(5):
                arrival = 6
                dy=1.5
                scout = Protoss(image=Protoss.scout,
                                x= games.screen.width - (15*i + 30),
                                y=arrival*dy*-50 - 40*i,
                                dx=0, dy=dy,
                                attack=1, health=2, score=10)
                games.screen.add(scout)

            #--5th Shuttle--#
            for i in range(1):
                arrival = 15
                dy=1
                shuttle = Protoss(image=Protoss.shuttle,
                                   x=random.randrange(games.screen.width),
                                   y=arrival*dy*-50,
                                   dy=dy, bonus=1, score=5)
                games.screen.add(shuttle)

            #--Wave 6 Corsairs--#
            for i in range(-4,5):
                arrival = 32
                dy=1
                corsair = Protoss(image=Protoss.corsair,
                                x= games.screen.width/2+100*i,
                                y=arrival*dy*-50 - abs(20*i),
                                dx=0, dy=dy, ai=0,
                                attack=2, health=4, score=20)
                games.screen.add(corsair)

        elif Game.level == 5:
            #--6th Shuttle--#
            for i in range(1):
                arrival = 0
                dy=1
                shuttle = Protoss(image=Protoss.shuttle,
                                   x=random.randrange(games.screen.width),
                                   y=arrival*dy*-50,
                                   dy=dy, bonus=2, score=5)
                games.screen.add(shuttle)

            #--Observer Bombs--#
            for i in range(100):
                arrival = 20
                dy=4
                observer = Protoss(image=Protoss.observer,
                                   x=random.randrange(games.screen.width),
                                   y=random.randrange(-1600,0)+arrival*-50,
                                   dy=dy, ai=0,
                                   angle = 180, score=20)
                games.screen.add(observer)

        elif Game.level == 6:
            #--7th Shuttle--#
            for i in range(1):
                arrival = 10
                dy=1
                shuttle = Protoss(image=Protoss.shuttle,
                                   x=random.randrange(games.screen.width),
                                   y=arrival*dy*-50,
                                   dy=dy, bonus=2, score=5)
                games.screen.add(shuttle)
            
           #--Wave 7 Corsairs--#
            for i in range(20):
                arrival = 12
                dy=1.5
                corsair = Protoss(image=Protoss.corsair,
                                x= 20*i + 40,
                                y=arrival*-50 - 55*i,
                                dx=0, dy=dy,
                                attack=2, health=4, score=20)
                games.screen.add(corsair)
            for i in range(20):
                arrival = 12
                dy=1.5
                corsair = Protoss(image=Protoss.corsair,
                                x= games.screen.width - (20*i + 40),
                                y=arrival*-50 - 55*i,
                                dx=0, dy=dy,
                                attack=2, health=4, score=20)
                games.screen.add(corsair)

            #--Wave 7 Scouts--#
            for k in range(8):
                for i in range(-1,2):
                    arrival = 10+k
                    dy=2.5
                    scout = Protoss(image=Protoss.scout,
                                x=games.screen.width/2+50*i,
                                y=arrival*dy*-50-abs(i)*50,
                                dy=dy, attack=1, health=2, ai=0, score=10)
                    games.screen.add(scout)

        elif Game.level == 7:
            #--8th Shuttle--#
            for i in range(2):
                arrival = 5
                dy=1
                shuttle = Protoss(image=Protoss.shuttle,
                                   x=random.randrange(games.screen.width),
                                   y=arrival*dy*-50,
                                   dy=dy, bonus=2, score=5)
                games.screen.add(shuttle)

            #--BOSS--#
            arrival = 0
            dy=1
            arbiter = Protoss(image=Protoss.arbiter,
                              x=games.screen.width/2,
                              y=arrival*-50,
                              dy=dy, health=200,
                              ai = 8, attack=0, score = 300)
            games.screen.add(arbiter)
        elif Game.level == 8:
            games.screen.add(games.Message(value="Wow. You won.", color=(255,255,255),size = 30,
                                           x=games.screen.width/2,y=games.screen.height/2-20,
                                           lifetime=5*games.screen.fps,
                                           after_death=games.screen.quit()))
            games.screen.add(games.Message(value="Go do something fun now...", color=(255,255,255),size = 30,
                                           x=games.screen.width/2,y=games.screen.height/2+20))



    advance = staticmethod(advance)

    def end():
        Game.malfunction.play(0)
        games.screen.add(games.Text(value="Foolish Terran",
                                 color = (164,0,164), size = 50,
                                 x=games.screen.width/2,
                                 y=games.screen.height/2+10))
        games.screen.add(games.Text(value="Now you shall burn in Adun's fires, forever...MUAHAHAHAHAHA",
                                 color = (164,0,164), size = 45,
                                 x=games.screen.width/2,
                                 y=games.screen.height/2 + 35))
        games.screen.add(games.Question(value="Hit space to be reincarnated...",
                                        color = (164,0,164), size = 30,
                                        x = games.screen.width/2,
                                        y = games.screen.height/2 + 150,
                                        responses = [(games.K_SPACE, Game.intro)]))
        games.screen.mainloop()

    end = staticmethod(end)


def main():
    Game.initialize()
    Game.intro()

main()
realize this includes:

A.I. From scratch.
Physics, from Scratch
item creation and placement, from scratch
EVERYTHING, including the way the game was rendered, was written from scratch.
Mustang
npc_combinegunship
npc_combinegunship
Posts: 795
Joined: Thu Jul 27, 2006 2:33 am
Location: witty phrase here

Post by Mustang »

I want to play it
Hyperjag3 wrote:God damnit, I can't take anymore of that fag's shit, banned.
skidz wrote:Your account and IP are banned for life, goodbye.
Tono-Tako
npc_combinegunship
npc_combinegunship
Posts: 785
Joined: Tue May 30, 2006 10:28 pm
Location: Half-LIfe series Fan

Post by Tono-Tako »

LOL, Starcraft.
Image
Vote for obsidian conflict in moddb
One click a day doesnt hurt your finger
Chandler
npc_hunter
npc_hunter
Posts: 559
Joined: Thu Jun 22, 2006 5:06 am

Post by Chandler »

It's a Galaga Clone.
Post Reply