Beispiel #1
0
def parse_tileset_images(elem, base_dir):
    spacing = int(elem.get('spacing') or 0)
    margin = int(elem.get('margin') or 0)
    tile_width = int(elem.get('tilewidth'))
    tile_height = int(elem.get('tileheight'))
    image = None
    for child in elem:
        if child.tag == 'image':
            filename = child.get('source')
            image = bacon.Image(os.path.join(base_dir, filename))

    images = []
    for y in range(margin, image.height - margin, spacing + tile_height):
        for x in range(margin, image.width - margin, spacing + tile_width):
            images.append(
                image.get_region(x, y, x + tile_width, y + tile_height))

    return images
Beispiel #2
0
import bacon

kitten = bacon.Image('res/kitten.png')


class Game(bacon.Game):
    def on_tick(self):
        bacon.clear(0, 0, 0, 1)
        x, y = bacon.mouse.x, bacon.mouse.y
        bacon.draw_image_region(kitten, x - 50, y - 50, x + 50, y + 50, x - 50,
                                y - 50, x + 50, y + 50)


bacon.run(Game())
Beispiel #3
0
import bacon
import math

moon_image = bacon.Image('res/moon.png', atlas=0)

shader = bacon.Shader(vertex_source="""
    precision highp float;
    attribute vec3 a_Position;
    attribute vec2 a_TexCoord0;
    attribute vec4 a_Color;

    varying vec2 v_TexCoord0;
    varying vec4 v_Color;
    varying vec2 v_Position;

    uniform mat4 g_Projection;

    void main()
    {
        gl_Position = g_Projection * vec4(a_Position, 1.0);
        v_TexCoord0 = a_TexCoord0;
        v_Color = a_Color;
        v_Position = a_Position.xy;
    }
    """,
                      fragment_source="""
    precision highp float;
    
    uniform sampler2D g_Texture0;
    uniform vec2 center;
    uniform float radius;
Beispiel #4
0
 def __init__(self, image, x=0, y=0, angle=0):
     self.image = bacon.Image(image)
     self.x = x
     self.y = y
     self.angle = angle
Beispiel #5
0
import bacon

font = bacon.Font('res/DejaVuSans.ttf', 48)

# The offscreen texture must be created in a separate atlas to the glyphs
# which will be drawn into it.  By specifying atlas=0, we disable atlasing
# for the image entirely.
offscreen = bacon.Image(width=128, height=128, atlas=0)


class Game(bacon.Game):
    def draw_scene(self):
        # Draw some overlapping letters
        bacon.draw_string(font, 'ABC', 0, 50)
        bacon.draw_string(font, 'abc', 20, 50)

    def on_tick(self):
        bacon.clear(0.3, 0.3, 0.3, 1)

        # Here the scene is drawn directly to the window,
        # and where the letters overlap there is double-blending.
        bacon.set_color(0.5, 0.5, 0.5, 0.5)
        self.draw_scene()

        # This time we render the scene to an image first
        bacon.push_target(offscreen)
        bacon.clear(0, 0, 0, 0)
        bacon.set_color(1, 1, 1, 1)
        self.draw_scene()
        bacon.pop_target()
Beispiel #6
0
import bacon
import math

ball_linear = bacon.Image('res/ball.png')
ball_nearest = bacon.Image('res/ball.png', sample_nearest=True)

bacon.window.width = 512
bacon.window.height = 512

class Game(bacon.Game):
    def on_tick(self):
        bacon.clear(0, 0, 0, 1)
        bacon.draw_image(ball_linear, 0, 0, 256, 256)
        bacon.draw_image(ball_nearest, 256, 0, 512, 256)
bacon.run(Game())
Beispiel #7
0
import bacon
import math

kitten = bacon.Image('res/kitten.png', wrap=True)


class Game(bacon.Game):
    def on_tick(self):
        bacon.clear(0, 0, 0, 1)
        bacon.draw_image_region(kitten, 0, 0, bacon.window.width,
                                bacon.window.height, 0, 0, bacon.window.width,
                                bacon.window.height)


bacon.run(Game())
Beispiel #8
0
import os
import random
import sys

import logging
logging.basicConfig(level=logging.INFO)

import bacon
import random

font = bacon.Font('res/DejaVuSans.ttf', 64)
ball_image = bacon.Image('res/ball.png')
ball_sound = bacon.Sound('res/ball.wav')

music = bacon.Voice(bacon.Sound('res/PowerChorus2.ogg', stream=True),
                    loop=True)
music.gain = 0.3
music.play()

bacon.window.resizable = True
bacon.window.title = 'Bouncing Balls'


class Ball(object):
    width = ball_image.width
    height = ball_image.height

    def __init__(self):
        self.x = random.random() * (bacon.window.width - self.width)
        self.y = random.random() * (bacon.window.height - self.height)
Beispiel #9
0
import bacon

bacon.window.resizable = True
bacon.window.width = 512
bacon.window.height = 512
bacon.window.target = bacon.Image(width=512, height=512, atlas=0)

font = bacon.Font(None, 16)


class Game(bacon.Game):
    def on_tick(self):
        bacon.clear(0.2, 0.2, 0.2, 1.0)
        bacon.draw_string(
            font,
            'Window target dimensions are fixed to 512x512 but window is resizable; press "f" for fullscreen',
            x=0,
            y=0,
            width=512,
            height=512,
            align=bacon.Alignment.center,
            vertical_align=bacon.VerticalAlignment.center)

    def on_key(self, key, pressed):
        if key == bacon.Keys.f and pressed:
            bacon.window.fullscreen = not bacon.window.fullscreen


bacon.run(Game())
Beispiel #10
0
                 bank=False,
                 cargo=False,
                 merchant=False,
                 destination=False):
        self.refuel = refuel
        self.bank = bank
        self.cargo = cargo
        self.merchant = merchant
        self.destination = destination


window = game_function()  # create instance of window class

fuel_cost = 21  # sets cost per unit of fuel for vehicle
#game images
title = bacon.Image('Galaxy.jpg')
background = bacon.Image('backdrop3.jpg')
star = bacon.Image('star3.png')
target = bacon.Image('pin72.png')
battery = bacon.Image('greenbattery.png')
market = bacon.Image('greenmarket.png')
depart = bacon.Image('greenrocket.png')
money = bacon.Image('greenbank.png')
cargo = bacon.Image('greencargo.png')
triangle = bacon.Image('triangle.png')
robot = bacon.Image('cargorobot.png')
redrocket = bacon.Image('redrocket.png')
ship1 = bacon.Image('dauntless.png')
ship2 = bacon.Image('firefly.png')
ship3 = bacon.Image('excelsior.png')
ship4 = bacon.Image('defiant.png')
 def __init__(self, img):
     # loads the image
     self.image = bacon.Image(img)
Beispiel #12
0
	def __init__(self, img, x = 0, y = 0):
		# loads the image
		super(BaconSprite, self).__init__()
		self.image = bacon.Image(img)
		self.x = x
		self.y = y