ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
move.c
Go to the documentation of this file.
1/*****************************************************************************
2 * ugBASIC - an isomorphic BASIC language compiler for retrocomputers *
3 *****************************************************************************
4 * Copyright 2021-2026 Marco Spedaletti (asimov@mclink.it)
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *----------------------------------------------------------------------------
18 * Concesso in licenza secondo i termini della Licenza Apache, versione 2.0
19 * (la "Licenza"); è proibito usare questo file se non in conformità alla
20 * Licenza. Una copia della Licenza è disponibile all'indirizzo:
21 *
22 * http://www.apache.org/licenses/LICENSE-2.0
23 *
24 * Se non richiesto dalla legislazione vigente o concordato per iscritto,
25 * il software distribuito nei termini della Licenza è distribuito
26 * "COSÌ COM'È", SENZA GARANZIE O CONDIZIONI DI ALCUN TIPO, esplicite o
27 * implicite. Consultare la Licenza per il testo specifico che regola le
28 * autorizzazioni e le limitazioni previste dalla medesima.
29 ****************************************************************************/
30
31/****************************************************************************
32 * INCLUDE SECTION
33 ****************************************************************************/
34
35#include "../../ugbc.h"
36
37/****************************************************************************
38 * CODE SECTION
39 ****************************************************************************/
40
47/* <usermanual>
48@keyword MOVE
49
50@english
51
52The ''MOVE'' command allows you to activate a specific movement from the current
53position. If a movement is already active, it will be abruptly interrupted and
54the indicated one will be started.
55
56It is also possible to indicate an animation to be run in a "synchronized" way
57with respect to the movement, using the keyword ''SYNC''. In particular,
58the synchronization will occur by executing the ease in of the animation and,
59at the end of the same, by starting the movement and the loop of the animation
60(which must therefore have one). At the end of the movement, the animation
61will be eased out.
62
63@italian
64
65Il comando ''MOVE'' consente di attivare un movimento specifico dalla posizione
66corrente. Se un movimento è già attivo, verrà interrotto bruscamente e verrà
67avviato quello indicato.
68
69E' possibile indicare anche una animazione da far viaggiare in modo "sincronizzato"
70rispetto al movimento, usando la parola chiave ''SYNC''. In particolare, il
71sincronismo avverrà facendo eseguire l'ease in dell'animazione e, al termine
72della stessa, facendo partire lo spostamento e il loop dell'animazione (che deve
73quindi averne uno). Al termine del movimento, si avrà l'ease out dell'animazione.
74
75@syntax MOVE id WITH movement [SYNC animation]
76@syntax MOVE id TO x,y WITH movement [SYNC animation]
77
78@example MOVE player TO 10, 10 WITH moveTo SYNC animWalking
79
80</usermanual> */
81void move( Environment * _environment, char * _prefix, char * _movement, char * _x, char * _y, char * _animation ) {
82
83#if defined(__gb__)
84 return;
85#endif
86
87 char prefixMovement[MAX_TEMPORARY_STORAGE]; sprintf( prefixMovement, "%sMovement", _prefix );
88
89 if ( ! variable_exists( _environment, prefixMovement ) ) {
91 }
92
93 Variable * prefixMovementVar = variable_retrieve( _environment, prefixMovement );
94
95 if ( prefixMovementVar->type != VT_THREAD ) {
97 }
98
99 char prefixAnimation[MAX_TEMPORARY_STORAGE]; sprintf( prefixAnimation, "%sAnimation", _prefix );
100 if ( _animation ) {
101
102 if ( ! procedure_exists( _environment, _animation ) ) {
104 }
105
106 animate_semivars( _environment, _prefix, _animation, NULL, NULL );
107
108 char prefixSync[MAX_TEMPORARY_STORAGE]; sprintf( prefixSync, "%sSync", _prefix );
109 Variable * prefixSyncVar = variable_retrieve( _environment, prefixSync );
110 variable_store( _environment, prefixSyncVar->name, 0x01 );
111
112 }
113
114 // DIM [prefix]TX AS POSITION
115 char prefixTX[MAX_TEMPORARY_STORAGE]; sprintf( prefixTX, "%sTX", _prefix );
116 Variable * prefixTXVar;
117 if ( _x ) {
118 if ( ! variable_exists( _environment, prefixTX ) ) {
120 }
121 Variable * x = variable_retrieve_or_define( _environment, _x, VT_POSITION, 0 );
122 prefixTXVar = variable_retrieve( _environment, prefixTX );
123 variable_move( _environment, x->name, prefixTXVar->name );
124 }
125
126 // DIM [prefix]TY AS POSITION
127 char prefixTY[MAX_TEMPORARY_STORAGE]; sprintf( prefixTY, "%sTY", _prefix );
128 Variable * prefixTYVar;
129 if ( _y ) {
130 if ( ! variable_exists( _environment, prefixTY ) ) {
132 }
133 Variable * y = variable_retrieve_or_define( _environment, _y, VT_POSITION, 0 );
134 prefixTYVar = variable_retrieve( _environment, prefixTY );
135 variable_move( _environment, y->name, prefixTYVar->name );
136 }
137
139
140 char skipKillLabel[MAX_TEMPORARY_STORAGE]; sprintf( skipKillLabel, "%sskip", label );
141 cpu_compare_and_branch_8bit_const( _environment, prefixMovementVar->realName, 0xff, skipKillLabel, 1 );
142
143 // KILL playerAnimation
144 kill_procedure( _environment, prefixMovementVar->name );
145
146 cpu_label( _environment, skipKillLabel );
147
148 // playerAnimation = SPAWN animPlayerPunch
149 variable_move( _environment, spawn_procedure( _environment, _movement, 0 )->name, prefixMovementVar->name );
150
151 run_parallel( _environment );
152
153}
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
void cpu_compare_and_branch_8bit_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6309: emit code to compare two 8 bit values and jump if they are equal/different
Definition 6309.c:876
int procedure_exists(Environment *_environment, char *_name)
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
int variable_exists(Environment *_environment, char *_name)
Variable * variable_move(Environment *_environment, char *_source, char *_destination)
Store the value of a variable inside another variable by converting it.
Variable * variable_store(Environment *_environment, char *_destination, unsigned int _value)
Store a direct value to a variable.
void animate_semivars(Environment *_environment, char *_prefix, char *_anim, char *_x, char *_y)
Emit code for ANIMATE ....
Definition animate.c:71
char * name
Definition _optimizer.c:672
void kill_procedure(Environment *_environment, char *_handle)
Emit code for KILL ....
Definition kill.c:77
void move(Environment *_environment, char *_prefix, char *_movement, char *_x, char *_y, char *_animation)
Emit code for MOVE ....
Definition move.c:81
void run_parallel(Environment *_environment)
Emit code for RUN PARALLEL.
Variable * spawn_procedure(Environment *_environment, char *_name, int _halted)
Emit code for SPAWN ....
Definition spawn.c:68
char * name
Definition ugbc.h:979
VariableType type
Definition ugbc.h:988
char * realName
Definition ugbc.h:982
#define CRITICAL_CANNOT_USE_MOVE_SYNC_WITHOUT_ANIMATIOn(n, m)
Definition ugbc.h:3784
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
struct _Variable Variable
Structure of a single variable.
#define CRITICAL_CANNOT_USE_ABSOLUTE_MOVE_WITHOUT_ABSOLUTE_MOVEMENT(n)
Definition ugbc.h:3781
struct _Environment Environment
Structure of compilation environment.
@ VT_THREAD
Definition ugbc.h:492
@ VT_POSITION
Definition ugbc.h:468
#define CRITICAL_CANNOT_USE_MOVE_WITHOUT_MOVEMENT(n)
Definition ugbc.h:3780
#define MAKE_LABEL
Definition ugbc.h:3351