├── InicioSnake.py ├── README.md └── img ├── Comida.gif ├── FondoIniciar.gif ├── FondoJuego.gif ├── Icono.ico ├── SnakeCafeDown.gif ├── SnakeCafeLeft.gif ├── SnakeCafeRight.gif ├── SnakeCafeUp.gif └── star.gif /InicioSnake.py: -------------------------------------------------------------------------------- 1 | import turtle 2 | 3 | 4 | Ventana=turtle.Screen() 5 | Ventana.title('Iniciar') 6 | Ventana.setup(width=600,height=600) 7 | Ventana.bgcolor('#FFFFFF') 8 | Ventana.bgpic("img/FondoIniciar.gif") 9 | Ventana.register_shape("img/FondoIniciar.gif") 10 | Ventana.register_shape("img/star.gif") 11 | 12 | BotonIniciar=turtle.Turtle() 13 | BotonIniciar.shape("img/star.gif") 14 | BotonIniciar.speed(0) 15 | BotonIniciar.color('#FCDC6D') 16 | BotonIniciar.penup() 17 | BotonIniciar.goto(0,-110) 18 | 19 | #TEXTO1 20 | texto1= turtle.Turtle() 21 | texto1.speed(0) 22 | texto1.color('#FCDC6D') 23 | texto1.penup() 24 | texto1.hideturtle() 25 | texto1.goto(0,150) 26 | texto1.write('Game', align='center', font=('Poppins',25, 'bold')) 27 | 28 | #TEXTO2 29 | texto2= turtle.Turtle() 30 | texto2.speed(0) 31 | texto2.color('#FCDC6D') 32 | texto2.penup() 33 | texto2.hideturtle() 34 | texto2.goto(0,30) 35 | texto2.write('Snake', align='center', font=('Poppins',80, 'bold')) 36 | 37 | #DETECTAR CLICK 38 | def BtnoClick(x,y): 39 | if(x > -73 < 70 and y > -143 and y < -80): 40 | import turtle 41 | import time 42 | import random 43 | 44 | posponer= 0.1 45 | texto1.clear() 46 | texto2.clear() 47 | BotonIniciar.hideturtle() 48 | #MARCADOR 49 | score=0 50 | highScore=0 51 | 52 | #CONFIGURACION DE LA VENTANA 53 | Ventana=turtle.Screen() 54 | Ventana.title('Juego Snake') 55 | Ventana.setup(width=600,height=600) 56 | Ventana.bgcolor('#FFFFFF') 57 | Ventana.bgpic("img/FondoJuego.gif") 58 | Ventana.tracer(0) 59 | 60 | #REGISTRAR IMAGENES 61 | Ventana.register_shape("img/Comida.gif") 62 | Ventana.register_shape("img/FondoJuego.gif") 63 | Ventana.register_shape('img/SnakeCafeUp.gif') 64 | Ventana.register_shape('img/SnakeCafeDown.gif') 65 | Ventana.register_shape('img/SnakeCafeLeft.gif') 66 | Ventana.register_shape('img/SnakeCafeRight.gif') 67 | 68 | #CABEZA SERPIENTE 69 | cabeza=turtle.Turtle() 70 | cabeza.speed(0) 71 | cabeza.shape('img/SnakeCafeUp.gif') 72 | cabeza.right(90) 73 | cabeza.color('#16DA34') 74 | cabeza.penup() 75 | cabeza.goto(0,0) 76 | cabeza.direction='stop' 77 | 78 | #COMIDA SERPIENTE 79 | 80 | comida=turtle.Turtle() 81 | comida.shape('img/Comida.gif') 82 | comida.color('red') 83 | comida.speed(0) 84 | comida.penup() 85 | comida.goto(0,100) 86 | 87 | 88 | #SEGMENTOS/CUERPO 89 | segmentos=[] 90 | 91 | #TEXTO 92 | texto= turtle.Turtle() 93 | texto.speed(0) 94 | texto.color('white') 95 | texto.penup() 96 | texto.hideturtle() 97 | texto.goto(0,260) 98 | texto.write('Score: 0 High Score: 0 ', align='center', font=('Courier',17, 'bold')) 99 | #FUNCIONES DE MOVIMIENTO TECLADO 100 | def Arriba(): 101 | cabeza.direction='up' 102 | cabeza.shape('img/SnakeCafeUp.gif') 103 | 104 | def Abajo(): 105 | cabeza.direction='down' 106 | cabeza.shape('img/SnakeCafeDown.gif') 107 | 108 | def Izquierda(): 109 | cabeza.direction='left' 110 | cabeza.shape('img/SnakeCafeLeft.gif') 111 | 112 | def Derecha(): 113 | cabeza.direction='right' 114 | cabeza.shape('img/SnakeCafeRight.gif') 115 | 116 | 117 | #FUNCION DE MOVIMIENTOS 118 | def movimientoSnake(): 119 | if cabeza.direction=='up': 120 | y = cabeza.ycor() 121 | cabeza.sety(y + 20) 122 | 123 | if cabeza.direction=='down': 124 | y = cabeza.ycor() 125 | cabeza.sety(y - 20) 126 | 127 | if cabeza.direction=='left': 128 | x = cabeza.xcor() 129 | cabeza.setx(x - 20) 130 | 131 | if cabeza.direction=='right': 132 | x = cabeza.xcor() 133 | cabeza.setx(x + 20) 134 | 135 | 136 | #EVENTOS TECLADO 137 | 138 | Ventana.listen() 139 | Ventana.onkeypress(Arriba, 'Up') 140 | Ventana.onkeypress(Abajo, 'Down') 141 | Ventana.onkeypress(Izquierda, 'Left') 142 | Ventana.onkeypress(Derecha, 'Right') 143 | 144 | 145 | while True: 146 | Ventana.update() 147 | 148 | #COLICION BORDER 149 | if cabeza.xcor() > 280 or cabeza.xcor() < -280 or cabeza.ycor() > 280 or cabeza.ycor() < -280: 150 | 151 | #TEXTO FINALIZACION 152 | texto4= turtle.Turtle() 153 | texto4.speed(0) 154 | texto4.color('white') 155 | texto4.hideturtle() 156 | texto4.goto(0,0) 157 | texto4.write('JUEGO TERMINADO', align='center', font=('Courier',30, 'bold')) 158 | time.sleep(1) 159 | cabeza.goto(0,0) 160 | cabeza.direction='stop' 161 | 162 | #Escoder los segmentos. 163 | for segmento in segmentos: 164 | segmento.hideturtle() 165 | #limpiar lista de segmentos 166 | segmentos.clear() 167 | 168 | #RESETAR MARCADOR 169 | score=0 170 | texto.clear() 171 | texto.write('Score: {} High Score: {}'.format(score,highScore),align='center', font=('Courier',17, 'bold')) 172 | texto4.clear() 173 | #COLICION COMIDA 174 | if cabeza.distance(comida) < 20: 175 | x = random.randint(-280,280) 176 | y = random.randint(-280,280) 177 | comida.goto(x,y) 178 | 179 | NuevoSeg=turtle.Turtle() 180 | NuevoSeg.speed(0) 181 | NuevoSeg.shape('circle') 182 | NuevoSeg.color('#834827') 183 | NuevoSeg.penup() 184 | segmentos.append(NuevoSeg) 185 | 186 | #AUMENTAR COMIDA 187 | score+=10 188 | 189 | if(score > highScore): 190 | highScore= score 191 | texto.clear() 192 | texto.write('Score: {} High Score: {}'.format(score,highScore),align='center', font=('Courier',17, 'bold')) 193 | 194 | #MOVER EL CUERPO 195 | totalSeg = len(segmentos) 196 | for index in range(totalSeg-1,0,-1): 197 | x=segmentos[index-1].xcor() 198 | y=segmentos[index-1].ycor() 199 | segmentos[index].goto(x,y) 200 | 201 | if totalSeg > 0: 202 | x=cabeza.xcor() 203 | y=cabeza.ycor() 204 | segmentos[0].goto(x,y) 205 | 206 | movimientoSnake() 207 | time.sleep(posponer) 208 | 209 | for segmento in segmentos: 210 | if segmento.distance(cabeza) < 20: 211 | texto5= turtle.Turtle() 212 | texto5.speed(0) 213 | texto5.color('white') 214 | texto5.hideturtle() 215 | texto5.goto(0,0) 216 | texto5.write('JUEGO TERMINADO', align='center', font=('Courier',30, 'bold')) 217 | time.sleep(1) 218 | cabeza.goto(0,0) 219 | cabeza.direction='stop' 220 | 221 | 222 | #Escoder los segmentos. 223 | for segmento in segmentos: 224 | segmento.hideturtle() 225 | #limpiar lista de segmentos 226 | segmentos.clear() 227 | 228 | #RESETAR MARCADOR 229 | score=0 230 | texto.clear() 231 | texto.write('Score: {} High Score: {}'.format(score,highScore),align='center', font=('Courier',17, 'bold')) 232 | texto5.clear() 233 | 234 | turtle.onscreenclick(BtnoClick, 1) 235 | turtle.listen() 236 | turtle.done() 237 | 238 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GameSneake-python 2 | 3 | ## START GAME 4 | 5 | ![Imagen Paso 1](https://raw.githubusercontent.com/Crismaxis/AssetsInfo/master/asset/sneake1.PNG) 6 | 7 | 8 | 9 | ## GAMEPLAY 10 | 11 | ![Imagen Paso 1](https://raw.githubusercontent.com/Crismaxis/AssetsInfo/master/asset/sneake2.PNG) 12 | -------------------------------------------------------------------------------- /img/Comida.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocobytes/GameSneake-python/0fec1c64f1e9892c05a8827a5ee258dbe7f4ac3b/img/Comida.gif -------------------------------------------------------------------------------- /img/FondoIniciar.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocobytes/GameSneake-python/0fec1c64f1e9892c05a8827a5ee258dbe7f4ac3b/img/FondoIniciar.gif -------------------------------------------------------------------------------- /img/FondoJuego.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocobytes/GameSneake-python/0fec1c64f1e9892c05a8827a5ee258dbe7f4ac3b/img/FondoJuego.gif -------------------------------------------------------------------------------- /img/Icono.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocobytes/GameSneake-python/0fec1c64f1e9892c05a8827a5ee258dbe7f4ac3b/img/Icono.ico -------------------------------------------------------------------------------- /img/SnakeCafeDown.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocobytes/GameSneake-python/0fec1c64f1e9892c05a8827a5ee258dbe7f4ac3b/img/SnakeCafeDown.gif -------------------------------------------------------------------------------- /img/SnakeCafeLeft.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocobytes/GameSneake-python/0fec1c64f1e9892c05a8827a5ee258dbe7f4ac3b/img/SnakeCafeLeft.gif -------------------------------------------------------------------------------- /img/SnakeCafeRight.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocobytes/GameSneake-python/0fec1c64f1e9892c05a8827a5ee258dbe7f4ac3b/img/SnakeCafeRight.gif -------------------------------------------------------------------------------- /img/SnakeCafeUp.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocobytes/GameSneake-python/0fec1c64f1e9892c05a8827a5ee258dbe7f4ac3b/img/SnakeCafeUp.gif -------------------------------------------------------------------------------- /img/star.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cocobytes/GameSneake-python/0fec1c64f1e9892c05a8827a5ee258dbe7f4ac3b/img/star.gif --------------------------------------------------------------------------------