Skip to content
Browse files

Merge branch 'master' of github.com:nightcracker/PyGG2

Conflicts:
	engine/sentry.py
	engine/weapon.py
  • Loading branch information...
2 parents a7bf71a + a70b57d commit de6c112efbc2c378281f3adae6ab148dab957e52 @Orpheon Orpheon committed Apr 16, 2012
View
8 client/character_renderer.py
@@ -65,6 +65,14 @@ def __init__(self):
self.spriteoffset = (14, 30)
self.spriteoffset_flipped = (36, 30)
+class MedicRenderer(ClassRenderer):
+ def __init__(self):
+ self.depth = 0
+ self.sprites = [pygrafix.image.load("characters/medicreds/%s.png" % i) for i in range(4)]
+
+ self.spriteoffset = (26, 30)
+ self.spriteoffset_flipped = (26, 30)
+
class EngineerRenderer(ClassRenderer):
def __init__(self):
self.depth = 0
View
21 client/projectile_renderer.py
@@ -21,8 +21,6 @@ def render(self, renderer, game, state, shot):
sprite.position = renderer.get_screen_coords(shot.x, shot.y)
renderer.world_sprites.append(sprite)
- def return_depth(self):
- return self.depth
class FlameRenderer(object):
@@ -50,9 +48,6 @@ def render(self, renderer, game, state, flame):
sprite.position = renderer.get_screen_coords(flame.x,flame.y)
renderer.world_sprites.append(sprite)
- def return_depth(self):
- return self.depth
-
class RocketRenderer(object):
def __init__(self):
@@ -68,6 +63,18 @@ def render(self, renderer, game, state, rocket):
sprite.position = renderer.get_screen_coords(rocket.x, rocket.y)
renderer.world_sprites.append(sprite)
- def return_depth(self):
- return self.depth
+class NeedleRenderer(object):
+ def __init__(self):
+ self.depth = 1
+ self.needlesprite = pygrafix.image.load("projectiles/needles/0.png")
+
+ def render(self, renderer, game, state, needle):
+ sprite = pygrafix.sprite.Sprite(self.needlesprite)
+ sprite.rotation = 360 - needle.direction
+
+ if needle.max_flight_time - needle.flight_time < needle.fade_time:
+ sprite.alpha = (needle.max_flight_time - needle.flight_time) / needle.fade_time
+
+ sprite.position = renderer.get_screen_coords(needle.x, needle.y)
+ renderer.world_sprites.append(sprite)
View
3 client/rendering.py
@@ -39,17 +39,20 @@ def __init__(self, client):
engine.character.Pyro: character_renderer.PyroRenderer(),
engine.character.Soldier: character_renderer.SoldierRenderer(),
engine.character.Heavy: character_renderer.HeavyRenderer(),
+ engine.character.Medic: character_renderer.MedicRenderer(),
engine.character.Engineer: character_renderer.EngineerRenderer(),
engine.character.Spy: character_renderer.SpyRenderer(),
engine.weapon.Scattergun: weapon_renderer.ScattergunRenderer(),
engine.weapon.Flamethrower: weapon_renderer.FlamethrowerRenderer(),
engine.weapon.Rocketlauncher: weapon_renderer.RocketlauncherRenderer(),
engine.weapon.Minigun: weapon_renderer.MinigunRenderer(),
+ engine.weapon.Medigun : weapon_renderer.MedigunRenderer(),
engine.weapon.Shotgun: weapon_renderer.ShotgunRenderer(),
engine.weapon.Revolver: weapon_renderer.RevolverRenderer(),
engine.projectile.Shot: projectile_renderer.ShotRenderer(),
engine.projectile.Flame: projectile_renderer.FlameRenderer(),
engine.projectile.Rocket: projectile_renderer.RocketRenderer(),
+ engine.projectile.Needle : projectile_renderer.NeedleRenderer(),
engine.sentry.Building_Sentry: sentry_renderer.BuildingSentryRenderer(),
}
View
5 client/sentry_renderer.py
@@ -12,13 +12,10 @@ def __init__(self):
self.sprites = list([pygrafix.image.load("sprites/ingameelements/sentryred/{0}.png".format(i)) for i in range(10)])
def render(self, renderer, game, state, sentry):
- self.sprite = self.sprites[int(sentry.animation_frame)]
+ self.sprite = self.sprites[min(int(sentry.animation_frame), 9)] # TODO, get rid of this min and figure out how to cap an image index
sprite = pygrafix.sprite.Sprite(self.sprite)
# TODO: Sprite offset correctly
sprite.position = renderer.get_screen_coords(sentry.x, sentry.y)
renderer.world_sprites.append(sprite)
-
- def return_depth(self):
- return self.depth
View
12 client/weapon_renderer.py
@@ -74,6 +74,18 @@ def __init__(self):
self.depth = 1
self.weaponsprite = pygrafix.image.load("weapons/miniguns/0.png")
self.firingsprite = pygrafix.image.load("weapons/miniguns/2.png")
+
+class MedigunRenderer(WeaponRenderer):
+ weapon_rotate_point = (10, -1) # where is the handle of the gun, where to rotate around
+ weapon_rotate_flipped = (10,11)
+ weaponoffset = (10, 9) # where the character should carry it's gun
+ weaponoffset_flipped = (2, 9)
+
+ def __init__(self):
+ self.depth = 1
+ self.weaponsprite = pygrafix.image.load("weapons/mediguns/0.png")
+ self.firingsprite = pygrafix.image.load("weapons/mediguns/0.png")
+
class ShotgunRenderer(WeaponRenderer):
weapon_rotate_point = (10, -1) # where is the handle of the gun, where to rotate around
View
3 client_main.py
@@ -365,6 +365,9 @@ def step(self):
elif self.window.is_key_pressed(key._4):
event = networking.event_serialize.ClientEventChangeclass(constants.CLASS_HEAVY)
self.networker.events.append((self.networker.sequence, event))
+ elif self.window.is_key_pressed(key._6):
+ event = networking.event_serialize.ClientEventChangeclass(constants.CLASS_MEDIC)
+ self.networker.events.append((self.networker.sequence, event))
elif self.window.is_key_pressed(key._7):
event = networking.event_serialize.ClientEventChangeclass(constants.CLASS_ENGINEER)
self.networker.events.append((self.networker.sequence, event))
View
46 engine/character.py
@@ -130,7 +130,7 @@ def die(self, game, state):
# Then we have to destroy our weapon
state.entities[self.weapon].destroy(state)
-
+ # TODO: destroy our sentry
self.destroy(state)
def get_player(self, game, state):
@@ -207,6 +207,24 @@ def __init__(self, game, state, player_id):
self.hp = self.maxhp
self.weapon = weapon.Rocketlauncher(game, state, self.id).id
+
+class Demoman(Character):
+ #TODO: this class
+ # FIXME: width, height of heavy - rectangle collision
+ collision_mask = mask.Mask(12, 33, True)
+ max_speed = 144
+ maxhp = 200
+
+ def __init__(self, game, state, player_id):
+ Character.__init__(self, game, state, player_id)
+
+ self.hp = self.maxhp
+ self.weapon = weapon.Minigun(game, state, self.id).id
+
+ def step(self, game, state, frametime):
+ Character.step(self, game, state, frametime)
+ if self.get_player(game, state).leftmouse:
+ self.hspeed = min(54, max(-54, self.hspeed))
class Heavy(Character):
# FIXME: width, height of heavy - rectangle collision
@@ -224,7 +242,20 @@ def step(self, game, state, frametime):
Character.step(self, game, state, frametime)
if self.get_player(game, state).leftmouse:
self.hspeed = min(54, max(-54, self.hspeed))
+
+class Medic(Character):
+ # FIXME: width, height of Medic - rectangle collision
+ # FIXME: offsets to be proper
+ collision_mask = mask.Mask(12, 33, True)
+ max_speed = 175
+ maxhp = 120
+
+ def __init__(self, game, state, player_id):
+ Character.__init__(self, game, state, player_id)
+ self.hp = self.maxhp
+ self.weapon = weapon.Medigun(game, state, self.id).id
+
class Engineer(Character):
# FIXME: width, height of engineer - rectangle collision
collision_mask = mask.Mask(12, 33, True)
@@ -249,3 +280,16 @@ def __init__(self, game, state, player_id):
self.hp = self.maxhp
self.weapon = weapon.Revolver(game, state, self.id).id
self.cloaking = False
+
+class Sniper(Character):
+ # FIXME: width, height of heavy - rectangle collision
+ # TODO: this class
+ collision_mask = mask.Mask(12, 33, True)
+ max_speed = 144
+ maxhp = 200
+
+ def __init__(self, game, state, player_id):
+ Character.__init__(self, game, state, player_id)
+
+ self.hp = self.maxhp
+ self.weapon = weapon.Minigun(game, state, self.id).id
View
65 engine/projectile.py
@@ -74,6 +74,71 @@ def interpolate(self, prev_obj, next_obj, alpha):
self.flight_time = prev_obj.flight_time + (next_obj.flight_time - prev_obj.flight_time) * alpha
+
+class Needle(entity.MovingObject):
+ shot_hitmasks = {}
+
+ fade_time = 0.8 # seconds of fading when max_flight_time is being reached
+ max_flight_time = 3
+
+ def __init__(self, game, state, sourceweapon, damage, direction, speed):
+ super(Needle, self).__init__(game, state)
+
+ self.direction = 0.0
+ self.flight_time = 0.0
+ self.sourceweapon = sourceweapon
+ self.damage = damage
+
+ srcwep = state.entities[sourceweapon]
+ srcchar = state.entities[srcwep.owner]
+
+ self.x = srcchar.x
+ self.y = srcchar.y+8
+
+ self.direction = direction
+
+ self.hspeed = math.cos(math.radians(self.direction)) * speed
+ self.vspeed = math.sin(math.radians(self.direction)) * -speed
+
+ def step(self, game, state, frametime):
+ # gravitational force
+ self.vspeed += 4.5 * frametime
+
+ # calculate direction
+ self.direction = function.point_direction(self.x - self.hspeed, self.y - self.vspeed, self.x, self.y)
+
+ def endstep(self, game, state, frametime):
+ super(Needle, self).endstep(game, state, frametime)
+
+ self.flight_time += frametime
+
+ angle = int(self.direction) % 360
+ if angle in self.shot_hitmasks:
+ mask = self.shot_hitmasks[angle]
+ else:
+ mask = function.load_mask("projectiles/needles/0").rotate(angle)
+ self.shot_hitmasks[angle] = mask
+
+ if game.map.collision_mask.overlap(mask, (int(self.x), int(self.y))) or self.flight_time > self.max_flight_time:
+ # calculate unit speeds (speeds normalized into the range 0-1)
+ h_unit_speed = math.cos(math.radians(self.direction))
+ v_unit_speed = -math.sin(math.radians(self.direction))
+
+ x, y = self.x, self.y
+
+ # move back until we're not colliding anymore - this is the colliding point
+ while game.map.collision_mask.overlap(mask, (int(x), int(y))):
+ x -= h_unit_speed
+ y -= v_unit_speed
+
+ self.destroy(state)
+
+ def interpolate(self, prev_obj, next_obj, alpha):
+ super(Needle, self).interpolate(prev_obj, next_obj, alpha)
+ self.direction = function.interpolate_angle(prev_obj.direction, next_obj.direction, alpha)
+
+ self.flight_time = prev_obj.flight_time + (next_obj.flight_time - prev_obj.flight_time) * alpha
+
class Rocket(entity.MovingObject):
rocket_hitmasks = {}
View
12 engine/sentry.py
@@ -8,9 +8,8 @@
class Building_Sentry(entity.MovingObject):
max_hp = 100 # Maximum hitpoints the sentry can ever have
starting_hp = 25 # At what hitpoints the sentry will start building
- build_time = 2 # Number of secs it takes to build
collision_mask = mask.Mask(26, 19, True) # TODO: Implement changing masks
-
+ build_time = 2 # Number of secs it takes to build
hp_increment = (max_hp-starting_hp)/build_time
animation_increment = 10/build_time # 10 == number of frames in sentry build animation
@@ -41,6 +40,7 @@ def step(self, game, state, frametime):
self.vspeed = min(800, self.vspeed)
if not self.isfalling:
+ print(self.animation_frame)
self.hspeed = 0
self.vspeed = 0
@@ -53,21 +53,24 @@ def step(self, game, state, frametime):
if self.hp >= self.max_hp:
self.hp = self.max_hp
# Create a finished sentry, and destroy the building sentry object
- self.owner.sentry = Sentry(game, state, self.owner_id, self.x, self.y, self.hp)
+ owner = state.players[self.owner_id]
+ owner.sentry = Sentry(game, state, self.owner_id, self.x, self.y, self.hp)
self.destroy(state)
else:
# Continue building
self.hp += self.hp_increment * frametime
- self.building_time += self.build_time * frametime
+ self.building_time += frametime
self.animation_frame += self.animation_increment * frametime
def interpolate(self, prev_obj, next_obj, alpha):
super(Building_Sentry, self).interpolate(prev_obj, next_obj, alpha)
self.animation_frame = prev_obj.animation_frame + (next_obj.animation_frame - prev_obj.animation_frame) * alpha
self.hp = prev_obj.hp + (next_obj.hp - prev_obj.hp) * alpha
+ self.build_time = prev_obj.build_time + (next_obj.build_time - prev_obj.build_time) * alpha
def destroy(self, state):
# TODO: Sentry destruction syncing, bubble
+ super(Building_Sentry, self).destroy(state)
owner = state.players[self.owner_id]
owner.sentry = None
@@ -93,5 +96,6 @@ def interpolate(self, prev_obj, next_obj, alpha):
def destroy(self, state):
# TODO: Sentry destruction syncing, bubble
+ super(Sentry, self).destroy(state)
owner = state.players[self.owner_id]
owner.sentry = None
View
22 engine/weapon.py
@@ -138,6 +138,28 @@ def fire_primary(self, game, state):
self.refirealarm = self.refiretime
sentry.Building_Sentry(game, state, state.players[owner.player_id])
+
+class Medigun(Weapon):
+ maxammo = 40
+ refiretime = 0.05
+ reloadtime = 1
+ shotdamage = 4
+
+ def fire_primary(self, game, state):
+ owner = state.entities[self.owner]
+ random.seed(str(owner.get_player(game, state).id) + ";" + str(state.time))
+
+ direction = owner.get_player(game, state).aimdirection + (5 - random.randint(0, 11))
+
+ # add user speed to needle speed but don't change direction of the bullet
+ playerdir = math.degrees(math.atan2(-owner.vspeed, owner.hspeed))
+ diffdir = direction - playerdir
+ playerspeed = math.hypot(owner.hspeed, owner.vspeed)
+ speed = 330 + random.randint(0, 4)*30 + math.cos(math.radians(diffdir)) * playerspeed
+
+ projectile.Needle(game, state, self.id, self.shotdamage, direction, speed)
+
+ self.refirealarm = self.refiretime
class Revolver(Weapon):
maxammo = 6
View
4 function.py
@@ -71,6 +71,8 @@ def convert_class(class_object):
return constants.CLASS_SOLDIER
elif class_object == engine.character.Heavy:
return constants.CLASS_HEAVY
+ elif class_object == engine.character.Medic:
+ return constants.CLASS_MEDIC
elif class_object == engine.character.Engineer:
return constants.CLASS_ENGINEER
elif class_object == engine.character.Spy:
@@ -85,6 +87,8 @@ def convert_class(class_object):
return engine.character.Soldier
elif class_object == constants.CLASS_HEAVY:
return engine.character.Heavy
+ elif class_object == constants.CLASS_MEDIC:
+ return engine.character.Medic
elif class_object == constants.CLASS_ENGINEER:
return engine.character.Engineer
elif class_object == constants.CLASS_SPY:

0 comments on commit de6c112

Please sign in to comment.
Something went wrong with that request. Please try again.