Ejemplo n.º 1
0
	def __init__(self, width=640, height=480):
		'''
		Description: The main controller class that handles the images
		Parameters: self, width, height - self is the default class parameter, width is the screen width, height is the screen height
		Return:none
		'''
		pygame.init()
		self.width = width
		self.height = height
		self.screen = pygame.display.set_mode((self.width,self.height))
		self.background = pygame.Surface(self.screen.get_size()).convert()
		self.textfont = pygame.font.SysFont("helvetica", 15)
		self.titlefont = pygame.font.SysFont("helvetica", 90)
		self.startRect = pygame.Rect(180,320,80,30)
		self.quitRect = pygame.Rect(380,320,80,30)
		self.cannon = cannon.Cannon(0, 420, "cannon.jpg")
		self.castle = castle.Castle(450, 310, "castle.png")
		self.rock = rock.Rock(105,420, "rocky.jpg")
		self.castlerect = self.castle.rect
		self.cannonSprite = pygame.sprite.Group(self.cannon) ##Used for drawing the cannon sprite
		self.castleSprite = pygame.sprite.Group(self.castle) ##Used for drawing the castle sprite
		self.rockSprite = pygame.sprite.Group(self.rock) ##Used for drawing the rock sprite
		self.shot = 0
		self.angle = 0
		self.velocity = 0
		self.ixvelocity =0
		self.iyvelocity = 0
		self.rocktime = 0
		self.bullets = 5
Ejemplo n.º 2
0
    def __init__(self, width, height):
        self.width = width
        self.height = height

        self.bullet = bullet.Bullet(self.width / 2, self.height / 2,
                                    self.width, self.height)

        self.cannon = cannon.Cannon(self.width, self.height, self.width / 2,
                                    self.height / 2)

        self.wall = wall.Wall(self.width, self.height, self.width / 2,
                              self.height / 2)
Ejemplo n.º 3
0
def handle_events():
    global curCannonPrepareTime
    events = get_events()
    for event in events:
        spearRespawnButton.handleEvent(event, coin)
        axeRespawnButton.handleEvent(event, coin)
        swordRespawnButton.handleEvent(event, coin)
        if event.type == SDL_QUIT:
            gameFramework.running = False
        elif event.type == SDL_MOUSEMOTION:
            camera.handleEvent(event.x)
        elif event.type == SDL_KEYDOWN:
            if event.key == SDLK_ESCAPE:
                gameFramework.change_state(titleState)
            elif event.key == SDLK_SPACE:
                if curCannonPrepareTime <= 0.0:
                    for i in range(4):
                        worldObjManager.addObject(cannon.Cannon(), 3)
                    curCannonPrepareTime = cannonPrepareTime
Ejemplo n.º 4
0
def enter():
    global allyBase, enemyBase
    global coin, spearRespawnButton, axeRespawnButton, swordRespawnButton
    global font
    global oldScroll
    worldObjManager.deleteAllObjects()
    camera.enter()
    tempCannon = cannon.Cannon()
    del (tempCannon)
    # fourth type is base type True: ally
    allyBase = AllyBase("base\\allyBase.png", 200, 150)
    enemyBase = EnemyBase("base\\enemyBase.png",
                          camera.backgroundImage.w - 200, 150)

    coin = GUI.Coin()
    spearRespawnButton = GUI.SpearmanRespawnButton()
    axeRespawnButton = GUI.AxemanRespawnButton()
    swordRespawnButton = GUI.SwordmanRespawnButton()
    worldObjManager.addObject(allyBase, 0)
    worldObjManager.addObject(enemyBase, 0)
    oldScroll = GUI.OldScroll()
    font = load_font('textfile\\Sofija.TTF', 25)
Ejemplo n.º 5
0
    def __init__(self, _color, _width, _height):
        print("Creating new Tank...")

        super().__init__()

        self.image = pygame.Surface([_width, _height])
        self.image.fill(_color)

        self.rect = self.image.get_rect()

        self.myHealthBar = healthBar.HealthBar()
        self.myHealthBar.setPos(2, 2)

        self.myBombBar = bombBar.BombBar()
        self.myBombBar.setPos(2, 10)

        self.myFuelBar = fuelBar.FuelBar()
        self.myFuelBar.setPos(2, 20)

        self.myChargeBar = chargeBar.ChargeBar()

        self.myCannon = cannon.Cannon(_color, (10, 2))

        self.active_group = pygame.sprite.Group()
