Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
UFCFVK-15-2 - Internet of things - Challenge 1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
ja3-saxby
UFCFVK-15-2 - Internet of things - Challenge 1
Commits
c6e912c9
Commit
c6e912c9
authored
5 years ago
by
ja3-saxby
Browse files
Options
Downloads
Patches
Plain Diff
Fixed lag and false game overs!
The game logic loop/collision-detection was at fault
parent
bdd9dfe9
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
source/main.cpp
+51
-40
51 additions, 40 deletions
source/main.cpp
with
51 additions
and
40 deletions
source/main.cpp
+
51
−
40
View file @
c6e912c9
...
...
@@ -276,18 +276,19 @@ bool can_shape_move(
if
(
shape_image
.
getPixelValue
(
x
,
y
)
!=
0
)
{
// calculate the translated position, including origin
Point
destination
=
origin
+
Point
(
x
,
y
);
// if Y is negative, skip this pixel as a special case
if
(
destination
.
y
<
0
)
{
continue
;
// we allow Blocks to be out of the top frame
}
// if out-of-bounds, of course it can't move
if
(
destination
.
x
<
0
or
destination
.
x
>
4
or
destination
.
y
>
4
// NOTE: there is no check for negative Y since we allow it
)
{
return
false
;
}
// if Y is negative, we don't need to check this row
if
(
destination
.
y
<
0
)
{
break
;
// no point checking this row, out of screen
}
// check if the translated position of this pixel is not free
if
(
stacked
.
getPixelValue
(
destination
.
x
,
destination
.
y
)
!=
0
)
{
return
false
;
...
...
@@ -388,8 +389,13 @@ void start_new_game() {
Point
origin
(
1
,
-
3
);
// this is the down unit-vector
Vector
down
(
0
,
1
);
// draw the scene
UBIT
.
display
.
print
(
stacked_shapes
);
// draw Block with transparency enabled on clear image pixels
UBIT
.
display
.
print
(
block
.
image
(),
origin
.
x
,
origin
.
y
,
1
);
// while Block can go down
while
(
can_shape_move
(
block
,
origin
,
stacked_shapes
,
down
))
{
if
(
can_shape_move
(
block
,
origin
,
stacked_shapes
,
down
))
{
while
(
true
)
{
// allow player to shift the Block left or right
/*
* read accelerometer manually for more controlled movement
...
...
@@ -416,8 +422,12 @@ void start_new_game() {
// check if enough time has elapsed to move the block
unsigned
long
stopwatch_now
=
UBIT
.
systemTime
();
if
((
stopwatch_now
-
stopwatch
)
>=
move_speed
)
{
// shift the shape down
// shift the shape down if it can
if
(
can_shape_move
(
block
,
origin
,
stacked_shapes
,
down
))
{
origin
=
origin
+
down
;
}
else
{
break
;
}
// update the "stopwatch"
stopwatch
=
stopwatch_now
;
}
...
...
@@ -429,6 +439,7 @@ void start_new_game() {
// delay
UBIT
.
sleep
(
10
);
// 10ms sleep = 100ticks/second
}
}
// if Block Y origin is less than 0 upon not being able to go down
if
(
origin
.
y
<
0
)
{
// it's Game Over, because the Block could never fully enter screen
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment