Skip to content

Commit

Permalink
Tarefa do vomito(#65) implementada, agora quando ele come bala de lic…
Browse files Browse the repository at this point in the history
…or ele vomita no chao. Para isto eu criei um ActionState para quando ele comer a bala de licor, tambem criei a classe VomitSpriter.java referente ao vomito, e fiz as devidas alteracoes nas classes PetWord.java e PetAttributes.java referente ao vomito.
  • Loading branch information
geovanecomp authored and rfabbri committed Jun 22, 2015
1 parent ff7d92d commit 7bbf565
Show file tree
Hide file tree
Showing 5 changed files with 299 additions and 2 deletions.
2 changes: 1 addition & 1 deletion assets/src/main/resources/assets/pet/jsons/triggers.json
Expand Up @@ -27,7 +27,7 @@
"Modifiers": [{ "nutricao": -10, "humor": 20, "social": 0, "higiene": -10, "estudo": 0, "saude": 0, "alcool": 0, "disciplina": -5, "sexualidade": 5, "fe": 0, "intestino": 0 }],
"AgeStage" : [{ "BEBE": "unlock", "CRIANCA": "unlock", "ADOLESCENTE": "unlock", "ADULTO": "unlock", "MEIA_IDADE": "unlock", "TERCEIRA_IDADE": "unlock", "ANCIAO": "unlock" }]
},
{"name": "Bombom de Licor", "action": "COMENDO", "duration": 3,
{"name": "Bombom de Licor", "action": "COMENDO_BOMBOM_LICOR", "duration": 3,
"Modifiers": [{ "nutricao": 5, "humor": 5, "social": 0, "higiene": -5, "estudo": 0, "saude": -2, "alcool": 10, "disciplina": -2, "sexualidade": 0, "fe": 0, "intestino": 0 }],
"AgeStage" : [{ "BEBE": "unlock", "CRIANCA": "unlock", "ADOLESCENTE": "unlock", "ADULTO": "unlock", "MEIA_IDADE": "unlock", "TERCEIRA_IDADE": "unlock", "ANCIAO": "unlock" }]
},
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/com/pulapirata/core/Pet.java
Expand Up @@ -736,6 +736,9 @@ public void wireButtonsToWorld() {
continue;
final TriggerType t = trigg[b][s];
final int but = b;
System.out.println("Valorrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr de t:"+t);
pprint("Valorrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr de t:"+t);
dprint("Valorrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr de t:"+t);
secondaryButtons_.get(b).get(s).clicked().connect(new UnitSlot() {
public void onEmit() {
//a().triggers(SOPA_DE_CENOURA).fire(a).fireIfAllowed(a, CRIANCA); // TODO remover argumento redundante ou criar overload
Expand All @@ -752,6 +755,9 @@ public void onEmit() {
} else {
pprint("[button] buttons are blocked at night.");
}
/* if (t == VARRENDO){
//dprint("GOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO");
}*/
}
});

Expand Down
14 changes: 13 additions & 1 deletion core/src/main/java/com/pulapirata/core/PetAttributes.java
Expand Up @@ -153,6 +153,12 @@ public enum TipoCoco {
MOLE
}

public enum TipoVomito {
NORMAL,
AGUADO
//Algum outro pode ser adicionado aqui.
}

public enum TipoCelular {
NENHUM,
GENERICO,
Expand Down Expand Up @@ -181,6 +187,7 @@ public int index() {
}

public enum ActionState {
COMENDO_BOMBOM_LICOR,
DEFAULT,
VARRENDO,
JOGANDO_BOLA,
Expand Down Expand Up @@ -293,6 +300,8 @@ public enum ActionState {
public PetAttributeEnum<ActionState> sAction() { return sAction_; }
private PetAttributeEnum<TipoCoco> sCoco_ = new PetAttributeEnum<TipoCoco>();
public PetAttributeEnum<TipoCoco> sCoco() { return sCoco_; }
private PetAttributeEnum<TipoVomito> sVomito_ = new PetAttributeEnum<TipoVomito>();
public PetAttributeEnum<TipoVomito> sVomito() { return sVomito_; }
private PetAttributeEnum<TipoCelular> sCelular_ = new PetAttributeEnum<TipoCelular>();
public PetAttributeEnum<TipoCelular> sCelular() { return sCelular_; }
private PetAttributeEnum<AgeStage> sAge_ = new PetAttributeEnum<AgeStage>();
Expand Down Expand Up @@ -419,6 +428,7 @@ public PetAttributes() {
s2vis_.put(State.NORMAL, VisibleCondition.NORMAL);
s2vis_.put(State.ONONOONO, VisibleCondition.NORMAL);

a2vis_.put(ActionState.COMENDO_BOMBOM_LICOR, VisibleCondition.COMENDO); // tentando solucionar a tarefa do plinio por aqui
a2vis_.put(ActionState.DEFAULT, VisibleCondition.NORMAL);
a2vis_.put(ActionState.VARRENDO, VisibleCondition.VARRENDO);
a2vis_.put(ActionState.COMENDO, VisibleCondition.COMENDO);
Expand Down Expand Up @@ -474,6 +484,7 @@ public PetAttributes() {

sAction_.updateState(ActionState.DEFAULT);
sCoco_.updateState(TipoCoco.NORMAL);
sVomito_.updateState(TipoVomito.NORMAL); //TESTANDO
sCelular_.updateState(TipoCelular.NENHUM);
sAge_.updateState(AgeStage.BEBE);

Expand Down Expand Up @@ -662,7 +673,8 @@ public void print() {
for (String key : ms_.keySet())
ms_.get(key).print();
pprint("[sattr] ageStage: " + sAge().getState());
pprint("[sattr] coco: " + sCoco().getState());
pprint("[sattr] coco: " + sCoco().getState());
pprint("[sattr] vomito: " + sVomito().getState());
pprint("[sattr] celular: " + sCelular().getState());
pprint("[sattr] action: " + sAction().getState());
}
Expand Down
28 changes: 28 additions & 0 deletions core/src/main/java/com/pulapirata/core/PetWorld.java
Expand Up @@ -63,6 +63,7 @@
import com.pulapirata.core.sprites.Spriter;
import com.pulapirata.core.sprites.PetSpriter;
import com.pulapirata.core.sprites.DroppingSpriter;
import com.pulapirata.core.sprites.VomitSpriter;
import com.pulapirata.core.sprites.MosquitoSpriter;
import static com.pulapirata.core.utils.Puts.*;

Expand Down Expand Up @@ -427,6 +428,11 @@ private void clampxyPoly(Point p, float r) {
vel_.set(eid, v);
pprint("[banho] setting velocity " + v);
}
if (type_.get(eid) == PET && pet_.get(eid).sAction().getState() == PetAttributes.ActionState.COMENDO_BOMBOM_LICOR) {
createVomit(pos_.getX(eid)-20, pos_.getY(eid)+5, pet_.get(eid).sVomito().getState());
pprint(" bundaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
}

}

if (beat_ % 2 != 0) // sprite update rate
Expand Down Expand Up @@ -986,6 +992,28 @@ protected Entity createDropping(float x, float y, PetAttributes.TipoCoco shitTyp
return poo;
}

/**
* Creates a vomit sprite.
*/
protected Entity createVomit(float x, float y, PetAttributes.TipoVomito vomitType) {
Entity vomit = create(true);
vomit.add(type_, sprite_, opos_, pos_, radius_, expires_, loaded_);

int id = vomit.id;
type_.set(id, VOMIT);
opos_.set(id, x, y);
pos_.set(id, x, y);
vel_.set(id, 0, 0);
expires_.set(id, beat_ + (int)(3*beatsCoelhoHora_)); // the vomit can automatically expire after some time..
loaded_.set(id, NOT_LOADED);

VomitSpriter vs = new VomitSpriter();
sprite_.set(id, vs); // also queues sprite to be added by other systems on wasAdded()
vs.set(vomitType);

return vomit;
}

public void reset() {
Iterator<Entity> iter = entities();
while (iter.hasNext()) iter.next().destroy();
Expand Down
251 changes: 251 additions & 0 deletions core/src/main/java/com/pulapirata/core/sprites/VomitSpriter.java
@@ -0,0 +1,251 @@
/**
* Pet - a comic pet simulator game
* Copyright (C) 2013-2015 Ricardo Fabbri and Edson "Presto" Correa
*
* This program is free software. You can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. A different license may be requested
* to the copyright holders.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>
*
* NOTE: this file may contain code derived from the PlayN, Tripleplay, and
* React libraries, all (C) The PlayN Authors or Three Rings Design, Inc. The
* original PlayN is released under the Apache, Version 2.0 License, and
* TriplePlay and React have their licenses listed in COPYING-OOO. PlayN and
* Three Rings are NOT responsible for the changes found herein, but are
* thankfully acknowledged.
*/
package com.pulapirata.core.sprites;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.EnumMap;
import react.Slot;
import playn.core.GroupLayer;
import playn.core.ImageLayer;
import playn.core.PlayN;
import playn.core.util.Callback;
import static playn.core.PlayN.log;
import com.pulapirata.core.PetAttributes.TipoVomito;
import static com.pulapirata.core.PetAttributes.TipoVomito.*;
import static com.pulapirata.core.utils.Puts.*;

/**
* Class to manage sets of Pet sprite animations.
* PetSprite always refers to the same global game atlas.
* It is just like Sprite, but changes internal animation
* based on the set state.
* TODO: make commong parts between this and PetSpriter into common base class
* CompositeSpriter
*/
public class VomitSpriter extends Spriter {
// public static String IMAGE = "pet/sprites/atlas.png";
// public static String JSON = "pet/sprites/atlas.json";

private final String prefix = "pet/sprites/dejetos/";
private final ArrayList<String> images =
new ArrayList<String>(Arrays.asList(
"dejetos_vomito.png",
"dejetos_cocomole.png"
));

private final ArrayList<String> jsons =
new ArrayList<String>(Arrays.asList(
"dejetos_vomito.json",
"dejetos_cocomole.json"
));

/* Apenas sugestao, que assim como coco, pode haver tipos de vomitos (NORMAL, AGUADO, PEDAÇOS DE COMIDA ETC...) */
private final ArrayList<TipoVomito> vc =
new ArrayList<TipoVomito>(Arrays.asList(
NORMAL,
AGUADO
));

// all member animations(sprites) should have same atlas as source,
// as built in PetSpriteLoader.java, and also the same layer
private EnumMap<TipoVomito, Sprite> animMap_ = new EnumMap<TipoVomito, Sprite> (TipoVomito.class);
private Sprite currentSprite_; // the current sprite animation
private TipoVomito currentTipoVomito_ = NORMAL;
private int spriteIndex_ = 0;
private int numLoaded_ = 0; // set to num of animations when resources have loaded and we can update
private boolean traversed_ = false;
protected GroupLayer.Clipped animLayer_ = PlayN.graphics().createGroupLayer(0, 0);

/**
* Copy constructor for sharing resources with a another preallocated
* spriter.
*/
public VomitSpriter(VomitSpriter another) {
// this.animMap_ = another.animMap_;


// for (int i = 0; i < another.animLayer_.size(); ++i)
// this.animLayer_.add(another.animLayer_.get(i));

// this.set(NORMAL);
// maybe recreate animLayer?

// THE RIGHT WAY
// - for each sprite,
// - create a new sprite using copy constructor to reuse
// another.sprite's SpriteImage
// - we'll have a way of doing this for global atlases as well.
}

public VomitSpriter() {
for (int i = 0; i < jsons.size(); i++) {
String spriteFnames = prefix + images.get(i);
String jsonFnames = prefix + jsons.get(i);
printd("[vomitSpriter] Loading sprite file: " + spriteFnames + jsonFnames);
Sprite s = SpriteLoader.getSprite(spriteFnames, jsonFnames);
//System.out.println("sprite true? : " + sprite == null + "i : " + i + vc.size());
animMap_.put(vc.get(i), s);

// Add a callback for when the image loads.
// This is necessary because we can't use the width/height (to center the
// image) until after the image has been loaded
s.addCallback(new Callback<Sprite>() {
@Override
public void onSuccess(Sprite sprite) {
sprite.setSprite(0);
sprite.layer().setOrigin(0, 0);
sprite.layer().setTranslation(0, 0);
sprite.layer().setVisible(false);
dprint("[vomitSpriter] added, visible: " +
sprite.layer().visible() + " full layer: " + animLayer_.visible());
animLayer_.add(sprite.layer());
numLoaded_++;
if (hasLoaded())
set(currentTipoVomito_);
}

@Override
public void onFailure(Throwable err) {
log().error("Error loading image!", err);
}
});
}

// Error check of internal structures - ifndef NDEBUG
int n = TipoVomito.values().length;
boolean[] hasState = new boolean[n];
for (int i = 0; i < vc.size(); ++i) {
hasState[vc.get(i).ordinal()] = true;
}
for (int i = 0; i < n; ++i) {
if (!hasState[i]) {
dprint("Warning: sprite file not specified for state " + TipoVomito.values()[i]);
dprint(" make sure this is rendered some other way");
}
}
}

public void set(TipoVomito s) {
currentTipoVomito_ = s;
dprint("[vomito] TipoVomito " + s);

if (!hasLoaded())
return;

Sprite newSprite = animMap_.get(s);

if (newSprite == null) {
pprint("[vomito] Warning: no direct anim for requested TipoVomito " + s);
}

if (currentSprite_ != null) // only happens during construction / asset loadding
currentSprite_.layer().setVisible(false);

traversed_ = false;
// switch currentAnim to next anim
spriteIndex_ = 0;

currentSprite_ = newSprite;
animLayer_.setSize(currentSprite_.maxWidth(), currentSprite_.maxHeight()); // where to clip the animations in this composite spritey
animLayer_.setScale(1.3f); // change the scale of the sprite for testing
animLayer_.setOrigin(animLayer_.width() / 2f, animLayer_.height() / 2f);
currentSprite_.layer().setVisible(true);
}

/**
* Flips horizontally
*/
public void flipLeft() {
currentSprite_.layer().setScaleX(-1);
currentSprite_.layer().setTx(currentSprite_.width());
}

public void flipRight() {
currentSprite_.layer().setScaleX(1);
currentSprite_.layer().setTx(0);
}

public void set(int i) {
set(TipoVomito.values()[i]);
}

@Override
public boolean hasLoaded() {
return numLoaded_ == jsons.size();
}

public void update(int delta) {
if (hasLoaded()) {
dprint( "[vomitSpriter] loaded & being updated.");
dprint(" currentTipoVomito_: " + currentTipoVomito_);
dprint(" initial-spriteIndex_: " + spriteIndex_);
dprint(" initial-currentSprite_.numSprites(): " + currentSprite_.numSprites());
spriteIndex_ = (spriteIndex_ + 1) % currentSprite_.numSprites();
currentSprite_.setSprite(spriteIndex_);
// currentSprite_.layer().setRotation(angle);
if (spriteIndex_ == currentSprite_.numSprites() - 1) {
traversed_ = true;
}
dprint("spriteIndex_: " + spriteIndex_ +
" currentSprite_.numSprites(): " + currentSprite_.numSprites());
}
}

/**
* The radius of the bounding sphere to the present sprite frame
*/
public float boundingRadius() {
return (float) Math.sqrt(
animLayer_.width()*animLayer_.width() +
animLayer_.height()*animLayer_.height())/2.0f;
}

private boolean traversed(){
return traversed_;
}

/**
* Returns a slot which can be used to wire the current sprite animation to
* the emissions of a {@link Signal} or another value.
*/
public Slot<Integer> slot() {
return new Slot<Integer>() {
@Override public void onEmit (Integer value) {
set(value);
}
};
}

/**
* Return the current animation sprite {@link ImageLayer}.
*/
@Override
public GroupLayer.Clipped layer() {
return animLayer_;
}
}

0 comments on commit 7bbf565

Please sign in to comment.