示例#1
0
def load(state):
    print("Enter name of image file to load: ")
    imageName = input()
    resetImage = dw.loadImage(imageName)
    state['original'] = resetImage
    state['processed'] = state['original'].copy()
    state['needsDisplayUpdate'] = True
    return state
示例#2
0
def load(state):
    print("Enter name of image file to load: ")
    imageName = input()
    resetImage = dw.loadImage(imageName)
    state['original'] = resetImage
    state['processed'] = state['original'].copy()
    state['needsDisplayUpdate'] = True
    return state
示例#3
0
def load(state):
    print("Enter name of image file to load: ")
    imageName = input()
    resetImage = dw.loadImage(imageName)
    state.original = resetImage
    state.processed = state.original.copy()
    state.needsDisplayUpdate = True
    return state
示例#4
0
def load(state):
    print("Enter name of image file to load: ")
    imageName = input()
    resetImage = dw.loadImage(imageName)
    state.original = resetImage
    state.processed = state.original.copy()
    state.needsDisplayUpdate = True
    return state
示例#5
0
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("cat.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
# first (fst) and second (snd) to extract fields from tuples.
# We then saw that the *record* construct enabled us to define
# tuple types with *named* fields. The compiler then provided
# projection functions with the names of the fields, making it
# much easier to write code where the intended interpretation
# is clarified by the use of meaningful field names.
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
        self.face = face
示例#7
0
import runWorld as rw
import drawWorld as dw
import pygame as pg
from random import randint

name = "Move the cursor over the Soccer Ball to Stop it from Going in the Goal!"
width = 800
height = 800
rw.newDisplay(width, height, name)

myimage = dw.loadImage("soccer_ball_1.bmp")
goal = dw.loadImage("goal.bmp")

class State:
    xpos = 400
    ypos = 700
    xvel = randint(-2,2)
    yvel = randint(-12,-10)
    def move(self):
        self.xpos = self.xpos + self.xvel
        self.ypos = self.ypos + self.yvel
    
initState = State()

def updateDisplay(state):
    dw.fill(dw.white)
    dw.draw(goal, (0, 0, 0, 0))
    dw.draw(myimage, (state.xpos, state.ypos, state.xvel, state.yvel))

def updateState(state):
    state.move()
示例#8
0
import runWorld as rw
import drawWorld as dw
import pygame as pg

from random import randint

gameState = 0
counter = 0

name = "The Kevin Sullivan Game!"
width = 600
height = 600
rw.newDisplay(width, height, name)

myImage = dw.loadImage("sullivan_kevin.bmp")

class State:
	def __init__(self, img, xpos, xvel, ypos, yvel):
		self.img = img
		self.xpos = xpos
		self.xvel = xvel
		self.ypos = ypos
		self.yvel = yvel
        
ourState = State(myImage, 100, 1, 100, 1)

def updateDisplay(state):
	dw.fill((100, 0, 70))
	dw.draw(state.img, (state.xpos, state.ypos))
	dw.draw(dw.makeLabel("Click to Survive! Score: " + str(counter), "Vendera", 25, dw.red), (12, 12))
示例#9
0
import runWorld as rw
import drawWorld as dw


# Initialize world
name = "Cat Go!"
width = 500
height = 500
rw.newDisplay(width, height, name)

# World state will be single x coordinate at left edge of world
initState = 0

# Display the state by drawing a cat at that x coordinate
myimage = dw.loadImage("cat.bmp")

# state -> image (IO)
def updateDisplay(state):
    dw.fill(dw.black)
    dw.draw(myimage, (state[0], height/2))


# We'll update the state on each tick by incrementing the x stateinate
# state -> state
def updateState(state):
    return((state[0]+state[1], state[1]))

# We'll terminate when the x coordinate reaches the screen edge

# tells the simulation when it's over
#
# The simulation ends when either player leaves the "ring" by fleeing
# or by being pushed out by the other player's slaps.

################################################################

# Initialize world
name = "SMACK"
width = 1200
height = 800
rw.newDisplay(width, height, name)

################################################################

# Display the state by drawing two torsos with arms.
rightTorso = dw.loadImage("T_R.png")
rightHigh = dw.loadImage("R_H.png")  # -150, +255
rightLow = dw.loadImage("R_L.png")  # -150, -100

leftTorso = dw.loadImage("T_L.png")
leftHigh = dw.loadImage("L_H.png")  # 200, +225
leftLow = dw.loadImage("L_L.png")  # 200, -100


def updateDisplay(state):
    dw.fill(dw.black)
    if state.player1arm == 1:
        dw.draw(leftHigh, (state.player1x + 200, state.player1y - 100))
    else:
        dw.draw(leftLow, (state.player1x + 200, state.player1y + 225))
    if state.player2arm == 1:
            print("The state is:", i)
            state.position = i
            break
        else:
            ##            print("this is Bin2", Bin)
            ##            print("this is CP2", CumulProb[0, (i+1)])
            Bin = Bin + CumulProb[0, (i + 1)]
    ##            print("This is new Bin", Bin)
    return state


################################################################
## Display the state by drawing the image at the current state's (x,y)
## pair

myimage = dw.loadImage("dog.jpg")
dot = dw.loadImage("white_dot.jpg")


def updateDisplay(state):
    d = 0
    dw.fill(dw.black)
    while d < numofs - 1:
        dw.draw(dot, (s[d][0], s[d][1]))
        d += 1
    dw.draw(state.image, (s[state.position][0], s[state.position][1]))


################################################################
## Terminates the simulation when the state is a given number
from random import randint

print(randint(1, 5))

################################################################

# Initialize world
name = "Trash it!"
width = 500
height = 500
rw.newDisplay(width, height, name)

################################################################

# Display the state by drawing trash and a trash can
myimage = dw.loadImage("papertrash.bmp")

otherimage = dw.loadImage("recycle.bmp")


# state -> image (IO)
# draw the trash at the bottom, center of the screne and
# paper trash at the top
def updateDisplay(state):
    dw.fill(dw.white)
    dw.draw(myimage, (state.xpos, state.yvel))
    dw.draw(otherimage, (width / 2, height - 100))


################################################################
示例#13
0
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)
    global scoreText
    global name

    if (gameState == 0):
        dw.draw(droneImage, (state[0], state[2]))
        dw.draw(deliveryImage, (deliveryInitState[0], deliveryInitState[1]))
        scoreText = font.render("Score: " + str(score), 1, (0, 0, 0))
        dw.draw(scoreText, (WIDTH / 2, 5))
