Exemple #1
0
func (f *fire) Think(ent game.Ent, g *game.Game) {
	player := ent.(*game.PlayerEnt)
	proc, ok := player.Processes[f.id].(*multiDrain)
	if !ok {
		return
	}
	if f.trigger && f.draining && proc.Stored > 1 {
		proc.Stored -= 0.1

		// TODO: This is assuming 60fps - maybe that should be checked somewhere?
		for f.xFrac += f.xps / 60.0; f.xFrac > 0.0; f.xFrac-- {
			g.Processes = append(g.Processes, &asplosionProc{
				StartRadius:    f.startRadius,
				EndRadius:      f.endRadius,
				DurationThinks: f.durationThinks,
				Dps:            f.dps,
				Pos:            f.getPos(ent, g),
			})
		}

		if proc.Stored <= 1.0 {
			f.draining = false
			f.xFrac = 0
		}
	}
}
Exemple #2
0
func (pm *placeMine) Input(ent game.Ent, g *game.Game, pressAmt float64, trigger bool) {
	player := ent.(*game.PlayerEnt)
	if pressAmt == 0 {
		delete(player.Processes, pm.id)
		return
	}
	proc, ok := player.Processes[pm.id].(*multiDrain)
	if !ok {
		player.Processes[pm.id] = &multiDrain{Gid: player.Gid, Unit: game.Mana{300, 0, 0}}
		return
	}
	if trigger && proc.Stored > 1 {
		proc.Stored--
		heading := (linear.Vec2{1, 0}).Rotate(ent.Angle())
		pos := ent.Pos().Add(heading.Scale(100))
		g.MakeMine(pos, linear.Vec2{}, 100, 100, 100, 100)
	}
}
Exemple #3
0
func (sc *spawnCreeps) Input(ent game.Ent, g *game.Game, pressAmt float64, trigger bool) {
	cp := ent.(*game.ControlPoint)
	if pressAmt == 0 {
		delete(cp.Processes, sc.id)
		return
	}
	_, ok := cp.Processes[sc.id].(*omniDrain)
	if !ok && cp.Controlled {
		cp.Processes[sc.id] = &omniDrain{Gid: cp.Gid}
		return
	}
	if !cp.Controlled {
		delete(cp.Processes, sc.id)
		return
	}
	if proc, _ := cp.Processes[sc.id].(*omniDrain); proc != nil && trigger {
		g.AddEnt(ent)
		delete(cp.Processes, sc.id)
		creepCount := int(proc.Stored.Magnitude() / 300)
		g.AddCreeps(cp.Pos(), creepCount, cp.Side(), map[string]interface{}{"target": cp.Targets[0]})
	}
}
Exemple #4
0
func (a *asplode) Input(ent game.Ent, g *game.Game, pressAmt float64, trigger bool) {
	if trigger && !ent.Dead() {
		// Kill ent and put down explosion
		ent.Suicide()
		g.Processes = append(g.Processes, &asplosionProc{
			StartRadius:    a.startRadius,
			EndRadius:      a.endRadius,
			DurationThinks: a.durationThinks,
			Dps:            a.dps,
			Pos:            ent.Pos(),
		})
	}
}
Exemple #5
0
func (l *lightning) Think(ent game.Ent, g *game.Game) {
	player := ent.(*game.PlayerEnt)
	proc, ok := player.Processes[l.id].(*multiDrain)
	if !ok {
		return
	}
	if l.trigger && proc.Stored > 1 {
		delete(player.Processes, l.id)
		// find the endpoits of the lightning
		forward := (linear.Vec2{1, 0}).Rotate(player.Angle()).Scale(10000)
		bounds := [2]linear.Seg2{
			linear.Seg2{
				player.Pos(),
				player.Pos().Add(forward),
			},
			linear.Seg2{
				player.Pos(),
				player.Pos().Sub(forward),
			},
		}
		mag2s := [2]float64{-1.0, -1.0}
		var isects [2]linear.Vec2
		isects[0] = bounds[0].Q
		isects[1] = bounds[1].Q
		for _, wall := range g.Level.Room.Walls {
			for i := range wall {
				seg := wall.Seg(i)
				for j := range bounds {
					if bounds[j].DoesIsect(seg) {
						isect := bounds[j].Isect(seg)
						isectMag2 := isect.Sub(player.Pos()).Mag2()
						if isectMag2 < mag2s[j] || mag2s[j] == -1 {
							mag2s[j] = isectMag2
							isects[j] = isect
						}
					}
				}
			}
		}
		g.Processes = append(g.Processes, &lightningBoltProc{
			BuildThinks:    l.buildThinks,
			DurationThinks: l.durationThinks,
			Width:          l.width * math.Sqrt(proc.Stored),
			Dps:            l.dps,
			Power:          proc.Stored,
			Seg:            linear.Seg2{isects[0], isects[1]},
		})
	}
}