public Facebuttons(Everybodyloveskimchi g, String n) { this.game = g; this.assignedname = n; texture = new Texture(Gdx.files.internal("faceicons/" + n + ".png")); this.renderer = new SkeletonRenderer(); renderer.setPremultipliedAlpha(true); this.atlas = new TextureAtlas(Gdx.files.internal("foodx.atlas")); SkeletonJson json = new SkeletonJson((TextureAtlas) atlas); json.setScale(0.7f); SkeletonData skeletonData = json.readSkeletonData(Gdx.files.internal("foodx.json")); skeleton = new Skeleton(skeletonData); skeleton.setPosition(0, 0); skeleton.getRootBone().setScale(0.6f); AnimationStateData stateData = new AnimationStateData(skeletonData); state = new AnimationState(stateData); state.setTimeScale(0.5f); state.setAnimation(0, "idle", false); setAg(); this.setBounds(0, 0, 98f, 106f); this.addListener( new InputListener() { @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { if (enabled) { System.out.println(assignedname + "down"); clickedY = -5f; game.members.get(assignedname).foodtoeat = game.currentFood; game.sendMemeber(assignedname); // clickedY // moveTo(0f,100f,10); // } return true; } @Override public void touchUp(InputEvent event, float x, float y, int pointer, int button) { if (enabled) { System.out.println(assignedname + "up"); clickedY = 0f; // trip(); } } }); }
void loadSkeleton(final FileHandle skeletonFile) { if (skeletonFile == null) return; try { // Setup a texture atlas that uses a white image for images not found in the atlas. Pixmap pixmap = new Pixmap(32, 32, Format.RGBA8888); pixmap.setColor(new Color(1, 1, 1, 0.33f)); pixmap.fill(); final AtlasRegion fake = new AtlasRegion(new Texture(pixmap), 0, 0, 32, 32); pixmap.dispose(); String atlasFileName = skeletonFile.nameWithoutExtension(); if (atlasFileName.endsWith(".json")) atlasFileName = new FileHandle(atlasFileName).nameWithoutExtension(); FileHandle atlasFile = skeletonFile.sibling(atlasFileName + ".atlas"); if (!atlasFile.exists()) atlasFile = skeletonFile.sibling(atlasFileName + ".atlas.txt"); TextureAtlasData data = !atlasFile.exists() ? null : new TextureAtlasData(atlasFile, atlasFile.parent(), false); TextureAtlas atlas = new TextureAtlas(data) { public AtlasRegion findRegion(String name) { AtlasRegion region = super.findRegion(name); if (region == null) { // Look for separate image file. FileHandle file = skeletonFile.sibling(name + ".png"); if (file.exists()) { Texture texture = new Texture(file); texture.setFilter(TextureFilter.Linear, TextureFilter.Linear); region = new AtlasRegion(texture, 0, 0, texture.getWidth(), texture.getHeight()); region.name = name; } } return region != null ? region : fake; } }; // Load skeleton data. String extension = skeletonFile.extension(); if (extension.equalsIgnoreCase("json") || extension.equalsIgnoreCase("txt")) { SkeletonJson json = new SkeletonJson(atlas); json.setScale(ui.scaleSlider.getValue()); skeletonData = json.readSkeletonData(skeletonFile); } else { SkeletonBinary binary = new SkeletonBinary(atlas); binary.setScale(ui.scaleSlider.getValue()); skeletonData = binary.readSkeletonData(skeletonFile); if (skeletonData.getBones().size == 0) throw new Exception("No bones in skeleton data."); } } catch (Exception ex) { ex.printStackTrace(); ui.toast("Error loading skeleton: " + skeletonFile.name()); lastModifiedCheck = 5; return; } skeleton = new Skeleton(skeletonData); skeleton.setToSetupPose(); skeleton = new Skeleton(skeleton); // Tests copy constructors. skeleton.updateWorldTransform(); state = new AnimationState(new AnimationStateData(skeletonData)); state.addListener( new AnimationStateAdapter() { public void event(TrackEntry entry, Event event) { ui.toast(event.getData().getName()); } }); this.skeletonFile = skeletonFile; prefs.putString("lastFile", skeletonFile.path()); prefs.flush(); lastModified = skeletonFile.lastModified(); lastModifiedCheck = checkModifiedInterval; // Populate UI. ui.window.getTitleLabel().setText(skeletonFile.name()); { Array<String> items = new Array(); for (Skin skin : skeletonData.getSkins()) items.add(skin.getName()); ui.skinList.setItems(items); } { Array<String> items = new Array(); for (Animation animation : skeletonData.getAnimations()) items.add(animation.getName()); ui.animationList.setItems(items); } ui.trackButtons.getButtons().first().setChecked(true); // Configure skeleton from UI. if (ui.skinList.getSelected() != null) skeleton.setSkin(ui.skinList.getSelected()); setAnimation(); // ui.animationList.clearListeners(); // state.setAnimation(0, "walk", true); }
public Gamescreen(Jamwteatrze game) { this.game = game; // set game state currentState = GameState.TITLE; // currentState = GameState.MAP; // currentState = GameState.ARENA; batch = new SpriteBatch(); camera = new OrthographicCamera(1280, 720); camera.position.set(camera.viewportWidth / 2f, camera.viewportHeight / 2f, 0); viewport = new FitViewport(1280, 720, camera); camera.update(); // spine sr = new SkeletonRenderer(); dr = new SkeletonRendererDebug(); dr.setBoundingBoxes(false); dr.setRegionAttachments(false); // stage stage = new Stage(viewport, batch); stageCharacters = new Stage(viewport, batch); Gdx.input.setInputProcessor(stage); // ----------------- DEKLARACJE playerIcon = new SpineActor(batch, sr, shpr, "characters/goral", true, game.player.playerHp); playerIcon.setPosition(-400, 180); stageCharacters.addActor(playerIcon); generujEnemys(); // atakuj button atakujTex = Assets.manager.get(Assets.atakuj, Texture.class); atakujTex.setFilter(TextureFilter.Linear, TextureFilter.Linear); atakujButton = new ImageButton(new SpriteDrawable(new Sprite(atakujTex))); atakujButton.setPosition(565, -200); atakujButton.addListener( new InputListener() { public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { if (pulaGracza > 0 && !atakowanie) { atakowanie = true; System.out.println("atakuj button pressed"); atakuj(); } return true; } }); stage.addActor(atakujButton); // gui font = Assets.manager.get(Assets.myFont, BitmapFont.class); font.getData().setScale(0.7f); font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear); scena = Assets.manager.get(Assets.scena, Texture.class); scena.setFilter(TextureFilter.Linear, TextureFilter.Linear); panel = Assets.manager.get(Assets.panel, Texture.class); panel.setFilter(TextureFilter.Linear, TextureFilter.Linear); // tla swiat00tlo = Assets.manager.get(Assets.swiat00tlo, Texture.class); swiat00tlo.setFilter(TextureFilter.Linear, TextureFilter.Linear); swiat01tlo = Assets.manager.get(Assets.swiat01tlo, Texture.class); swiat01tlo.setFilter(TextureFilter.Linear, TextureFilter.Linear); swiat02tlo = Assets.manager.get(Assets.swiat02tlo, Texture.class); swiat02tlo.setFilter(TextureFilter.Linear, TextureFilter.Linear); swiat03tlo = Assets.manager.get(Assets.swiat03tlo, Texture.class); swiat03tlo.setFilter(TextureFilter.Linear, TextureFilter.Linear); kowadloTex = Assets.manager.get(Assets.kowadloTex, Texture.class); kowadloTex.setFilter(TextureFilter.Linear, TextureFilter.Linear); // kowadlo = new Sprite(kowadloTex); // kowadlo.setPosition(100, 100); // DICES heroDices = new Array<Dice>(); enemyDices = new Array<Dice>(); // ------ generate hero dieces heroDices.add(new Dice(this, true)); heroDices.add(new Dice(this, true)); // heroDices.add(new Dice(this)); numberHeroDieces = heroDices.size; baseHeroDieces = numberHeroDieces; for (Dice dice : heroDices) { // dice.debug(); dice.setTouchable(Touchable.disabled); dice.setVisible(false); stage.addActor(dice); } // ------ generate enemy dieces enemyDices.add(new Dice(this, false)); enemyDices.add(new Dice(this, false)); numberEnemyDieces = enemyDices.size; baseEnemyDieces = numberEnemyDieces; for (int i = 0; i < enemyDices.size; i++) { enemyDices.get(i).setPosition(725 + (i * 133), -150); if (!heroTurn) { enemyDices.get(i).addAction(moveTo(725 + (i * 133), 37, 1.0f, Interpolation.bounceOut)); } } for (Dice dice : enemyDices) { // dice.debug(); stage.addActor(dice); } // kotara kotaraAtlas = new TextureAtlas(Gdx.files.internal("gui/kotara.atlas")); kotaraJson = new SkeletonJson(kotaraAtlas); kotaraSkeletonData = kotaraJson.readSkeletonData(Gdx.files.internal("gui/kotara.json")); kotaraSkeleton = new Skeleton(kotaraSkeletonData); kotaraIdleAnimation = kotaraSkeletonData.findAnimation("idle"); AnimationStateData stateData = new AnimationStateData(kotaraSkeletonData); kotaraState = new AnimationState(stateData); kotaraState.addAnimation(0, "idle", true, 0); kotaraSkeleton.setPosition(-200, -150); // title title = new SpineButton(batch, sr, "gui/title", "idle", 100, 0, 800, 600); // title.debug(); title.setClicked(false); if (currentState == GameState.TITLE) { resetTitle(); } // title listeners title.addListener( new InputListener() { public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { if (!title.isClicked() && title.getY() <= 20) { title.setClicked(true); fadeOutTitle(Gdx.graphics.getDeltaTime()); } return true; } }); stage.addActor(title); // mapa mapa = new SpineButton(batch, sr, "gui/mapa", "show0", 100, 0, 800, 600); mapa.setPosition(mapaX, -900); // mapa.debug(); mapa.setClicked(false); // mapa listeners TODO! mapa.addListener( new InputListener() { public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { fadeOutMapa(Gdx.graphics.getDeltaTime()); return true; } }); stage.addActor(mapa); // if (currentState == GameState.ARENA) { // resetArena(); // } }