예제 #1
0
파일: intro.py 프로젝트: r452031538/csci321
def jump(kx, ky):
	target = None
	d2 = settings.maxjump ** 2
	for ship in state.ships:
		if ship is control["cursor"]:
			continue
		dx = math.Xmod(ship.X - control["cursor"].X) * control["cursor"].y
		dy = ship.y - control["cursor"].y
		if dx * dx + dy * dy < d2:
			if abs(math.Xmod(math.atan2(kx, ky) - math.atan2(dx, dy))) < math.tau / 11:
				target = ship
				d2 = dx * dx + dy * dy
	if target:
		control["cursor"] = target
예제 #2
0
파일: thing.py 프로젝트: r452031538/csci321
	def think(self, dt):
		dx = math.Xmod(self.X0 - self.X) * self.y
		dy = self.y0 - self.y
		d = math.sqrt(dx ** 2 + dy ** 2)
		if d < 2:
			self.die()
		else:
			f = min(dt * self.v / d, 1)
			self.X += dx * f / self.y
			self.y += dy * f
예제 #3
0
 def follow(self, obj):
     if obj is self.following:
         return
     oldfollow = self.following
     self.following = obj
     self.tfollow = 0.4
     self.oldX = obj.X + math.Xmod(self.X0 - obj.X)
     self.oldy = self.y0
     if oldfollow is None:
         self.tfollow = 0
         self.think(0)
예제 #4
0
def retarget():
    target = None
    d2 = 4 * settings.rqteleport**2
    X, y = control["qtarget"]
    for ship in state.ships:
        if window.distance(ship, state.you) > settings.rqteleport:
            continue
        dx = math.Xmod(ship.X - X) * (ship.y + y) / 2
        dy = ship.y - y
        if dx**2 + dy**2 < d2:
            target = ship
            d2 = dx**2 + dy**2
    if target:
        control["cursor"] = target
예제 #5
0
파일: thing.py 프로젝트: r452031538/csci321
	def draw(self):
		if not self.deployed:
			return
		px0, py0 = window.screenpos(self.X, self.y)
		for obj in state.goals:
			dx = math.Xmod(obj.X - self.X) * (self.y + obj.y) / 2
			dy = obj.y - self.y
			d = math.sqrt(dx ** 2 + dy ** 2)
			if d < 8:
				continue
			dx /= d
			dy /= d
			px = px0 + int(window.camera.R * 2 * dx)
			py = py0 - int(window.camera.R * 2 * dy)
			pygame.draw.circle(window.screen, (0, 0, 255), (px, py), F(2))
예제 #6
0
 def near(self, obj):
     return self.Cy0 <= obj.y <= self.Cy1 and abs(
         math.Xmod(self.X0 - obj.X)) <= self.CdX
예제 #7
0
 def on(self, obj):
     return self.By0 <= obj.y <= self.By1 and abs(
         math.Xmod(self.X0 - obj.X)) <= self.BdX
예제 #8
0
def dbycoord(p1, p2):
    (X1, y1), (X2, y2) = p1, p2
    dx = math.Xmod(X1 - X2) * 2 / (y1 + y2)
    dy = y1 - y2
    return math.sqrt(dx * dx + dy * dy)
예제 #9
0
def distance(obj1, obj2):
    dx = math.Xmod(obj1.X - obj2.X) * (obj1.y + obj2.y) / 2
    dy = obj1.y - obj2.y
    return math.sqrt(dx**2 + dy**2)
