From 3dbf2661548e5ef96852c6720555d8906e7a3982 Mon Sep 17 00:00:00 2001 From: Aaron Mueller Date: Thu, 2 May 2013 22:41:31 +0200 Subject: [PATCH] Add the player name chooser thingy --- dev/lib/game/entities/namefield.js | 71 ++++++++++++++++++++++++++++++ dev/lib/game/main.js | 17 +++---- 2 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 dev/lib/game/entities/namefield.js diff --git a/dev/lib/game/entities/namefield.js b/dev/lib/game/entities/namefield.js new file mode 100644 index 0000000..f0662f7 --- /dev/null +++ b/dev/lib/game/entities/namefield.js @@ -0,0 +1,71 @@ +ig.module( + 'game.entities.namefield' +) +.requires( + 'impact.entity' +) +.defines(function() { + EntityNameField = ig.Entity.extend({ + font: new ig.Font('media/lcddot.grey.font.png'), + fontActiveChar: new ig.Font('media/lcddot.font.png'), + activeCharArrows: new ig.Image('media/lcddot.arrows.png'), + + symbols: ['_', 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'], + numberOfChars: 3, + highlightedChar: 0, + _name: [], + + init: function(x, y, settings) { + this.parent(x, y, settings); + + ig.input.bind(ig.KEY.RIGHT_ARROW, 'next-char'); + ig.input.bind(ig.KEY.LEFT_ARROW, 'prev-char'); + + ig.input.bind(ig.KEY.UP_ARROW, 'next-symbol'); + ig.input.bind(ig.KEY.DOWN_ARROW, 'prev-symbol'); + + this._name = []; + for(var i=0; i 0) + this.highlightedChar--; + if (ig.input.pressed('next-char') && this.highlightedChar < this.numberOfChars-1) + this.highlightedChar++; + + // Switch symbols + if (ig.input.pressed('prev-symbol') && this._name[this.highlightedChar] > 0) + this._name[this.highlightedChar]--; + if (ig.input.pressed('next-symbol') && this._name[this.highlightedChar] < this.symbols.length-1) + this._name[this.highlightedChar]++; + + this.parent(); + }, + + draw: function() { + this.parent(); + for(var i=0; i