示例#1
0
        public override void ApplicationDidFinishLaunching(CCApplication application, CCWindow mainWindow)
        {
            application.PreferMultiSampling = false;
            application.ContentRootDirectory = "Content";
            application.ContentSearchPaths.Add ("fonts");
            application.ContentSearchPaths.Add ("landscape");
            application.ContentSearchPaths.Add ("menu");
            application.ContentSearchPaths.Add ("interface");
            application.ContentSearchPaths.Add ("particle");

            gameContainer = new mapKnightLibrary.Container ();
            gameContainer.mainCharacter= new RoboBob();
            gameContainer.physicsHandler = new PhysicsHandler ();

            runningWindow = mainWindow;
            // This tells the application to not use antialiasing which can
            // improve the performance of your game.

            // Get the resolution of the main window...
            var bounds = mainWindow.WindowSizeInPixels;

            ////definieren der Windowgröße auf 1280x576 p (16:9)
            CCScene.SetDefaultDesignResolution (bounds.Width, bounds.Height, CCSceneResolutionPolicy.ShowAll);

            //startScene = new StartScene (mainWindow);
            gameScene = new GameScene (mainWindow, gameContainer, RunningControlType);
            optionScene = new OptionScene (mainWindow);

            // startet das erste Fenster
            mainWindow.RunWithScene (gameScene);
            //startScene.Version = app_version;
            //startScene.startGame += startGame;
            //if (ApplicationFinishedLaunching != null)
            //	ApplicationFinishedLaunching (this, EventArgs.Empty);
        }
示例#2
0
        public static List<Platform> LoadPlatformFromLayer(CCTileMap TileMap, CCTileMapObjectGroup PlatformHolder, Container gameContainer)
        {
            List<Platform> LoadedPlatforms = new List<Platform> ();

            foreach (Dictionary<string,string> LayerObject in PlatformHolder.Objects) {
                if (LayerObject.ContainsKey ("type") == true) {
                    if (LayerObject ["type"] == "platform") {
                        int LoadedSpeed = 200;
                        if (LayerObject.ContainsKey ("speed"))
                            LoadedSpeed = Convert.ToInt32 (LayerObject ["speed"]);
                        List<CCPoint> LoadedWaipoints = new List<CCPoint> ();
                        LoadedWaipoints.Add (new CCPoint ((float)Convert.ToInt32 (LayerObject ["x"]) * TileMap.ScaleX, (float)Convert.ToInt32 (LayerObject ["y"]) * TileMap.ScaleY));
                        if (LayerObject.ContainsKey ("waypoints") == true) {
                            foreach (string WayPointPair in LayerObject ["waypoints"].Split(new char[]{';'},StringSplitOptions.RemoveEmptyEntries)) {
                                CCPoint TempLoadedPoint = new CCPoint ();
                                string[] Waypoint = WayPointPair.Split (new char[]{ ',' }, StringSplitOptions.RemoveEmptyEntries);
                                if (Waypoint.Length > 1) {
                                    TempLoadedPoint.X = LoadedWaipoints [LoadedWaipoints.Count - 1].X + (float)Convert.ToInt32 (Waypoint [0]) * TileMap.ScaleX * TileMap.TileTexelSize.Width;
                                    TempLoadedPoint.Y = LoadedWaipoints [LoadedWaipoints.Count - 1].Y + (float)Convert.ToInt32 (Waypoint [1]) * TileMap.ScaleY * TileMap.TileTexelSize.Height;
                                } else {
                                    throw new ArgumentException ("Incorrect Waypoints");
                                }
                                LoadedWaipoints.Add (TempLoadedPoint);
                            }
                        }
                        LoadedPlatforms.Add (new Platform (LoadedWaipoints, LoadedSpeed, gameContainer));
                    }
                }
            }

            return LoadedPlatforms;
        }
示例#3
0
        public MergedLayer(CCWindow mainWindow, Container mainContainer)
        {
            screenSize = mainWindow.WindowSizeInPixels;
            gameContainer = mainContainer;

            mapVersion = "unspecified";
            mapCreator = "unspecified";
            mapName = "unspecified";
        }
