Merge lp:pyqtrpg/debug into lp:pyqtrpg/trunk

Proposed by Alistair Broomhead
Status: Merged
Approved by: Alistair Broomhead
Approved revision: 4
Merged at revision: 2
Proposed branch: lp:pyqtrpg/debug
Merge into: lp:pyqtrpg/trunk
Diff against target: 1000 lines (+734/-38)
20 files modified
Display.py (+4/-0)
GameObjects/_Character.py (+46/-0)
GameObjects/_Containable.py (+2/-1)
GameObjects/_GameObject.py (+44/-15)
GameObjects/_Level.py (+5/-0)
GameObjects/__init__.py (+5/-3)
GameObjects/_fifo.py (+47/-0)
GameObjects/commandList.py (+21/-0)
Levels/Level00.py (+27/-0)
Levels/World00.py (+3/-0)
Levels/__init__.py (+2/-0)
Levels/objects.py (+92/-0)
_Display/_DebugOutput.py (+32/-0)
_Display/_DisplayObject.py (+52/-0)
_Display/_DisplayWindow.py (+79/-0)
_Display/_Interface.py (+114/-0)
_Display/__init__.py (+4/-0)
_Display/_clickableIcon.py (+29/-0)
_Display/_interfaceButton.py (+51/-0)
pyrpg.py (+75/-19)
To merge this branch: bzr merge lp:pyqtrpg/debug
Reviewer Review Type Date Requested Status
Alistair Broomhead Approve
Review via email: mp+46349@code.launchpad.net

Description of the change

merging features and fixes from debug to trunk

To post a comment you must log in.
Revision history for this message
Alistair Broomhead (alistair-broomhead) wrote :

