1. Tao Chen
  2. sha-qmark

Commits

Tao Chen  committed 0e1f01b

roll in bg

  • Participants
  • Parent commits 9692764
  • Branches default

Comments (0)

Files changed (8)

File woot/BulletMan.as

View file
 		static public var enemyBullet : FlxGroup;
 		
 		private static var PLAYER_BULLET_SPEED : int = 350;
+		private static var ENEMY_BULLET_SPEED : int = 150;
 		
 		static public function static_init() : void
 		{
 			bullet.setup(0, dir, PLAYER_BULLET_SPEED, player.x + player.origin.x, player.y + player.origin.y);
 		}
 		
+		static public function AddEnemyBullet(dir:uint, enemy:FlxSprite) : void
+		{
+			var obj : FlxBasic = enemyBullet.getFirstDead();
+			var bullet : Bullet;
+			if (!obj)
+			{
+				bullet = new Bullet();
+				enemyBullet.add(bullet);
+			}
+			else
+			{
+				bullet = obj as Bullet;
+			}
+			
+			bullet.setup(1, dir, ENEMY_BULLET_SPEED, enemy.x + enemy.origin.x, enemy.y + enemy.origin.y);
+		}
+		
 		
 	}
 

File woot/Level.as

View file
 		[Embed(source="./data/masktile.png")]
 		private static var s_tileImg:Class;
 		
+		
 		public function Level() 
 		{
 			super();

File woot/PlayState.as

View file
 		public var map : Level;
 		public var player1 : Player;
 		
+		[Embed(source="./data/bg.png")]
+		private static var s_bg:Class;
+		
 		public function PlayState() 
 		{
 			instance = this;
 			FlxG.bgColor = 0xFFFFFFFF;
 			BulletMan.static_init();
 			Walky.static_init();
+			Shooty.static_init();
 			
 			map = new Level();
 			player1 = new Player(1);
+			var bg : FlxSprite = new FlxSprite(0, 0, s_bg);
 			
 			add(map);
+			add(bg);
 			add(player1);
 			add(Walky.group);
+			add(Shooty.group);
 			add(BulletMan.playerBullet);
 			add(BulletMan.enemyBullet);
+
 			
 			Walky.add_walky(2, 9, FlxObject.RIGHT);
+			Shooty.add_shooty(10, 1);
 		
 			FlxG.camera.setBounds(0, 0, map.width, map.height, true);
 			FlxG.camera.follow(player1);
 			// DEBUG
 			FlxG.watch(BulletMan.playerBullet, "length");
+						FlxG.watch(BulletMan.enemyBullet, "length");
 		}
 		
 		override public function update():void
 		{
 			FlxG.collide(player1, map);
 			FlxG.collide(Walky.group, map);
+			FlxG.collide(Shooty.group, map);
 			
 			FlxG.overlap(BulletMan.playerBullet, Walky.group, BulletEntityOverlap);
-			
+			FlxG.overlap(BulletMan.enemyBullet, player1, BulletEntityOverlap);
 			super.update();
 		}
 		

File woot/Player.as

View file
 			super.update();
 		}
 		
-		
+		override public function kill():void 
+		{
+			alive = false;
+		}
 	}
 
 }

File woot/data/bg.png

Added
New image

File woot/data/main.oel

View file
 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
+0,0,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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
-0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
-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</tiling>
+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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1</tiling>
+  <ent>
+    <NewObject0 id="0" x="0" y="0" />
+  </ent>
 </level>

File woot/enemy/Shooty.as

View file
 package woot.enemy 
 {
-	import org.flixel.FlxSprite;
+	import org.flixel.*;
+	import woot.*;
 	
 	/**
 	 * ...
 	 */
 	public class Shooty extends FlxSprite 
 	{
+		static private var SPEED : int = 100;
+		static private var JUMP : int = 300;
+		static private var MAXSPEED_Y : int = 200;
+		static private var CD : Number = 2.0;
 		
+		static public var group : FlxGroup;
+		static public function static_init() : void
+		{
+			group = new FlxGroup();
+		}
+		
+		static public function add_shooty(tileX : int, tileY : int) : void
+		{
+			var obj : FlxBasic = group.getFirstAvailable()
+			var shooty : Shooty;
+			if (!obj)
+			{
+				shooty = new Shooty();
+				group.add(shooty);
+			}
+			else
+			{
+				shooty = obj as Shooty;
+			}
+			
+			shooty.reset(Comm.tile2pixel(tileX), Comm.tile2pixel(tileY));
+		}
+		
+		private var _timer : Number;
 		public function Shooty() 
 		{
+			super( -100, -100);
+			width = 32;
+			height = 64;
+			fill(0xFFFF00FF);
+			centerOffsets();
+			super.kill();
 			
+			// stay static
+			
+			acceleration.y = Comm.GRAVITY;
+			allowCollisions = FlxObject.DOWN;
+			_timer = 0;
 		}
 		
+		override public function update():void 
+		{
+			if (alive && onScreen())
+			{
+				_timer -= FlxG.elapsed;
+				if (_timer < 0)
+				{
+					// shoot to player direction
+					var dx : Number = PlayState.instance.player1.x - x;
+					var dy : Number = PlayState.instance.player1.y - y;
+					var deg : Number = Comm.rad2deg(Math.atan2(dy, dx));
+					BulletMan.AddEnemyBullet(Comm.deg2dir(deg), this);					
+					_timer = CD;
+				}
+			}
+			
+			super.update();
+		}
 	}
 
 }

File woot/enemy/Walky.as

View file
 			height = 64;
 			fill(0xFF0000FF);
 			centerOffsets();
-			kill();
+			super.kill();
 			
 			acceleration.y = Comm.GRAVITY / 2;
 			maxVelocity.y = MAXSPEED_Y;