コード例 #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
ファイル: iceblock.go プロジェクト: fergstar/pen.go
func (i *Iceblock) Draw(s *tl.Screen) {

	// if the iceblock has a direction
	if i.direction != NONE {
		// then move it in the direction specified
		i.time += s.TimeDelta()
		if i.time > i.update {
			switch i.direction {
			case RIGHT:
				i.r.SetPosition(i.endPos.x+1, i.endPos.y)
				break
			case LEFT:
				i.r.SetPosition(i.endPos.x-1, i.endPos.y)
				break
			case UP:
				i.r.SetPosition(i.endPos.x, i.endPos.y-1)
				break
			case DOWN:
				i.r.SetPosition(i.endPos.x, i.endPos.y+1)
			}
			// updated its previous position
			i.endPos.x, i.endPos.y = i.r.Position()
			i.time -= i.update
		}
	}
	i.r.Draw(s)
}
コード例 #3
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)
}
コード例 #4
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)
}
コード例 #5
0
ファイル: board.go プロジェクト: aquilax/number_crusher
func (sq *Square) Draw(screen *tl.Screen) {
	if sq.visible {
		x, y := sq.getPosition()
		for i := 0; i < 5; i++ {
			screen.RenderCell(x+i, y, &sq.canvas[i])
		}
	}
}
コード例 #6
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)
}
コード例 #7
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)
}
コード例 #8
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()
}
コード例 #9
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)
	}
}
コード例 #10
0
ファイル: main.go プロジェクト: swapagarwal/gotapper
func (r *RemainingTime) Draw(s *tl.Screen) {
	if Status == 1 {
		r.t = math.Max(r.t-s.TimeDelta(), 0)
		if r.t == 0 {
			Status = 0
			r.e.SetText("Time up!")
		} else {
			if Response == 1 {
				s, _ := strconv.Atoi(r.s.Text())
				s = s + 1
				if s%5 == 0 {
					r.t = r.t + 1
				}
				r.s.SetText(strconv.Itoa(s))
				switch s {
				case 10:
					r.m.SetText("You've got it!")
				case 20:
					r.m.SetText("Keep going!")
				case 30:
					r.m.SetText("You're doing great!")
				case 40:
					r.m.SetText("You rock!")
				case 50:
					r.m.SetText("Don't stop!")
				case 60:
					r.m.SetText("I like your style!")
				case 70:
					r.m.SetText("Awesome!")
				case 80:
					r.m.SetText("How do you do that?")
				case 90:
					r.m.SetText("Don't ever stop!!")
				case 100:
					r.m.SetText("I'm really impressed.")
				case 150:
					r.m.SetText("You're really still here?")
				case 200:
					r.m.SetText("That's incredible!")
				}
			} else if Response == 2 {
				Status = 0
				r.e.SetText("Game Over")
			}
		}
		Response = 0
		r.r.SetText(fmt.Sprintf("%.3f", r.t))
	}
	r.r.Draw(s)
	r.s.Draw(s)
	r.m.Draw(s)
	r.e.Draw(s)
}
コード例 #11
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)
}
コード例 #12
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)
}
コード例 #13
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 {
	}
}
コード例 #14
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
}
コード例 #15
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)
}
コード例 #16
0
ファイル: gamestate.go プロジェクト: pandoragabor/letty
func (gamestate *GameState) StartLevel(levelIndex int, screen *tl.Screen) {
	gamestate.LevelIndex = levelIndex
	gamestate.Level = gamestate.CreateLevelByIndex()

	gamestate.Bullets = make([]*Bullet, 0)

	gamestate.Player = NewPlayer(gamestate.Level.StartX, gamestate.Level.StartY)
	gamestate.Level.AddEntity(gamestate.Player)

	screen.SetLevel(gamestate.Level)

	screen.AddEntity(gamestate.Player.Score)
	screen.AddEntity(gamestate.Player.Level)
	screen.AddEntity(gamestate.Player.Health)

	// animate the beasts
	go func() {
		for {
			for _, enemy := range TheGameState.Level.Enemies {
				enemy.Animate()
			}
			time.Sleep(500 * time.Millisecond)
		}
	}()
}
コード例 #17
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()
	}
}
コード例 #18
0
ファイル: dialog.go プロジェクト: middric/codesweeper
// Draw draws the Dialog to the Screen s.
func (d *Dialog) Draw(s *termloop.Screen) {
	width, height := d.Size()

	// Render shadow
	for x := 1; x < width; x++ {
		s.RenderCell(d.x+x, d.y+height, &termloop.Cell{Ch: '▒', Fg: d.fg, Bg: termloop.ColorDefault})
	}
	for y := 1; y < height; y++ {
		s.RenderCell(d.x+width, d.y+y, &termloop.Cell{Ch: '▒', Fg: d.fg, Bg: termloop.ColorDefault})
	}
	s.RenderCell(d.x+width, d.y+height, &termloop.Cell{Ch: '▒', Fg: d.fg, Bg: termloop.ColorDefault})

	// Render content
	for x := 0; x < height; x++ {
		for y := 0; y < width; y++ {
			s.RenderCell(d.x+y, d.y+x, &d.canvas[x][y])
		}
	}
}
コード例 #19
0
ファイル: word.go プロジェクト: gophergala2016/gopher_typer
func (w *word) Draw(s *tl.Screen) {
	for i, ch := range w.str {
		if w.startedBy == 0 {
			s.RenderCell(w.x+i, w.y, &tl.Cell{Fg: w.fgTodo, Bg: tl.ColorDefault, Ch: ch})
		} else {
			var bg tl.Attr
			if w.startedBy == pc {
				bg = w.bgPlayer
			} else {
				bg = w.bgGoroutine
			}
			if i < w.completedChars {
				s.RenderCell(w.x+i, w.y, &tl.Cell{Fg: w.fgComplete, Bg: bg, Ch: ch})
			} else {
				s.RenderCell(w.x+i, w.y, &tl.Cell{Fg: w.fgTodo, Bg: bg, Ch: ch})
			}
		}
	}
}
コード例 #20
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)
}
コード例 #21
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()
	}
}
コード例 #22
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)
	}
}