Permalink
Browse files

Done

  • Loading branch information...
Zielak committed Feb 3, 2015
1 parent 4d47698 commit 6b0607dbb00092cbc44ed4349e5a2c1c13e479d4
Showing with 119 additions and 38 deletions.
  1. BIN simon_prev.gif
  2. +33 −2 src/Main.hx
  3. +37 −10 src/Simon.hx
  4. +35 −8 src/SimonButton.hx
  5. +8 −10 src/components/Clickable.hx
  6. +6 −8 src/components/Shine.hx
BIN +336 KB simon_prev.gif
Binary file not shown.
@@ -6,6 +6,7 @@ import luxe.Color;
import luxe.Rectangle;
import luxe.Visual;
import luxe.Text;
@@ -16,7 +17,8 @@ class Main extends luxe.Game
var score:Int;
var welcomeText:Text;
var scoreText:Text;
var playScene:Scene;
@@ -54,7 +56,7 @@ class Main extends luxe.Game
for(i in 0...4){
simonColors[i] = new Array<Color>();
for(j in 0...3){
simonColors[i][j] = new Color().rgb(config.runtime.colors[i][j]);
simonColors[i][j] = new Color().rgb( Std.parseInt(config.runtime.colors[i][j]) );
}
}
}
@@ -109,6 +111,7 @@ class Main extends luxe.Game
menuScene = new Scene('menu');
addBackground();
addText();
addSimon();
@@ -128,6 +131,33 @@ class Main extends luxe.Game
}),
color: turnColorSimon,
});
Luxe.events.listen('simon.finished', function(e){
background.color = turnColorYou;
});
Luxe.events.listen('simon.turn', function(e){
background.color = turnColorSimon;
});
}
function addText():Void
{
welcomeText = new Text({
bounds: new Rectangle(0,100,Luxe.screen.w, 100),
align: center,
point_size: 16,
text: 'Press [ENTER] to let Simon talk...',
batcher: Luxe.renderer.batcher
});
scoreText = new Text({
bounds: new Rectangle(10, 10, Luxe.screen.w-10, 30),
align: left,
point_size: 24,
text: 'SCORE: 0',
});
scoreText.visible = false;
score = 0;
}
// Adds clickable buttons of Simon
@@ -200,6 +230,7 @@ class Main extends luxe.Game
function playGame():Void
{
playing = true;
welcomeText.visible = false;
Luxe.events.fire('simon.turn');
}
@@ -26,14 +26,16 @@ class Simon extends Entity
{
trace('simon.init()');
simonSays = false;
memory = new Array<Int>();
addToMemory(3);
playerTurn = 0;
simonTurn = 0;
addToMemory(4);
// Timers for saying
saying = 0;
interval = 0.5;
interval = 0.75;
Luxe.events.listen('player.clicked', function(e:SimonButtonEvent){
if(!simonSays){
@@ -42,11 +44,18 @@ class Simon extends Entity
});
Luxe.events.listen('simon.turn', function(e){
trace('simon.turn(e)');
if(!simonSays){
startTalking();
}
});
Luxe.events.listen('simon.finished', function(e){
if(simonSays){
stopTalking();
}
});
}
@@ -67,23 +76,30 @@ class Simon extends Entity
function startTalking():Void
{
trace('simon.startTalking()');
simonSays = true;
sayNext();
}
function stopTalking():Void
{
simonSays = false;
}
function sayNext():Void
{
trace('simon.sayNext()');
simonTurn++;
if(simonTurn > memory.length)
if(simonTurn >= memory.length)
{
trace('simon.sayNext() -> Stopped talking');
Luxe.events.fire('simon.finished');
}
else
{
saying = interval;
saying = interval;
trace('simon.sayNext() -> ${memory[simonTurn]}');
Luxe.events.fire('simon.says', {number: memory[simonTurn]});
}
Luxe.events.fire('simon.says', {number: memory[simonTurn]});
simonTurn++;
}
@@ -92,13 +108,20 @@ class Simon extends Entity
function playerSaid(btn:Int):Void
{
trace('playerSaid(${btn})');
if(memory[playerTurn] == btn)
{
trace('player.said.good');
Luxe.events.fire('player.said.good');
playerTurn++;
if(playerTurn >= memory.length)
{
playerPassed();
}
}
else
{
trace('player.said.bad -> memory[${playerTurn}] = ${memory[playerTurn]}');
Luxe.events.fire('player.said.bad');
playerFailed();
}
@@ -118,9 +141,10 @@ class Simon extends Entity
function playerPassed():Void
{
trace('player.passed');
trace('####################################');
Luxe.events.fire('player.passed');
resetRound(true);
addToMemory(1);
}
@@ -132,10 +156,12 @@ class Simon extends Entity
if(passed)
{
playerTurn = 0;
simonTurn = 0;
addToMemory(1);
}
else
{
simonTurn = 0;
playerTurn = 0;
}
@@ -149,6 +175,7 @@ class Simon extends Entity
{
memory.push(Math.floor(Math.random()*4));
}
trace('addToMemory -> ${memory}');
}
@@ -48,6 +48,7 @@ class SimonButton extends Visual
name: 'clickable',
eventName: 'simon',
});
clickable.enabled = false;
overColor = _options.colorOver;
downColor = _options.colorDown;
@@ -60,34 +61,60 @@ class SimonButton extends Visual
add(clickable);
Luxe.events.listen('buttons.disable', function(e){
Luxe.events.listen('simon.turn', function(e){
clickable.enabled = false;
color = downColor;
});
Luxe.events.listen('buttons.enable', function(e){
Luxe.events.listen('simon.finished', function(e){
clickable.enabled = true;
color = outColor;
});
Luxe.events.listen('simon.says', function(e:SimonButtonEvent){
if(e.number == number){
trace('simon.says ${number} THATS ME!');
add(new components.Shine({
name: 'shine',
time: 0.3,
time: 0.5,
}));
}
});
}
override function update(dt:Float):Void
{
if(clickable.isDown && clickable.enabled){
color = downColor;
Luxe.events.fire('player.clicked', this.number);
}else if(clickable.isOver && clickable.enabled){
color = overColor;
if(clickable.enabled)
{
if(clickable.justClicked && clickable.isDown)
{
trace('BTN : clickable.justClicked number: ${this.number}');
Luxe.events.fire('player.clicked', {number:this.number});
color = downColor;
}
if (clickable.isOver && !clickable.isDown)
{
color = overColor;
}
else if (clickable.isDown)
{
color = downColor;
}
else
{
color = outColor;
}
}else{
color = outColor;
}
// Change color when shining
if(has('shine')){
color = get('shine').color;
}
}
@@ -19,6 +19,7 @@ class Clickable extends Component
public var isOver:Bool = false;
public var isDown:Bool = false;
public var justClicked:Bool = false;
public var enabled:Bool = true;
@@ -38,16 +39,12 @@ class Clickable extends Component
}
override function onfixedupdate(rate:Float):Void
override function update(dt:Float):Void
{
// bounds.x = entity.pos.x;
// bounds.y = entity.pos.y;
// if(entity.transform.parent != null)
// {
// bounds.x += entity.transform.parent.local.pos.x;
// bounds.y += entity.transform.parent.local.pos.y;
// }
if(justClicked && isDown)
{
justClicked = false;
}
}
override public function onmousemove(event:MouseEvent):Void
@@ -66,14 +63,15 @@ class Clickable extends Component
{
if(isOver)
{
justClicked = true;
Luxe.events.fire(eventName+'.mouseclick', entity);
isDown = true;
}
}
override public function onmouseup(event:MouseEvent):Void
{
if(isDown = true)
if(isDown)
{
Luxe.events.fire(eventName+'.mouseup', entity);
isDown = false;
@@ -9,10 +9,10 @@ import luxe.Visual;
class Shine extends Component
{
var shineTime:Float;
public var color:Color;
var lastColor:Color;
var newColor:Color;
var shineTime:Float;
var shineColor:Color;
override public function new(_options:ShineOptions):Void
{
@@ -21,17 +21,16 @@ class Shine extends Component
shineTime = _options.time;
if(_options.color != null)
{
newColor = _options.color;
shineColor = _options.color;
}else{
newColor = new Color().rgb(0xFFFFFF);
shineColor = new Color().rgb(0xCCCCCC);
}
}
override function init():Void
{
lastColor = cast(entity, Visual).color;
cast(entity, Visual).color = newColor;
color = shineColor;
}
override function update(dt:Float):Void
@@ -40,7 +39,6 @@ class Shine extends Component
if(shineTime <=0)
{
cast(entity, Visual).color = lastColor;
remove('shine');
}
}

0 comments on commit 6b0607d

Please sign in to comment.