/*
* menu_scene.c
* c4
*
* Created by jrk on 8/2/11.
* Copyright 2011 Jaroslaw Szpilewski. All rights reserved.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "elite.h"
#include "menu_scene.h"
#include <unistd.h>
typedef struct menu_scene_state
{
le_entity_manager_t mgr;
le_garbage_system_t gs;
le_action_system_t as;
le_render_system_t rs;
le_particle_system_t ps;
le_entity_t *bubble;
le_entity_t *minyx;
le_entity_t *oh_hai;
le_entity_t *firetail;
fs_audio_id sound;
le_entity_t *time;
double time_counter;
} menu_scene_state;
static int scene_init(scene_t *scene)
{
menu_scene_state *state = scene->user_data;
state->sound = fs_audio_sound_load("click.mp3");
printf("menu scene init %p ...\n", scene);
em_init(&state->mgr);
action_system_init(&state->as, &state->mgr);
garbage_system_init(&state->gs, &state->mgr);
render_system_init(&state->rs, &state->mgr);
particle_system_init(&state->ps, &state->mgr);
//background
le_entity_t *ent = em_create_entity(&state->mgr);
le_component_header_t *comp = entity_add_component(ent, COMP_FAMILY_POSITION);
comp_position_init(comp, vec2d_make(g_sysconfig.screen_w/2, g_sysconfig.screen_h/2), -4.0);
comp = entity_add_component(ent, COMP_FAMILY_RENDERABLE);
comp_quad_init(comp, "menu_back.png");
//text label
state->oh_hai = em_create_entity(&state->mgr);
comp = entity_add_component(state->oh_hai, COMP_FAMILY_POSITION);
comp_position_init(comp, vec2d_make(g_sysconfig.screen_w/2, g_sysconfig.screen_h/2), -2.0);
comp = entity_add_component(state->oh_hai, COMP_FAMILY_RENDERABLE);
comp_text_init(comp, "impact20.fnt", "oh hai!");
comp_text_set_text(comp, "minyx games");
//particle left
ent = em_create_entity(&state->mgr);
comp = entity_add_component(ent, COMP_FAMILY_POSITION);
comp_position_init(comp, vec2d_make(0,0), -1.0);
comp = entity_add_component(ent, COMP_FAMILY_RENDERABLE);
comp_pe_init(comp, "stars.pex");
//particle right
ent = em_create_entity(&state->mgr);
comp = entity_add_component(ent, COMP_FAMILY_POSITION);
comp_position_init(comp, vec2d_make(g_sysconfig.screen_w,0), -1.0);
comp = entity_add_component(ent, COMP_FAMILY_RENDERABLE);
comp_pe_init(comp, "stars.pex");
//bubble
for (int i = 0; i < 1; i++)
{
state->bubble = em_create_entity(&state->mgr);
comp = entity_add_component(state->bubble, COMP_FAMILY_POSITION);
comp_position_init(comp, vec2d_make(rand()%320, rand()%480), -3.0);
comp = entity_add_component(state->bubble, COMP_FAMILY_RENDERABLE);
cd_atlas_quad_t *aq = comp_atlas_quad_init(comp, "bubbles.png", rect_make(0.0, 0.0, 41.0, 41.0));
aq->atlas_quad->ri.scale = vec2d_make(2.0, 2.0);
aq->atlas_quad->ri.alpha = 0.3;
}
//das minyx
state->minyx = em_create_entity(&state->mgr);
comp = entity_add_component(state->minyx, COMP_FAMILY_POSITION);
comp_position_init(comp, vec2d_make(g_sysconfig.screen_w/2, g_sysconfig.screen_h/2), 1.0);
comp = entity_add_component(state->minyx, COMP_FAMILY_RENDERABLE);
comp_quad_init(comp, "minyx_bw.png");
//firetail
state->firetail = em_create_entity(&state->mgr);
comp = entity_add_component(state->firetail, COMP_FAMILY_RENDERABLE);
comp_pe_init(comp, "cool.pex");
comp = entity_add_component(state->firetail, COMP_FAMILY_POSITION);
comp_position_init(comp, vec2d_make(g_sysconfig.screen_w/2, g_sysconfig.screen_w/2), 1.0);
//rainshit
ent = em_create_entity(&state->mgr);
comp = entity_add_component(ent, COMP_FAMILY_RENDERABLE);
comp_pe_init(comp, "tss.pex");
comp = entity_add_component(ent, COMP_FAMILY_POSITION);
comp_position_init(comp, vec2d_make(g_sysconfig.screen_w/2, g_sysconfig.screen_h), 1.0);
//time label
state->time = em_create_entity(&state->mgr);
comp = entity_add_component(state->time, COMP_FAMILY_POSITION);
comp_position_init(comp, vec2d_make(g_sysconfig.screen_w, g_sysconfig.screen_h), -2.0);
comp = entity_add_component(state->time, COMP_FAMILY_RENDERABLE);
cd_text_t *t = comp_text_init(comp, "impact20.fnt", "00:00:00");
t->font->ri.anchor_point = vec2d_make(1.0, 1.0);
state->time_counter = 0.0;
action_header_t *acthdr = action_system_add_action_to_entity(&state->as, state->time);
action_move_to_init(acthdr, vec2d_make(g_sysconfig.screen_w/2 , g_sysconfig.screen_h/2));
acthdr->duration = 10.0;
// cd_actn_move_to_t *acn = action_move_to_init(comp, vec2d_make(g_sysconfig.screen_w/2, g_sysconfig.screen_h/2));
// acn->header.duration = 10.0;
return 0;
}
static void scene_pre_frame(scene_t *scene)
{
}
static void scene_update(scene_t *scene, double dt)
{
//printf("%f\n", dt);
menu_scene_state *state = scene->user_data;
garbage_system_collect(&state->gs); //collect previous frame's garbage
action_system_update(&state->as, dt);
particle_system_update(&state->ps, dt);
cd_position_t *pos = entity_get_component(state->minyx, COMP_FAMILY_POSITION);
pos->rot += dt * 360.0;
pos = entity_get_component(state->firetail, COMP_FAMILY_POSITION);
pos->pos.x = g_sysconfig.screen_w/2 + 100.0 * sin(timer_get_double_time()*5.0);
pos->pos.y = g_sysconfig.screen_h/2 + 100.0 * cos(timer_get_double_time()*5.0);
pos = entity_get_component(state->oh_hai, COMP_FAMILY_POSITION);
pos->rot -= dt * 360.0;
state->time_counter+=dt;
char c[255];
sprintf(c,"%.4f", state->time_counter);
comp_text_set_text(entity_get_component_header(state->time, COMP_FAMILY_RENDERABLE), c);
if (state->time_counter > 1.0)
{
state->time_counter = 0.0;
fs_audio_sound_play(state->sound);
}
if (fs_input_touch_up_received())
{
if (fs_input_touch_inside_rect(&(rect_t)
{
.x = 0,
.y = 0,
.w = 256,
.h = 256
}
))
{
printf("playing sound %i ...\n", state->sound);
//fs_audio_sound_play(state->sound);
game_pop_scene();
//entity_add_component(state->bubble, COMP_FAMILY_GARBAGE);
}
}
}
static void scene_render(scene_t *scene)
{
menu_scene_state *state = scene->user_data;
render_system_render(&state->rs);
}
//clean up post frame
static void scene_post_frame(scene_t *scene)
{
menu_scene_state *state = scene->user_data;
em_update(&state->mgr); //set mgr->is_dirty to false
}
static int scene_free(scene_t *scene)
{
menu_scene_state *state = scene->user_data;
printf("menuscene free %p ...\n", scene);
action_system_shutdown(&state->as);
garbage_system_shutdown(&state->gs);
particle_system_shutdown(&state->ps);
render_system_shutdown(&state->rs);
em_shutdown(&state->mgr);
free(scene->user_data);
return 0;
}
scene_t menu_scene_create(void)
{
scene_t ret;
ret.init_func = scene_init;
ret.pre_frame_func = scene_pre_frame;
ret.update_func = scene_update;
ret.render_func = scene_render;
ret.post_frame_func = scene_post_frame;
ret.free_func = scene_free;
ret.user_data = calloc(1, sizeof(menu_scene_state));
return ret;
}
没有合适的资源?快使用搜索试试~ 我知道了~
iOS游戏应用源代码——jsz-c4-f0d043c.zip
共124个文件
h:53个
c:27个
m:16个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 137 浏览量
2023-07-05
23:17:16
上传
评论
收藏 4.62MB ZIP 举报
温馨提示
iOS游戏应用源代码——jsz-c4-f0d043c.zip
资源推荐
资源详情
资源评论
收起资源包目录
iOS游戏应用源代码——jsz-c4-f0d043c.zip (124个子文件)
menu_scene.c 7KB
sys_config.c 6KB
game.c 6KB
action_system.c 5KB
bm_font.c 5KB
texture.c 4KB
comp_renderable.c 4KB
entity_manager.c 4KB
renderer.c 3KB
entity.c 3KB
render_system.c 3KB
font.c 3KB
input.c 2KB
atlas_quad.c 2KB
hash.c 2KB
quad.c 2KB
particle_system.c 2KB
timer.c 2KB
startup_scene.c 1KB
garbage_system.c 1013B
le_pause_scene.c 942B
comp_position.c 815B
vec2d.c 650B
elite.c 580B
renderinfo.c 535B
component.c 153B
scene.c 144B
impact20.fnt 14KB
Shader.fsh 205B
.gitignore 87B
stb_image_aug.h 17KB
SOIL.h 16KB
stbi_DDS_aug_c.h 15KB
CocosDenshion.h 13KB
CDAudioManager.h 9KB
ParticleEmitter.h 5KB
TBXML.h 5KB
OBJCTexture2D.h 4KB
SimpleAudioEngine.h 4KB
CDOpenALSupport.h 3KB
Global.h 3KB
image_DXT.h 3KB
TBXMLParticleAdditions.h 3KB
CDConfig.h 3KB
NSDataAdditions.h 3KB
image_helper.h 2KB
Structures.h 1KB
particle_emitter.h 1KB
action_system.h 1KB
ogl.h 1KB
entity_manager.h 1KB
sys_config.h 1KB
bm_font.h 1022B
audio.h 998B
EAGLView.h 977B
comp_renderable.h 925B
texture.h 868B
input.h 863B
entity.h 800B
elite.h 799B
stbi_DDS_aug.h 797B
renderinfo.h 788B
garbage_system.h 766B
c4ViewController.h 673B
component.h 657B
scene.h 632B
render_system.h 627B
game.h 620B
atlas_quad.h 585B
vec2d.h 566B
quad.h 558B
font.h 551B
particle_system.h 521B
timer.h 498B
c4AppDelegate.h 441B
renderer.h 399B
comp_position.h 378B
startup_scene.h 276B
hash.h 265B
menu_scene.h 238B
le_types.h 228B
le_pause_scene.h 210B
util.h 190B
CocosDenshion.m 42KB
CDAudioManager.m 26KB
ParticleEmitter.m 24KB
OBJCTexture2D.m 20KB
TBXML.m 18KB
CDOpenALSupport.m 10KB
NSDataAdditions.m 9KB
c4ViewController.m 8KB
EAGLView.m 5KB
audio.m 5KB
SimpleAudioEngine.m 5KB
TBXMLParticleAdditions.m 3KB
particle_emitter.m 2KB
util.m 1KB
c4AppDelegate.m 1KB
main.m 348B
menu.m4a 783KB
共 124 条
- 1
- 2
资源评论
快乐无限出发
- 粉丝: 1137
- 资源: 7276
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功