Ejemplo n.º 6
0
from levels import Level
import pymunk as pm
import math
import physics
from pig import Pig
import cannon

# Init
pygame.init()
window = pygame.display.set_mode((contants.WIDTH, contants.HEIGHT))
clock = pygame.time.Clock()

Background = background.Background("images\\background.png")
SlingShot = slingShot.SlingShot()
Physics = physics.Physics()
Cannon = cannon.Cannon()

Running = True

ParabolaList = []

birds = []
pigs = []
redbird = pygame.image.load("images\\red-bird3.png").convert_alpha()
pigImage = pygame.image.load("images\\rsz_pig_failed.png").convert_alpha()

space = pm.Space()
space.gravity = (0.0, -982)

physics.Polygon.create_ground(space)
Ejemplo n.º 7
0
    screen_width = 500
    screen_height = 150
    screen = pygame.display.set_mode((screen_width,screen_height))
    screen.fill(BLACK)
    canPlay = True
    clock = pygame.time.Clock()

    myHealthBar = healthBar.HealthBar()
    myBombBar = bombBar.BombBar()
    myFuelBar = fuelBar.FuelBar()
    myChargeBar = chargeBar.ChargeBar()
    myChargeBar.addHealthCharge()
    myChargeBar.addBombCharge()
    myChargeBar.addFuelCharge()

    myCannon = cannon.Cannon(GREEN, (10,2))
    myCannon.setPos(100,100)

    group = pygame.sprite.Group()
    group.add(myCannon)
    
    myHealthBar.setPos(2,2)
    myBombBar.setPos(2,10)
    myFuelBar.setPos(2,20)
    hasShoot = False

    while canPlay:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                canPlay = False
            elif event.type == pygame.KEYDOWN:
Ejemplo n.º 8
0
                    trigLoop = gameFileIO.drawLeaderboard(
                        ldrSurf, screen, ldrEl, heading)
                    if trigLoop:
                        ldrBoardSetup = False
                        menuLoop = mainMenu

    if activeLoop == game:

        if gameSetup == False:
            gameData[0] += 1
            gameSurf = pygame.Surface(size)
            hudElements = hud.createHUD(gameData, gameSurf, size)

            # Create Objects and Object containers

            cann = cannon.Cannon(size, gameSurf)
            collisions = []
            groundImpacts = [
            ]  #    track seperately to allow seperate animations
            asteroids = []
            startDayFrame = frameTag

            # load assets
            background = pygame.image.load("assets/gameBackground.png")

            score = 0  # right now score is reset, will change when load game feature implemented
            oldScore = 0
            gameSetup = True
            betweenDays = False

            try:
Ejemplo n.º 9
0
import camera
import cannon
import numpy as np
import time

dart_cannon = cannon.Cannon()
cam = camera.CameraTracker(
    0, np.matrix([[700., 0., 640. / 2.], [0., 700., 480 / 2.], [0., 0., 1.]]))

pan, tilt, _ = cam.wait_for_event()
print "Pan: {}, tilt: {}".format(np.rad2deg(pan), np.rad2deg(tilt))
dart_cannon.set_pan_tilt(np.rad2deg(pan), 0.)
time.sleep(0.25)
dart_cannon.fire()
Ejemplo n.º 10
0
import numpy as np
import random
import time
import cv2
import math
import cannon as cn

if __name__ == "__main__":
    #creates a bunch of jpgs that can be made into a git     
    k = cn.Cannon()
    img = np.zeros([28,28,3])
    length = 20
    x, y = k.generate_28x28(1, length)
    for i in xrange(length/2):
        img[:,:,0] = x[0,i*2,:].reshape(28,28)
        img[:,:,1] = x[0,i*2,:].reshape(28,28)
        img[:,:,2] = x[0,i*2,:].reshape(28,28)
        cv2.imwrite(str(i).zfill(3) + '.jpg', img*255)
        cv2.imshow('image', img)
        cv2.waitKey(0)
    cv2.destroyAllWindows()