Assignment 3, CSC 101

due Wednesday, February 5th, 11:59pm

For this third assignment you will start to increase the complexity of interactions in your world by increasing the number of resources in the world, increasing the visual complexity of your world via the use of sprites, having resources change the visual appearance of parts of the world, and inlcuding pygame events (both mouse and keyboard) to trigger actions. In general, this assignment focuses on:

Learning objectives more generally include:

Files

Create a hw3 directory in which to develop your solution.

You will develop your program solution in multiple files.

You will continue to work with your files from the last assignment, A2_base.py and A2_sol.py. Please make copies of all relevant files and re-name these A3_base.py and A3_sol.py.

Develop multiple resources

Working with your exisiting code, you need to modify your world in order to support multiple resources (between 3 and 10). These resources should be stored in a list and should all be created relative to the location of the generator. In addition, these resources cannot initially spawn in the same cell.

Consider writing a function called spawnResources which takes in any necessary arguments and creates the resource list.

Mouse triggered resource selection to effect local region of the grid

Next, a resource must be able to affect some local region of the world around it, when triggered by a mosue event (i.e., when the resource is 'clicked' by the mouse). This effect on the local region must be visualized. This effect can affect either all 8 cells next to the resouce or more (but must at least affect 3 cells near the resource). The effect can be limited to just a visual effect (i.e., the cells are drawn differently - or it can be a more concrete effect - e.g., the resource is duplicated, increasing the total resources or entities in the world).

To accomplish this, consider writing at least two functions. One which maps a pixel value to a correct grid value (see below notes about modifications to a grid cell size based on sprites) and one function called ResourceEffect, which again takes in any relevant arguments and affects some local region of the world around the "clicked" resource. See below images for an example where a peice of seaweed, when clicked, grows another type of seaweed nearby.

Be sure that you are always checking to make sure that the region of the grid you are effecting is valid!


Keyboard triggered gatherer motion

Gatherer behaviour: When your world starts, for this assignment, your gatherer will stay in place until a keyboard event triggers it to move (use the space bar for consistency at this time). Once the space bar is pressed, the gatherer should start moving. Again, for now, please include a visual effect for the path the gatherer takes through the world (see below images with bubble path for the sub).

In addition, at this point you may want to start thinking about how your gatherer is moving through the world. In our next assignment, you will add more complex movement, but some things you can start to think about are moving through the world without walking over a resource or proceeding onto other resources after visiting one, etc.

Keyboard triggered gatherer behaviour

Your program must support two different modes of targeting resources by the gatherer - seeking the closest resource and seeking the furthest resource. Your program must also support the ability to reset the world (i.e., return the gatherer to its start position and erase the prior path). You may measure distance either as Euclidean distance or Manhattan distance - your choice - please specify which you used in a file named README.txt.

Specifically:

Note that since you are not required to have your pathing be intelligent at this stage,when traveling to the furtest resource, your gatherer may stomp on other entities - see below image - just be sure to reset all entities correctly on a reset event.

Visualizing and representing your world with sprites

At this point, your team should start identifying "sprites" (general definition) to represent the differnt elements of your scene.

Sprites are small images that you can draw for each cell. There are good references about sprites in pygame here. For consistency in look, at this time, we would like you to all use bitmap (bmp) images that are 32x32 (this is very small). An example of a single sprite (for the sub in this case) might look like this:

You can either find and rescale images or draw them. Long term you may want animations, so you can either use a place holder image at this point and identify or create animations later.

In general, as a team, you need to think more about the look and feel of your world. This means you need to start picking colors/images carefully, think about how your gatherer travels, what is the look of the resource's effect on the world, etc. We will talk more about this in class, but, in general, your team should start being able to defend the choices you are making about your world's appearance.

Occupancy grid notes
Note at this point, we'd like you to start looking at the occupancy grid code more carefully to make sure you understand the structure. Since we have now discussed lists, you should be able to recognize the structure (a list that contains lists) and feel confident about adding any functions you may need to navigate or scale the grid. In particular, since each tile now represents 32x32 pixels in the space of our grid (see below), you need to make sure you understand how to "move" in your grid when converting units from pixels to grid elements.

An example of the world and interactions might look like the following:
Image of the world after one peice of seaweed has been clicked - causing it to spawn neighboring seaweed

An image of the world after the space bar has been clicked - causing the sub (the gatherer) to move towards a resource

Image of the world at the start - generator is Atlantis, which generates seaweed nearby - the gatherer, a sub, does not move until triggered via a keyboard event

An image of the the sub (the gatherer) targeting and reaching the "closest resource"

An image of the the sub (the gatherer) targeting and reaching the "furthest resource" (note due to simple pathing the sub goes right through Atlantis (the generator)

Handin

You must submit your solution on unix1.csc.calpoly.edu (or on unix2, unix3, or unix4) by 11:59pm on the due date.

Note that you can resubmit your files as often as you'd like prior to the deadline. Each subsequent submission will replace files of the same name.

Grading

The grading breakdown for this assignment is as follows.