# # Pressing a mouse button down while this simulation run updates the cat state # by leaving pos unchanged but reversing delta-pos (changing 1 to -1 and vice # versa). That is, pressing a mouse key reverses the direction of the # cat. # # The simulation ends when the cat is allowed to reach either the left # or the right edge of the screen. ################################################################ # Initialize world name = "Cat Fun. Press the mouse (but not too fast)!" width = 500 height = 500 rw.newDisplay(width, height, name) ################################################################ # Display the state by drawing a cat at that x coordinate myimage = dw.loadImage("cat.bmp") # state -> image (IO) # draw the cat halfway up the screen (height/2) and at the x # coordinate given by the first component of the state tuple # def updateDisplay(state): dw.fill(dw.black) dw.draw(myimage, (state[0], state[1]))
# pdb.set_trace() import pygame as pg import runWorld as rw import drawWorld as dw import image_processing as ip import imagineFun as af ################################################################ # Initialize display name = "Imaginator!" width = 1200 height = 500 rw.newDisplay(width, height, name) ################################################################ # An image that we'll use when the system starts initImage = dw.loadImage("twoeyes.bmp") # In our initial exercise with this simulation framework, we # represented the "game state" as a tuple. A problem with that # approach is that it doesn't give us good names for the fields # of the tuples (records), so we end up with lots of cryptically # subscripted tuple values, make it hard to write, reason about, # debug, and enhance the code. We could of course write our own # nicely named projection functions, and that would help. This # is what we did in Idris, where we wrote functions such as
# Define the colors we will use in RGB format BLACK = (0, 0, 0) WHITE = (255, 255, 255) BLUE = (0, 0, 255) GREEN = (0, 255, 0) RED = (255, 0, 0) VISOR = (170, 170, 170) HELM = (150, 150, 150) TORSO = (100, 100, 100) SHIELD = (174, 88, 11) # Initialize world name = "proj" width = 1200 height = 800 screen = rw.newDisplay(width, height, name) target1 = dw.loadImage("target1.png") target2 = dw.loadImage("target2.png") target3 = dw.loadImage("target3.png") target4 = dw.loadImage("target4.png") target5 = dw.loadImage("target5.png") class Turret(object): def __init__(self, X, Y, screen, kind, face=0): self.Xcoord = X self.Ycoord = Y self.health = 100 self.alive = True self.kind = kind
# Define the colors we will use in RGB format BLACK = (0, 0, 0) WHITE = (255, 255, 255) BLUE = (0, 0, 255) GREEN = (0, 255, 0) RED = (255, 0, 0) VISOR = (170, 170, 170) HELM = (150, 150, 150) TORSO = (100, 100, 100) SHIELD = (174, 88, 11) # Initialize world name = "Beauregarde of Flankingshire" width = 1200 height = 800 screen = rw.newDisplay(width, height, name) target1 = dw.loadImage("target1.png") target2 = dw.loadImage("target2.png") target3 = dw.loadImage("target3.png") target4 = dw.loadImage("target4.png") target5 = dw.loadImage("target5.png") class Turret(object): def __init__(self, X, Y, screen, kind, face=0): self.Xcoord = X self.Ycoord = Y self.health = 100 self.alive = True self.kind = kind
# Global variables touchRange = ([], []) score = 0 scoreText = "" # 0 - The game is being played, 1 = The player lost, 2 = The player won gameState = 0 # Static variables DRONE_SIZE = 48 DELIVERY_SIZE = 16 WIDTH = 1024 HEIGHT = 700 # Initialize world name = "Drolivery - Fast & Accurate Drone Delivery" rw.newDisplay(WIDTH, HEIGHT, name) # Initialize font -> must be called after pygame.init() to avoid 'Font not Initialized' error font = pg.font.Font(None, 35) ################################################################ # Loads the images droneImage = dw.loadImage("drone.png") deliveryImage = dw.loadImage("delivery.png") """ Update the display accordingly with the game state """ def updateDisplay(state): dw.fill(dw.white)