本文整理匯總了Golang中github.com/JoelOtter/termloop.Screen類的典型用法代碼示例。如果您正苦於以下問題:Golang Screen類的具體用法?Golang Screen怎麽用?Golang Screen使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Screen類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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)
}
示例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)
}
示例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)
}
示例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)
}
示例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])
}
}
}
示例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)
}
示例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)
}
示例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()
}
示例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)
}
示例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)
}
示例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)
}
示例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 {
}
}
示例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
}
示例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)
}
示例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)
}
}()
}