示例#4
0
        public Platform(List<CCPoint> platformWaypoints, int platformSpeed, Container gameContainer)
        {
            this.Texture = new CCTexture2D("platform");
            this.Scale = SpriteScale;
            this.IsAntialiased = false;

            this.Position = platformWaypoints [0];
            Waypoints = platformWaypoints;
            speed = platformSpeed;
            //umso geringer der speed umso schneller die platform

            CurrentWaypoint = 0;
            wayToMove = new CCSize (Waypoints [CurrentWaypoint + 1].X - Waypoints [CurrentWaypoint].X, Waypoints [CurrentWaypoint + 1].Y - Waypoints [CurrentWaypoint].Y);

            //box2d
            b2BodyDef platformDef = new b2BodyDef ();
            platformDef.type = b2BodyType.b2_kinematicBody;
            platformDef.position = new b2Vec2 (Waypoints[CurrentWaypoint].X / PhysicsHandler.pixelPerMeter, Waypoints[CurrentWaypoint].Y / PhysicsHandler.pixelPerMeter);
            platformBody = gameContainer.physicsHandler.gameWorld.CreateBody (platformDef);

            b2PolygonShape platformShape = new b2PolygonShape ();
            platformShape.SetAsBox ((float)this.ScaledContentSize.Width / PhysicsHandler.pixelPerMeter / 2, (float)this.ScaledContentSize.Height / PhysicsHandler.pixelPerMeter / 2);

            b2FixtureDef platformFixture = new b2FixtureDef ();
            platformFixture.shape = platformShape;
            platformFixture.density = 0.0f; //Dichte
            platformFixture.restitution = 0f; //Rückprall
            platformFixture.userData = WorldFixtureData.platform;
            platformBody.CreateFixture (platformFixture);
            //

            this.Position = new CCPoint (platformBody.Position.x * PhysicsHandler.pixelPerMeter, platformBody.Position.y * PhysicsHandler.pixelPerMeter);

            progressionX = wayToMove.Width/ (float)speed;
            progressionY =  wayToMove.Height/(float)speed ;
            if (float.IsInfinity (progressionX))
                progressionX = 0;
            if (float.IsInfinity (progressionY))
                progressionY = 0;
            b2Vec2 Velocity = platformBody.LinearVelocity;
            Velocity.y = progressionY;
            Velocity.x = progressionX;
            platformBody.LinearVelocity = Velocity;
        }
示例#5
0
        public void Initialize(float mapSizeWidth, Character Character, CCTileMapLayer physicsLayer, CCTileMap physicsMap, Container gameContainer)
        {
            mapSizeWidth /= pixelPerMeter;
            gameWorld = new b2World (new b2Vec2 (0, -9.8f));
            gameWorld.AllowSleep = false;

            //definiert den MainCharacter
            Character.createPhysicsBody (gameWorld);
            defineGround (mapSizeWidth);

            createBox2DWorldByLayer (physicsLayer, physicsMap);

            debugDrawer = new DebugDraw ();
            gameWorld.SetDebugDraw (debugDrawer);
            debugDrawer.AppendFlags (b2DrawFlags.e_shapeBit);

            collusionSensor = new CollusionSensor (gameContainer);
            gameWorld.SetContactListener (collusionSensor);
        }
示例#6
0
        public static List<JumpPad> LoadJumpPadFromLayer(CCTileMap TileMap, CCTileMapObjectGroup PlatformHolder, Container gameContainer)
        {
            List<JumpPad> LoadedJumpPads = new List<JumpPad> ();

            foreach (Dictionary<string,string> LayerObject in PlatformHolder.Objects) {
                if (LayerObject.ContainsKey ("type") == true) {
                    if (LayerObject ["type"] == "jumppad") {
                        b2Vec2 LoadedBoostVector = new b2Vec2 ();
                        if (LayerObject.ContainsKey ("boostvec")) {
                            string[] BoostVecData = LayerObject ["boostvec"].Split (new char[]{ ',' }, StringSplitOptions.RemoveEmptyEntries);
                            if (BoostVecData.Length > 1) {
                                LoadedBoostVector = new b2Vec2 ((float)Convert.ToInt32 (BoostVecData [0]), (float)Convert.ToInt32 (BoostVecData [1]));
                            }
                        }
                        CCPoint LoadedPosition;
                        LoadedPosition = new CCPoint ((float)Convert.ToInt16 (LayerObject ["x"]) * TileMap.ScaleX - JumpPad.JumpPadSize.Width / 2, (float)Convert.ToInt32 (LayerObject ["y"]) * TileMap.ScaleY - JumpPad.JumpPadSize.Height);
                        LoadedJumpPads.Add (new JumpPad (LoadedBoostVector, LoadedPosition, gameContainer.physicsHandler.gameWorld));
                    }
                }
            }

            return LoadedJumpPads;
        }
示例#7
0
 public CollusionSensor(Container GameContainer)
 {
     gameContainer = GameContainer;
 }