now runs fine on windows

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'Display.py'
2--- Display.py 1970-01-01 00:00:00 +0000
3+++ Display.py 2011-01-14 22:02:00 +0000
4@@ -0,0 +1,4 @@
5+from _Display import (DisplayObject,
6+ DisplayWindow,
7+ Interface,
8+ DebugOutput)
9\ No newline at end of file
10
11=== added file 'GameObjects/_Character.py'
12--- GameObjects/_Character.py 1970-01-01 00:00:00 +0000
13+++ GameObjects/_Character.py 2011-01-14 22:02:00 +0000
14@@ -0,0 +1,46 @@
15+from PyQt4.Qt import pyqtSignal
16+from _Containable import Containable
17+class Character(Containable):
18+ broadcast = pyqtSignal(str)
19+ def tick(self):
20+ def getcmd(c):
21+ x = c.getfirst()
22+ return x[0], x[1:]
23+ c = self.commands
24+ if c.len:
25+ obj,cmd = getcmd(c)
26+ while obj != self:
27+ obj.commands.add(c.pop())
28+ obj,cmd = getcmd(c)
29+ x,y = self.position
30+ self.broadcast.emit("%s@%s:\t%s"%(self.name, self.position,`cmd`))
31+ if cmd[0] == 'up':
32+ self.position = (x,y-1)
33+ c.pop()
34+ elif cmd[0] == 'down':
35+ self.position = (x,y+1)
36+ c.pop()
37+ elif cmd[0] == 'left':
38+ self.position = (x-1,y)
39+ c.pop()
40+ elif cmd[0] == 'right':
41+ self.position = (x+1,y)
42+ c.pop()
43+ elif cmd[0] in ['move', 'attack']:
44+ X,Y = cmd[1]
45+ if X-x > 0:
46+ self.position = (x+1,y)
47+ elif X-x < 0:
48+ self.position = (x-1,y)
49+ elif Y-y > 0:
50+ self.position = (x,y+1)
51+ elif Y-y < 0:
52+ self.position = (x,y-1)
53+ if (X-x)**2 + (Y-y)**2 == 1:
54+ c.pop()
55+ self._allObjects[0].Changed.emit()
56+
57+ def __init__(self, **kwargs):
58+ if not 'name' in kwargs:
59+ kwargs['name'] = 'Unknown Character'
60+ Containable.__init__(self, **kwargs)
61\ No newline at end of file
62
63=== modified file 'GameObjects/_Containable.py'
64--- GameObjects/_Containable.py 2010-11-22 06:47:41 +0000
65+++ GameObjects/_Containable.py 2011-01-14 22:02:00 +0000
66@@ -9,5 +9,6 @@
67 assert isinstance(info[1], info[0])
68 self.container = container
69 container.addContent(self)
70- except Exception, e:
71+ container.contents.sort()
72+ except Exception, e:
73 e.args = self._custAssert(info, e.args),
74\ No newline at end of file
75
76=== modified file 'GameObjects/_GameObject.py'
77--- GameObjects/_GameObject.py 2010-11-22 06:47:41 +0000
78+++ GameObjects/_GameObject.py 2011-01-14 22:02:00 +0000
79@@ -1,4 +1,9 @@
80-class GameObject(object):
81+from commandList import commandQueue
82+from PyQt4.QtCore import QObject, pyqtSignal
83+class _contentList(list):
84+ def sort(self):
85+ list.sort(self,key=lambda tile:tile.flag)
86+class GameObject(QObject):
87 """
88 This is the class which all objects in the game must subclass. This
89 enables us to keep a list of all game objects.
90@@ -7,6 +12,8 @@
91 detection - this should also be useful for debugging, and probably for
92 purposes I have not yet thought of.
93 """
94+ ItemAdded = pyqtSignal(str)
95+ Changed = pyqtSignal()
96 _allObjects = []
97 def __getitem__(self,i):
98 return self.contents[i]
99@@ -17,7 +24,7 @@
100 """Returns all GameObjects decended from the same type as self"""
101 return [x for x in self._allObjects
102 if isinstance(x, type(self))]
103-
104+
105 def _custAssert(self,(expected, got, input), e_args):
106 return ' '.join(("You tried to input a", `input`, ':',
107 `type(got)`, ',', `got`, 'into ',
108@@ -28,7 +35,7 @@
109 info = (GameObject, content, "Item to be added to "+self.name)
110 assert isinstance(info[1], info[0])
111 self.contents.append(content)
112- except Exception, e:
113+ except Exception, e:
114 e.args = self._custAssert(info, e.args),
115 raise
116 def __init__(self, position=(0,0),
117@@ -36,10 +43,23 @@
118 size=(-1,-1),
119 stats={},
120 contents=[],
121- name="Unknown Object"):
122+ name="Unknown Object",
123+ image='',
124+ flag=0):
125+ QObject.__init__(self)
126+
127+ self.commands = commandQueue()
128 try:
129+ # On some platforms there is no support for python beyond 2.5.4
130+ # ABC's were only implemented in python 2.6 so we'll fall back to
131+ # integers if we can't use Number - the base class for int and float etc
132 from numbers import Number
133- # Check position is a tuple
134+ except:
135+ Number = int
136+ try:
137+ self.flag = flag
138+
139+ # Check position is a tuple
140 info = (tuple, position, "position")
141 assert isinstance(info[1], info[0])
142 info = (Number, position[0], "position_x")
143@@ -47,8 +67,8 @@
144 info = (Number, position[1], "position_y")
145 assert isinstance(info[1], info[0])
146 self.position = position
147-
148- # Check size is a tuple
149+
150+ # Check heading is a tuple
151 info = (tuple, heading, "heading")
152 assert isinstance(info[1], info[0])
153 info = (Number, heading[0], "heading_speed")
154@@ -56,30 +76,39 @@
155 info = (Number, heading[1], "heading_XY_angle")
156 assert isinstance(info[1], info[0])
157 self.heading = heading
158-
159+
160 # Check size is a tuple
161 info = (tuple, size, "size")
162 assert isinstance(info[1], info[0])
163 self.size = size
164-
165- # Check size is a tuple
166+
167+ # Check name is a string
168 info = (str, name, "name")
169 assert isinstance(info[1], info[0])
170 self.name = name
171-
172+
173 # Check stats is a dictionary
174 info = (dict, stats, "stats")
175 assert isinstance(info[1], info[0])
176 self.stats = stats.copy()
177-
178+
179 # Check contents is a list
180 info = (list, contents, "contents")
181 assert isinstance(info[1], info[0])
182 for obj in contents:
183 info = (GameObject, obj, "object in contents")
184 assert isinstance(info[1], info[0])
185- self.contents = contents[:]
186+ def _sort():
187+ pass
188+ self.contents = _contentList(contents[:])
189+ #self.contents.sort = _sort
190 self._allObjects.append(self)
191- except Exception, e:
192+ self._allObjects[0].ItemAdded.emit(self.name)
193+
194+ # Check image is a string
195+ info = (str, image, "image")
196+ assert isinstance(info[1], info[0])
197+ self.image = image
198+ except Exception, e:
199 e.args = self._custAssert(info, e.args),
200- raise
201\ No newline at end of file
202+ raise
203
204=== added file 'GameObjects/_Level.py'
205--- GameObjects/_Level.py 1970-01-01 00:00:00 +0000
206+++ GameObjects/_Level.py 2011-01-14 22:02:00 +0000
207@@ -0,0 +1,5 @@
208+from _World import World
209+class Level(World):
210+ def __init__(self, container, **kwargs):
211+ kwargs.setdefault('name', 'Unknown Level')
212+ parent = World.__init__(self, container, **kwargs)
213\ No newline at end of file
214
215=== modified file 'GameObjects/__init__.py'
216--- GameObjects/__init__.py 2010-11-22 06:47:41 +0000
217+++ GameObjects/__init__.py 2011-01-14 22:02:00 +0000
218@@ -1,10 +1,12 @@
219 from _GameObject import GameObject
220 from _Containable import Containable
221 from _World import World
222+from _Level import Level
223 from _Weapon import Weapon
224+
225+# Further object types being defined
226+from _Character import Character as Character
227 # Further object types to be implemented
228 #from _Potion import Potion
229-#from _Resource import Resource
230-#from _Character import Character
231-#from _NCP import NCP
232+#from _Resource import Resource
233#from _NCP import NCP
234 #from _Quests import Quests
235
236=== added file 'GameObjects/_fifo.py'
237--- GameObjects/_fifo.py 1970-01-01 00:00:00 +0000
238+++ GameObjects/_fifo.py 2011-01-14 22:02:00 +0000
239@@ -0,0 +1,47 @@
240+class _first(object):
241+ def __get__(self):
242+ new_ = (x for x in self._parent._list[0])
243+ return self._parent._list[0]
244+ def __set__(self, new_):
245+ #new_ = (x for x in new_)
246+ self._parent._parent.takenFrom.emit(self._parent._list[0])
247+ self._parent._parent.addedTo.emit(new_)
248+ self._parent._list[0] = (new_)
249+ def __del__(self):
250+ self._parent._parent.takenFrom.emit(self._parent._list.pop(0))
251+ if not self._parent._list:
252+ self._parent._parent.isEmpty.emit()
253+ def __init__(self,parent):
254+ self._parent = parent
255+
256+class _fifo(object):
257+ def __get__(self):
258+ new_ = [x for x in self._list]
259+ return new_
260+ def __set__(self, new_):
261+ #new_ = (x for x in new_)
262+ if not self._list:
263+ self._parent.isNotEmpty.emit()
264+ self._list.extend(new_)
265+ for item in new_:
266+ self._parent.addedTo.emit(item)
267+ def __getitem__(self, k):
268+ new_ = (x for x in self._list[k])
269+ return self._list[k]
270+ def getfirst(self):
271+ new_ = (x for x in self._list[0])
272+ return self._list[0]
273+ def pop(self):
274+ item = self.getfirst()
275+ self.first.__del__()
276+ return item
277+ def append(self, item):
278+ self.__set__([item,])
279+ def __init__(self, parent, other=None):
280+ self._list = []
281+ self._parent = parent
282+ self.first = _first(self)
283+ if other:
284+ for X in other:
285+ #X = (x for x in X)
286+ self._list.append(X)
287\ No newline at end of file
288
289=== added file 'GameObjects/commandList.py'
290--- GameObjects/commandList.py 1970-01-01 00:00:00 +0000
291+++ GameObjects/commandList.py 2011-01-14 22:02:00 +0000
292@@ -0,0 +1,21 @@
293+from PyQt4.Qt import (QObject,
294+ pyqtSignal,
295+ QString)
296+from _fifo import _fifo
297+class commandQueue(QObject):
298+ addedTo = pyqtSignal(tuple)
299+ takenFrom = pyqtSignal(tuple)
300+ isNotEmpty = pyqtSignal()
301+ isEmpty = pyqtSignal()
302+ def add(self, *item):
303+ self._fifo.append(tuple(item))
304+ def __init__(self):
305+ QObject.__init__(self)
306+ self._fifo = _fifo(self)
307+ self.first = self._fifo.first
308+ self.getfirst = self._fifo.getfirst
309+ self.pop = self._fifo.pop
310+ self.isEmpty.emit()
311+ @property
312+ def len(self):
313+ return len(self._fifo._list)
314\ No newline at end of file
315
316=== added directory 'Levels'
317=== added file 'Levels/Level00.py'
318--- Levels/Level00.py 1970-01-01 00:00:00 +0000
319+++ Levels/Level00.py 2011-01-14 22:02:00 +0000
320@@ -0,0 +1,27 @@
321+# Levels are defined as tuple grids - each square of the tuple grid
322+# is a square of a game map.
323+from objects import *
324+level = (
325+( Wall, Wall, Wall, Wall, Wall, Wall, Wall, Wall, Wall, Wall, Wall, Wall),
326+
327+( Wall, Floor, Floor, Floor, Wall, Out, Out, Wall, Floor, Floor, Floor, Wall),
328+
329+( Wall, Floor, (Floor,
330+ Player),Floor, Wall, Out, Out, Wall, Floor, Floor, Floor, Wall),
331+
332+( Wall, Floor, Floor, Floor, Wall, Wall, Wall, Floor, Floor, Floor, Floor, Wall),
333+
334+( Wall, Floor, (Floor,
335+ Sword), Floor, Floor, Floor, Floor, Floor, Wall, Wall, Floor, (Floor,
336+ Door)),
337+
338+( Wall, Floor, Floor, Floor, Floor, Floor, Floor, Wall, Out, Wall, Floor, Wall),
339+
340+( Wall, Floor, Floor, Floor, Floor, Floor, Floor, Wall, Out, Wall, Floor, Wall),
341+
342+( Wall, Floor, Floor, Floor, Floor, Floor, Floor, Wall, Out, Wall, Floor, Wall),
343+
344+( Wall, Floor, Floor, Floor, Floor, Floor, Floor, Wall, Out, Wall, Floor, Wall),
345+
346+( Wall, Wall, Wall, Wall, Wall, Wall, Wall, Wall, Wall, Wall, Wall, Wall),
347+)
348\ No newline at end of file
349
350=== added file 'Levels/Level01.py'
351=== added file 'Levels/World00.py'
352--- Levels/World00.py 1970-01-01 00:00:00 +0000
353+++ Levels/World00.py 2011-01-14 22:02:00 +0000
354@@ -0,0 +1,3 @@
355+world = []
356+import Level00; world.append(Level00.level)
357+#import Level01; world.append(Level01.level)
358\ No newline at end of file
359
360=== added file 'Levels/__init__.py'
361--- Levels/__init__.py 1970-01-01 00:00:00 +0000
362+++ Levels/__init__.py 2011-01-14 22:02:00 +0000
363@@ -0,0 +1,2 @@
364+worlds = []
365+import World00; worlds.append(World00.world)
366\ No newline at end of file
367
368=== added file 'Levels/objects.py'
369--- Levels/objects.py 1970-01-01 00:00:00 +0000
370+++ Levels/objects.py 2011-01-14 22:02:00 +0000
371@@ -0,0 +1,92 @@
372+# This gives a set of objects that can be used to build levels
373+
374+class _statsobject(object):
375+ def __get__(self):
376+ return self.__dict__.__get__()
377+ def __str__(self):
378+ return self.__dict__.__str__()
379+ def __repr__(self):
380+ return self.__dict__.__repr__()
381+ def copy(self):
382+ return self.__init__(self)
383+ def __getattr__(self,k):
384+ return None
385+ def __init__(self,old=None):
386+ if old:
387+ self.__dict__ = old.__dict__.copy()
388+ else: self.__dict__ = {}
389+class _flagobject(object):
390+ def __call__(self, flag):
391+ if type(flag) == type(int) and flag&self._value:
392+ return True
393+ if type(flag) == type(self) and flag._value&self._value:
394+ return True
395+ return False
396+ def __get__(self):
397+ return self._value.__get__()
398+ def __str__(self):
399+ return hex(self._value)
400+ def __repr__(self):
401+ return repr(hex(self._value))
402+ def __init__(self,flag):
403+ if flag == 0:
404+ self._value = 0
405+ else:
406+ self._value = 2**(flag-1)
407+class _objectMarker(object):
408+ @property
409+ def stats(self):
410+ return self._stats
411+ @property
412+ def flag(self):
413+ return self._flag
414+ @property
415+ def image(self):
416+ return self._image
417+ def __get__(self):
418+ return self._flag.__get__()
419+ def __str__(self):
420+ return self._flag.__str__()
421+ def __repr__(self):
422+ return self._flag.__repr__()
423+ def __nonzero__(self):
424+ return self._flag.__nonzero__()
425+ def __cmp__(self, other):
426+ return self._flag.__cmp__(other)
427+ def __init__(self,flag,image='',**kwargs):
428+ self.__dict__['_flag'] = _flagobject(flag)
429+ self.__dict__['_stats'] = _statsobject()
430+ self.__dict__['_stats'].__dict__ = kwargs
431+ self.__dict__['_image'] = image
432+ def __setattr__(self,k,v):
433+ try:
434+ assert k in self.__dict__
435+ self.__dict__[k] = v
436+ except AssertionError:
437+ raise AttributeError, "'%s' is not an attribute of class '%s'"%(k,self.__class__.__name__)
438+
439+
440+Out = _objectMarker(0)
441+
442+Floor = _objectMarker(1, 'GenericCarpet')
443+Wall = _objectMarker(2, 'GenericWall')
444+Door = _objectMarker(3)
445+
446+Player = _objectMarker(4, 'GenericCharacter')
447+#Friend = _objectMarker(5)
448+#Neutral = _objectMarker(6)
449+#Enemy = _objectMarker(7)
450+
451+#Book = _objectMarker(8)
452+#Scroll = _objectMarker(9)
453+#HPotion = _objectMarker(10)
454+#MPotion = _objectMarker(11)
455+
456+#Box = _objectMarker(12)
457+#Resource = _objectMarker(13)
458+
459+#Dagger = _objectMarker(14)
460+#Bow = _objectMarker(15)
461+#Axe = _objectMarker(16)
462+Shield = _objectMarker(17)
463+Sword = _objectMarker(18, 'GenericWeapon')
464
465=== added directory '_Display'
466=== added directory '_Display/Buttons'
467=== added file '_Display/Buttons/attack.png'
468Binary files _Display/Buttons/attack.png 1970-01-01 00:00:00 +0000 and _Display/Buttons/attack.png 2011-01-14 22:02:00 +0000 differ
469=== added file '_Display/Buttons/close.png'
470Binary files _Display/Buttons/close.png 1970-01-01 00:00:00 +0000 and _Display/Buttons/close.png 2011-01-14 22:02:00 +0000 differ
471=== added file '_Display/Buttons/down.png'
472Binary files _Display/Buttons/down.png 1970-01-01 00:00:00 +0000 and _Display/Buttons/down.png 2011-01-14 22:02:00 +0000 differ
473=== added file '_Display/Buttons/fullscr.png'
474Binary files _Display/Buttons/fullscr.png 1970-01-01 00:00:00 +0000 and _Display/Buttons/fullscr.png 2011-01-14 22:02:00 +0000 differ
475=== added file '_Display/Buttons/left.png'
476Binary files _Display/Buttons/left.png 1970-01-01 00:00:00 +0000 and _Display/Buttons/left.png 2011-01-14 22:02:00 +0000 differ
477=== added file '_Display/Buttons/move.png'
478Binary files _Display/Buttons/move.png 1970-01-01 00:00:00 +0000 and _Display/Buttons/move.png 2011-01-14 22:02:00 +0000 differ
479=== added file '_Display/Buttons/right.png'
480Binary files _Display/Buttons/right.png 1970-01-01 00:00:00 +0000 and _Display/Buttons/right.png 2011-01-14 22:02:00 +0000 differ
481=== added file '_Display/Buttons/up.png'
482Binary files _Display/Buttons/up.png 1970-01-01 00:00:00 +0000 and _Display/Buttons/up.png 2011-01-14 22:02:00 +0000 differ
483=== added directory '_Display/Sprites'
484=== added file '_Display/Sprites/Generic.png'
485Binary files _Display/Sprites/Generic.png 1970-01-01 00:00:00 +0000 and _Display/Sprites/Generic.png 2011-01-14 22:02:00 +0000 differ
486=== added file '_Display/Sprites/GenericCarpet.png'
487Binary files _Display/Sprites/GenericCarpet.png 1970-01-01 00:00:00 +0000 and _Display/Sprites/GenericCarpet.png 2011-01-14 22:02:00 +0000 differ
488=== added file '_Display/Sprites/GenericCharacter.png'
489Binary files _Display/Sprites/GenericCharacter.png 1970-01-01 00:00:00 +0000 and _Display/Sprites/GenericCharacter.png 2011-01-14 22:02:00 +0000 differ
490=== added file '_Display/Sprites/GenericPotion.png'
491Binary files _Display/Sprites/GenericPotion.png 1970-01-01 00:00:00 +0000 and _Display/Sprites/GenericPotion.png 2011-01-14 22:02:00 +0000 differ
492=== added file '_Display/Sprites/GenericWall.png'
493Binary files _Display/Sprites/GenericWall.png 1970-01-01 00:00:00 +0000 and _Display/Sprites/GenericWall.png 2011-01-14 22:02:00 +0000 differ
494=== added file '_Display/Sprites/GenericWeapon.png'
495Binary files _Display/Sprites/GenericWeapon.png 1970-01-01 00:00:00 +0000 and _Display/Sprites/GenericWeapon.png 2011-01-14 22:02:00 +0000 differ
496=== added file '_Display/Sprites/Thumbs.db'
497Binary files _Display/Sprites/Thumbs.db 1970-01-01 00:00:00 +0000 and _Display/Sprites/Thumbs.db 2011-01-14 22:02:00 +0000 differ
498=== added file '_Display/_DebugOutput.py'
499--- _Display/_DebugOutput.py 1970-01-01 00:00:00 +0000
500+++ _Display/_DebugOutput.py 2011-01-14 22:02:00 +0000
501@@ -0,0 +1,32 @@
502+from PyQt4.Qt import QTextEdit, QString
503+class DebugOutput(QTextEdit):
504+ def __init__(self, player, parent, *args, **kwargs):
505+ QTextEdit.__init__(self, *args, **kwargs)
506+ QTextEdit.setFontPointSize(self, 10)
507+ self.setFixedWidth(320)
508+ self.setReadOnly(True)
509+ x = self.property("kineticScroller").toPyObject()
510+ if x:
511+ x.setEnabled(True)
512+ del x
513+ self.text = ''
514+ self.parent = parent
515+ self.player = player
516+ player.commands.addedTo.connect(self._append)
517+ player.broadcast.connect(self._append)
518+ def _append(self,line):
519+ self.append(str(line))
520+ #anchor = QString(line)
521+ #self.text += '\n'+line
522+ #QTextEdit.setText(self,self.text)
523+ #self.scrollContentsBy(0,-self.rect().height())
524+
525+ def resizeEvent(self, event):
526+ rect = self.rect()
527+ # self.append( 'Debug output:\t' +
528+ # `rect.width()` +
529+ # "x" +
530+ # `rect.height()`)
531+ QTextEdit.resizeEvent(self, event)
532+ def paintEvent(self, event):
533+ QTextEdit.paintEvent(self, event)
534
535=== added file '_Display/_DisplayObject.py'
536--- _Display/_DisplayObject.py 1970-01-01 00:00:00 +0000
537+++ _Display/_DisplayObject.py 2011-01-14 22:02:00 +0000
538@@ -0,0 +1,52 @@
539+from PyQt4.Qt import QMainWindow, QTimer
540+class DisplayObject(QMainWindow):
541+ def doTicks(s):
542+ for char in s.Game.Player.getAllSameClass():
543+ char.tick()
544+ def exec_(s):
545+ s._a.exec_()
546+ def __init__(s, Game):
547+ from _DebugOutput import DebugOutput
548+ from _DisplayWindow import DisplayWindow
549+ from _Interface import Interface
550+ from PyQt4.Qt import QApplication, QWidget, QGridLayout, QIcon
551+ from sys import argv
552+ import os.path
553+ win = (800, 480)
554+ s.Game = Game
555+ a = QApplication(argv) # We'll need a QApplication.
556+ QMainWindow.__init__(s) # And it'll be a subclass of QMainWindow,
557+ s.resize(*win) # so initialise it and give it a size.
558+ central = QWidget()
559+ s.setCentralWidget(central) # Central widget to contain layout,
560+ s.grid = QGridLayout(central) # like so...
561+ s.setWindowTitle("pyRPG") # Let's give it a nice title.
562+ s._a = a
563+ s.commands = Game.commands
564+ iconpath = ("Display/pyrpg.png")
565+ s.icon_ = QIcon()
566+ s.icon_.addFile(iconpath)
567+ s.setWindowIcon(s.icon_)
568+
569+ s.DebugOutput = DebugOutput(player=Game.Player,parent=s)
570+ s.MainGraphicView = DisplayWindow(player=Game.Player,textstream=s.DebugOutput)
571+ s.Options = Interface(player=Game.Player,parent=s,textstream=s.DebugOutput)
572+
573+ s.grid.addWidget(s.MainGraphicView, 0, 0)
574+ s.grid.addWidget(s.Options, 1, 0, 1, 0)
575+ s.grid.addWidget(s.DebugOutput, 0, 1)
576+
577+ s.grid.setMargin(0)
578+ s.grid.setSpacing(0)
579+ s.grid.setRowStretch (0, 400)
580+ s.grid.setRowStretch (1, 80)
581+ s.grid.setColumnStretch (0, 480)
582+ s.grid.setColumnStretch (1, 320)
583+
584+ s.Timer = QTimer()
585+ s.Timer.start(200)
586+ s.Timer.timeout.connect(s.doTicks)
587+ s.Game.Changed.connect(s.MainGraphicView.update)
588+
589+ s.showFullScreen() # There's no point doing all of this if we
590+ # don't show it(FullScreen?)
591
592=== added file '_Display/_DisplayWindow.py'
593--- _Display/_DisplayWindow.py 1970-01-01 00:00:00 +0000
594+++ _Display/_DisplayWindow.py 2011-01-14 22:02:00 +0000
595@@ -0,0 +1,79 @@
596+from PyQt4.Qt import (QWidget,
597+ QColor,
598+ QPainter,
599+ QBrush,
600+ pyqtSignal,
601+ QRect)
602+
603+from PyQt4.QtCore import Qt
604+
605+class DisplayWindow(QWidget):
606+ pressed = pyqtSignal(tuple)
607+ released = pyqtSignal(tuple)
608+ clicked = pyqtSignal(tuple)
609+ dragged = pyqtSignal(tuple)
610+ def giveTile(self,x,y):
611+ x += self.x_offset
612+ y += self.y_offset
613+ tsx,tsy = self.tilesize
614+ X = x/tsx - 1 + ((x % tsx) != 0)
615+ Y = y/tsy - 1 + ((y % tsy) != 0)
616+ return X,Y
617+ def mousePressEvent(self, event):
618+ if event.button() == Qt.LeftButton:
619+ pos = self.giveTile(event.x(),event.y())
620+ self.pressed.emit(pos)
621+ self._TouchStarted = pos
622+ def mouseReleaseEvent(self, event):
623+ if event.button() == Qt.LeftButton:
624+ x,y = self.giveTile(event.x(),event.y())
625+ self.released.emit((x,y))
626+ X,Y = self._TouchStarted
627+ if (x,y) == (X,Y):
628+ self.clicked.emit((x,y))
629+ else:
630+ self.dragged.emit((X-x,Y-y))
631+ self._TouchStarted = None
632+ def __init__(self, player, textstream, **kwargs):
633+ QWidget.__init__(self)
634+ self.qp = QPainter()
635+ self.textstream = textstream
636+ self._TouchStarted = None
637+ self.displayQueue = []
638+ self.x_offset = 0
639+ self.y_offset = 0
640+ self.tilesize = (40,40)
641+ self.player = player
642+ def resizeEvent(self, event):
643+ rect = self.rect()
644+ self.textstream.append( 'Display window:\t' + `rect.width()` + "x" + `rect.height()`)
645+ def _showtile(self, tile, event):
646+ from _clickableIcon import clickableIcon
647+ for subtile in tile.contents:
648+ self._showTile(subtile, event)
649+ if tile.image:
650+ image = clickableIcon(self, tile.image)
651+ x,y = tile.position
652+ X,Y = self.tilesize
653+ image.setRect(x*X, y*Y, X, Y)
654+ image.paintEvent(event)
655+ def paintEvent(self, event):
656+ self.qp = QPainter()
657+ c = (QColor("#121"),
658+ QColor("#101"))
659+ brush = QBrush(Qt.SolidPattern)
660+ rect = self.rect()
661+ self.qp.begin(self)
662+ self.qp.setBrush(brush)
663+ currlevel = self.player.container
664+ currworld = currlevel.container
665+ otherlevels = ( level
666+ for level
667+ in currworld.contents
668+ if type(level) == type(currlevel)
669+ and level != currlevel)
670+ for tile in currlevel.contents:
671+ self._showtile(tile, event)
672+ self.qp.end()
673+ QWidget.paintEvent(self, event)
674+ self.textstream.append("Drawing")
675\ No newline at end of file
676
677=== added file '_Display/_Interface.py'
678--- _Display/_Interface.py 1970-01-01 00:00:00 +0000
679+++ _Display/_Interface.py 2011-01-14 22:02:00 +0000
680@@ -0,0 +1,114 @@
681+from PyQt4.QtGui import (QGridLayout,
682+ QWidget,
683+ QColor,
684+ QPainter,
685+ QBrush)
686+
687+from PyQt4.QtCore import Qt
688+import os.path
689+class Interface(QWidget):
690+ def toggleFullscreen(self):
691+ p = self.parent
692+ if p.isFullScreen():
693+ p.setWindowState(Qt.WindowNoState)
694+ else:
695+ p.setWindowState(Qt.WindowFullScreen)
696+ def move_up(self):
697+ self.player.commands.add(self.player,'up')
698+ def move_down(self):
699+ self.player.commands.add(self.player,'down')
700+ def move_left(self):
701+ self.player.commands.add(self.player,'left')
702+ def move_right(self):
703+ self.player.commands.add(self.player,'right')
704+ def set_attack(self,bool_in):
705+ self.attackmode = bool_in
706+ def set_move(self,bool_in):
707+ self.movemode = bool_in
708+ def handleDisplayDragged(self, pos):
709+ self.textstream.append('screen dragged by: '+`pos`)
710+ def handleDisplayClicked(self, pos):
711+ if self.attackmode:
712+ self.player.commands.add(self.player,'attack',pos)
713+ self.B_ATTK.toggle()
714+ elif self.movemode:
715+ self.player.commands.add(self.player,'move',pos)
716+ self.B_MOVE.toggle()
717+ else:
718+ self.textstream.append('screen clicked at: '+`pos`)
719+
720+ def __init__(self, player, parent, textstream, **kwargs):
721+ QWidget.__init__(self)
722+
723+ def mkbutton(y,x,h=1,w=1,image=None,act=None,toggle=False):
724+ from _interfaceButton import interfaceButton
725+ if image:
726+ b = interfaceButton(self, "_Display/Buttons/"+image+".png")
727+ else:
728+ b = interfaceButton(self)
729+ self.OptionsGrid.addWidget(b,y,x,h,w)
730+ if act:
731+ if toggle:
732+ b.setCheckable(True)
733+ b.toggled.connect(act)
734+ else:
735+ b.clicked.connect(act)
736+ return b
737+
738+ self.qp = QPainter()
739+ self.OptionsGrid = QGridLayout(self)
740+ self.parent = parent
741+ self.player = player
742+ self.textstream = textstream
743+ self.height = 32
744+ self.margin = 4
745+ self.spacing = 8
746+ self.attackmode = False
747+ self.movemode = False
748+
749+ self.OptionsGrid.setMargin(self.margin)
750+ self.OptionsGrid.setSpacing(self.spacing)
751+
752+ self.parent.MainGraphicView.clicked.connect(self.handleDisplayClicked)
753+ self.parent.MainGraphicView.dragged.connect(self.handleDisplayDragged)
754+
755+ if True: #Spawn buttons
756+ self.B_ATTK = mkbutton(0,0,1,1,"Attack", self.set_attack,True)
757+ self.B_MVUP = mkbutton(0,1,1,1,"up", self.move_up)
758+ self.B_MOVE = mkbutton(0,2,1,1,"Move", self.set_move,True)
759+ self.B_0__3 = mkbutton(0,3)
760+ self.B_0__4 = mkbutton(0,4)
761+ self.B_0__5 = mkbutton(0,5)
762+ self.B_0__6 = mkbutton(0,6)
763+ self.B_0__7 = mkbutton(0,7)
764+ self.B_MVLT = mkbutton(1,0,1,1,"left", self.move_left)
765+ self.B_MVDN = mkbutton(1,1,1,1,"down", self.move_down)
766+ self.B_MVRT = mkbutton(1,2,1,1,"right", self.move_right)
767+ self.B_1__3 = mkbutton(1,3)
768+ self.B_1__4 = mkbutton(1,4)
769+ self.B_1__5 = mkbutton(1,5)
770+ self.B_1__6 = mkbutton(1,6)
771+ self.B_1__7 = mkbutton(1,7)
772+ self.B_QUIT = mkbutton(0,12,2,2,"close", self.parent.close)
773+ self.B_FULL = mkbutton(0,14,2,2,"fullscr",self.toggleFullscreen)
774+ self.rowcount = self.OptionsGrid.rowCount()
775+ self.setFixedHeight(self.height*self.rowcount +
776+ self.margin*2 +
777+ self.spacing*(self.rowcount-1))
778+ def resizeEvent(self, event):
779+ rect = self.rect()
780+ self.textstream.append( 'Interface:\t\t' +
781+ `rect.width()` +
782+ "x" +
783+ `rect.height()`)
784+ def paintEvent(self, event):
785+ #print "Painting options"
786+ charcoal = QColor("#101010")
787+ black = QColor("#000000")
788+ brush = QBrush(Qt.SolidPattern)
789+ rect = self.rect()
790+ self.qp.begin(self)
791+ self.qp.setBrush(brush)
792+ self.qp.fillRect(rect, charcoal)
793+ self.qp.end()
794+
795
796=== added file '_Display/__init__.py'
797--- _Display/__init__.py 1970-01-01 00:00:00 +0000
798+++ _Display/__init__.py 2011-01-14 22:02:00 +0000
799@@ -0,0 +1,4 @@
800+from _DisplayObject import DisplayObject
801+from _DisplayWindow import DisplayWindow
802+from _Interface import Interface
803+from _DebugOutput import DebugOutput
804\ No newline at end of file
805
806=== added file '_Display/_clickableIcon.py'
807--- _Display/_clickableIcon.py 1970-01-01 00:00:00 +0000
808+++ _Display/_clickableIcon.py 2011-01-14 22:02:00 +0000
809@@ -0,0 +1,29 @@
810+from PyQt4.QtGui import QPushButton, QBrush, QIcon
811+from PyQt4.QtCore import Qt, QRect
812+
813+class clickableIcon(QPushButton):
814+ def paintEvent(self, event):
815+ r = QRect(self.x, self.y, self.w, self.h)
816+ self.image.paint(self.qp, r)
817+ def setRect(self,x,y,w,h):
818+ r = self.rect()
819+ self.x = x
820+ self.y = y
821+ self.w = w
822+ self.h = h
823+ r.setRect(x,y,w,h)
824+ self.setGeometry(r)
825+ def centre(self):
826+ r = self.rect()
827+ return (r.x()+r.width()/2, r.y()+r.height()/2)
828+ def __init__(self,parent,image):
829+ QPushButton.__init__(self)
830+ self.image = QIcon()
831+ self.qp = parent.qp
832+ self.x = 0
833+ self.y = 0
834+ self.w = 0
835+ self.h = 0
836+ self.imagename = "_Display/Sprites/"+image+".png"
837+ self.image.addFile(self.imagename)
838+ #self.move(x,y) translates the sprite's rectangle
839\ No newline at end of file
840
841=== added file '_Display/_interfaceButton.py'
842--- _Display/_interfaceButton.py 1970-01-01 00:00:00 +0000
843+++ _Display/_interfaceButton.py 2011-01-14 22:02:00 +0000
844@@ -0,0 +1,51 @@
845+from PyQt4.QtGui import (QColor,
846+ QPainter,
847+ QIcon,
848+ QImage,
849+ QBrush,
850+ QPushButton,
851+ QLabel,
852+ QSizePolicy,
853+ QKeySequence)
854+from PyQt4.QtCore import (QString,
855+ QSize,
856+ Qt)
857+import os.path
858+class interfaceButton(QPushButton):
859+ def paintEvent_(self, event):
860+ black = QColor("#000000")
861+ charcoal = QColor("#101010")
862+ orange = QColor("#F08038")
863+ if self.isDown() or (self.isChecked() and self.isCheckable()):
864+ background = orange
865+ else:
866+ background = black
867+ brush = QBrush(Qt.SolidPattern)
868+ self.qp.begin(self)
869+ self.qp.setBrush(brush)
870+ self.qp.fillRect(self.rect(), background)
871+ self.image.paint(self.qp, self.rect(), state=QIcon.On)
872+ self.qp.end()
873+ def paintEvent__(self, event):
874+ QPushButton.paintEvent(self, event)
875+ pass
876+ def __init__(self, parent, display='', shortcut=None):
877+ QPushButton.__init__(self)
878+ self.parent = parent
879+ self.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
880+ try:
881+ assert os.path.isfile(display)
882+ self.imagename = display
883+ self.image = QIcon()
884+ self.image.addFile(display)
885+ self.image.sizeHint = self.sizeHint
886+ self.qp = parent.qp
887+ self.paintEvent = self.paintEvent_
888+ self.setFlat(True)
889+ except:
890+ self.setText(display)
891+ if display=='':
892+ self.setFlat(True)
893+ self.paintEvent = self.paintEvent__
894+ if shortcut:
895+ self.setShortcut(QKeySequence(shortcut))
896\ No newline at end of file
897
898=== added file '_Display/pyrpg.png'
899Binary files _Display/pyrpg.png 1970-01-01 00:00:00 +0000 and _Display/pyrpg.png 2011-01-14 22:02:00 +0000 differ
900=== added file 'layered.ico'
901Binary files layered.ico 1970-01-01 00:00:00 +0000 and layered.ico 2011-01-14 22:02:00 +0000 differ
902=== modified file 'pyrpg.py'
903--- pyrpg.py 2010-11-22 06:47:41 +0000
904+++ pyrpg.py 2011-01-14 22:02:00 +0000
905@@ -1,20 +1,76 @@
906-from GameObjects import GameObject, Containable, World, Weapon
907+#!/usr/bin/python
908+#
909+from GameObjects import GameObject, World, Level, Weapon, Character, Containable
910+from Display import DisplayObject
911+from Levels import worlds
912+from Levels import objects
913+def setupTile(x, y, tile, thisLevel, Game):
914+ cont = thisLevel
915+ if tile.flag != objects.Out.flag:
916+ if tile.flag(objects.Floor.flag):# This needs to not be collision-tested
917+ Containable(flag=tile.flag, container=cont, position=(x,y), name="Floor@%s"%(`(x,y)`), image=tile.image)
918+ if tile.flag(objects.Wall.flag): # This needs to be indestructable
919+ Containable(flag=tile.flag, container=cont, position=(x,y), name="Wall@%s"%(`(x,y)`), image=tile.image)
920+ if tile.flag(objects.Door.flag): # This needs to link levels
921+ Containable(flag=tile.flag, container=cont, position=(x,y), name="Door@%s"%(`(x,y)`), image=tile.image)
922+ if tile.flag(objects.Player.flag):
923+ Game.Player = Character(flag=tile.flag, container=cont, position=(x,y), name="Player 1", image=tile.image)
924+ # if tile.flag(objects.Box.flag): # Not implemented yet
925+ # print "Adding a box","at %s"%(`(x,y)`)
926+ # if tile.flag(objects.Resource.flag):# Not implemented yet
927+ # print "Adding a resource stash","at %s"%(`(x,y)`)
928+ # if tile.flag(objects.Friend.flag): # Not implemented yet
929+ # print "Adding a friend","at %s"%(`(x,y)`)
930+ # if tile.flag(objects.Enemy.flag): # Not implemented yet
931+ # print "Adding an enemy","at %s"%(`(x,y)`)
932+ # if tile.flag(objects.Neutral.flag): # Not implemented yet
933+ # print "Adding a neutral party","at %s"%(`(x,y)`)
934+ # if tile.flag(objects.Book.flag): # Not implemented yet
935+ # print "Adding a book","at %s"%(`(x,y)`)
936+ # if tile.flag(objects.Scroll.flag): # Not implemented yet
937+ # print "Adding a scroll","at %s"%(`(x,y)`)
938+ # if tile.flag(objects.HPotion.flag): # Not implemented yet
939+ # print "Adding a health potion","at %s"%(`(x,y)`)
940+ # if tile.flag(objects.MPotion.flag): # Not implemented yet
941+ # print "Adding a mana potion","at %s"%(`(x,y)`)
942+ # if tile.flag(objects.Dagger.flag): # Not implemented yet
943+ # print "Adding a dagger","at %s"%(`(x,y)`)
944+ # if tile.flag(objects.Bow.flag): # Not implemented yet
945+ # print "Adding a bow","at %s"%(`(x,y)`)
946+ # if tile.flag(objects.Axe.flag): # Not implemented yet
947+ # print "Adding an axe","at %s"%(`(x,y)`)
948+ if tile.flag(objects.Shield.flag):
949+ Weapon(flag=tile.flag, container=cont, position=(x,y), name="Sheild@%s"%(`(x,y)`), image=tile.image)
950+ if tile.flag(objects.Sword.flag):
951+ Weapon(flag=tile.flag, container=cont, position=(x,y), name="Sword@%s"%(`(x,y)`), image=tile.image)
952+ return cont
953+
954+
955+def setupGame():
956+ Game = GameObject(flag=objects.Out.flag, name="Game")
957+ DisplayList = []
958+
959+ wn = 0
960+ for world in worlds:
961+ thisWorld = World(flag=objects.Out.flag, container=Game, name="World_%s"%(`wn`))
962+ ln = 0
963+ for level in world:
964+ thisLevel = Level(flag=objects.Out.flag, container=thisWorld, name="Level_%s.%s"%(`wn`,`ln`))
965+ x,y = 0,0
966+ for line in level:
967+ for tile in line:
968+ if type(tile) == type(tuple()):
969+ cont = thisLevel
970+ for item in tile:
971+ cont = setupTile(x, y, item, cont, Game)
972+ else:
973+ setupTile(x, y, tile, thisLevel, Game)
974+ x += 1
975+ x = 0
976+ y += 1
977+ wn += 1
978+ return Game
979 if __name__ == "__main__":
980- print '\n'*100
981- Game = GameObject(name="Game")
982- w1 = World(container=Game, name="World1")
983- w2 = World(container=Game, name="World2")
984- W1 = Weapon(container=w1, name="Weapon1")
985- print "W2"
986- W2 = Weapon(container=w2, name="Weapon2")
987- print '\n'*100
988- Objects = Game.getAllSameClass()
989- for Object in Objects:
990- if len(Object.contents):
991- print `Object.name`, "contains:\n\t", ', '.join([`x.name` for x in Object])
992- else:
993- print `Object.name`, "is empty."
994- if hasattr(Object, 'container'):
995- print `Object.name`, "contained by", `Object.container.name`+'.'
996- else:
997- print `Object.name`, "has no container."
998\ No newline at end of file
999+ Game = setupGame()
1000+ d = DisplayObject(Game)
1001+ d.exec_()

Subscribers

People subscribed via source and target branches

to all changes: