Ayuda para terminar mi juego de zombies
Publicado por Alejandro Pinchetti (1 intervención) el 02/12/2014 14:09:03
Estoy recien empezando con una carrera de diseño de videojuegos
Estoy programando un juego de zombies para mi final y necesito ayuda con la generacion automatica de zombies
estoy usando arrays y no se por que falla
Estoy programando un juego de zombies para mi final y necesito ayuda con la generacion automatica de zombies
estoy usando arrays y no se por que falla
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.sensors.Accelerometer;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.ui.Keyboard;
import flash.utils.clearInterval;
import flash.utils.setInterval;
[SWF(width="900",height="900",backgroundColor="0xdd837c")]
public class Main extends Sprite
{
public var personaje:Sprite;
public var Zombie:Array = new Array();
/*public var direccionX:Array = new Array();
public var direccionY:Array = new Array();
public var direccionXA:Array = new Array();
public var direccionYA:Array = new Array();
public var velocidad2:Array = new Array();
*/
public var velocidad:int=20;
public var der:Boolean = false;
public var izq:Boolean = false;
public var arr:Boolean = false;
public var abj:Boolean = false;
public var direccionX:int=1;
public var direccionY:int=1;
public var direccionXA:int=-1;
public var direccionYA:int=-1;
public var velocidad2:int=1;
public var enemigos : MC_Zombie = new MC_Zombie;
public function Main()
{
crearzombies();
personaje = dibujarCirculo(0xff0000,15,450,450);
stage.addEventListener(Event.ENTER_FRAME,update);
stage.addEventListener(KeyboardEvent.KEY_DOWN , apretoTecla);
stage.addEventListener(KeyboardEvent.KEY_UP , sueltoTecla);
}
public function update(e:Event):void
{
moverPersonaje();
moverzombies();
}
public function crearzombies():void
{
for (var i:int = 0; i < 20; i++)
{
stage.addChild(enemigos);
enemigos.x=obtenerRandom(0,900)
enemigos.y=obtenerRandom(0,900)
Zombie.push(enemigos);
}
}
public function obtenerRandom(min:int , max:int):int
{
var num:int = (Math.random() * (max - min)) + min;
return num;
}
public function moverzombies():void
{
for (var i:int = 0; i < Zombie.length; i++)
{
if(personaje.x==Zombie[i].x && personaje.y>Zombie[i].y)
{
Zombie[i].y = Zombie[i].y + velocidad2 * direccionY;
}
if(personaje.x==Zombie[i].x && personaje.y<Zombie[i].y)
{
Zombie[i].y = Zombie[i].y + velocidad2* direccionYA;
}
if(personaje.y==Zombie[i].y && personaje.x>Zombie[i].x)
{
Zombie[i].x = Zombie[i].x + velocidad2* direccionY;
}
if(personaje.y==Zombie[i].y && personaje.x<Zombie[i].x)
{
Zombie[i].x = Zombie[i].x + velocidad2* direccionYA;
}
if(personaje.x>Zombie[i].x)
{
Zombie[i].x = Zombie[i].x + velocidad2* direccionX;
}
if(personaje.x<Zombie[i].x)
{
Zombie[i].x = Zombie[i].x + velocidad2* direccionXA;
}
if(personaje.y>Zombie[i].y)
{
Zombie[i].y = Zombie[i].y + velocidad2 * direccionY;
}
if(personaje.y<Zombie[i].y)
{
Zombie[i].y = Zombie[i].y + velocidad2* direccionYA;
}
}
}
public function moverPersonaje():void
{
if (der == true)
{
personaje.x += velocidad;
}
if (izq == true)
{
personaje.x -= velocidad;
}
if (arr == true)
{
personaje.y -= velocidad;
}
if (abj == true)
{
personaje.y += velocidad;
}
}
public function sueltoTecla(e:KeyboardEvent):void
{
switch(e.keyCode)
{
case Keyboard.RIGHT:
der = false;
break;
case Keyboard.LEFT:
izq = false;
break;
case Keyboard.DOWN:
abj = false;
break;
case Keyboard.UP:
arr = false;
break;
}
}
public function apretoTecla(e:KeyboardEvent):void
{
switch(e.keyCode)
{
case Keyboard.RIGHT:
der = true;
break;
case Keyboard.LEFT:
izq = true;
break;
case Keyboard.DOWN:
abj = true
break;
case Keyboard.UP:
arr = true;
break;
}
}
public function dibujarCirculo(color:int,radio:int , x:int , y:int):Sprite
{
var dj:Sprite = new Sprite();
dj.graphics.beginFill(color);
dj.graphics.drawCircle(0,0,radio);
dj.graphics.endFill();
stage.addChild(dj);
dj.x = x;
dj.y = y;
return dj;
}
}
}
Valora esta pregunta
0