示例#8
0
        public GameScene(CCWindow mainWindow, Container mainContainer, ControlType RunningControlType)
            : base(mainWindow)
        {
            CurrentControlType = RunningControlType;

            gameContainer = mainContainer;
            GameLayer = new MergedLayer (mainWindow, gameContainer);

            this.AddChild (GameLayer);

            screenSize = mainWindow.WindowSizeInPixels;

            //Touchlistener Initialisierung
            touchListener = new CCEventListenerTouchAllAtOnce ();

            switch (RunningControlType) {
            case ControlType.Slide:
                touchListener.OnTouchesMoved = Slide_HandleTouchesMoved;
                touchListener.OnTouchesBegan = Slide_HandleTouchesBegan;
                touchListener.OnTouchesEnded = Slide_HandleTouchesEnded;
                touchListener.OnTouchesCancelled = Slide_HandleTouchesCanceled;

                break;
            case ControlType.Button:
                JumpButton = new CCSprite ("menu_arrow");
                MoveLeftButton = new CCSprite ("menu_arrow");
                MoveRightButton = new CCSprite ("menu_arrow");

                JumpButton.Scale = screenSize.Width / 4 / JumpButton.TextureRectInPixels.Size.Width;
                MoveLeftButton.Scale = screenSize.Width / 6 / MoveLeftButton.TextureRectInPixels.Size.Width;
                MoveRightButton.Scale = screenSize.Width / 6 / MoveRightButton.TextureRectInPixels.Size.Width;

                JumpButton.Position = new CCPoint (screenSize.Width - JumpButton.ScaledContentSize.Width / 2, JumpButton.ScaledContentSize.Height / 2);
                MoveLeftButton.Position = new CCPoint (MoveLeftButton.ScaledContentSize.Width / 2, MoveLeftButton.ScaledContentSize.Height / 2);
                MoveRightButton.Position = new CCPoint (MoveLeftButton.PositionX + 20f + MoveRightButton.ScaledContentSize.Width, MoveLeftButton.ScaledContentSize.Height / 2);

                CCRotateTo LeftRotate = new CCRotateTo (0, 270f);
                MoveLeftButton.RunAction (LeftRotate);

                CCRotateTo RightRotate = new CCRotateTo (0, 90f);
                MoveRightButton.RunAction (RightRotate);

                this.AddChild (JumpButton);
                this.AddChild (MoveLeftButton);
                this.AddChild (MoveRightButton);

                touchListener.OnTouchesMoved = Button_HandleTouchesMoved;
                touchListener.OnTouchesBegan = Button_HandleTouchesBegan;
                touchListener.OnTouchesEnded = Button_HandleTouchesEnded;
                touchListener.OnTouchesCancelled = Button_HandleTouchesCanceled;

                break;
            }

            AddEventListener (touchListener, this);

            //FPS Label
            FPSLabel = new CCLabel ("Score: 0", "arial", 22);
            FPSLabel.Position = new CCPoint (100, 100);
            FPSLabel.Color = new CCColor3B (255, 255, 0);
            AddChild (FPSLabel);

            //Map Label
            MapNameLabel = new CCLabel ("Map Name : " + GameLayer.mapName, "arial", 22) {
                Color = new CCColor3B (255, 255, 255)
            };
            MapNameLabel.Position = new CCPoint (MapNameLabel.ContentSize.Width / 2, screenSize.Height - 10 - MapNameLabel.ContentSize.Height);
            MapCreatorLabel = new CCLabel ("Map Creator : " + GameLayer.mapCreator, "arial", 22) {
                Color = new CCColor3B (255, 255, 255)
            };
            MapCreatorLabel.Position = new CCPoint (MapCreatorLabel.ContentSize.Width / 2, MapNameLabel.Position.Y - 10 - MapCreatorLabel.ContentSize.Height);
            MapVersionLabel = new CCLabel ("Map Version : " + GameLayer.mapVersion, "arial", 22) {
                Color = new CCColor3B (255, 255, 255)
            };
            MapVersionLabel.Position = new CCPoint (MapVersionLabel.ContentSize.Width / 2, MapCreatorLabel.Position.Y - 10 - MapVersionLabel.ContentSize.Height);

            this.AddChild (MapNameLabel);
            this.AddChild (MapCreatorLabel);
            this.AddChild (MapVersionLabel);

            //Interface
            ManaSprite = new CCSprite[2];
            LifeSprite = new CCSprite[2];

            ManaSprite [0] = new CCSprite ("bottleinside"){ IsAntialiased = false };
            ManaSprite [1] = new CCSprite ("bottleoutside"){ IsAntialiased = false };
            LifeSprite [0] = new CCSprite ("lifefull"){ IsAntialiased = false };
            LifeSprite [1] = new CCSprite ("lifeempty"){ IsAntialiased = false };

            ManaSprite [0].Scale = 12f;
            ManaSprite [1].Scale = 12f;
            LifeSprite [0].Scale = 12f;
            LifeSprite [1].Scale = 12f;

            ManaSprite [1].Position = new CCPoint (screenSize.Width - ManaSprite [1].ScaledContentSize.Width, screenSize.Height - ManaSprite [1].ScaledContentSize.Height);
            LifeSprite [1].Position = new CCPoint (screenSize.Width - LifeSprite [1].ScaledContentSize.Width, ManaSprite [1].Position.Y - LifeSprite [1].ScaledContentSize.Height);

            this.AddChild (ManaSprite [1]);
            this.AddChild (ManaSprite [0]);
            this.AddChild (LifeSprite [1]);
            this.AddChild (LifeSprite [0]);

            this.InterfaceUpdate (null, new StatisticChangeEventArgHandler (Statistic.Life));
            this.InterfaceUpdate (null, new StatisticChangeEventArgHandler (Statistic.Mana));

            gameContainer.mainCharacter.StatChanged += InterfaceUpdate;

            gameContainer.mainCharacter.CurrentLife = 23;
            gameContainer.mainCharacter.CurrentMana = 4;

            Schedule (GameLoop);
        }