Пуля в Processing
Вот мой код:
PImage ship, space;
float cpaceY = -5110;
boolean pause = false;
boolean b1 = false, b2 = false;
void setup ()
{
noCursor();
size(700, 650);
smooth();
ship = loadImage("Ship.gif");
space = loadImage("Space.png");
}
void draw () {
if (pause)
{
image(space, 0, cpaceY);
image(ship, mouseX, mouseY);
cpaceY += 3;
if (cpaceY > -5)
{
cpaceY = -5110;
}
}
}
class Bullet
{
float x;
float y;
Bullet(float tx, float ty)
{
x = tx;
y = ty;
}
void display()
{
stroke(255);
rect(x,y+30, 3, 15);
}
void move()
{
y -= 7.5;
}
}
void mousePressed()
{
/////////////////////////// что тут
}
void moveAll()
{
/////////////////////////// и что тут
}
Как сделать пули, которие летят вверх по клику мышки?
Ответы (1 шт):
Автор решения: фымышонок
→ Ссылка
Для Processing Python, простейшую стрелялку можно сделать на основе:
Стреляем, нажимая на клавишу 'Пробел'

bullets = []
gunX = 280
gunY = 570
bullet_speed = 5
def setup():
size(600, 600)
def gun():
fill(255, 154, 165)
rect(gunX, gunY, 60, 20)
def keyPressed():
global bullets
if key == ' ':
bullets.append([gunY - 10])
def draw():
background(134)
gun()
for bullet in bullets:
bullet[0] = bullet[0] - bullet_speed
circle(gunX + 30, bullet[0], 20)