示例#14
0
import runWorld as rw
import drawWorld as dw
import pygame as pg
from random import randint

################################################################

# Initialize world
name = "Cat Fun. Press the mouse (but not too fast)!"
width = 1000
height = 700
rw.newDisplay(width, height, name)

################################################################

myimage = dw.loadImage("realball.bmp")
secondimage = dw.loadImage("bballhoop.bmp")

class State:
    BallXpos = randint(125, 375)
    BallXvel = randint(1, 3)
    BallYpos = randint(125, 375)
    BallYvel = randint(1, 3)
    HoopYpos = height/2
    HoopYvel = randint(1, 3)
    def updateDisplay(self):
        dw.fill(dw.blue)
        dw.draw(myimage, (self.BallXpos, self.BallYpos))
        dw.draw(secondimage, (750, self.HoopYpos))
    def updateState(self):
        self.BallXpos = self.BallXpos + self.BallXvel
示例#15
0
文件: catFun.py 项目: eak2xt/cs1
#
# The goal of the game is to keep Grumpy Cat alive by avoiding both
# the sides of the screen and the dog!

################################################################

# Initialize world
name = "Colorific Cat & Dog Fun!"
width = 750
height = 750
rw.newDisplay(width, height, name)

################################################################

# Display the state by drawing a cat and a dog at their designated coordinates
catimage = dw.loadImage("grumpycat.bmp")
pugimage = dw.loadImage("pug.bmp")
color = (randint(0,255), randint(0,255), randint(0,255))
start = time.time()

# state -> image (IO)
# draw the cat and the dog at the points determined by the state tuple
# The cat and dog start at random points moving in a random directions in
# both x and y directions

class newState:
    x_pos_cat = 300
    y_pos_cat = 300
    x_vel_cat = randint(-3,3)
    y_vel_cat = randint(-3,3)
    x_pos_pug = 600
示例#16
0
#
# 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("10426306_10203780151533733_2057102321053958166_n.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[2]))


################################################################

# Change pos by delta-pos, leaving delta-pos unchanged
# Note that pos is accessed as state[0], and delta-pos
# as state[1]. Later on we'll see how to access state
示例#17
0
from random import randint

#########
# Description goes here
#########

# Initialize World
name = "Name Goes Here"
width = 500
height = 500
rw.newDisplay(width, height, name)

################################################################

# Display the state by drawing a cat at that x coordinate
myimage = dw.loadImage("Image Name Goes Here")

# 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]))


################################################################

