コード例 #1
0
ファイル: player.go プロジェクト: middric/codesweeper
// Draw func
func (player *Player) Draw(screen *termloop.Screen) {
	if player.state != Dead {
		// Keep player in bounds
		x, y := player.entity.Position()
		if x < 0 {
			x = 0
		} else if x >= width {
			x = width - 1
		}

		if y < 0 {
			y = 0
		} else if y >= height {
			y = height - 1
		}

		player.entity.SetPosition(x, y)

		// Draw player
		player.entity.Draw(screen)
	}

	screenWidth, screenHeight := screen.Size()
	level.SetOffset((screenWidth-width)/2, (screenHeight-height)/2)
}
コード例 #2
0
ファイル: hud.go プロジェクト: Wouterbeets/gomoku
func (h *hud) Draw(screen *tl.Screen) {
	w, _ := screen.Size()
	h.offsetX = w - 80
mainLoop:
	for {
		select {
		case str := <-h.com:
			i := hudMem - 1
			for i > 0 {
				h.toDisp[i] = h.toDisp[i-1]
				if h.toDisp[i] != nil {
					h.toDisp[i].SetPosition(h.offsetX, h.offsetY+i+2)
				}
				i--
			}
			h.toDisp[0] = tl.NewText(h.offsetX, h.offsetY+2, str, Fg, Bg)
		default:
			break mainLoop
		}
	}
	for _, v := range h.toDisp {
		v.Draw(screen)
	}
	h.header.SetPosition(h.offsetX, h.offsetY)
	h.header2.SetPosition(h.offsetX, h.offsetY+1)
	h.header.Draw(screen)
	h.header2.Draw(screen)
}
コード例 #3
0
ファイル: game.go プロジェクト: keithblaha/go_game_jam
func (player *Player) Draw(s *tl.Screen) {
	screenWidthidth, screenh := s.Size()
	x := player.sprite.x + screenWidthidth/2 - 30
	y := player.sprite.y + screenh - 25
	bg := tl.NewRectangle(x, y, x+20, y+10, StatsBG)
	bg.Draw(s)

	health := tl.NewText(x+1, y+1, fmt.Sprintf("%3.f%% health", float32(player.health)/float32(player.maxHealth)*100), tl.ColorRed, StatsBG)
	health.Draw(s)

	mana := tl.NewText(x+27, y+1, fmt.Sprintf("%3.f%% mana", float32(player.mana)/float32(player.maxMana)*100), tl.ColorBlue, StatsBG)
	mana.Draw(s)

	gold := tl.NewText(x+1, y+12, fmt.Sprintf("%d gold", player.gold), tl.ColorYellow, StatsBG)
	gold.Draw(s)

	experience := tl.NewText(x+29, y+12, fmt.Sprintf("%3.f%% xp", float32(player.experience)/float32(player.experienceToLevel)*100), tl.ColorMagenta, StatsBG)
	experience.Draw(s)

	if player.isCasting {
		player.isCasting = false

		newSpellEffect := NewSpellEffect(player.sprite, player.spellCanvases[player.sprite.direction], player.sprite.level)
		player.sprite.level.AddEntity(newSpellEffect)
	}

	e := tl.NewEntityFromCanvas(x+12, y+1, *player.portrait)
	e.Draw(s)
}
コード例 #4
0
ファイル: game.go プロジェクト: jodizzle/snake
func (text *StartLevel) Draw(screen *tl.Screen) {
	screenWidth, screenHeight := screen.Size()
	text.message.SetPosition(screenWidth/2, screenHeight/2)
	text.message.Draw(screen)
	text.instructions.SetPosition(screenWidth/2-5, screenHeight/2+1)
	text.instructions.Draw(screen)
	text.instructions2.SetPosition(screenWidth/2-5, screenHeight/2+2)
	text.instructions2.Draw(screen)
}
コード例 #5
0
ファイル: pyramid.go プロジェクト: gandilong/termloop
func (b *Block) Draw(s *tl.Screen) {
	if l, ok := b.g.Level().(*tl.BaseLevel); ok {
		// Set the level offset so the player is always in the
		// center of the screen. This simulates moving the camera.
		sw, sh := s.Size()
		x, y := b.r.Position()
		l.SetOffset(sw/2-x, sh/2-y)
	}
	b.r.Draw(s)
}
コード例 #6
0
ファイル: snake.go プロジェクト: towry/snakego
func (s *Snake) Draw(screen *tl.Screen) {
	s.bodyCollideDetect(s.px, s.py)
	// check border collision
	w, h := screen.Size()

	if s.px > w {
		s.px = 0
	} else if s.px < 0 {
		s.px = w
	}

	if s.py > h {
		s.py = 0
	} else if s.py < 0 {
		s.py = h
	}

	s.head.Draw(screen)
	s.drawBody(screen)

	if s.stop {
		return
	}

	// Control the speed.
	update := time.Now()
	delta := update.Sub(s.update).Seconds()

	if delta <= 1 {
		return
	} else {
		s.update = update
	}

	x, y := s.head.Position()
	switch s.dir {
	case KeyArrowRight:
		x += 1
		break
	case KeyArrowDown:
		y += 1
		break
	case KeyArrowLeft:
		x -= 1
		break
	case KeyArrowUp:
		y -= 1
		break
	}

	s.head.SetPosition(x, y)
	s.px = x
	s.py = y
	s.moveBody()
}
コード例 #7
0
ファイル: game.go プロジェクト: keithblaha/go_game_jam
func (sprite *Sprite) Draw(s *tl.Screen) {
	if (sprite.IsPlayer() && sprite.player.health <= 0) || (sprite.IsEnemy() && sprite.enemy.health <= 0) {
		sprite.level.RemoveEntity(sprite.CurrentEntity())
	} else {
		if sprite.IsPlayer() {
			screenWidthidth, screenh := s.Size()
			sprite.level.SetOffset(screenWidthidth/2-7-sprite.x, screenh/5-sprite.y)
		}
		sprite.CurrentEntity().Draw(s)
	}
}
コード例 #8
0
ファイル: food.go プロジェクト: towry/snakego
func (food *Food) Draw(screen *tl.Screen) {
	if food.x == -1 {
		sx, sw := screen.Size()
		rx := random(1, sx)
		ry := random(1, sw)
		food.x = rx
		food.y = ry
		food.entity.SetPosition(rx, ry)
	}

	food.entity.Draw(screen)
}
コード例 #9
0
ファイル: dodgeballRL.go プロジェクト: kaibacorp/roguelike
func (player *Player) Draw(screen *tl.Screen) {
	screenWidth, screenHeight := screen.Size()
	levelX, levelY := player.level.Offset()
	x, y := player.entity.Position()
	nearEdgeX := x+levelX < screenWidth/5 || x+levelX > (screenWidth-screenWidth/5)
	nearEdgeY := y+levelY < screenHeight/5 || y+levelY > (screenHeight-screenHeight/5)

	if nearEdgeX || nearEdgeY {
		player.level.SetOffset(screenWidth/2-x, screenHeight/2-y)
	}
	player.entity.Draw(screen)
}
コード例 #10
0
ファイル: welcome.go プロジェクト: Wouterbeets/gomoku
func (w *welcome) Draw(screen *tl.Screen) {
	if !w.done {
		width, height := screen.Size()
		w.game.Screen().Level().(*tl.BaseLevel).SetOffset(width/2-(len(header[0])/2), height/2-(len(header)/2))
		for _, v := range w.header {
			v.Draw(screen)
		}
		w.msg.Draw(screen)
		w.choices[w.selected].SetColor(Bg, Fg)
		for _, v := range w.choices {
			v.Draw(screen)
		}
	} else {
	}
}
コード例 #11
0
ファイル: player.go プロジェクト: jodizzle/gosnake
// Handles player movement and food spawn rate.
func (player *Player) Update(screen *tl.Screen) {
	player.snakeTime += screen.TimeDelta()
	if player.snakeTime > snakeRate {
		player.snakeTime -= snakeRate

		player.prevX, player.prevY = player.Position()
		switch player.direction {
		case "right":
			player.SetPosition(player.prevX+1, player.prevY)
		case "left":
			player.SetPosition(player.prevX-1, player.prevY)
		case "up":
			player.SetPosition(player.prevX, player.prevY-1)
		case "down":
			player.SetPosition(player.prevX, player.prevY+1)
		}

		player.SnakeMovement()
	}

	player.spawnTime += screen.TimeDelta()
	if player.spawnTime > spawnRate {
		player.spawnTime -= spawnRate

		screenWidth, screenHeight := screen.Size()
		rando := rand.New(rand.NewSource(time.Now().UnixNano()))
		spawnX, spawnY := rando.Intn(screenWidth), rando.Intn(screenHeight)
		screen.Level().AddEntity(tl.NewRectangle(spawnX, spawnY, 1, 1, tl.ColorGreen))

		game.Log("Spawn at (%d,%d)", spawnX, spawnY)
	}

	//Check box boundaries
	playerX, playerY := player.Position()
	screenWidth, screenHeight := game.Screen().Size()

	//<= is used on the upper-boundaries to prevent the player from disappearing offscreen
	//by one square
	//(Funnily enough, when player.snake is more than one unit long, just stopping the player at
	//the boundaries also causes a game over state because the tail slides into the head)
	if playerX < 0 || playerX >= screenWidth {
		GameOver()
	}
	if playerY < 0 || playerY >= screenHeight {
		GameOver()
	}
}
コード例 #12
0
ファイル: game.go プロジェクト: Wouterbeets/gomoku
func (b *board) Draw(screen *tl.Screen) {
	if b.wel.done {
		b.initPlayers()
		w, h := screen.Size()
		b.level.SetOffset(w/2-((boardSize*tileSizeX)/2), h/2-((boardSize*tileSizeY)/2))
		b.tilesDisp[b.sY][b.sX].selected()
		if (b.turn == AI1 || b.turn == AI2) && b.state != WINP1 && b.state != WINP2 {
			b.handleAIInput()
		}
		for _, tY := range b.tilesDisp {
			for _, tX := range tY {
				tX.Draw(screen)
			}
		}
	}
	//TODO if b.state == WINP1 || b.state == WINP2 {
	// highlight win
}
コード例 #13
0
ファイル: body.go プロジェクト: towry/snakego
func (body *Body) Draw(s *tl.Screen) {
	// border collision detect
	w, h := s.Size()

	if body.px > w {
		body.px = 0
	} else if body.px < 0 {
		body.px = w
	}

	if body.py > h {
		body.py = 0
	} else if body.py < 0 {
		body.py = h
	}

	body.entity.Draw(s)
}
コード例 #14
0
ファイル: player.go プロジェクト: pandoragabor/letty
func (player *Player) Draw(screen *tl.Screen) {
	screenWidth, screenHeight := screen.Size()
	x, y := player.entity.Position()
	TheGameState.Level.SetOffset(screenWidth/2-x, screenHeight/2-y)
	player.entity.Draw(screen)
}
コード例 #15
0
ファイル: game.go プロジェクト: jodizzle/snake
//Handles auto events
func (player *Player) Update(screen *tl.Screen) {
	//tl.Screen.size() parameters are evidently zero until the game.Start(),
	//So this is a crude solution intended to center the player after the game has begun
	if firstPass {
		screenWidth, screenHeight := screen.Size()
		player.SetPosition(screenWidth/2, screenHeight/2)
		firstPass = false
	}

	snakeTime += screen.TimeDelta()
	if snakeTime > 0.1 {
		snakeTime -= 0.1

		player.prevX, player.prevY = player.Position()
		switch player.direction {
		case "right":
			player.SetPosition(player.prevX+1, player.prevY)
			//player.SnakeMovement(player.prevX+1, player.prevY)
		case "left":
			player.SetPosition(player.prevX-1, player.prevY)
			//player.SnakeMovement(player.prevX-1, player.prevY)
		case "up":
			player.SetPosition(player.prevX, player.prevY-1)
			//player.SnakeMovement(player.prevX, player.prevY-1)
		case "down":
			player.SetPosition(player.prevX, player.prevY+1)
			//player.SnakeMovement(player.prevX, player.prevY+1)
		}

		player.SnakeMovement()
	}

	spawnTime += screen.TimeDelta()
	if spawnTime > 1 {
		spawnTime -= 1

		screenWidth, screenHeight := screen.Size()
		rando := rand.New(rand.NewSource(time.Now().UnixNano()))
		spawnX, spawnY := rando.Intn(screenWidth), rando.Intn(screenHeight)
		screen.Level().AddEntity(tl.NewRectangle(spawnX, spawnY, 1, 1, tl.ColorGreen))

		game.Log("Spawn at (%d,%d)", spawnX, spawnY)
	}

	//Check box boundaries
	playerX, playerY := player.Position()
	screenWidth, screenHeight := game.Screen().Size()

	//<= is used on the upper-boundaries to prevent the player from disappearing offscreen
	//by one square
	//(Funnily enough, when player.snake is more than one unit long, just stopping the player at
	//the boundaries also causes a game over state because the tail slides into the head)
	if playerX < 0 || playerX >= screenWidth {
		GameOver()
		//player.SetPosition(player.prevX, player.prevY)
	}
	if playerY < 0 || playerY >= screenHeight {
		GameOver()
		//player.SetPosition(player.prevX, player.prevY)
	}
}
コード例 #16
0
func (l *gameLevel) Draw(screen *tl.Screen) {
	l.Level.Draw(screen)

	if time.Now().After(l.garbageCollectEndsAt) {
		for _, i := range l.gt.items {
			i.Tick(l)
		}
	}

	sw, sh := screen.Size()
	gameLost := false
	gameWon := false
	totalComplete := 0
	for _, w := range l.words {
		w.Update()
		if !w.Complete() && w.y > sh-3 {
			gameLost = true
		}
		if w.Complete() {
			totalComplete++
		}
	}
	if totalComplete == len(l.words) {
		gameWon = true
	}
	if l.currentWord != nil && l.currentWord.Complete() {
		l.currentWord = nil
	}
	var possibleWords []int
	for i, w := range l.words {
		if !w.Complete() && w.startedBy == 0 {
			possibleWords = append(possibleWords, i)
		}
	}

	if l.currentWord == nil && len(possibleWords) > 0 {
		l.currentWord = l.words[possibleWords[rand.Intn(len(possibleWords))]]
		l.currentWord.startedBy = pc
	}

	if l.gt.stats.GarbageCollect() {
		l.gt.stats.Garbage = 0
		if l.gt.stats.GoVersion < 1.5 {
			l.garbageCollectEndsAt = time.Now().Add(time.Second * 3)
		} else {
			l.garbageCollectEndsAt = time.Now().Add(time.Second)
		}

	}
	var msg string
	if time.Now().Before(l.garbageCollectEndsAt) {
		msg = fmt.Sprintf("COLLECTING GARBAGE: PLEASE WAIT")
		l.garbageText.SetText(msg)
		bgColor := tl.ColorBlue
		if math.Remainder(float64(time.Now().Sub(l.garbageCollectEndsAt)), float64(time.Second)) > 0.5 {
			bgColor = tl.ColorBlack
		}
		l.garbageText.SetColor(tl.ColorRed, bgColor)
		l.garbageText.SetPosition(sw/2-len(msg)/2, 4)
	} else {
		msg = fmt.Sprintf("Garbage: %d ", l.gt.stats.Garbage)
		l.garbageText.SetText(msg)
		l.garbageText.SetColor(tl.ColorRed, tl.ColorBlue)
		l.garbageText.SetPosition(sw-len(msg), sh-1)
	}

	if l.currentWord != nil {
		l.currentWordText.SetText("Current Word: " + l.currentWord.str[l.currentWord.completedChars:])
	} else {
		l.currentWordText.SetText("")
	}
	// End conditions
	if gameWon {
		l.gt.goToEndWin()
	}
	if gameLost {
		l.gt.goToEndFail()
	}
}