Skip to content

Commit

Permalink
Goblin made, not working all the way yet
Browse files Browse the repository at this point in the history
  • Loading branch information
sgoodspeed committed Apr 29, 2012
1 parent 56198b5 commit f89cd32
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 16 deletions.
78 changes: 77 additions & 1 deletion core/enemies.py
Expand Up @@ -8,6 +8,7 @@
import math
from anim import Animation, AnimationFrames
from core.spritesheet import SpriteSheet
from world.projectiles import Sponge,MelRect

class Enemy(Sprite):
vY = 0
Expand All @@ -22,6 +23,7 @@ def __init__(self, startPos):
self.onGround = False
self.timer = 0
self.dying = False
self.directed = False

def touches(self, group):
touching = Group()
Expand Down Expand Up @@ -60,10 +62,12 @@ def update(self, dT, level, player):
if self.rect.left <= rect.right and prev_rect.left >= rect.right:
self.rect.left = rect.right+1
self.direction *=-1
self.directed = True

if self.rect.right >= rect.left and prev_rect.right <= rect.left:
self.rect.right = rect.left-1
self.direction *=-1
self.directed = True

# handle cielings
#if rect.left < self.rect.right and self.rect.left < rect.right:
Expand Down Expand Up @@ -97,7 +101,7 @@ def getDistance(self,playerPos):
def die(self, level, dT=0):
if not self.dying:
self.dying = True
level.ammo.add(AmmoPickup(self.rect.x, self.rect.y, self.direction, 300))
level.ammo.add(Sponge(self.rect.x, self.rect.y, self.direction, 300))
self.timer += dT
if self.timer > 1500:
self.kill()
Expand Down Expand Up @@ -212,3 +216,75 @@ def jumpAttackCheck(self):
else:
return False


class Goblin(Enemy):
damage = GOB_DAMAGE
health = GOB_HEALTH
size = GOB_SIZE
speed = GOB_SPEED
boundSize = GOB_BOUNDS
weight = GOB_WEIGHT
attackDist = GOB_ATTACK_DIST
meleeGroup = Group()

def __init__(self, startPos):
Enemy.__init__(self, startPos)
self.melee = False
self.leftBound = self.rect.left - self.boundSize
self.rightBound = self.rect.right + self.boundSize
self.timer = 0
self.state = "roaming"
self.attacking = False
self.pick = 0


def update(self, dT, level, player):
self.timer += dT

if self.melee:
self.attackTimer +=dT
if self.attackTimer >= 700:
self.melee = False
if self.timer >3000:
self.pick = randrange(0,3)
self.directed = False
self.timer = 0
if self.pick == 0:
self.pause()
self.timer
elif self.pick == 1:
self.moveRight()
elif self.pick == 2:
self.moveLeft()
Enemy.update(self,dT,level,player)
self.facing = self.direction


if abs(self.distance)<400:
self.direction = self.distance / abs(self.distance)
self.directed = True
if abs(self.distance)<100:
self.melAttack()



def moveLeft(self):
if not self.directed:
self.direction = -1


def moveRight(self):
if not self.directed:
self.direction = 1

def pause(self):
if not self.directed:
self.direction = 0

def melAttack(self):
if not self.melee:
self.melee = True
if self.melee:
self.attack = MelRect(self)
self.meleeGroup.add(self.attack)
self.attackTimer = 0
17 changes: 16 additions & 1 deletion core/settings.py
Expand Up @@ -39,6 +39,15 @@
SPONGE_DAMAGE = 10
ENEMY_THROWBACK = 200


### ATTACKS
BULLET_SIZE = PLY_W*2, PLY_H
BULLET_SPEED = 400
BULLET_DAMAGE = 10

MELEE_DAMAGE = 15
MELEE_SIZE = (100,10)

##RAT VARIABLES
RAT_SIZE = (T_W*1.5, T_H*1.5)
RAT_SPEED = 150
Expand All @@ -56,7 +65,13 @@
FRANK_WEIGHT = .5



GOB_SIZE = (T_W*.8, T_H*1.8)
GOB_SPEED = 80
GOB_DAMAGE = 40
GOB_HEALTH = 50
GOB_BOUNDS = 250
GOB_WEIGHT = 1
GOB_ATTACK_DIST = MELEE_SIZE[0]+(GOB_SIZE[0]/2)

### ATTACKS
BULLET_SIZE = PLY_W*2, PLY_H
Expand Down
2 changes: 1 addition & 1 deletion data/levels/0.lvl
Expand Up @@ -18,4 +18,4 @@
~~~~~~~~~~~o2~~~~~~~~o1~~~~~~~~~.
,,,,,,,,,,,....................
EOL
Rat 500 500
Goblin 600 500
10 changes: 1 addition & 9 deletions world/pickUp.py
Expand Up @@ -17,6 +17,7 @@ def touches(self, group):
return touching

def update(self, dT, level):

self.vY -= dT * GRAVITY_SPEED
dX = self.vX * dT
dY = -self.vY * dT
Expand Down Expand Up @@ -55,12 +56,3 @@ def update(self, dT, level):
self.rect.bottom = rect.top
self.vX = 0

class AmmoPickup(Pickup):
def __init__(self, x, y, direction, vY):
Pickup.__init__(self)
self.direction = direction
self.vX = self.direction * PICKUP_THROW_SPEED
self.rect = Rect((x,y), AMMO_SIZE)
self.image = Surface(self.rect.size)
draw.rect(self.image, (255,0,0), self.image.get_rect())
self.vY = vY
11 changes: 8 additions & 3 deletions world/player.py
Expand Up @@ -20,8 +20,8 @@ def __init__(self, player, image, duration):
self.y = self._rows["still"]

spritesheet = SpriteSheet(image, (2, 9), colorkey=(255,255,255))
frames = [ (duration, 0),
(duration, 1)]
frames = [ (duration, 0)]
#(duration, 1)]

Animation.__init__(self, spritesheet, frames)

Expand Down Expand Up @@ -170,7 +170,12 @@ def update(self, dT, level):

def shoot(self):
if self.ammo > 0:
bullet = Sponge(self.rect.x, self.rect.y, self.facing, SPONGE_THROW_SPEED)
if self.facing == 1:
bullet = Sponge(self.rect.right,self.rect.top, self.facing, SPONGE_THROW_SPEED)
elif self.facing == -1:
bullet = Sponge(self.rect.left,self.rect.top, self.facing, SPONGE_THROW_SPEED)
else:
bullet = Sponge(self.rect.x,self.rect.y,self.facing, SPONGE_THROW_SPEED)
self.bullets.add(bullet)
self.ammo -= 1

Expand Down
4 changes: 3 additions & 1 deletion world/projectiles.py
Expand Up @@ -3,7 +3,7 @@
from pygame.sprite import *
from pygame import draw, Surface
from core.settings import *
from pickUp import Pickup, AmmoPickup
from pickUp import Pickup


class Weapon(object):
Expand All @@ -20,8 +20,10 @@ class Sponge(Pickup, Weapon):
def __init__(self, x, y, direction, vY):
Pickup.__init__(self)
self.direction = direction

self.vX = self.direction * SPONGE_THROW_SPEED
self.rect = Rect((x,y), SPONGE_SIZE)

self.image = Surface(self.rect.size)
draw.rect(self.image, (255,0,0), self.image.get_rect())
self.vY = vY
Expand Down

0 comments on commit f89cd32

Please sign in to comment.