Commit a38e041d authored by Sébastien Bernery's avatar Sébastien Bernery
Browse files

Interaction with objects

parent 46b977db
This diff is collapsed.
......@@ -3,19 +3,32 @@ package;
class Alice extends FlxSprite {
public var walking = false;
public var walking_speed = 500.;
public var walking_speed = 200.;
public var hungry = 1.;
public var thirst = 1.;
public var fatigue = 1.;
public var moral = 1.;
public var kilometers = 0.;
@:isVar public var water(get, set) = 5;
@:isVar public var food(get, set) = 3;
@:isVar public var wood(get, set) = 1;
public var current_interaction_obj:Null<SceneElement>;
public function new() {
super(0, 0);
FlxG.camera.follow(this, FlxCameraFollowStyle.PLATFORMER);
this.loadGraphic("assets/alice.png");
this.loadGraphic("assets/alice.png", true, 100, 180);
this.animation.add("stand", [0], 5);
this.animation.add("walk", [1, 2, 3], 5);
}
public function walk() {
this.walking = true;
this.walking = ! this.walking;
}
override public function update(dt:Float) {
......@@ -23,9 +36,60 @@ class Alice extends FlxSprite {
if (walking) {
this.velocity.x = this.walking_speed;
this.hungry -= dt*0.04;
this.animation.play("walk");
} else {
this.velocity.x = 0;
this.animation.play("stand");
}
this.hungry -= dt*0.03;
if (this.current_interaction_obj != null) {
var cont = this.current_interaction_obj.update_action(dt);
if (! cont) {
this.current_interaction_obj = null;
}
}
}
}
public function start_action(element:SceneElement) {
this.current_interaction_obj = element;
}
public function get_water() {
return this.water;
}
public function get_food() {
return this.food;
}
public function get_wood() {
return this.wood;
}
public function set_water(new_val:Int) {
this.water = new_val;
if (this.water > 5) {
this.water = 5;
}
return this.water;
}
public function set_food(new_val:Int) {
this.food= new_val;
if (this.food > 3) {
this.food = 3;
}
return this.food;
}
public function set_wood(new_val:Int) {
this.wood = new_val;
if (this.wood > 3) {
this.wood = 3;
}
return this.wood;
}
}
package;
class Cactus extends SceneElement {
public function new(x:Int, y:Int) {
super(x, y);
this.sprite.loadGraphic("assets/objects/cactus.png");
this.create_button("Get cactus pulp");
}
override public function button_clicked() {
Reg.playstate.world.alice.start_action(this);
}
override public function update_action(dt:Float) {
this.completion += dt;
Reg.playstate.world.alice.moral -= 0.1*dt;
return super.update_action(dt);
}
override public function end_of_action() {
Reg.playstate.world.alice.water += 2;
}
}
......@@ -2,6 +2,10 @@ package;
class Gui extends FlxSpriteGroup {
var hungry_bar:FlxBar;
var thirst_bar:FlxBar;
var fatigue_bar:FlxBar;
var moral_bar:FlxBar;
var walk_button:FlxButton;
......@@ -11,7 +15,16 @@ class Gui extends FlxSpriteGroup {
this.walk_button = new FlxButton(FlxG.width/2, FlxG.height-100, "walk", clicked_walk_button);
this.hungry_bar = new FlxBar(10, 10, 80, 8, Reg.playstate.world.alice, "hungry", 0., 1.);
this.thirst_bar = new FlxBar(10, 25, 80, 8, Reg.playstate.world.alice, "thirst", 0., 1.);
this.fatigue_bar = new FlxBar(10, 40, 80, 8, Reg.playstate.world.alice, "fatigue", 0., 1.);
this.moral_bar = new FlxBar(10, 55, 80, 8, Reg.playstate.world.alice, "moral", 0., 1.);
this.add(this.walk_button);
this.add(this.hungry_bar);
this.add(this.thirst_bar);
this.add(this.fatigue_bar);
this.add(this.moral_bar);
}
public function clicked_walk_button() {
......
......@@ -15,8 +15,8 @@ class PlayState extends FlxState {
super.create();
Reg.playstate = this;
this.gui = new Gui();
this.world = new World();
this.gui = new Gui();
this.add(this.world);
this.add(this.gui);
......
......@@ -11,7 +11,7 @@ class Scene extends FlxSpriteGroup {
this.background = new FlxSpriteGroup(0, 0);
this.foreground = new FlxSpriteGroup(0, 0);
var cactus = new FlxSprite(40, 100, "assets/objects/cactus.png");
var cactus = new Cactus(40, 500);
this.add(this.background);
this.add(this.foreground);
......
package;
class SceneElement extends FlxSpriteGroup {
public var sprite:FlxSprite;
public var button:FlxButton;
public var completion = 0.;
public function new(x:Int, y:Int) {
super(x, y);
this.sprite = new FlxSprite(0, 0);
this.add(this.sprite);
}
public function create_button(name:String) {
this.button = new FlxButton(0, -20, name, button_clicked);
this.button.x = this.sprite.width/2 - this.button.width/2;
this.add(this.button);
}
public function button_clicked() {
}
public function update_action(dt:Float) {
if (this.completion > 1.) {
this.end_of_action();
return false;
}
return true;
}
public function end_of_action() {
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment