Exemple #1
0
def game_loop():

    #start player 1
    player1 = tank(540, 135, 1)

    #start player 2
    player2 = tank(20, 45, 2)

    #random who will start
    playerStart = random.randint(0, 1)
    if playerStart == 0:
        player1.canShoot = True
    else:
        player2.canShoot = True

    while True:
        #check keys pressed
        playerKeyPress(player1, player2)

        #action for player1
        playerAction(player1, player2)
        #action for player2
        playerAction(player2, player1)

        #draw the display
        draw_display(player1, player2)

        #check if someone is winning
        winGame(player1, player2)

        #tick clock
        clock.tick(30)
Exemple #2
0
    def setup_plant(self):
        ## River water cooling circuit:

        # Water intake from river
        river_intake1 = self.add(river("River water intake 1"))
        river_intake2 = self.add(river("River water intake 2"))

        # River pumps
        river_pump1 = self.add(pump("River Pump 1", physics.large_pump_pressure_Pa, base_height_m=-4.0))
        river_pump2 = self.add(pump("River Pump 2", physics.large_pump_pressure_Pa, base_height_m=-4.0))
        river_pump1.in_port.connect(river_intake1.port)
        river_pump2.in_port.connect(river_intake2.port)

        # Backflow valves for pumps
        river_valve1 = self.add(valve("River Backflow Valve 1", height_m=-4.0))
        river_valve2 = self.add(valve("River Backflow Valve 2", height_m=-4.0))
        river_valve1.in_port.connect(river_pump1.out_port)
        river_valve2.in_port.connect(river_pump2.out_port)

        # Tank that combines inflows from river pumps
        river_in_tank = self.add(tank("River intake tank", 10.0, 2.0, 1.0))
        river_in_tank.add_port("in1").connect(river_valve1.out_port)
        river_in_tank.add_port("in2").connect(river_valve2.out_port)
        river_tank_out_port = river_in_tank.add_port("out")
        river_in_pipe = self.add(pipe("River tank to steam condenser pipe", 30.0, area_m2=physics.large_pipe_size_m2))
        river_in_pipe.in_port.connect(river_tank_out_port)

        # Steam condenser
        steam_condenser = self.add(heat_exchanger("Steam condenser"))
        steam_condenser.a_in.connect(river_in_pipe.out_port)

        # River waste-water pipe
        river_out = self.add(river("River cooling water outlet"))
        river_out_pipe = self.add(pipe("Steam condenser to river pipe", 40.0, area_m2=physics.large_pipe_size_m2))
        river_out_pipe.in_port.connect(steam_condenser.a_out)
        river_out_pipe.out_port.connect(river_out.port)
Exemple #3
0
 def addnewtank(self, x, y):
     self.sim.unitops.append(tank(len(self.sim.unitops), x, y, \
         globe.TankInitFracInventory, globe.TankInitRadius, globe.TankInitHeight))
Exemple #4
0
BLACK = (0, 0, 0)
RED = (255, 5, 5)
GREEN = (23, 165, 23)
GRAY = (232, 232, 232)
LBROWN = (222, 184, 135)
DBROWN = (165, 130, 85)

screenwidth = 1280
screenheight = 650
size = (screenwidth, screenheight)
screen = pygame.display.set_mode(size, 0, 32)
pygame.display.set_caption("Tank Game")

all_sprites_list = pygame.sprite.Group()

player1Tank = tank(RED, 100, 100)
player1Tank.rect.x = 75
player1Tank.rect.y = 75

all_sprites_list.add(player1Tank)

playing = True
clock = pygame.time.Clock()


def checkcol(sprite1, sprite2):
    col = pygame.sprite.collide_rect(sprite1, sprite2)
    if col == True:
        sprite1.rect.x += -10
    else:
        sprite1.rect.x += 10
