Example #1
0
func (game *Game) Setup(w *engi.World) {
	engi.SetBg(0x2d3739)

	// Add all of the systems
	w.AddSystem(&engi.RenderSystem{})
	w.AddSystem(&engi.CollisionSystem{})
	w.AddSystem(&DeathSystem{})
	w.AddSystem(&FallingSystem{})
	w.AddSystem(&ControlSystem{})
	w.AddSystem(&RockSpawnSystem{})

	// Create new entity subscribed to all the systems!
	guy := engi.NewEntity([]string{"RenderSystem", "ControlSystem", "RockSpawnSystem", "CollisionSystem", "DeathSystem"})
	texture := engi.Files.Image("icon.png")
	render := engi.NewRenderComponent(texture, engi.Point{4, 4}, "guy")
	// Tell the collision system that this player is solid
	collision := &engi.CollisionComponent{Solid: true, Main: true}

	width := texture.Width() * render.Scale.X
	height := texture.Height() * render.Scale.Y

	space := &engi.SpaceComponent{engi.Point{(engi.Width() - width) / 2, (engi.Height() - height) / 2}, width, height}

	guy.AddComponent(render)
	guy.AddComponent(space)
	guy.AddComponent(collision)

	w.AddEntity(guy)
}
Example #2
0
// Setup is called before the main loop is started
func (game *Game) Setup(w *ecs.World) {
	engi.SetBg(0x222222)
	w.AddSystem(&engi.RenderSystem{})
	w.AddSystem(engi.NewMouseZoomer(zoomSpeed))

	// Create the background; this way we'll see when we actually zoom
	w.AddEntity(generateBackground())
}
Example #3
0
func (pong *PongGame) Setup(w *ecs.World) {
	engi.SetBg(0x2d3739)
	w.AddSystem(&engi.RenderSystem{})
	w.AddSystem(&engi.CollisionSystem{})
	w.AddSystem(&SpeedSystem{})
	w.AddSystem(&ControlSystem{})
	w.AddSystem(&BallSystem{})
	w.AddSystem(&ScoreSystem{})

	basicFont = (&engi.Font{URL: "Roboto-Regular.ttf", Size: 32, FG: color.NRGBA{255, 255, 255, 255}})
	if err := basicFont.CreatePreloaded(); err != nil {
		log.Fatalln("Could not load font:", err)
	}

	ball := ecs.NewEntity([]string{"RenderSystem", "CollisionSystem", "SpeedSystem", "BallSystem"})
	ballTexture := engi.Files.Image("ball.png")
	ballRender := engi.NewRenderComponent(ballTexture, engi.Point{2, 2}, "ball")
	ballSpace := &engi.SpaceComponent{engi.Point{(engi.Width() - ballTexture.Width()) / 2, (engi.Height() - ballTexture.Height()) / 2}, ballTexture.Width() * ballRender.Scale().X, ballTexture.Height() * ballRender.Scale().Y}
	ballCollision := &engi.CollisionComponent{Main: true, Solid: true}
	ballSpeed := &SpeedComponent{}
	ballSpeed.Point = engi.Point{300, 100}

	ball.AddComponent(ballRender)
	ball.AddComponent(ballSpace)
	ball.AddComponent(ballCollision)
	ball.AddComponent(ballSpeed)
	w.AddEntity(ball)

	score := ecs.NewEntity([]string{"RenderSystem", "ScoreSystem"})

	scoreRender := engi.NewRenderComponent(basicFont.Render(" "), engi.Point{1, 1}, "YOLO <3")

	scoreSpace := &engi.SpaceComponent{engi.Point{100, 100}, 100, 100}
	score.AddComponent(scoreRender)
	score.AddComponent(scoreSpace)
	w.AddEntity(score)

	schemes := []string{"WASD", ""}
	for i := 0; i < 2; i++ {
		paddle := ecs.NewEntity([]string{"RenderSystem", "CollisionSystem", "ControlSystem"})
		paddleTexture := engi.Files.Image("paddle.png")
		paddleRender := engi.NewRenderComponent(paddleTexture, engi.Point{2, 2}, "paddle")
		x := float32(0)
		if i != 0 {
			x = 800 - 16
		}

		paddleSpace := &engi.SpaceComponent{engi.Point{x, (engi.Height() - paddleTexture.Height()) / 2}, paddleRender.Scale().X * paddleTexture.Width(), paddleRender.Scale().Y * paddleTexture.Height()}
		paddleControl := &ControlComponent{schemes[i]}
		paddleCollision := &engi.CollisionComponent{Main: false, Solid: true}
		paddle.AddComponent(paddleRender)
		paddle.AddComponent(paddleSpace)
		paddle.AddComponent(paddleControl)
		paddle.AddComponent(paddleCollision)
		w.AddEntity(paddle)
	}
}
Example #4
0
// Setup is called before the main loop is started
func (game *Game) Setup(w *ecs.World) {
	engi.SetBg(0x222222)
	w.AddSystem(&engi.RenderSystem{})

	// The most important line in this whole demo:
	w.AddSystem(engi.NewEdgeScroller(scrollSpeed, edgeMargin))

	// Create the background; this way we'll see when we actually scroll
	w.AddEntity(generateBackground())
}
Example #5
0
func (b *BCIGame) Setup(w *ecs.World) {
	engi.SetBg(0x444444)

	w.AddSystem(&systems.MenuListener{})
	w.AddSystem(&systems.Maze{LevelDirectory: filepath.Join(assetsDir, levelsDir), Controller: &systems.ErroneousKeyboardController{}})
	w.AddSystem(&systems.FPS{BaseTitle: gameTitle})
	w.AddSystem(&systems.MovementSystem{})
	w.AddSystem(&systems.Calibrate{})
	w.AddSystem(&engi.RenderSystem{})
}
Example #6
0
func (game *GameWorld) Setup(w *ecs.World) {
	engi.SetBg(0xFFFFFF)

	w.AddSystem(&engi.MouseSystem{})
	w.AddSystem(&engi.RenderSystem{})
	w.AddSystem(&ControlSystem{})
	w.AddSystem(engi.NewMouseZoomer(-0.125))

	w.AddEntity(game.CreateEntity())
}
Example #7
0
func (game *Game) Setup(w *ecs.World) {
	engi.SetBg(0xFFFFFF)

	w.AddSystem(&engi.RenderSystem{})
	w.AddSystem(&engi.AudioSystem{})

	backgroundMusic := ecs.NewEntity([]string{"AudioSystem"})
	backgroundMusic.AddComponent(&engi.AudioComponent{File: "326488.wav", Repeat: true, Background: true})

	w.AddEntity(backgroundMusic)
}
Example #8
0
File: zoom.go Project: Kunde21/engi
// Setup is called before the main loop is started
func (game *Game) Setup(w *engi.World) {
	engi.SetBg(0x222222)
	w.AddSystem(&engi.RenderSystem{})
	w.AddSystem(engi.NewMouseZoomer(zoomSpeed))

	// Explicitly set WorldBounds for better default CameraSystem values
	engi.WorldBounds.Max = engi.Point{worldWidth, worldHeight}

	// Create the background; this way we'll see when we actually zoom
	w.AddEntity(generateBackground())
}
Example #9
0
func (game *GameWorld) Setup(w *ecs.World) {
	engi.SetBg(0xFFFFFF)

	w.AddSystem(&engi.RenderSystem{})
	w.AddSystem(&engi.AnimationSystem{})
	w.AddSystem(&ControlSystem{})
	w.AddSystem(engi.NewMouseZoomer(zoomSpeed))

	spriteSheet := engi.NewSpritesheetFromFile("hero.png", 150, 150)

	w.AddEntity(game.CreateEntity(&engi.Point{0, 0}, spriteSheet, StopAction))
}
Example #10
0
func (pong *PongGame) Setup(w *engi.World) {
	engi.SetBg(0x2d3739)
	w.AddSystem(&engi.RenderSystem{})
	w.AddSystem(&engi.CollisionSystem{})
	w.AddSystem(&SpeedSystem{})
	w.AddSystem(&ControlSystem{})
	w.AddSystem(&BallSystem{})
	w.AddSystem(&ScoreSystem{})

	ball := engi.NewEntity([]string{"RenderSystem", "CollisionSystem", "SpeedSystem", "BallSystem"})
	ballTexture := engi.Files.Image("ball.png")
	ballRender := engi.NewRenderComponent(ballTexture, engi.Point{2, 2}, "ball")
	ballSpace := &engi.SpaceComponent{engi.Point{(engi.Width() - ballTexture.Width()) / 2, (engi.Height() - ballTexture.Height()) / 2}, ballTexture.Width() * ballRender.Scale.X, ballTexture.Height() * ballRender.Scale.Y}
	ballCollision := &engi.CollisionComponent{Main: true, Solid: true}
	ballSpeed := &SpeedComponent{}
	ballSpeed.Point = engi.Point{300, 100}
	ball.AddComponent(ballRender)
	ball.AddComponent(ballSpace)
	ball.AddComponent(ballCollision)
	ball.AddComponent(ballSpeed)
	w.AddEntity(ball)

	score := engi.NewEntity([]string{"RenderSystem", "ScoreSystem"})

	scoreRender := engi.NewRenderComponent(basicFont.Render(" "), engi.Point{1, 1}, "YOLO <3")
	scoreSpace := &engi.SpaceComponent{engi.Point{100, 100}, 100, 100}
	score.AddComponent(scoreRender)
	score.AddComponent(scoreSpace)
	w.AddEntity(score)

	schemes := []string{"WASD", ""}
	for i := 0; i < 2; i++ {
		paddle := engi.NewEntity([]string{"RenderSystem", "CollisionSystem", "ControlSystem"})
		paddleTexture := engi.Files.Image("paddle.png")
		paddleRender := engi.NewRenderComponent(paddleTexture, engi.Point{2, 2}, "paddle")
		x := float32(0)
		if i != 0 {
			x = 800 - 16
		}
		paddleSpace := &engi.SpaceComponent{engi.Point{x, (engi.Height() - paddleTexture.Height()) / 2}, paddleRender.Scale.X * paddleTexture.Width(), paddleRender.Scale.Y * paddleTexture.Height()}
		paddleControl := &ControlComponent{schemes[i]}
		paddleCollision := &engi.CollisionComponent{Main: false, Solid: true}
		paddle.AddComponent(paddleRender)
		paddle.AddComponent(paddleSpace)
		paddle.AddComponent(paddleControl)
		paddle.AddComponent(paddleCollision)
		w.AddEntity(paddle)
	}
}
Example #11
0
// Setup is called before the main loop is started
func (game *Game) Setup(w *ecs.World) {
	engi.SetBg(0x222222)
	w.AddSystem(&engi.RenderSystem{})

	// Adding KeyboardScroller so we can actually see the difference between background and HUD when scrolling
	w.AddSystem(engi.NewKeyboardScroller(scrollSpeed, engi.W, engi.D, engi.S, engi.A))
	w.AddSystem(engi.NewMouseZoomer(zoomSpeed))

	// Create background, so we can see difference between this and HUD
	w.AddEntity(generateBackground())

	// Creating the HUD
	hudWidth := float32(200)         // Can be anything you want
	hudHeight := engi.WindowHeight() // Can be anything you want

	// Generate something that uses the PriorityLevel HUDGround or up
	hudBg := generateHUDBackground(hudWidth, hudHeight)
	w.AddEntity(hudBg)
}
Example #12
0
func (game *GameWorld) Setup() {
	engi.SetBg(0x2d3739)

	game.AddSystem(&engi.RenderSystem{})

	gameMap := ecs.NewEntity([]string{"RenderSystem"})
	tilemap := engi.NewTilemap(
		[][]string{
			{"0", "2", "0"},
			{"4", "5", "1"},
			{"2", "3", "4"},
			{"5", "1", "2"}},
		engi.Files.Image("sheet"), 16)

	mapRender := engi.NewRenderComponent(tilemap, engi.Point{1, 1}, "map")
	mapSpace := &engi.SpaceComponent{engi.Point{100, 100}, 0, 0}
	gameMap.AddComponent(mapRender)
	gameMap.AddComponent(mapSpace)

	game.AddEntity(gameMap)
}
Example #13
0
func (game *GameWorld) Setup(w *engi.World) {
	engi.SetBg(0xFFFFFF)

	w.AddSystem(&engi.RenderSystem{})
	w.AddSystem(&engi.AnimationSystem{})
	w.AddSystem(&engi.PauseSystem{})

	spriteSheet := engi.NewSpritesheetFromFile("hero.png", 150, 150)

	w.AddEntity(game.CreateEntity(&engi.Point{0, 0}, spriteSheet, game.RUN_ACTION))
	w.AddEntity(game.CreateEntity(&engi.Point{300, 0}, spriteSheet, game.WALK_ACTION))
	w.AddEntity(game.CreateEntity(&engi.Point{600, 0}, spriteSheet, game.STOP_ACTION))
	w.AddEntity(game.CreateEntity(&engi.Point{900, 0}, spriteSheet, game.SKILL_ACTION))

	// This animation is special
	d_entity := game.CreateEntity(&engi.Point{1200, 0}, spriteSheet, game.DIE_ACTION)
	// ... because now, it's not affected by pausing
	d_entity.AddComponent(&engi.UnpauseComponent{})

	w.AddEntity(d_entity)
}
Example #14
0
func (game *GameWorld) Setup(w *ecs.World) {
	engi.SetBg(0x2d3739)

	w.AddSystem(&engi.RenderSystem{})
	w.AddSystem(&HideSystem{})

	guy := ecs.NewEntity([]string{"RenderSystem", "HideSystem"})
	texture := engi.Files.Image("rock.png")
	render := engi.NewRenderComponent(texture, engi.Point{8, 8}, "guy")
	collision := &engi.CollisionComponent{Solid: true, Main: true}

	width := texture.Width() * render.Scale().X
	height := texture.Height() * render.Scale().Y

	space := &engi.SpaceComponent{engi.Point{(engi.Width() - width) / 2, (engi.Height() - height) / 2}, width, height}

	guy.AddComponent(render)
	guy.AddComponent(space)
	guy.AddComponent(collision)

	w.AddEntity(guy)
}
Example #15
0
func (game *GameWorld) Setup(w *ecs.World) {
	engi.SetBg(0x2d3739)

	w.AddSystem(&engi.RenderSystem{})

	// Create an entity part of the Render and Scale systems
	guy := ecs.NewEntity([]string{"RenderSystem", "ScaleSystem"})
	// Retrieve a texture
	texture := engi.Files.Image("icon.png")

	// Create RenderComponent... Set scale to 8x, give lable "guy"
	render := engi.NewRenderComponent(texture, engi.Point{8, 8}, "guy")

	width := texture.Width() * render.Scale().X
	height := texture.Height() * render.Scale().Y

	space := &engi.SpaceComponent{engi.Point{0, 0}, width, height}

	guy.AddComponent(render)
	guy.AddComponent(space)

	w.AddEntity(guy)
}
Example #16
0
func (game *RockScene) Setup(w *ecs.World) {
	engi.SetBg(0x2d3739)

	w.AddSystem(&engi.RenderSystem{})
	w.AddSystem(&ScaleSystem{})
	w.AddSystem(&SceneSwitcherSystem{NextScene: "IconScene", WaitTime: time.Second * 3})

	guy := ecs.NewEntity([]string{"RenderSystem", "ScaleSystem"})
	texture := engi.Files.Image("rock.png")
	render := engi.NewRenderComponent(texture, engi.Point{8, 8}, "rock")
	collision := &engi.CollisionComponent{Solid: true, Main: true}

	width := texture.Width() * render.Scale().X
	height := texture.Height() * render.Scale().Y

	space := &engi.SpaceComponent{engi.Point{(engi.Width() - width) / 2, (engi.Height() - height) / 2}, width, height}

	guy.AddComponent(render)
	guy.AddComponent(space)
	guy.AddComponent(collision)

	w.AddEntity(guy)
}