-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnowball.cpp
More file actions
63 lines (51 loc) · 1.56 KB
/
snowball.cpp
File metadata and controls
63 lines (51 loc) · 1.56 KB
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
#include "snowball.h"
#include <stdlib.h>
#include <iostream>
VoxImg Snowball::snowballimage("data/snowball2.vox",0,VOX_FILE);
Vox_Scene * Snowball::ground=NULL;
std::list<Snowball*> Snowball::snowballs;
Snowball::Snowball(Pt3d pos, Pt3d velocity)
: to_destroy(false),m_velocity(velocity)
{
if (Snowball::ground==NULL) std::cout<<"Error! Snowball::ground not initialized!"<<std::endl;
set_img(&snowballimage);
set_pos(pos);
Snowball::snowballs.push_back(this);
}
Snowball::~Snowball()
{
}
void Snowball::move()
{
m_pos.x+=m_velocity.x;
m_pos.y+=m_velocity.y;
m_pos.z+=m_velocity.z;
m_velocity.z+=0.1;
}
void Snowball::update_snowballs()
{
for(std::list<Snowball*>::iterator it = Snowball::snowballs.begin(); it != Snowball::snowballs.end(); ++it)
{
(*it)->move();
if (((*it)->get_pos()->z)>=ground->zsiz) (*it)->to_destroy=true;
if ((((*it)->get_pos()->x)<0)||(((*it)->get_pos()->x)>=ground->xsiz)) (*it)->to_destroy=true;
if ((((*it)->get_pos()->y)<0)||(((*it)->get_pos()->y)>=ground->ysiz)) (*it)->to_destroy=true;
if ((ground->collide(**it)))//touch_center is too dangerous (snowballs are fast)
{
(*it)->to_destroy=true;
ground->add(**it,false,true);
}
if ((*it)->to_destroy)
{
delete *it;
it=Snowball::snowballs.erase(it);
}
}
}
void Snowball::blit_all(Vox_Scene *scene)
{
for(std::list<Snowball*>::iterator it = snowballs.begin(); it != snowballs.end(); ++it)
{
scene->blit(**it);
}
}