Exemple #5
0
    def copyfrom(self, simcopyfrom):
        #//MemoryStream myStream = new MemoryStream();
        #//simulation tempsim = new simulation();
        #//BinaryFormatter bf = new BinaryFormatter();
        #//bf.Serialize(myStream, simcopyfrom);
        #//myStream.Seek(0, SeekOrigin.Begin);
        #//tempsim = (simulation)bf.Deserialize(myStream);
        #//myStream.Close();
        #//unitops = tempsim.unitops;
        #//streams = tempsim.streams;
        #//pidcontrollers = tempsim.pidcontrollers;
        if (len(self.unitops) == 0):
            self.unitops = []
            for i in range(len(simcopyfrom.unitops)):
                #if simcopyfrom.unitops[i].objecttype == globe.objecttypes.CoolingTowerSimple:
                #    #obj = coolingtowersimple()
                #    obj.coolingtowersimplecopyconstructor(simcopyfrom.unitops[i])
                #    self.unitops.append(obj)
                #elif simcopyfrom.unitops[i].objecttype == globe.objecttypes.CoolingTowerHeatExchangerSimple:
                #    obj = coolingtowerheatexchangersimple()
                #    obj.coolingtowerheatexchangersimplecopyconstructor(simcopyfrom.unitops[i])
                #    self.unitops.append(obj)
                if simcopyfrom.unitops[
                        i].objecttype == globe.objecttypes.CoolingTower:
                    obj = coolingtower(0, 0, 0)
                    obj.copyfrom(simcopyfrom.unitops[i])
                    self.unitops.append(obj)
                #elif simcopyfrom.unitops[i].objecttype == globe.objecttypes.DistillationColumn:
                #    obj = distillationcolumn()
                #    obj.copyfrom(simcopyfrom.unitops[i])
                #   self.unitops.append(obj)
                #elif simcopyfrom.unitops[i].objecttype == globe.objecttypes.Flange:
                #    obj = flange()
                #    obj.flangecopyconstructor(simcopyfrom.unitops[i])
                #    self.unitops.append(obj)
                #elif simcopyfrom.unitops[i].objecttype == globe.objecttypes.GasPipe:
                #   obj = gaspipe()
                #   obj.gaspipecopyconstructor(simcopyfrom.unitops[i])
                #    self.unitops.append(obj)
                elif simcopyfrom.unitops[
                        i].objecttype == globe.objecttypes.HeatExchangerSimple:
                    obj = heatexchangersimple(0, 0, 0)
                    obj.copyfrom(simcopyfrom.unitops[i])
                    self.unitops.append(obj)
                elif simcopyfrom.unitops[
                        i].objecttype == globe.objecttypes.Mixer:
                    obj = mixer(0, 0, 0, simcopyfrom.unitops[i].nin)
                    obj.copyfrom(simcopyfrom.unitops[i])
                    self.unitops.append(obj)
                elif simcopyfrom.unitops[
                        i].objecttype == globe.objecttypes.Pump:
                    obj = pump(0.0, 0.0, 0.0, 0.0, 0.0, \
                            0.0, 0.0, 1)
                    obj.copyfrom(simcopyfrom.unitops[i])
                    self.unitops.append(obj)
                elif simcopyfrom.unitops[
                        i].objecttype == globe.objecttypes.Tee:
                    obj = tee(0.0, 0.0, 0.0, simcopyfrom.unitops[i].nout)
                    obj.copyfrom(simcopyfrom.unitops[i])
                    self.unitops.append(obj)
                elif simcopyfrom.unitops[
                        i].objecttype == globe.objecttypes.Valve:
                    obj = valve(0, 0.0, 0.0)
                    obj.copyfrom(simcopyfrom.unitops[i])
                    self.unitops.append(obj)
                elif simcopyfrom.unitops[
                        i].objecttype == globe.objecttypes.Tank:
                    obj = tank(0, 0.0, 0.0)
                    obj.copyfrom(simcopyfrom.unitops[i])
                    self.unitops.append(obj)
                else:
                    break
        else:
            for i in range(len(simcopyfrom.unitops)):
                self.unitops[i].copyfrom(simcopyfrom.unitops[i])

        if (len(self.streams) == 0):
            self.streams = []
            for i in range(len(simcopyfrom.streams)):
                obj = stream(0, 0.0, 0.0, 0.0, 0.0)
                obj.copyfrom(simcopyfrom.streams[i])
                self.streams.append(obj)
        else:
            for i in range(len(simcopyfrom.streams)):
                self.streams[i].copyfrom(simcopyfrom.streams[i])

        #if (len(self.signals) == 0):
        #    self.signals = []
        #    for i in range(len(simcopyfrom.signals)):
        #        obj = signal()
        #       obj.copyfrom(simcopyfrom.signals[i])
        #        self.signals.append(obj)
        #else:
        #    for i in range(len(simcopyfrom.signals)):
        #        self.signals[i].copyfrom(simcopyfrom.signals[i])

        if (len(self.pidcontrollers) == 0):
            self.pidcontrollers = []
            for i in range(len(simcopyfrom.pidcontrollers)):
                obj = pidcontroller()
                obj.copyfrom(simcopyfrom.pidcontrollers[i])
                self.pidcontrollers.append(obj)
        else:
            for i in range(len(simcopyfrom.pidcontrollers)):
                self.pidcontrollers[i].copyfrom(simcopyfrom.pidcontrollers[i])

        #if (len(self.blocks) == 0):
        #    self.blocks = []
        #    for i in range(len(simcopyfrom.blocks)):
        #       if simcopyfrom.blocks[i].objecttype == globe.objecttypes.ControlMVSignalSplitter:
        #           obj = controlmvsignalsplitter()
        #           obj.copyfrom(simcopyfrom.blocks[i])
        #           blocks.append(obj)
        #       else:
        #           break
        #else:
        #   for i in range(len(simcopyfrom.blocks)):
        #        self.blocks[i].copyfrom(simcopyfrom.blocks[i])

        #//public List<nmpc> nmpccontrollers; The nmpc controller(s) are not going to be copied at this point in time.
        self.simi = simcopyfrom.simi  #//Counting index for this class for simulation indexing for historisation and simulation.