예제 #10
0
def think(dt, events, kpressed):
    global todraw
    kx = kpressed["right"] - kpressed["left"]
    ky = kpressed["up"] - kpressed["down"]

    dt0 = dt
    if kpressed["go"] and control:
        dt *= 0.3

    hud.think(dt0)
    quest.think(dt)
    dialog.think(dt0)
    background.think(dt)
    sound.epicness = 2 - (state.you.y - 100) / 160
    sound.think(dt)

    oldX, oldy = state.you.X, state.you.y

    if 1e10 * random.random() < dt:
        state.ships.append(
            thing.Skiff(X=random.uniform(0, math.tau),
                        y=state.R,
                        vx=random.uniform(-6, 6)))
        state.ships.append(
            thing.Beacon(X=random.uniform(0, math.tau),
                         y=state.R,
                         vx=random.uniform(-6, 6)))
    nbubble = int(dt * 30) + (random.random() < dt * 30 % 1)
    for _ in range(nbubble):
        X = random.gauss(state.you.X, 30 / state.you.y)
        y = random.gauss(state.you.y, 30)
        if y < state.R - 10:
            state.effects.append(thing.Bubble(X=X, y=y))

    if sum(isinstance(effect, thing.BubbleChain)
           for effect in state.effects) < 10:
        for c in state.convergences:
            N = math.clamp((100 / window.distance(state.you, c))**2, 0.05, 1)
            nbubble = int(dt * N) + (random.random() < dt * N % 1)
            for _ in range(nbubble):
                X = random.gauss(state.you.X, 30 / state.you.y)
                y = random.gauss(state.you.y, 30)
                if state.Rcore < y < state.R - 20:
                    state.effects.append(
                        thing.BubbleChain(X=X, y=y, X0=c.X, y0=c.y))

    for event in events:
        if event.type == KEYDOWN and event.key == "go":
            control.clear()
            control["cursor"] = state.you
            control["queue"] = {}
            control["qtarget"] = [state.you.X, state.you.y]
            control["t0"] = 0.001 * pygame.time.get_ticks()
        if event.type == KEYDOWN and event.key == "abort":
            if not state.you.significant:
                state.you.die()
            regenerate()
        if event.type == KEYUP:
            if not state.quickteleport and "queue" in control and event.key in (
                    "up", "left", "right", "down"):
                control["queue"][event.key] = 0
        if event.type == KEYUP and event.key == "go" and "cursor" in control:
            if control["cursor"] is not state.you:
                state.effects.append(
                    thing.Teleport(X=state.you.X,
                                   y=state.you.y,
                                   targetid=control["cursor"].thingid))
                sound.play("teleport")
                state.you = control["cursor"]
            elif 0.001 * pygame.time.get_ticks(
            ) - control["t0"] < settings.tactivate:
                state.you.deploy()
            control.clear()

    if kpressed["go"] and control:
        if any(kpressed[x] for x in ("left", "right", "up", "down")):
            control["t0"] = -1000
        if state.quickteleport:
            control["qtarget"][
                0] += kx * dt0 * settings.vqteleport / control["qtarget"][1]
            control["qtarget"][1] += ky * dt0 * settings.vqteleport
            dx = math.Xmod(control["qtarget"][0] - state.you.X) * state.you.y
            dy = control["qtarget"][1] - state.you.y
            f = math.sqrt(dx**2 + dy**2) / settings.rqteleport
            if f > 1:
                dx /= f
                dy /= f
                control["qtarget"] = [
                    state.you.X + dx / state.you.y, state.you.y + dy
                ]
            retarget()
        else:
            q = control["queue"]
            for key in q:
                q[key] += dt0
                if q[key] >= settings.jumpcombotime:
                    dx = ("right" in q) - ("left" in q)
                    dy = ("up" in q) - ("down" in q)
                    jump(dx, dy)
                    q.clear()
                    break
    else:
        dvx = kx * dt * 20
        dvy = ky * dt * 20
        state.you.vx += dvx
        state.you.vy = min(state.you.vy + dvy, 0)

    todraw = []
    scollide = []
    hcollide = []

    state.you.think(0)  # Clear out any controls that should be overridden

    for convergence in state.convergences:
        if window.camera.near(convergence):
            convergence.think(dt)
            todraw.append(convergence)

    repopulating = (dt + state.you.t % 1) // 1
    if repopulating:
        nships = []
        for ship in state.ships:
            if not window.camera.on(
                    ship) and ship is not state.you and not ship.significant:
                continue
            ship.think(dt)
            if ship.alive:
                nships.append(ship)
                todraw.append(ship)
            else:
                ship.die()
        state.ships = nships
        repopulateslice()
    else:
        nships = []
        for ship in state.ships:
            if not window.camera.near(ship):
                nships.append(ship)
                continue
            ship.think(dt)
            if ship.alive:
                nships.append(ship)
                if window.camera.on(ship):
                    todraw.append(ship)
            else:
                ship.die()
        state.ships = nships
    if not state.you.alive:
        regenerate()
    nobjs = []
    for obj in state.objs:
        if not window.camera.on(obj):
            nobjs.append(obj)
            continue
        obj.think(dt)
        if obj.alive:
            nobjs.append(obj)
            todraw.append(obj)
        else:
            obj.die()
    state.obj = nobjs
    for hazard in state.hazards:
        if not window.camera.near(hazard):
            continue
        hazard.think(dt)
        todraw.append(hazard)
        if window.camera.on(hazard):
            hcollide.append(hazard)
    state.obj = nobjs
    #	for filament in state.filaments:
    #		filament.think(dt)

    neffects = []
    for effect in state.effects:
        effect.think(dt)
        if effect.alive:
            todraw.append(effect)
            neffects.append(effect)
        else:
            effect.die()
    state.effects = neffects

    scollide = [state.you]
    for s in scollide:
        if not s.vulnerable():
            continue
        for h in hcollide:
            if window.distance(h, s) < h.hazardsize:
                s.takedamage(h.dhp)

    if window.dbycoord((oldX, oldy),
                       (state.you.X, state.you.y)) > settings.rqteleport + 10:
        clearfull()
        populatefull()

    if state.quickteleport and "qtarget" in control:
        X, y = control["qtarget"]
        dX = math.Xmod(X - state.you.X)
        dy = y - state.you.y
        window.camera.X0 = state.you.X + dX * 0.5
        window.camera.y0 = state.you.y + dy * 0.5
        window.camera.setlimits()
    else:
        window.camera.follow(state.you)
        window.camera.think(dt)