# Change pos by delta-pos, leaving delta-pos unchanged
# Note that pos is accessed as state[0], and delta-pos
# as state[1]. Later on we'll see how to access state
示例#18
0
#
# 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 = 1000
height = 1000
rw.newDisplay(width, height, name)

################################################################

# Display the state by drawing a cat at that x coordinate
myimage = dw.loadImage("cat.bmp")
mouseimage = dw.loadImage("mouse.png")

# 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[2]])
    dw.draw(mouseimage, [state[0], state[3]])


################################################################

# Change pos by delta-pos, leaving delta-pos unchanged
示例#19
0
name = "Arrow Simulation"
width = 1100
height = 750
rw.newDisplay(width, height, name)


class State:
    x = 0
    y = 600
    v = 1


ballState = State()


myimage = dw.loadImage("soccer.jpeg")
goal=dw.loadImage("goall.gif")
player=dw.loadImage("p6.jpeg")
player2=dw.loadImage("p6.jpeg")

def updateDisplay(state):
    dw.fill(dw.green)
    dw.draw(myimage, (state.x, state.y))
    dw.draw(goal, (870,550))
    dw.draw(player,(0,500))
    dw.draw(player2, (550,10))

def updateState(state):
    if(state.x == 750 and state.v == 1):
        print("Goal!")
    state.x = state.x + state.v
示例#20
0
from random import randint

name = "Planets"
width = 500
height = 500
rw.newDisplay(width, height, name)

def loadImage(filename):
    imageSurface = pg.image.load(filename)
    imageSurface.convert()
    return imageSurface

sun = loadImage("sun2.jpeg")
earth = loadImage("earth1.jpeg")
comet = loadImage("comet.png")
impact = dw.loadImage("impact.jpg")

def updateDisplay(state):
    dw.fill(dw.black)
    dw.draw(sun, (200, 200))
    dw.draw(earth, (state[0], state[1]))
    dw.draw(comet, (state[2], state[3]))

def updateState(state):
    if (50 <= state[1] < 350 and state[0] == 50):
        y_down_velocity = 1
        location = (state[0], state[1]+y_down_velocity, state[2]+state[4], state[3]+state[5], state[4], state[5])
    elif (state[1] == 350 and 50 <= state[0] < 350):
        x_right_velocity = 1
        location = (state[0]+x_right_velocity, state[1], state[2]+state[4], state[3]+state[5], state[4], state[5])
    elif (50 < state[1] <= 350 and state[0] == 350):
示例#21
0
speed5 = 2.4

#these are the initial acceleration base rates for each gear n.
#tweak these to make the car accelerate faster or slower within
#a given gear
accel1 = .029
accel2 = .025
accel3 = .019
accel4 = .015
accel5 = .01

# Display the state by drawing a car at that x coordinate
# the tach image is a blue bar. Bar moves up and down to simulate a
# a tachometer (RPM indicator). 
#the gear indicators are .bmps that appear when their gear is active.
myimage = dw.loadImage("car.bmp")
tach = dw.loadImage("tach.bmp")
gear1 = dw.loadImage("gear1.bmp")
gear2 = dw.loadImage("gear2.bmp")
gear3 = dw.loadImage("gear3.bmp")
gear4 = dw.loadImage("gear4.bmp")
gear5 = dw.loadImage("gear5.bmp")


# define class
class Car:
    def __init__(self, pos, velo, accel, rpm):
        self.pos = pos
        self.velo = velo
        self.accel = accel
        self.rpm = rpm
#
# 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("alligator.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.white)
    dw.draw(myimage, (state[0], state[1]))


################################################################

# Change pos by delta-pos, leaving delta-pos unchanged
# Note that pos is accessed as state[0], and delta-pos
# as state[1]. Later on we'll see how to access state
示例#23
0
import drawWorld as dw
import pygame as pg



# Initialize world
name = "Cat Go!"
width = 1000
height = 1000
rw.newDisplay(width, height, name)

# World state will be single x coordinate at left edge of world


# Display the state by drawing a cat at that x coordinate
myimage = dw.loadImage("cat.bmp")
pondimage = dw.loadImage("pond.bmp")
dogimage = dw.loadImage("dog2.bmp")
waterimage = dw.loadImage("water.bmp")
beeimage = dw.loadImage("bee.bmp")
cactusimage = dw.loadImage("cactus.bmp")
faucetimage = dw.loadImage("faucet.bmp")
winimage = dw.loadImage("youwin.bmp")
catfood = dw.loadImage ("catfood.bmp")


