1
0
forked from sniff/sniffpest
sniffpest/sniffpest.py

131 lines
3.9 KiB
Python
Raw Normal View History

2020-11-12 17:14:29 +00:00
"""
Snifftest - A clone of a game I never played
"""
import arcade
# import random
import math
OUTER_POINTS = ((288, 135),
(360, 175),
(420, 230),
(466, 355),
(445, 560),
(380, 610),
(260, 625),
(107, 575),
(70, 530),
(90, 324),
(140, 225),
(220, 168))
INNER_POINTS = ((277, 324),
(292, 332),
(305, 345),
(315, 370),
(310, 416),
(292, 425),
(270, 428),
(239, 420),
(233, 410),
(235, 363),
(246, 341),
(262, 329))
LINE_COLOR = arcade.color.BRIGHT_GREEN
PLAYER_COLOR = arcade.color.CANDY_APPLE_RED
def midpoint(p1, p2):
x = (p1[0] + p2[0]) / 2
y = (p1[1] + p2[1]) / 2
return x, y
class Laser:
def __init__(self, position):
p1 = position
p2 = (position + 1) if position < len(OUTER_POINTS) else 0
self.start = midpoint(OUTER_POINTS[p1], OUTER_POINTS[p2])
self.target = midpoint(INNER_POINTS[p1], INNER_POINTS[p2])
self.angle = math.atan2(-(self.target[1] - self.start[1]),
self.target[0] - self.start[0])
self.current = self.start
self.speed = 5
def update(self):
""" move towards center """
d_y = -self.speed * math.sin(self.angle)
d_x = self.speed * math.cos(self.angle)
self.current = (self.current[0] + d_x, self.current[1] + d_y)
def draw(self):
arcade.draw_circle_filled(*self.current, 3, arcade.color.ANDROID_GREEN)
class Sniffpest(arcade.Window):
""" da fuckin game """
def __init__(self, width, height, title):
""" init """
super().__init__(width, height, title)
arcade.set_background_color(arcade.color.BLACK)
self.player_pos = 0
self.enemies = None
self.l0dey_alpha = 0
self.lasers = None
def setup(self):
""" reset the level """
self.player_pos = 0
self.l0dey_alpha = 0
self.lasers = []
def on_update(self, delta_time):
""" called on every update """
for laser in self.lasers:
laser.update()
def on_draw(self):
""" draw da fuckin screen """
arcade.start_render()
# l0dey
l0dey = arcade.load_texture('l0de.png')
arcade.draw_texture_rectangle(550 / 2, 750 / 2, 512, 512,
l0dey, 0, self.l0dey_alpha)
# gameboard
arcade.draw_polygon_outline(OUTER_POINTS, LINE_COLOR, 2)
arcade.draw_polygon_outline(INNER_POINTS, LINE_COLOR, 2)
for outer_point, inner_point in zip(OUTER_POINTS, INNER_POINTS):
arcade.draw_line(*outer_point, *inner_point, LINE_COLOR, 1)
# player
p1 = self.player_pos
p2 = (self.player_pos+1) if self.player_pos < len(OUTER_POINTS) else 0
p1 = OUTER_POINTS[p1]
p2 = OUTER_POINTS[p2]
arcade.draw_line(*p1, *p2, PLAYER_COLOR, 10)
# lasers
for laser in self.lasers:
laser.draw()
def on_key_press(self, key, modifier):
""" handle key presses """
# Q or Esc to quit
if key in (arcade.key.Q, arcade.key.ESCAPE):
arcade.close_window()
# Move around the board
if key == arcade.key.LEFT:
self.player_pos = (self.player_pos + 1) % (len(OUTER_POINTS) - 1)
elif key == arcade.key.RIGHT:
self.player_pos = (self.player_pos - 1) % (len(OUTER_POINTS) - 1)
# Shoot yer lasers
if key == arcade.key.SPACE:
laser = Laser(self.player_pos)
self.lasers.append(laser)
self.l0dey_alpha = min(self.l0dey_alpha + 1, 30)
if __name__ == '__main__':
sniffpest = Sniffpest(550, 750, 'Sniffpest')
sniffpest.setup()
arcade.run()