Merge lp:virqua into lp:virqua/preview

Proposed by Daniel Phillips
Status: Merged
Approved by: Daniel Phillips
Approved revision: 3
Merged at revision: 3
Proposed branch: lp:virqua
Merge into: lp:virqua/preview
Diff against target: 413 lines (+139/-141)
16 files modified
config.py (+1/-1)
constants.py (+17/-1)
decofish.py (+62/-0)
exfighter.py (+9/-0)
exhunter.py (+9/-0)
exprey.py (+9/-0)
fish.py (+14/-0)
fish/__init__.py (+0/-14)
fish/cloak.py (+0/-10)
fish/decofish.py (+0/-51)
fish/exfighter.py (+0/-9)
fish/exhunter.py (+0/-9)
fish/exprey.py (+0/-9)
fish/functions.py (+0/-32)
functions.py (+1/-1)
main.py (+17/-4)
To merge this branch: bzr merge lp:virqua
Reviewer Review Type Date Requested Status
Daniel Phillips Approve
Review via email: mp+77606@code.launchpad.net

Description of the change

Updated preview due to changes in how the environment will interact with the fish.

update() is the only method in a fish class that should move the rect or change the fish's direction.

The other methods are just to provide info to the environment or obtain updated information from the environment. The new info is used the next time update() runs. See decofish.py for an almost-complete fish.

Also, everything has moved into the same directory level so ignore the mention of fish/ in readme.txt.

To post a comment you must log in.
Revision history for this message
Daniel Phillips (daniel-phillips) wrote :

Approved since people need to know how to write fish the right way.

Using anything other then update() to tell the fish to move would make the environment code a lot more work.

Basically, I can shove all the fish in pygame sprite-groups then call update() on the sprite-group which will automatically call update() on each of the fish.