예제 #11
0
def think(dt, events, kpressed):
    kx = kpressed["right"] - kpressed["left"]
    ky = kpressed["up"] - kpressed["down"]

    dt0 = dt
    if kpressed["go"] and control:
        dt *= 0.3

    hud.think(dt0)
    quest.think(dt)
    dialog.think(dt0)
    background.think(dt, 1)

    for event in events:
        if event.type == KEYDOWN and event.key == "go":
            control.clear()
            control["cursor"] = state.you
            control["queue"] = {}
            control["qtarget"] = [state.you.X, state.you.y]
        if event.type == KEYUP:
            if not state.quickteleport and "queue" in control and event.key in (
                    "up", "left", "right", "down"):
                control["queue"][event.key] = 0
        if event.type == KEYUP and event.key == "go" and "cursor" in control:
            if control["cursor"] is not state.you:
                state.effects.append(
                    thing.Teleport(X=state.you.X,
                                   y=state.you.y,
                                   targetid=control["cursor"].thingid))
                sound.play("teleport")
                state.you = control["cursor"]
            control.clear()

    if kpressed["go"] and control:
        if state.quickteleport:
            control["qtarget"][
                0] += kx * dt0 * settings.vqteleport / control["qtarget"][1]
            control["qtarget"][1] += ky * dt0 * settings.vqteleport
            dx = math.Xmod(control["qtarget"][0] - state.you.X) * state.you.y
            dy = control["qtarget"][1] - state.you.y
            f = math.sqrt(dx**2 + dy**2) / settings.rqteleport
            if f > 1:
                dx /= f
                dy /= f
                control["qtarget"] = [
                    state.you.X + dx / state.you.y, state.you.y + dy
                ]
            retarget()
        else:
            q = control["queue"]
            for key in q:
                q[key] += dt0
                if q[key] >= settings.jumpcombotime:
                    dx = ("right" in q) - ("left" in q)
                    dy = ("up" in q) - ("down" in q)
                    jump(dx, dy)
                    q.clear()
                    break
    else:
        dvx = kx * dt * 20
        dvy = ky * dt * 20
        state.you.vx += dvx
        state.you.vy += dvy

    state.you.think(0)  # Clear out any controls that should be overridden
    for ship in state.ships:
        ship.think(dt)
        dx = y0 * ship.X
        dy = ship.y - y0
        f = math.sqrt(dx**2 + dy**2) / 15
        if f > 1:
            ship.X /= f
            ship.y = y0 + dy / f
            ship.vx = 0
            ship.vy = 0
    for effect in state.effects:
        effect.think(dt)
    state.effects = [e for e in state.effects if e.alive]

    window.camera.X0 = 0
    window.camera.y0 = y0
    window.camera.R = window.sy / 32