Commits

Don Spaulding  committed 05a33ab

Initial import

  • Participants

Comments (0)

Files changed (8)

+syntax:glob
+*.pyc
+Game Assets/*
+*DS_Store

File data/hero.png

Added
New image

File data/zombie.png

Added
New image

File lib/__init__.py

Empty file added.

File lib/actor.py

+import pyglet
+
+class Actor(object):
+	def __init__(self, x,y):
+		self.x = x
+		self.y = y
+		self.health = 100
+		self.image = pyglet.image.load("data/zombie.png")
+		self.remove = False
+	def draw(self):
+		self.image.blit(self.x,self.y)
+
+	#dt = time inbetween each frame, others=all the other actors, level = level object, to interact with collision
+	def update(self, dt, others,level):
+		if self.health < 0:
+			self.onDie()
+
+		self.x += 100 * dt
+		if self.x > 800:
+			self.x = 0
+
+		#if this game object needs to be deleted
+		return self.remove
+
+	def getHit(self,actor,damage):
+		#other objects use this to inflict damage on this actor
+		self.health -= damage
+
+	#override this for each type of actor
+	def onDie(self):
+		pass

File lib/level.py

+import pyglet
+
+class Tile(object):
+	def __init__(self, x,y, tile_type):
+		self.x = x
+		self.y = y
+		self.type = tile_type
+
+
+class Map(object):
+	def __init__(self, file):
+
+		self.num_rows = 30
+		self.num_columns = 40
+
+		self.tile_w = 20
+		self.tile_h = 20
+
+		self.tiles = []
+		self.tile_images = []
+
+		#blanck map
+		for x in range(self.num_columns):
+			for y in range(self.num_rows):
+				tiles.append(Tile(x*self.tile_w,y*self.tile_h,0))
+
+	def draw(self):
+		for i in self.tiles:
+			self.tile_images[i.type].blit(i.x,i.y)
+import pyglet
+from . import level
+from . import actor
+
+class GameWindow(pyglet.window.Window):
+	def __init__(self):
+		super(GameWindow, self).__init__()
+		#make the update function run every sixtyth of a second
+		pyglet.clock.schedule_interval(self.update, 1.0/60.0)
+
+		self.actors = []
+		self.actors.append(actor.Actor(0,300))
+		self.level = None
+
+	def on_draw(self):
+		self.clear()
+		for i in self.actors:
+			i.draw()
+
+	def update(self,dt):
+		#run all the actors update functions
+		for i in self.actors:
+			i.update(dt,self.actors, self.level)
+
+
+
+def Run():
+	window = GameWindow()
+	pyglet.app.run()
+from lib import main
+
+main.Run()