forked from LGortzak/Opdracht-1---Sneeuwlandschap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SneeuwLandschap.cpp
executable file
·89 lines (72 loc) · 2.16 KB
/
SneeuwLandschap.cpp
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
/*
* SneeuwLandschap.cpp
*
* Created on: 8 feb. 2012
* Author: Niek Zuure
*/
#include "SneeuwLandschap.hpp"
#include <mastdlib.h>
//globale variabelen voor breedte en hoogte van het scherm
int screenWidth;
int screenHeight;
//constructor
SneeuwLandschap::SneeuwLandschap()
{
//sla schermgrootte op in globale variabelen
MAExtent screenSize = maGetScrSize();
screenWidth = EXTENT_X( screenSize );
screenHeight = EXTENT_Y( screenSize );
//stel sneeuwhoogte in (vanaf bodem)
this->sneeuwHoogte = 30;
//maak een nieuwe sneeuwman
this->sneeuwMan = new SneeuwMan( screenWidth / 2, screenHeight - this->sneeuwHoogte );
}
//wordt aangeroepen als er input is (druk op de toets, touch van scherm)
void SneeuwLandschap::run( MAEvent event )
{
//als er een key is ingetoetst
if( event.type == EVENT_TYPE_KEY_PRESSED )
{
//pak de key code
int key = maGetKeys();
//kijk voor linkertoets
if( key == MAKB_LEFT )
this->sneeuwMan->move( -6 ); //beweeg sneeuwman -6 pixels
//kijk voor rechtertoets
if( key == MAKB_RIGHT )
this->sneeuwMan->move( 6 ); //beweeg sneeuwman 6 pixels
}
//TODO: voeg een sneeuwvlok toe
for(int i= 0; i < 3; i++)
{
SneeuwVlok* sneeuwVlok = new SneeuwVlok((rand()%screenWidth),0);
this->sneeuwVlokArray.add(sneeuwVlok);
}
//TODO: laat alle sneeuwvlokken vallen
for(int i = 0; i <this->sneeuwVlokArray.size();i++)
{
sneeuwVlokArray[i]->fall(screenHeight - sneeuwHoogte);
}
}
//wordt elke "tick" aangeroepen om het winterlandschap, sneeuwman en sneeuwvlokken te tekenen
void SneeuwLandschap::draw()
{
//kleur de lucht blauw
maSetColor( 0x0055ff );
maFillRect( 0, 0, screenWidth, screenHeight );
//maak sneeuw op de grond, a.d.h.v. sneeuwHoogte
maSetColor( 0xffffff );
maFillRect( 0, screenHeight - this->sneeuwHoogte, screenWidth, this->sneeuwHoogte );
//TODO: teken de sneeuwman
sneeuwMan->draw();
//TODO: teken alle sneeuwvlokken
for(int i = 0; i <this->sneeuwVlokArray.size();i++)
{
this->sneeuwVlokArray[i]->draw();
if(this->sneeuwVlokArray[i]->isDead())
{
delete sneeuwVlokArray[i];
sneeuwVlokArray.remove(i);
}
}
}