File: screen.cpp

package info (click to toggle)
epiphany 0.5.1-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,540 kB
  • ctags: 593
  • sloc: cpp: 4,223; makefile: 80; sh: 11
file content (152 lines) | stat: -rw-r--r-- 3,673 bytes parent folder | download | duplicates (2)
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
/***************************************************************************
                          screen.cpp  -  description
                             -------------------
    begin                : Mon Oct 22 2001
    copyright            : (C) 2001 by Giuseppe D'Aqu
    email                : kumber@tiscalinet.it
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
#include "dephine.h"
#include "screen.h"
#include "sprite.h"
#include "entity.h"


Screen::Screen(unsigned int resolution_x, unsigned int resolution_y, unsigned int level_size_x, unsigned int level_size_y, unsigned int cell_size)
{
	m_win_pos_x=0;
	m_win_pos_y=0;
	m_win_size_x=resolution_x;
	m_win_size_y=resolution_y;
	m_cell_size=cell_size;
	
	m_screen_size_x=level_size_x*m_cell_size;
	m_screen_size_y=level_size_y*m_cell_size;
	
	try
	{
	CL_Display::set_videomode ((int)resolution_x, (int)resolution_y,8, false);
	}
	catch(CL_Error ex)
	{
		std::cout<<"Error initializing video mode\n";
	}
}

Screen::Screen()
{
	m_screen_size_x=0;
	m_screen_size_y=0;
	m_cell_size=0;
}

unsigned int Screen::get_screen_size_x()
{
	return m_screen_size_x;
	
}

unsigned int Screen::get_screen_size_y()
{

	return m_screen_size_y;
	
}

void Screen::init(unsigned int resolution_x, unsigned int resolution_y, unsigned int level_size_x, unsigned int level_size_y, unsigned int cell_size)
{
	m_win_pos_x=0;
	m_win_pos_y=0;
	m_win_size_x=resolution_x;
	m_win_size_y=resolution_y-k_score_size_y;
	m_cell_size=cell_size;
	
	m_screen_size_x=level_size_x*m_cell_size;
	m_screen_size_y=level_size_y*m_cell_size;
	
	try
	{
	CL_Display::set_videomode ((int)resolution_x, (int)resolution_y,16, false);
	}
	catch(CL_Error ex)
	{
		std::cout<<"Error initializing video mode\n";
	}
}


void Screen::put(Sprite& sprite)
{
	int curr_pos_x=sprite.get_pos_x();
	int curr_pos_y=sprite.get_pos_y();
	if(	((curr_pos_x+48>m_win_pos_x)&&
			(curr_pos_x<(m_win_pos_x+m_win_size_x)))&&
			((curr_pos_y+48>m_win_pos_y)&&
			(curr_pos_y<(m_win_pos_y+m_win_size_y))))
	{
//	DEBOUT("drawing sprite at: "<<curr_pos_x<<", "<<curr_pos_y<<"\n");
	int frame=sprite.get_frame_number();
	sprite->put_screen((int)(curr_pos_x-m_win_pos_x), (int)(curr_pos_y-m_win_pos_y), (int)m_cell_size, (int)m_cell_size, frame);
	}
	
}

void Screen::set_cell_size(unsigned int cell_size)
{
	
	m_cell_size=cell_size;
	
}

void Screen::set_window_center(int x, int y)
{

	if(x>(m_win_size_x/2))
	{
		if((x+(m_win_size_x/2))<m_screen_size_x)
		{
			m_win_pos_x=(x-(m_win_size_x/2));
		}	
		else
		{
			m_win_pos_x=(m_screen_size_x-(m_win_size_x));
		}
	}
	else
	{
		m_win_pos_x=0;
	}
		
	if(y>(m_win_size_y/2))
	{
		if((y+(m_win_size_y/2))<m_screen_size_y)
		{
			m_win_pos_y=(y-(m_win_size_y/2));
		}	
		else
		{
			m_win_pos_y=(m_screen_size_y-(m_win_size_y));
		}
	}
	else
	{
		m_win_pos_y=0;
	}

//	if((x>(m_win_size_x/2))&&((x+(m_win_size_x/2))<m_screen_size_x))
//		m_win_pos_x=(x-(m_win_size_x/2));
		
//	if((y>(m_win_size_y/2))&&((y+(m_win_size_y/2))<m_screen_size_y))
//		m_win_pos_y=(y-(m_win_size_y/2));
}