Skip to content

Commit

Permalink
Working scenes
Browse files Browse the repository at this point in the history
  • Loading branch information
tanis2000 committed Dec 10, 2015
1 parent a48d3f6 commit 7c1e7a5
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 22 deletions.
1 change: 1 addition & 0 deletions FutileProject/Assets/Platformer/Code/Core/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public Core ()
Engine engine = new Engine();
engine.Initialize();
ShowPage (engine);
Engine.Scene = new MainScene();

ListenForUpdate (Update);
}
Expand Down
2 changes: 2 additions & 0 deletions FutileProject/Assets/Platformer/Code/Game/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ public class Block : Entity
public Block () : base()
{
sprite = new FSprite("Game/green-16");
Collider = new Hitbox(16, 16);
}

override public void Added(Scene scene)
{
Debug.Log("block added");
base.Added(scene);
scene.AddChild (sprite);
}
Expand Down
2 changes: 1 addition & 1 deletion FutileProject/Assets/Platformer/Code/Game/Circle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public override Collider Clone()

public override void Render(Color color)
{
//Draw.Circle(AbsolutePosition, Radius, color, 4);
Platformer.Draw.Circle(AbsolutePosition, Radius, color, 4);
}

/*
Expand Down
6 changes: 3 additions & 3 deletions FutileProject/Assets/Platformer/Code/Game/Collider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ public Vector2 BottomRight {
}
}

/*public void Render()
public void Render()
{
Render(Color.Red);
}*/
Render(Color.red);
}

public Vector2 AbsolutePosition {
get {
Expand Down
2 changes: 2 additions & 0 deletions FutileProject/Assets/Platformer/Code/Game/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ protected void Update(/*GameTime gameTime*/)
}

//base.Update(gameTime);
Platformer.Draw.SpriteBatch.MoveToFront();

}

protected void Draw(/*GameTime gameTime*/)
Expand Down
21 changes: 21 additions & 0 deletions FutileProject/Assets/Platformer/Code/Game/GravityComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using UnityEngine;
using System;


namespace Platformer
{
public class GravityComponent : Component
{
public float gravity = -9.8f;
public GravityComponent () : base(true, false)
{
}

public override void Update ()
{
base.Update ();
Entity.Position.y += gravity * Time.deltaTime;
}
}
}

12 changes: 12 additions & 0 deletions FutileProject/Assets/Platformer/Code/Game/GravityComponent.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 19 additions & 14 deletions FutileProject/Assets/Platformer/Code/Game/Hero.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ public class Hero : Entity
public FContainer body;
public FSprite bodySprite;

float vx = 0;
float vy = 0;

public Hero () : base()
{
body = new FContainer ();
Engine.Scene.AddChild(body);
bodySprite = new FSprite ("Game/player");
body.AddChild (bodySprite);
/*
this.components.Add(new InputComponent(true, true));

this.Collider = new Circle(bodySprite.width/2, xx, yy);
Add(new InputComponent(true, true));
Add(new GravityComponent());
this.Collider = new Circle(bodySprite.width/2, CenterX, CenterY);
this.quad = new Quad(this.Collider.Left, this.Collider.Bottom, this.Collider.Right, this.Collider.Top);
entityContainer.quadTree.Insert(Collider, ref quad);*/
Engine.Scene.quadTree.Insert(Collider, ref quad);
}
/*
override public void HandleAdded ()
Expand All @@ -31,27 +35,28 @@ override public void HandleRemoved ()
{
base.HandleRemoved ();
body.RemoveFromContainer ();
}
}*/

override public void Update() {
base.Update();

InputComponent ic = components.Get<InputComponent>();
InputComponent ic = Components.Get<InputComponent>();
float speed = 0.04f;

if(ic.leftPressed)
dx -= speed;
vx -= speed;

if( ic.rightPressed )
dx += speed;
vx += speed;

if( ic.jumpPressed && OnGround() )
dy = 0.7f;
if( ic.jumpPressed /*&& OnGround()*/ )
vy = 0.7f;

SetPosition(xx, yy);
body.SetPosition(xx, yy);
Draw.Circle(Collider.Center, Collider.Width/2, Color.white, 10);
Position.x += vx;
Position.y += vy;
body.SetPosition(Position);
Draw.Circle(Collider.AbsolutePosition, Collider.Width/2, Color.white, 10);
}
*/

}
}
19 changes: 18 additions & 1 deletion FutileProject/Assets/Platformer/Code/Game/MainScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,27 @@ namespace Platformer
{
public class MainScene : Scene
{
bool initialized = false;

public MainScene () : base()
{
Map map = new Map(50, 20);
Debug.Log("MainScene");
}

public override void Update ()
{
base.Update ();
if (Engine.Scene != null && !initialized) {
Map map = new Map(50, 20);

Debug.Log (Core.playerManager.players.Count);
Hero hero = new Hero();
hero.Position.x = 1 * Config.GRID;
hero.Position.y = 1 * Config.GRID;
Engine.Scene.Add(hero);

initialized = true;
}
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions FutileProject/Assets/Platformer/Code/Game/Map.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ public Map(int width, int height)
Engine.Scene.Add(b);
}

/*Heart h = new Heart(GamePage.instance.entityContainer);
h.SetPosition(4*Config.GRID, 2 * Config.GRID);
h.AddToContainer();*/
Heart h = new Heart();
h.Position.x = 4*Config.GRID;
h.Position.y = 2 * Config.GRID;
Engine.Scene.Add(h);

}
}
Expand Down
2 changes: 2 additions & 0 deletions FutileProject/Assets/Platformer/Code/Game/Scene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,15 @@ void HandleUpdate()
public virtual void Begin()
{
Focused = true;
Engine.Instance.AddChild(this);
foreach (var entity in Entities)
entity.SceneBegin();
}

public virtual void End()
{
Focused = false;
RemoveFromContainer();
foreach (var entity in Entities)
entity.SceneEnd();
}
Expand Down

0 comments on commit 7c1e7a5

Please sign in to comment.