Also, I can call draw() on the sprite-group to easily repaint all the fish.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.py'
2--- config.py 2011-09-28 17:17:19 +0000
3+++ config.py 2011-09-29 20:37:48 +0000
4@@ -1,6 +1,6 @@
5 # Virtual Aquarium
6 # Settings
7-# Build 0002
8+# MIT License FTW
9
10 WINDOW_WIDTH = 800
11 WINDOW_HEIGHT = 600
12
13=== modified file 'constants.py'
14--- constants.py 2011-09-28 17:17:19 +0000
15+++ constants.py 2011-09-29 20:37:48 +0000
16@@ -1,10 +1,26 @@
17 # Virtual Aquarium
18 # Written by Daniel Phillips
19+# MIT License FTW
20 #
21 # Constants
22-# Build 0002
23 #
24 # DO NOT CHANGE THIS FILE
25 # Changes here will prevent your fish from working on the display computer
26
27+# vertical direction
28+VERTICAL_UP = 1
29+VERTICAL_SAME = 0
30+VERTICAL_DOWN = -1
31+
32+# horizontal direction
33+HORIZ_RIGHT = 1
34+HORIZ_SAME = 0
35+HORIZ_LEFT = -1
36+
37+# wall identifiers (think clock positions
38+WALL_RIGHT = 3
39+WALL_BOTTOM = 6
40+WALL_LEFT = 9
41+WALL_TOP = 12
42+
43 # colours
44\ No newline at end of file
45
46=== added file 'decofish.py'
47--- decofish.py 1970-01-01 00:00:00 +0000
48+++ decofish.py 2011-09-29 20:37:48 +0000
49@@ -0,0 +1,62 @@
50+# Virtual Aquarium
51+# Written by Daniel Phillips
52+# MIT License FTW
53+#
54+# The standard decoration fish
55+#
56+# Use this as a starting point for writing decoration fish
57+#
58+# Must have all the methods listed here
59+# Methods not here will be ignored by environment code
60+#
61+# The sprite must be loaded into self.image
62+# The bounding must be stored in self.rect
63+# Use of other names for the sprite and rect
64+# will cause pygame to throw exceptions.
65+
66+import constants
67+import functions
68+
69+# local constants
70+SPRITE_PATH = "decofish.gif"
71+
72+class deco_fish:
73+ # Constructor
74+ def __init__(self, point, v_dir, h_dir):
75+ self.image, self.rect = functions.load_image(SPRITE_PATH)
76+ self.rect.topleft = point
77+ self.vertical_direction = v_dir
78+ self.horizontal_direction = h_dir
79+ self.food_target = None
80+ self.health = 3
81+
82+ # Check for starvation
83+ def is_dead(self):
84+ return self.health == 0
85+
86+ # Lose health from hunger
87+ def notify_day_elapsed(self):
88+ self.health -= 1
89+
90+ # Tell fish food's been dropped in the tank
91+ def notify_food_drop(self, direction):
92+ self.food_target = direction
93+
94+ # Tell fish it collided with food
95+ def notify_food_eaten(self):
96+ self.food_target = None
97+ if self.health < 3:
98+ self.health += 1
99+
100+ # Tell the fish it hit the wall
101+ def notify_wall_collide(self, edge_id):
102+ if edge_id in (constants.WALL_TOP, constants.WALL_BOTTOM):
103+ self.vertical_direction = -self.vertical_direction
104+ elif edge_id in (constants.WALL_RIGHT, constants.WALL_LEFT):
105+ self.horizontal_direction = -self.horizontal_direction
106+
107+ # Determine the new position of the fish and move the rect
108+ def update(self, *args):
109+ pass
110+
111+
112\ No newline at end of file
113
114=== added file 'exfighter.py'
115--- exfighter.py 1970-01-01 00:00:00 +0000
116+++ exfighter.py 2011-09-29 20:37:48 +0000
117@@ -0,0 +1,9 @@
118+# Virtual Aquarium
119+# Written by Daniel Phillips
120+# MIT License FTW
121+#
122+# Example of a basic fighter
123+
124+import functions
125+
126+# TODO
127
128=== added file 'exhunter.py'
129--- exhunter.py 1970-01-01 00:00:00 +0000
130+++ exhunter.py 2011-09-29 20:37:48 +0000
131@@ -0,0 +1,9 @@
132+# Virtual Aquarium
133+# Written by Daniel Phillips
134+# MIT License FTW
135+#
136+# Example of a basic hunter
137+
138+import functions
139+
140+# TODO
141\ No newline at end of file
142
143=== added file 'exprey.py'
144--- exprey.py 1970-01-01 00:00:00 +0000
145+++ exprey.py 2011-09-29 20:37:48 +0000
146@@ -0,0 +1,9 @@
147+# Virtual Aquarium
148+# Written by Daniel Phillips
149+# MIT License FTW
150+#
151+# Example of a basic prey fish
152+
153+import functions
154+
155+# TODO
156\ No newline at end of file
157
158=== removed directory 'fish'
159=== added file 'fish.py'
160--- fish.py 1970-01-01 00:00:00 +0000
161+++ fish.py 2011-09-29 20:37:48 +0000
162@@ -0,0 +1,14 @@
163+# Virtual Aquarium
164+# Written by Daniel Phillips
165+# MIT License FTW
166+#
167+# Fish module - provide access to fish
168+
169+# import fish modules
170+import decofish
171+
172+# add classes to lists for use by main.py
173+deco_fish = [decofish.deco_fish]
174+prey_fish = []
175+hunters = []
176+fighters = []
177\ No newline at end of file
178
179=== removed file 'fish/__init__.py'
180--- fish/__init__.py 2011-09-28 17:17:19 +0000
181+++ fish/__init__.py 1970-01-01 00:00:00 +0000
182@@ -1,14 +0,0 @@
183-# Virtual Aquarium
184-# Written by Daniel Phillips
185-#
186-# Fish module - provide access to fish
187-# Build 0002
188-
189-# import fish modules
190-import decofish
191-
192-# add classes to lists for use by main.py
193-deco_fish = [decofish.deco_fish]
194-prey_fish = []
195-hunters = []
196-fighters = []
197\ No newline at end of file
198
199=== removed file 'fish/cloak.py'
200--- fish/cloak.py 2011-09-28 17:17:19 +0000
201+++ fish/cloak.py 1970-01-01 00:00:00 +0000
202@@ -1,10 +0,0 @@
203-# Virtual Aquarium
204-# Written by Daniel Phillips
205-#
206-# A trolling fighter that looks like a decofish
207-# while it waits for a foe to appear
208-# Build 0002
209-
210-import functions
211-
212-# TODO
213\ No newline at end of file
214
215=== removed file 'fish/decofish.py'
216--- fish/decofish.py 2011-09-28 17:17:19 +0000
217+++ fish/decofish.py 1970-01-01 00:00:00 +0000
218@@ -1,51 +0,0 @@
219-# Virtual Aquarium
220-# Written by Daniel Phillips
221-#
222-# The standard decoration fish
223-# Build 0002
224-
225-import functions
226-
227-class deco_fish:
228- def __init__(point):
229- self.position = point
230- self.current_direction = 0.0
231- self.next_direction = 0.0
232- self.food_target = None
233- self.health = 3
234-
235- def get_position():
236- return self.position
237-
238- # return a pair, change in X and change in Y
239- def get_current_direction():
240- return self.current_direction
241-
242- # return a pair, change in X and change in Y
243- def get_next_direction():
244- return self.next_direction
245-
246- # takes a pair, change in X and change in Y
247- def set_current_direction(dir):
248- self.current_direction = dir
249-
250- def set_position(point):
251- self.position = point
252-
253- def move():
254- if self.food_target:
255- pass
256- else:
257- pass
258-
259- def notify_day_elapsed():
260- health -= 1
261-
262- def notify_food_drop(point):
263- self.food_target = point
264-
265- def notify_food_eaten():
266- self.food_target = None
267- if self.health < 3:
268- self.health += 1
269-
270
271=== removed file 'fish/exfighter.py'
272--- fish/exfighter.py 2011-09-28 17:17:19 +0000
273+++ fish/exfighter.py 1970-01-01 00:00:00 +0000
274@@ -1,9 +0,0 @@
275-# Virtual Aquarium
276-# Written by Daniel Phillips
277-#
278-# Example of a basic fighter
279-# Build 0002
280-
281-import functions
282-
283-# TODO
284
285=== removed file 'fish/exhunter.py'
286--- fish/exhunter.py 2011-09-28 17:17:19 +0000
287+++ fish/exhunter.py 1970-01-01 00:00:00 +0000
288@@ -1,9 +0,0 @@
289-# Virtual Aquarium
290-# Written by Daniel Phillips
291-#
292-# Example of a basic hunter
293-# Build 0002
294-
295-import functions
296-
297-# TODO
298\ No newline at end of file
299
300=== removed file 'fish/exprey.py'
301--- fish/exprey.py 2011-09-28 17:17:19 +0000
302+++ fish/exprey.py 1970-01-01 00:00:00 +0000
303@@ -1,9 +0,0 @@
304-# Virtual Aquarium
305-# Written by Daniel Phillips
306-#
307-# Example of a basic prey fish
308-# Build 0002
309-
310-import functions
311-
312-# TODO
313\ No newline at end of file
314
315=== removed file 'fish/functions.py'
316--- fish/functions.py 2011-09-28 17:17:19 +0000
317+++ fish/functions.py 1970-01-01 00:00:00 +0000
318@@ -1,32 +0,0 @@
319-# Virtual Aquarium
320-# Written by Daniel Phillips
321-#
322-# Utility functions
323-# Build 0002
324-#
325-# These functions, and only these functions,
326-# will be available on the display computer
327-
328-# python/pygame imports
329-import os
330-import pygame
331-import sys
332-from pygame.locals import *
333-
334-# local imports
335-import constants
336-import config
337-
338-# Read image from file
339-def load_image(name, colorkey=None):
340- try:
341- image = pygame.image.load(name)
342- except pygame.error, message:
343- print "Cannot load image: ", name
344- raise SystemExit, message
345- image = image.convert()
346- if colorkey is not None:
347- if colorkey is -1:
348- colorkey = image.get_at((0,0))
349- image.set_colorkey(colorkey, RLEACCEL)
350- return image, image.get_rect()
351
352=== modified file 'functions.py'
353--- functions.py 2011-09-28 17:17:19 +0000
354+++ functions.py 2011-09-29 20:37:48 +0000
355@@ -1,8 +1,8 @@
356 # Virtual Aquarium
357 # Written by Daniel Phillips
358+# MIT License FTW
359 #
360 # Utility functions
361-# Build 0002
362 #
363 # These functions, and only these functions,
364 # will be available on the display computer
365
366=== modified file 'main.py'
367--- main.py 2011-09-28 17:17:19 +0000
368+++ main.py 2011-09-29 20:37:48 +0000
369@@ -1,8 +1,10 @@
370+#!/usr/bin/env python
371+#
372 # Virtual Aquarium
373 # Written by Daniel Phillips
374+# MIT License FTW
375 #
376 # Entry point - setup and event loop
377-# Build 0002
378 #
379 # DO NOT CHANGE THIS FILE
380 # Changes here will prevent your fish from working on the display computer
381@@ -48,7 +50,7 @@
382
383 # load fish
384
385-# process events
386+# input event handler
387 def input(events):
388 for event in events:
389 if event.type == pygame.QUIT:
390@@ -61,10 +63,21 @@
391
392 # event loop
393 while True:
394- # handle input
395+ # handle input events
396 input(pygame.event.get())
397
398- # update fish
399+ # process collisions
400+
401+ # update time
402+
403+ # remove dead fish
404+
405+ # drop food if enough time has passed
406+
407+ # geometry
408+
409+ # move fish
410+ # -just call update() on the groups which calls update() on the fish
411
412 # update display
413 pygame.display.flip()

Subscribers

People subscribed via source and target branches