repl.it
@MinecraftMrGabe/

spaceships: conquer the void

Pygame

sick jittery scripting languages lol a mix of space engineers and airships: conquer the skies?

fork
loading
Files
  • main.py
  • nohup.out
  • temp block.png
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import pygame
from pygame.locals import *
pygame.init()
'''
so, trying to make a game that's like an open world airships: conquer the skies
'''
camx = 0
camy = 0
screen = pygame.display.set_mode((800,600))
clock = pygame.time.Clock()
spaceships = []
IMAGES = {'temp block': pygame.image.load('temp block.png')

}
def m_pos():
  return pygame.mouse.get_pos()
class projectile():
  def __init__(self,home,x,y,x2,y2,weight,damage,spd):
    self.x = x
    self.y = y
    self.yspd = y2/5*spd
    self.xspd = x2/5*spd
    self.weight = weight
  def draw(self):
    for x in spaceships:
      if x != self.home:
        pass
    self.x+=self.xspd
    self.y-=self.yspd
    self.yspd-=weight/2
    self.xspd-=weight/2
    pygame.draw.circle(screen,(125,125,215),(self.x-camx,self.y-camy),10,0)
class block():
  def __init__(self,x,y,length,height,image,ship,connections = []):
    self.x = x
    self.y = y
    self.length = length
    self.height = height
    self.image = image
    self.image = pygame.transform.scale(self.image,(length,height))
    self.health = 10*self.length*self.height
    self.ship = ship
    self.connections = connections

class canon(block):
  def __init__(self,x,y,lenth,height,image,ship):
    super().__init__(x,y,lenth,height,image,ship)
    self.ship.canons.append(self)
    self.x = x
    self.y = y
    self.ship = ship
    self.projectiles = []
  def fire(x,y):
    self.projectiles.append(projectile(self.ship,x,y,m_pos[0],m_pos[1],10,5,10))

  
class ship():
  def __init__(self,data = []):
    self.canons = []
    self.data = data
    self.x = 0
    self.y = 0
    spaceships.append(self)
  def shootcanons(self,x,y):
    for r in self.canons:
      r.fire(x,y)
  def draw(self):
    for b in self.data:
      screen.blit(b.image,(b.x-camx,b.y-camy))
    for c in self.canons:
      for p in c.projectiles:
        p.draw()
  def build(self):
    temp_camx = 0
    temp_camy = 0
    run = True
    #def temp_item():
    #  block(m_pos[0],m_pos[1],20,20,IMAGES['temp block'],self)
    print("Working")
    while(run):
      screen.fill((255,255,255))
      for event in pygame.event.get():
        if event.type==KEYDOWN:
          if event.key==K_LEFT:
            temp_camx-=5
          elif event.key==K_RIGHT:
            temp_camx+=5
          elif event.key==K_UP:
            temp_camy+=5
          elif event.key==K_DOWN:
            temp_camy-=5
        elif event.type==MOUSEBUTTONDOWN:
          closest = 1000000
          closest2 = [None]
          for b in self.data:
            if ((b.x-(int(m_pos()[0]/20)*20+temp_camx))**2+(b.y-(int(m_pos()[1]/20)*20+temp_camy))**2)**(1/2)<=closest:
              if ((b.x-(int(m_pos()[0]/20)*20+temp_camx))**2+(b.y-(int(m_pos()[1]/20)*20+temp_camy))**2)**(1/2)==closest:
                closest2.append(b)
              else:
                closest = ((b.x-(int(m_pos()[0]/20)*20+temp_camx))**2+(b.y-(int(m_pos()[1]/20)*20+temp_camy))**2)**(1/2)
                closest2=[b]
          if closest2 ==[None]:
            closest2=[]
          connections = []
          for x in closest2:
            connections.append(x)
          closest = 1000000
          closest2 = [None]
          for b in self.data:
            if ((b.x-(int(m_pos()[0]/20)*20+temp_camx))**2+(b.y-(int(m_pos()[1]/20)*20+temp_camy))**2)**(1/2)<=closest and b not in connections:
              if ((b.x-(int(m_pos()[0]/20)*20+temp_camx))**2+(b.y-(int(m_pos()[1]/20)*20+temp_camy))**2)**(1/2)==closest:
                closest2.append(b)
              else:
                closest = ((b.x-(int(m_pos()[0]/20)*20+temp_camx))**2+(b.y-(int(m_pos()[1]/20)*20+temp_camy))**2)**(1/2)
                closest2=[b]
          if closest2 ==[None]:
            closest2=[]
          for x in closest2:
            connections.append(x)
          

          
          self.data.append(block(int((m_pos()[0])/20)*20+temp_camx-self.x,int(m_pos()[1]/20)*20+temp_camy-self.y,20,20,IMAGES['temp block'],self,connections))
      for b in self.data:
        for c in b.connections:
          pygame.draw.line(screen,(1,1,1),(b.x-temp_camx+10,b.y-temp_camy+10),(c.x-temp_camx+10,c.y-temp_camy+10),5)
        screen.blit(b.image,(b.x-temp_camx,b.y-temp_camy))
      screen.blit(IMAGES['temp block'],(int((m_pos()[0]-temp_camx/20)*20),(int((m_pos()[1]-temp_camy)/20)*20)))
      pygame.display.update()
      pygame.display.flip()
      clock.tick(30)
      #print(m_pos())

shoop = ship()
print("working")
shoop.build()
while(True):
  screen.fill((255,255,255))
  for s in spaceships:
    s.draw()
  clock.tick(30)
  pygame.display.update()