本文整理汇总了Golang中github.com/JoelOtter/termloop.Screen类的典型用法代码示例。如果您正苦于以下问题:Golang Screen类的具体用法?Golang Screen怎么用?Golang Screen使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Screen类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Draw
// 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)
}
开发者ID:middric,项目名称:codesweeper,代码行数:26,代码来源:player.go
示例2: Draw
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)
}
开发者ID:fergstar,项目名称:pen.go,代码行数:27,代码来源:iceblock.go
示例3: Draw
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)
}
开发者ID:Wouterbeets,项目名称:gomoku,代码行数:28,代码来源:hud.go
示例4: Draw
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)
}
开发者ID:keithblaha,项目名称:go_game_jam,代码行数:29,代码来源:game.go
示例5: Draw
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])
}
}
}
开发者ID:aquilax,项目名称:number_crusher,代码行数:8,代码来源:board.go
示例6: Draw
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)
}
开发者ID:jodizzle,项目名称:snake,代码行数:9,代码来源:game.go
示例7: Draw
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)
}
开发者ID:gandilong,项目名称:termloop,代码行数:10,代码来源:pyramid.go
示例8: Draw
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()
}
开发者ID:towry,项目名称:snakego,代码行数:55,代码来源:snake.go
示例9: Draw
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)
}
开发者ID:swapagarwal,项目名称:gotapper,代码行数:53,代码来源:main.go
示例10: Draw
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)
}
开发者ID:kaibacorp,项目名称:roguelike,代码行数:12,代码来源:dodgeballRL.go
示例11: Draw
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)
}
开发者ID:towry,项目名称:snakego,代码行数:12,代码来源:food.go
示例12: Draw
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 {
}
}
开发者ID:Wouterbeets,项目名称:gomoku,代码行数:15,代码来源:welcome.go
示例13: Draw
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
}
开发者ID:Wouterbeets,项目名称:gomoku,代码行数:18,代码来源:game.go
示例14: Draw
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)
}
开发者ID:towry,项目名称:snakego,代码行数:18,代码来源:body.go
示例15: StartLevel
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)
}
}()
}
开发者ID:pandoragabor,项目名称:letty,代码行数:25,代码来源:gamestate.go
示例16: Update
// 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()
}
}
开发者ID:jodizzle,项目名称:gosnake,代码行数:48,代码来源:player.go
示例17: Draw
// 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])
}
}
}
开发者ID:middric,项目名称:codesweeper,代码行数:20,代码来源:dialog.go
示例18: Draw
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})
}
}
}
}
开发者ID:gophergala2016,项目名称:gopher_typer,代码行数:19,代码来源:word.go
示例19: Draw
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)
}
开发者ID:pandoragabor,项目名称:letty,代码行数:6,代码来源:player.go
示例20: Draw
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()
}
}
开发者ID:gophergala2016,项目名称:gopher_typer,代码行数:79,代码来源:game_level.go
注:本文中的github.com/JoelOtter/termloop.Screen类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论