Exemple #6
0
        tinyTim.forward()
      elif ypos < -3:
        tinyTim.reverse()
      else:
        tinyTim.stop()

      conn.sendall('')

  conn.close()

comms = tankcomms.tankcomms(8876)
comms.openSocket()
comms.sock.listen(1)
comms.sock.settimeout(10)

tinyTim = tank.tank()

GPIO.setup(tinyTim.right_motor.switchmodule.ch1, GPIO.OUT)
GPIO.setup(tinyTim.right_motor.switchmodule.ch2, GPIO.OUT)
GPIO.output(tinyTim.right_motor.switchmodule.ch1, 0)
GPIO.output(tinyTim.right_motor.switchmodule.ch2, 1)

GPIO.setup(tinyTim.left_motor.switchmodule.ch1, GPIO.OUT)
GPIO.setup(tinyTim.left_motor.switchmodule.ch2, GPIO.OUT)
GPIO.output(tinyTim.left_motor.switchmodule.ch1, 0)
GPIO.output(tinyTim.left_motor.switchmodule.ch2, 1)


# tinyTim.left()
# time.sleep(5)
# tinyTim.right()
Exemple #7
0
import pygame
import tank
import own_group
import referee

SIZE = (512, 512)

pygame.init()
screen = pygame.display.set_mode(SIZE)
clock = pygame.time.Clock()
running = True
tank1 = tank.tank(3, 5, 1, 1, 0.034, pygame.math.Vector2(512 / 2, 512 / 2), 0,
                  0, "tank.png", "turret.png")
tank2 = tank.tank(3, 5, 1, 1, 0.034, pygame.math.Vector2(512 / 2, 512 / 2), 0,
                  0, "tank.png", "turret.png")
referee = referee.referee([tank1, tank2])
all_sprite = own_group.own_group()
all_sprite.add(tank1, tank2)
while running:
    clock.tick(60)
    events = pygame.event.get()
    for e in events:
        if e.type == pygame.QUIT:
            running = False
    keys = pygame.key.get_pressed()
    if keys[pygame.K_UP]:
        tank1.update(True, False, False, False, False, False, False)
    if keys[pygame.K_DOWN]:
        tank1.update(False, True, False, False, False, False, False)
    if keys[pygame.K_LEFT]:
        tank1.update(False, False, True, False, False, False, False)