Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdint.h>
- #include <iostream>
- #include <whycpp/application_listener.h>
- #include <whycpp/whycpp.h>
- #include <whycpp/drawing.h>
- #include <whycpp/time.h>
- #include <cmath>
- #include <vector>
- #include <whycpp/color.h>
- #include <whycpp/buttons.h>
- #include <whycpp/input.h>
- #include <whycpp/palette.h>
- #include <whycpp/lifecycle.h>
- #include "../cmake-build-debug/whycpp-src/include/whycpp/buttons.h"
- class Enemy {
- public:
- double Ex = 50;
- int Ey = 25;
- int Esp = 0; //enemy speed
- int height = 15;
- int width = 15;
- int check = 1;
- Enemy(double Ex_, int Ey_, int Esp_) : Ex(Ex_), Ey(Ey_), Esp(Esp_) {}
- void Update(Context &ctx) {
- DrawRectFill(ctx, Ex, static_cast<int>(Ey), height, width, PALETTE[3]);
- DrawRectFill(ctx, Ex+25, static_cast<int>(Ey), height, width, PALETTE[3]);
- DrawRectFill(ctx, Ex+50, static_cast<int>(Ey), height, width, PALETTE[3]);
- DrawRectFill(ctx, Ex+75, static_cast<int>(Ey), height, width, PALETTE[3]);
- DrawRectFill(ctx, Ex+100, static_cast<int>(Ey), height, width, PALETTE[3]);
- DrawRectFill(ctx, Ex+125, static_cast<int>(Ey), height, width, PALETTE[3]);
- DrawRectFill(ctx, Ex-25, static_cast<int>(Ey), height, width, PALETTE[3]);
- DrawRectFill(ctx, Ex+150, static_cast<int>(Ey), height, width, PALETTE[3]);
- // if (IsPressed(ctx, Button::KEY_SPACE)){
- // check+=1;
- // }
- // if (Ex <= 236) {
- // if ((check % 2 == 0) && (check <= 100)) {
- // Ex += 1;
- // check+=1;
- // }
- // }
- // else if(Ex>= 10){
- // if (check % 2 == 0) {
- // Ex -= 1;
- // }
- // }
- }
- };
- class Player {
- public:
- double x = 100;
- int y = 125;
- int sp = 100;
- int height = 15;
- int width = 15;
- Player(double x, int y, int sp) : x(x), y(y), sp(sp) {}
- void Update(Context &ctx) {
- DrawRectFill(ctx, static_cast<int>(x), y, height, width, PALETTE[2]);
- if (IsPressed(ctx, Button::KEY_LEFT)) {
- if (x >= 10) {
- x -= sp * GetDelta(ctx);
- }
- }
- if (IsPressed(ctx, Button::KEY_RIGHT)) {
- if (x <= 236)
- x += sp * GetDelta(ctx);
- }
- if (IsPressed(ctx, Button::KEY_ESCAPE)) {
- ExitApp(ctx);
- }
- }
- };
- class Game : public ApplicationListener {
- public:
- Player *player = nullptr;
- Enemy *enemy = nullptr;
- void OnCreate(Context &context) override {
- enemy = new Enemy(50, 25, 10);
- player = new Player(115, 125, 100);
- }
- void OnRender(Context &ctx) override {
- DrawClearScreen(ctx, PALETTE[1]);
- player->Update(ctx);
- enemy->Update(ctx);
- }
- };
- int main(int argc, char *argv[]) {
- RunApp<Game>();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement