Skip to content

Commit

Permalink
Added some item graphics
Browse files Browse the repository at this point in the history
  • Loading branch information
noonat committed May 2, 2011
1 parent 7003018 commit eb7aa8e
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 7 deletions.
Binary file added assets/wooden_shield.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/wooden_sword.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/Game.as
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ package {
add(this.level = level);
level.createEntities(this);

_vendorMenu = new VendorMenu(itemClasses, FP.width / 2, FP.height - 16);
_vendorMenu = new VendorMenu(itemClasses, FP.width / 2, FP.height - 48);
_vendorMenu.onItem.add(onVendorItem);
_vendorMenu.show();
add(_vendorMenu);
Expand Down
8 changes: 5 additions & 3 deletions src/Item.as
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ package {
protected var _inventory:Inventory;

function Item() {
super(0, 0, Image.createRect(8, 8, 0x00ffff));
(graphic as Image).centerOO();
setHitbox(8, 8, 4, 4);
super(0, 0);
setHitbox(Level.TILE, Level.TILE);
centerOrigin();
++originX;
++width;
layer = Layers.ITEMS;
type = 'item';
itemName = 'Item';
Expand Down
23 changes: 20 additions & 3 deletions src/VendorMenu.as
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package {
import flash.geom.Rectangle;
import net.flashpunk.FP;
import net.flashpunk.graphics.Text;
import net.flashpunk.Signal;
import net.flashpunk.World;
import net.flashpunk.utils.Draw;
Expand All @@ -11,6 +12,7 @@ package {
protected var _buttons:Vector.<Button>;
protected var _items:Vector.<Item>;
protected var _rect:Rectangle;
protected var _text:Text;

function VendorMenu(itemClasses:Array, x:Number, y:Number) {
super(x, y, 1, 1);
Expand All @@ -22,9 +24,19 @@ package {
_buttons = new Vector.<Button>();
_items = new Vector.<Item>();
for each (var cls:Class in itemClasses) {
_items.push(new cls() as Item);
var item:Item = new cls() as Item;
item.layer = Layers.MENU_BUTTON;
_items.push(item);
}
createButtons();

_text = new Text('choose');
_text.size = 8;
_text.alpha = 0.3;
_text.x = 0;
_text.y = Level.TILE * 2;
_text.centerOO();
graphic = _text;
}

override public function added():void {
Expand Down Expand Up @@ -59,7 +71,7 @@ package {
item.x += _rect.x;
item.y += _rect.y;
}
_rect.inflate(Level.TILE, Level.TILE);
_rect.inflate(Level.TILE / 2, Level.TILE / 2);
setHitbox(_rect.width, _rect.height);
}

Expand All @@ -86,7 +98,12 @@ package {
}

override public function render():void {
Draw.rect(_rect.x, _rect.y, _rect.width, _rect.height, 0xff0000, 0.1);
Draw.rect(_rect.x, _rect.y, _rect.width, _rect.height, 0x111111);
for each (var item:Item in _items) {
Draw.rect(
item.x - item.originX, item.y - item.originY,
item.width, item.height, 0xB294BB, 0.3);
}
super.render();
}

Expand Down
22 changes: 22 additions & 0 deletions src/Warrior.as
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package {
import flash.display.BitmapData;
import flash.geom.Point;
import net.flashpunk.components.Health;
import net.flashpunk.Entity;
import net.flashpunk.FP;
import net.flashpunk.Graphic;
import net.flashpunk.graphics.Image;

public class Warrior extends Monster {
Expand All @@ -12,6 +14,8 @@ package {
protected var _boon:Item;
protected var _wanderX:Number = 0;
protected var _wanderY:Number = 0;
private var _camera:Point = new Point();
private var _point:Point = new Point();

function Warrior() {
super();
Expand Down Expand Up @@ -56,6 +60,24 @@ package {
_boon = null;
}

override public function render():void {
super.render();
if (_health.alive && _boon !== null) {
var g:Graphic = _boon.graphic;
if (g && g.visible) {
if (g.relative) {
_point.x = x - 2;
_point.y = y - 1;
} else {
_point.x = _point.y = 0;
}
_camera.x = FP.camera.x;
_camera.y = FP.camera.y;
g.render(renderTarget ? renderTarget : FP.buffer, _point, _camera);
}
}
}

override protected function think():void {
if (_boon !== null) {
super.think();
Expand Down
13 changes: 13 additions & 0 deletions src/items/WoodenShield.as
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
package items {
import flash.display.BitmapData;
import net.flashpunk.graphics.Image;

public class WoodenShield extends Item {
[Embed(source="../../assets/wooden_shield.png")]
static protected const IMAGE:Class;

protected var _image:Image;

function WoodenShield() {
super();
Assets.getBitmap(IMAGE, function(bitmap:BitmapData):void {
_image = new Image(bitmap);
_image.centerOO();
graphic = _image;
});
type = 'shield';
itemName = 'Wooden Shield';
}
Expand Down
13 changes: 13 additions & 0 deletions src/items/WoodenSword.as
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
package items {
import flash.display.BitmapData;
import net.flashpunk.graphics.Image;

public class WoodenSword extends Item {
[Embed(source="../../assets/wooden_sword.png")]
static protected const IMAGE:Class;

protected var _image:Image;

function WoodenSword() {
super();
Assets.getBitmap(IMAGE, function(bitmap:BitmapData):void {
_image = new Image(bitmap);
_image.centerOO();
graphic = _image;
});
type = 'sword';
stats.damage = 1;
itemName = 'Wooden Sword';
Expand Down

0 comments on commit eb7aa8e

Please sign in to comment.