Skip to content

Commit

Permalink
Adding hittable blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
mcgrue committed Oct 1, 2010
1 parent c03b871 commit 5a10b82
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 14 deletions.
22 changes: 11 additions & 11 deletions data/maps/mariobros.tmx
Expand Up @@ -3,24 +3,24 @@
<tileset firstgid="1" name="Mario" tilewidth="16" tileheight="16">
<image source="../tilesets/mario.png" trans="ff43f7"/>
</tileset>
<layer name="Obstructions" width="16" height="16" opacity="0">
<layer name="Obstructions" width="16" height="16" visible="0" opacity="0.97">
<data encoding="csv">
2,17,18,19,33,34,35,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
2,2,1,1,1,1,1,1,1,1,1,1,1,1,2,2,
2,2,1,1,1,1,1,1,1,1,1,1,1,1,2,2,
2,2,2,2,2,2,1,1,1,1,2,2,2,2,2,2,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,2,2,2,2,2,2,2,2,1,1,1,1,
2,2,1,1,1,1,1,1,1,1,1,1,1,1,2,2,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
2,2,2,2,2,2,1,1,1,1,2,2,2,2,2,2,
2,2,1,1,1,1,1,1,1,1,1,1,1,1,2,2,
2,2,1,1,1,1,1,1,1,1,1,1,1,1,2,2,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
</data>
</layer>
<layer name="PlayingField" width="16" height="16">
Expand Down
Binary file added data/sprites/hit_block.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/sprites/pow_block.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 37 additions & 3 deletions src/game/GameState.as
Expand Up @@ -10,14 +10,24 @@ package game {
public var map_group:FlxGroup = new FlxGroup();
public var obs_group:FlxGroup = new FlxGroup();
public var plr_group:FlxGroup = new FlxGroup();
public static const obstructed_tiles:Array = [4,17,18,19,33,34,35];

[Embed (source = "../../data/tilesets/mario.png")] private var marioTiles:Class;
[Embed (source = "../../data/sprites/hit_block.png")] private var hittableTile:Class;
[Embed (source = "../../data/maps/mariobros.tmx", mimeType = "application/octet-stream")] private var marioMap:Class;

public function GameState() {

}

public static function is_hittable_brick(idx:int): Boolean {
return idx == 2;
}

public static function is_obstruction_tile(idx:int):Boolean {
return obstructed_tiles.indexOf(idx) >= 0;
}

override public function create():void {

add(obs_group);
Expand All @@ -26,7 +36,7 @@ package game {

var xml:XML = new XML( new marioMap );
var mapxml:XMLList = xml.*;

map = new FlxTilemap();
map.startingIndex = 1;
map.collideIndex = 1;
Expand All @@ -40,13 +50,37 @@ package game {
obs.startingIndex = 1;
obs.collideIndex = 2;
obs.loadMap(
mapxml.(@name=="Obstructions").data,
mapxml.(@name=="PlayingField").data,
marioTiles,
16, 16
);

obs_group.add(obs);
map_group.add(map);

for( var x:int = 0; x<obs.widthInTiles; x++ ) {
for( var y:int = 0; y<obs.heightInTiles; y++ ) {

if( is_obstruction_tile(obs.getTile(x,y)) ) {
obs.setTile(x, y, 2);
} else {
if( is_hittable_brick(obs.getTile(x,y)) ) {

var hb:HittableBlock = new HittableBlock(x*16, y*16, 16, 16);
hb.loadTiles(hittableTile, 16, 16);
obs_group.add(hb);

trace('added a hittable block at ('+x+','+y+')');
}

obs.setTile(x, y, 1);
}

//obs.setTile(x, y, ((y==15)?3:1) );
}
}


// map_group.add(map);

plr_group.add( new Player(4*16,9*16,1) );
plr_group.add( new Player(11*16,9*16,2) );
Expand Down
9 changes: 9 additions & 0 deletions src/game/HittableBlock.as
@@ -0,0 +1,9 @@
package game {
import org.flixel.FlxTileblock;

public class HittableBlock extends FlxTileblock {
public function HittableBlock(X:int, Y:int, Width:uint, Height:uint) {
super(X, Y, Width, Height);
}
}
}
9 changes: 9 additions & 0 deletions src/game/Player.as
Expand Up @@ -102,5 +102,14 @@ package game {
do_animation(player_idx);
super.update();
}

override public function preCollide(Contact:FlxObject):void {

if( Contact is HittableBlock ) {
trace('preCollide 1');
}

super.preCollide(Contact);
}
}
}

0 comments on commit 5a10b82

Please sign in to comment.