def updateDisplay(state):
    dw.fill(dw.sage)
    dw.draw (catfood, [920,0])
    dw.draw(myimage, (state.x, state.y))
    dw.draw(dogimage, [200, 400])
示例#24
0
#
# The simulation ends when the cat is allowed to reach either the left
# or the right edge of the screen.

################################################################

# Initialize world
name = "Catch the Dot to Win the Game!"
width = 500
height = 500
rw.newDisplay(width, height, name)

################################################################

# Display the state by drawing a cat at that x coordinate
myimage = dw.loadImage("cat.png")

# 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.white)
    dw.draw(myimage, (state[0], state[1]))


################################################################

# Change pos by delta-pos, leaving delta-pos unchanged
# Note that pos is accessed as state[0], and delta-pos
# as state[1]. Later on we'll see how to access state
示例#25
0
import runWorld as rw
import drawWorld as dw
import pygame as pg

name = "UVA"
width = 1000
height = 1000
rw.newDisplay(width, height, name)

initState = (0,1)

myimage = dw.loadImage("uva.png")

mylabel = dw.makeLabel("Go Hoos!", "arial", 100, (0,0,255))
otherlabel = dw.makeLabel("Don't lose the Hoos", "serif", 80, (255,255,255))

def updateDisplay(state):
    dw.fill(dw.blue)
    dw.draw(otherlabel, (150,100))
    dw.draw(myimage, (state[0], width/50))
    dw.draw(mylabel, (250,250))

    
def updateState(state):
    return((state[0]+state[1]),state[1])


def endState(state):
    if (state[0] >= width or state[0] < -width):
        return True
    else:
示例#26
0
文件: sleep.py 项目: Stdjohnson/Lab
import runWorld as rw
import drawWorld as dw


# Initialize world
name = "Cat Go!"
width = 500
height = 500
rw.newDisplay(width, height, name)

# World state will be single x coordinate at left edge of world
initState = 0

# Display the state by drawing a cat at that x coordinate
myimage = dw.loadImage("sullivan-kevin.bmp")


def updateDisplay(state):
    dw.fill(dw.black)
    dw.draw(myimage, (state, width/2))


# We'll update the state on each tick by incrementing the x stateinate
def updateState(state):
    return(state+1)

# We'll terminate when the x stateinate reaches the screen edge


def endState(state):
示例#27
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
        self.face = face
        if (self.kind == "norm") or (self.kind == "direct"):
示例#28
0
#
# 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 = 1280
height = 720
rw.newDisplay(width, height, name)

################################################################

