hashengine_asteroids/asteroids.py

88 lines
2.4 KiB
Python

import hashengine as he
import time
import random
game = he.game()
player = []
for i in range(3):
player.append(he.object("#", gravity=0, x=int(game.size.columns/2)+i, y=game.size.lines-1, antixforce=1))
player.append(he.object("#", gravity=0, x=int(game.size.columns/2)+1, y=game.size.lines-2, antixforce=0))
for i in player:
game.addobj(i)
def lose():
print("you lose!")
exit()
asteroids = []
bullets = []
class asteroid():
def __init__(self):
self.object = he.object("", gravity=0, x=random.randint(1, game.size.columns-2), y=1, antixforce=0)
game.addobj(self.object)
def update(self):
self.object.targety = self.object.y + 1
try:
if self.object.y == game.size.lines-1:
self.temp = True
elif game.map["{}:{}".format(self.object.y+1, self.object.x)] == "#":
lose()
elif game.map["{}:{}".format(self.object.y+1, self.object.x)] == "":
self.temp = True
game.update()
if self.temp:
self.object.targetx = 100000
except:
pass
class bullet():
def __init__(self):
self.object = he.object("", gravity=0, x=player[0].x+1, y=game.size.lines-3, antixforce=0)
game.addobj(self.object)
def update(self):
try:
if game.map["{}:{}".format(self.object.y-1, self.object.x)] == "":
self.temp = True
game.update()
else:
self.object.targety = self.object.y - 1
if self.temp:
self.object.targetx = 10000
except:
pass
asteroidcount = 0
count = 0
acm = 10
while True:
game.update()
if game.pressedkeys["d"] == True:
if player[-1].x != game.size.columns-2:
for i in player:
i.targetx = i.x + 1
if game.pressedkeys["a"] == True:
if player[1].x != 1:
for i in player:
i.targetx = i.x - 1
if game.pressedkeys["q"] == True:
bullets.append(bullet())
asteroidcount += 1
count += 1
if asteroidcount == acm:
asteroidcount = 0
asteroids.append(asteroid())
if count == 100:
acm = 1
print("is it easy?")
time.sleep(3)
print("well if its so easy try this out:")
time.sleep(3)
for i in asteroids:
i.update()
for i in bullets:
i.update()
time.sleep(0.05)