ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
animate.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 ANIMATE
49
50@english
51
52The ''ANIMATE'' command allows you to activate a specific animation at the current
53position, or at one indicated in the command. If an animation is already active,
54it will be abruptly interrupted and the indicated one will be started
55
56@italian
57
58Il comando ''ANIMATE'' permette di attivare una specifica animazione nella posizione
59attuale, oppure in una indicata nel comando. Se è già attiva una animazione, la stessa
60sarà interrotta bruscamente e sarà fatta partire quella indicata.
61
62@syntax ANIMATE prefix WITH anim [AT x, y]
63
64@example flyingAirplane := LOAD ATLAS("airplane.png") FRAME SIZE (16, 16)
65@example ANIMATION BOUNCE anim WITH flyingAirplane USING airplane
66@example ANIMATE airplane WITH anim AT 20, 20
67@example DO: RUN PARALLEL: LOOP
68
69@target all
70</usermanual> */
71void animate_semivars( Environment * _environment, char * _prefix, char * _anim, char * _x, char * _y ) {
72
73#if defined(__gb__)
74 return;
75#endif
76
77 char prefixAnimation[MAX_TEMPORARY_STORAGE]; sprintf( prefixAnimation, "%sAnimation", _prefix );
78
79 if ( ! variable_exists( _environment, prefixAnimation ) ) {
81 }
82
83 Variable * prefixAnimationVar = variable_retrieve( _environment, prefixAnimation );
84
85 if ( prefixAnimationVar->type != VT_THREAD ) {
87 }
88
89 if ( _x ) {
90 Variable * x = variable_retrieve_or_define( _environment, _x, VT_POSITION, 0 );
91 char prefixX[MAX_TEMPORARY_STORAGE]; sprintf( prefixX, "%sX", _prefix );
92 Variable * prefixXVar = variable_retrieve( _environment, prefixX );
93 variable_move( _environment, x->name, prefixXVar->name );
94 }
95
96 if ( _y ) {
97 Variable * y = variable_retrieve_or_define( _environment, _y, VT_POSITION, 0 );
98 char prefixY[MAX_TEMPORARY_STORAGE]; sprintf( prefixY, "%sY", _prefix );
99 Variable * prefixYVar = variable_retrieve( _environment, prefixY );
100 variable_move( _environment, y->name, prefixYVar->name );
101 }
102
104
105 char skipKillLabel[MAX_TEMPORARY_STORAGE]; sprintf( skipKillLabel, "%sskip", label );
106 cpu_compare_and_branch_8bit_const( _environment, prefixAnimationVar->realName, 0xff, skipKillLabel, 1 );
107
108 // KILL playerAnimation
109 kill_procedure( _environment, prefixAnimationVar->name );
110
111 cpu_label( _environment, skipKillLabel );
112
113 // playerAnimation = SPAWN animPlayerPunch
114 variable_move( _environment, spawn_procedure( _environment, _anim, 0 )->name, prefixAnimationVar->name );
115
116 run_parallel( _environment );
117
118}
119
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
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.
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 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 MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_THREAD
Definition ugbc.h:492
@ VT_POSITION
Definition ugbc.h:468
#define CRITICAL_CANNOT_USE_ANIMATE_WITHOUT_ANIMATION(n)
Definition ugbc.h:3772
#define MAKE_LABEL
Definition ugbc.h:3351