forked from DusteDdk/Wizznic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcursor.c
106 lines (91 loc) · 2.67 KB
/
cursor.c
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
/************************************************************************
* This file is part of Wizznic. *
* Copyright 2009-2011 Jimmy Christensen <[email protected]> *
* Wizznic 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 3 of the License, or *
* (at your option) any later version. *
* *
* Wizznic is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with Foobar. If not, see <http://www.gnu.org/licenses/>. *
************************************************************************/
#include "cursor.h"
#include "settings.h"
void setCursor(cursorType* c, int x, int y)
{
c->dx = x;
c->dy = y;
c->x = x;
c->y = y;
c->moving=0;
c->lock=0;
c->px = c->dx*brickSize+boardOffsetX-4;
c->py = c->dy*brickSize+boardOffsetY-4;
}
void updateCursor(cursorType* c)
{
//printf("Cur: (%i,%i) Dst: (%i,%i) Lock: %i\n",c->x,c->y,c->dx,c->dy, c->lock);
int destX = c->dx*brickSize+boardOffsetX-4;
int destY = c->dy*brickSize+boardOffsetY-4;
if(c->px != destX || c->py != destY)
c->moving=1;
else
c->moving=0;
//If Cursor is locked to a brick, let the board-code set cursor position
if(c->lock) return;
if(c->px > destX)
{
c->px -= CURSORMOVESPEED;
if(c->px < destX)
c->px=destX;
} else if(c->px < destX)
{
c->px += CURSORMOVESPEED;
if(c->px > destX)
c->px=destX;
} else {
c->x=c->dx;
}
if(c->py > destY)
{
c->py -= CURSORMOVESPEED;
if(c->py < destY)
c->py=destY;
} else if(c->py < destY)
{
c->py += CURSORMOVESPEED;
if(c->py > destY)
c->py=destY;
} else {
c->y=c->dy;
}
}
int moveCursor(cursorType* c, int dirX, int dirY, int limit)
{
int dx = c->dx + dirX;
int dy = c->dy + dirY;
if(dx < 0 || dx+1 > FIELDSIZE || dy < 0 || dy+1 > FIELDSIZE) return(0);
if(c->x == c->dx || !limit)
{
c->dx += dirX;
}
if(c->y == c->dy || !limit)
{
c->dy += dirY;
}
return(1);
}
void initCursor(cursorType* c)
{
c->x = 5;
c->y = 5;
c->dx=c->x;
c->dy=c->y;
c->px=160;
c->py=120;
}