# Display the state by drawing a cat at that x coordinate
myimage = dw.loadImage("target.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[2]))


################################################################

# Change pos by delta-pos, leaving delta-pos unchanged
# Note that pos is accessed as state[0], and delta-pos
# as state[1]. Later on we'll see how to access state
示例#29
0
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
# first (fst) and second (snd) to extract fields from tuples.
# We then saw that the *record* construct enabled us to define
# tuple types with *named* fields. The compiler then provided
# projection functions with the names of the fields, making it
# much easier to write code where the intended interpretation
# is clarified by the use of meaningful field names.
示例#30
0
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
# first (fst) and second (snd) to extract fields from tuples.
# We then saw that the *record* construct enabled us to define
# tuple types with *named* fields. The compiler then provided
# projection functions with the names of the fields, making it
# much easier to write code where the intended interpretation
# is clarified by the use of meaningful field names.
示例#31
0
#
# 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]))


################################################################

# Change pos by delta-pos, leaving delta-pos unchanged
# Note that pos is accessed as state[0], and delta-pos
# as state[1]. Later on we'll see how to access state
示例#32
0
#
def handleEvent(state, event):  
#    print("Handling event: " + str(event))
    if (event.type == pg.MOUSEBUTTONDOWN):
        state.img_w1_.change_direction(0)
        state.img_w2_.change_direction(1)
        
        
        return(aniState(state.img_w1_, state.img_w2_))
    else:
        return(state)

################################################################

# World state will be single x coordinate at left edge of world

# The cat starts at the left, moving right 
initState = aniState( image_wrapper(dw.loadImage("cat.bmp"),
                                    randint(100,400), randint(100,400),
                                    randint(-2,2), randint(-2,2)),
                      image_wrapper(dw.loadImage("rotunda.jpg"),
                                    randint(100,400), randint(100,400),
                                    randint(-2,2), randint(-2,2)))

# Run the simulation no faster than 60 frames per second
frameRate = 60

# Run the simulation!
rw.runWorld(initState, updateDisplay, updateState, handleEvent,
            endState, frameRate)
示例#33
0
# or the right edge of the screen.

################################################################

# Initialize world
name = "Cat Fun. Press the mouse (but not too fast)!"
width = 500
height = 500
fig = 20
tiffany = (66,199,249)
rw.newDisplay(width, height, name)

################################################################

# Display the state by drawing a cat at that x coordinate
myimage = dw.loadImage("cat.bmp")
myfish= dw.loadImage("Fish.bmp")
myacpnt = dw.loadImage("circle.bmp")
inst_line1 = "When the cat catches the fish, you win!"
inst_line2 = "Every time the cat reaches one of the points, it would accelerate."
inst_line3 = "When the cat reaches the lower and upper bounds, it will bounce back."
inst_line4 = "When the cat touches the left and right sides, it will die and the game is over."
inst_line5 = "Click the mouse and get start. Enjoy!"
mylabel0 = dw.makeLabel("Instructions:","serif",24,dw.black)
mylabel1 = dw.makeLabel(inst_line1,"serif",12,dw.black)
mylabel2 = dw.makeLabel(inst_line2,"serif",12,dw.black)
mylabel3 = dw.makeLabel(inst_line3,"serif",12,dw.black)
mylabel4 = dw.makeLabel(inst_line4,"serif",12,dw.black)
mylabel5 = dw.makeLabel(inst_line5,"serif",12,dw.black)
firstdisp = True
示例#34
0
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("cat.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
# first (fst) and second (snd) to extract fields from tuples.
# We then saw that the *record* construct enabled us to define
# tuple types with *named* fields. The compiler then provided
# projection functions with the names of the fields, making it
# much easier to write code where the intended interpretation
# is clarified by the use of meaningful field names.
#
# Team Wyatt and Friends is comprised of Matthew Boustany, Catherine
# Jin, and Simon Whittle (there is no Wyatt, we are just the friends).

################################################################

# Initialize world
name = "!~SMACK~!"
width = 1200
height = 800
rw.newDisplay(width, height, name)

################################################################

# Display the state by drawing two torsos with arms.
rightTorso = dw.loadImage("T_R.png")
rightHigh = dw.loadImage("R_H.png")  # -150, +255
rightLow = dw.loadImage("R_L.png")  # -150, -100

leftTorso = dw.loadImage("T_L.png")
leftHigh = dw.loadImage("L_H.png")  # 200, +225
leftLow = dw.loadImage("L_L.png")  # 200, -100


def updateDisplay(state):
    dw.fill(dw.black)
    if (state[4] == 1):  # if state sub 4 is 1, draw left arm up
        dw.draw(leftHigh, (state[0] + 200, state[1] - 100))
    else:  # else draw left arm down
        dw.draw(leftLow, (state[0] + 200, state[1] + 225))
    if (state[5] == 1):  # if state sub 5 is 1, draw right arm up
示例#36
0
# you can help it win if it is losing by clicking and changing
# the velocities

################################################################

# Initialize world
name = "Car Race! Press the mouse to help your car win!"
width = 800
height = 300
rw.newDisplay(width, height, name)

################################################################

#loads the two car images

myimage1 = dw.loadImage("racecar2.jpg")
myimage2 = dw.loadImage("blackcar.jpg")


def updateDisplay(state):
    dw.fill(dw.white)
    dw.draw(myimage1, (car1.xpos,car1.ypos))
    dw.draw(myimage2, (car2.xpos,car2.ypos))



################################################################

# defines the movement of the two cars using two tuples of (x,dx,y,dy).
# also defines the change in direction caused by bouncing of the top and bottom.
################################################################


################################################################

# Initialize world
name = "Click to Move! Get the Cheese! Avoid the Cat!"
width = 500
height = 500
rw.newDisplay(width, height, name)

################################################################


# Display the state by drawing a cat at that x coordinate
myimage = dw.loadImage("level1.jpeg")
myimage2 = dw.loadImage("level2.jpeg")
myimage3 = dw.loadImage("level3.jpeg")
myimage4 = dw.loadImage("level4.jpeg")
myimage5 = dw.loadImage("level5.jpeg")
mymouse = dw.loadImage("mouse.jpeg")
mycheese = dw.loadImage("cheese.jpeg")

# state -> image (IO)

def updateDisplay(state):
    dw.fill(dw.black)
    dw.draw(myimage, (state[0], state[2]))
    dw.draw(mymouse, (state[4], state[6]))
    dw.draw(mycheese,(state[8],state[9]))
    dw.draw(myimage2, (state[10],state[12]))