def __init__(self, *args, **kargs): kargs["size"] = (250, 250) kargs["position"] = (0, 0) super().__init__(Texture('resorces/dpad.PNG'), *args, **kargs) self.anchor_point = (0, 0) self.alpha = 0.95 self.middle = SpriteNode(Texture('resorces/dstick.PNG'), position=self.size / 2, size=(50, 50), parent=self) self.middle.alpha = 0.9 self.value = Vector2(0, 0)
def __init__(self, debug=False): self.path = 'resorces/' if debug: self.blocks = Texture(self.path + 'BLOCKS.PNG') else: self.blocks = Texture(self.path + 'IMG_4287.PNG') self.block = [] for x in range(16): for y in range(16): self.block.append( self.blocks.subtexture(((y / 16), 1 - ((x + 1) / 16), 1 / 16, 1 / 16))) self.block[-1].filtering_mode = 1
def __init__(self): super(Scene, self).__init__() lights = self.make_example_light() lights.add_diffuse(Vector3(0, 1, 0), Vector3(0, 0, 1)) def tex_color(x): X = 0.3 if (x.x % (X * 2)) < X != (x.y % (X * 2)) < X: return Vector3(0, 0, 1) else: return Vector3(1, 1, 1) img = Image.load('linux.jpg') tex_img = Texture(img, Vector2(2, -2)) d = 50 S = 13 self.objects += self.make_tetrahedron( lights, Vector3(-2, -3, d), Vector3(2, -3, d), Vector3(0, -3, d - S * 2), Vector3(0, 2, d - S), texture=tex_img, ) self.objects += [Sphere(lights, Vector3(0.5, 0, 29), 0.3)]
class datafiles: def __init__(self, debug=False): self.path = 'resorces/' if debug: self.blocks = Texture(self.path + 'BLOCKS.PNG') else: self.blocks = Texture(self.path + 'IMG_4287.PNG') self.block = [] for x in range(16): for y in range(16): self.block.append( self.blocks.subtexture(((y / 16), 1 - ((x + 1) / 16), 1 / 16, 1 / 16))) self.block[-1].filtering_mode = 1 def get_values(self, name): my_list = [] with open(self.path + name, 'r') as f: for i in f.readlines(): my_list.append(float(i)) return my_list def get(self, file): with open(self.path + file, 'r') as data: return data.read()
def pil2texture(pil_imgs): texture_imgs = [] for pil_img in pil_imgs: with io.BytesIO() as buffer: pil_img.save(buffer, format='PNG') texture_img = Texture(ui.Image.from_data(buffer.getvalue())) img_size = texture_img.size texture_imgs.append((texture_img, img_size)) return texture_imgs
def __init__(self, *args, **kargs): super().__init__(*args, **kargs, num=(10, 1)) self.select = SpriteNode(Texture('emj:Anger_Symbol'), position=(0, 0), size=(75, 69), parent=self) self.select.anchor_point = (0, 0) self.select.alpha = 0.95 self.select.position = (self.BW, self.BW) self.holding = 0
def __init__(self, caller, msg, img): Scene.__init__(self) self.msg = msg self.caller = caller self.img = SpriteNode(Texture(img))
from scene import Scene, Texture, SpriteNode, Vector2 MISSING_TEXTURE = Texture('assets/textures/missing_texture.png') GRAVITY = -9.8 / 1000 # Acceleration of gravity RAM_VEL = 0.2 # Velocity required to break tiles class Entity(SpriteNode): """Base class. Is not used by itself""" def __init__(self, game, pos, size): self.game = game self.size = size self.anchor_point = (0, 0) self.texture = MISSING_TEXTURE self.set_position(pos) game.add_child(self) self.pos = pos self.vel = Vector2(0, 0) self.acc = Vector2(0, 0) self.gravity = False self.tiles = [] # Used to check tiles for collision self.setup() def setup(self): pass def update(self): self.acc = Vector2(0, 0)
def setup(self): print("setup") #self.bace = self self.zize = (1, 1) self.bace = Node(parent=self, position=(0, 0)) self.bace.size = Vector2(1024, 768) self.tsize = Vector2(1024, 768) self.zize = Vector2(self.size[0] / 1024, self.size[1] / 768) self.bace.x_scale = self.size[0] / 1024 self.bace.y_scale = self.size[1] / 768 self.tiles = tile_shader.TileShader(parent=self.bace, data=self.data) self.data.player.newplayer() self.hotbar = inputs.HotBar(self.datafiles, self.data, self.taps, parent=self.bace, position=(300, 14)) self.invintory = inputs.ItemMenu(self.datafiles, self.data, self.taps, num=(9, 4), parent=self.bace, position=(300, 80), offset=10) self.hotbar.other = self.invintory self.invintory.other = self.hotbar self.ham = SpriteNode(Texture("iow:arrow_right_b_256"), parent=self.bace, position=self.hotbar.bbox.origin + self.hotbar.bbox.size) self.ham.anchor_point = (0.3, 0.75) self.ham.x_scale = 0.5 self.ham.y_scale = 0.5 self.invintory.anchor_point = (0, 0) self.select = SpriteNode(Texture('emj:Anger_Symbol'), position=(0, 0), size=(75, 69), parent=self.bace) self.select.anchor_point = (1, 0) self.select.alpha = 0.95 self.directionpad = inputs.DPad(parent=self.bace) self.cash = LabelNode(str(self.data.player.cash), position=(0, self.bace.size[1]), parent=self.bace) self.cash.anchor_point = (0, 1) self.player = SpriteNode(Texture('emj:Hamster_Face'), position=self.bace.size / 2, size=(20, 20), parent=self.bace) self.HOTBAR = self.taps.add(self.hotbar.bbox) self.INV = self.taps.add(self.invintory.bbox) self.DPAD = self.taps.add(self.directionpad.bbox) self.CASH = self.taps.add(self.cash.bbox) self.HAM = self.taps.add(self.ham.bbox, layer=2) self.invintory.tapid = self.INV self.taps.size = self.size self.taps.zize = self.tsize if self.init: self.setupinit = True if self.lan: self.data.loop() self.invintory.hide = True self.tiles._refresh()
from scene import Texture, gravity from entity import Entity ACC = -1 / 80 ENTITY_PLAYER = Texture('assets/textures/entity_player.png') class EntityPlayer(Entity): def setup(self): self.texture = ENTITY_PLAYER self.gravity = True def check_inputs(self): g = gravity() if abs(g.y) > 0.1: self.input = True self.acc.x += ACC * g.y
from scene import SpriteNode, ShapeNode, LabelNode, Action, Scene, Node, Rect, Point from dataclasses import dataclass from typing import ClassVar, List import time from functools import partial from scene import SpriteNode, ShapeNode, LabelNode, Action, Scene, Node, Rect, Point, Texture from urllib.request import urlopen FPS: float = 60 DEBUG = False #url = urlopen('https://pre00.deviantart.net/ba81/th/pre/f/2009/242/f/4/space_invaders_sprite_sheet_by_gooperblooper22.png') with open('space_invaders.png', 'rb') as f: img = ui.Image.from_data(f.read()) whole_sprite = Texture(img) taito_sprite = whole_sprite.subtexture(Rect(0.0, 0.837, 1, 0.163)) invader1 = whole_sprite.subtexture(Rect(0.0, 0.88, 0.05, 0.012)) invader2 = whole_sprite.subtexture(Rect(0.054, 0.88, 0.05, 0.012)) invader3 = whole_sprite.subtexture(Rect(0.112, 0.88, 0.05, 0.012)) invader4 = whole_sprite.subtexture(Rect(0.167, 0.88, 0.05, 0.012)) invader5 = whole_sprite.subtexture(Rect(0.232, 0.88, 0.05, 0.012)) invader6 = whole_sprite.subtexture(Rect(0.285, 0.88, 0.05, 0.012)) ufo = whole_sprite.subtexture(Rect(0.342, 0.88, 0.09, 0.012)) ship = whole_sprite.subtexture(Rect(0.445, 0.88, 0.05, 0.01)) shield1 = whole_sprite.subtexture(Rect(0.505, 0.88, 0.085, 0.019)) shield2 = whole_sprite.subtexture(Rect(0.598, 0.88, 0.085, 0.019)) shield3 = whole_sprite.subtexture(Rect(0.683, 0.88, 0.085, 0.019)) shield4 = whole_sprite.subtexture(Rect(0.77, 0.88, 0.085, 0.019)) shield5 = whole_sprite.subtexture(Rect(0.77, 0.853, 0.085, 0.019)) shield6 = whole_sprite.subtexture(Rect(0.575, 0.856, 0.085, 0.019))